1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

LibJS: Convert get_super_base() to ThrowCompletionOr

Also add spec step comments to it while we're here.
This commit is contained in:
Linus Groh 2021-10-09 16:41:18 +01:00
parent a456eae4b1
commit 4f03138971
3 changed files with 14 additions and 5 deletions

View file

@ -5,8 +5,8 @@
*/
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS {
@ -29,13 +29,21 @@ void FunctionEnvironment::visit_edges(Visitor& visitor)
}
// 9.1.1.3.5 GetSuperBase ( ), https://tc39.es/ecma262/#sec-getsuperbase
Value FunctionEnvironment::get_super_base() const
ThrowCompletionOr<Value> FunctionEnvironment::get_super_base() const
{
VERIFY(m_function_object);
// 1. Let home be envRec.[[FunctionObject]].[[HomeObject]].
auto home_object = m_function_object->home_object();
// 2. If home has the value undefined, return undefined.
if (!home_object)
return js_undefined();
return TRY_OR_DISCARD(home_object->internal_get_prototype_of());
// 3. Assert: Type(home) is Object.
// 4. Return ? home.[[GetPrototypeOf]]().
return { TRY(home_object->internal_get_prototype_of()) };
}
// 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding