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

LibJS: Convert get_this_environment() to NonnullGCPtr

This commit is contained in:
Linus Groh 2022-12-15 20:07:13 +00:00 committed by Andreas Kling
parent c132064ee9
commit e785c66f91
5 changed files with 16 additions and 16 deletions

View file

@ -443,7 +443,7 @@ NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironm
}
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment
Environment& get_this_environment(VM& vm)
NonnullGCPtr<Environment> get_this_environment(VM& vm)
{
// 1. Let env be the running execution context's LexicalEnvironment.
// 2. Repeat,
@ -483,12 +483,12 @@ bool can_be_held_weakly(Value value)
Object* get_super_constructor(VM& vm)
{
// 1. Let envRec be GetThisEnvironment().
auto& env = get_this_environment(vm);
auto env = get_this_environment(vm);
// 2. Assert: envRec is a function Environment Record.
// 3. Let activeFunction be envRec.[[FunctionObject]].
// 4. Assert: activeFunction is an ECMAScript function object.
auto& active_function = verify_cast<FunctionEnvironment>(env).function_object();
auto& active_function = verify_cast<FunctionEnvironment>(*env).function_object();
// 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
auto* super_constructor = MUST(active_function.internal_get_prototype_of());
@ -501,7 +501,7 @@ Object* get_super_constructor(VM& vm)
ThrowCompletionOr<Reference> make_super_property_reference(VM& vm, Value actual_this, PropertyKey const& property_key, bool strict)
{
// 1. Let env be GetThisEnvironment().
auto& env = verify_cast<FunctionEnvironment>(get_this_environment(vm));
auto& env = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
// 2. Assert: env.HasSuperBinding() is true.
VERIFY(env.has_super_binding());
@ -548,11 +548,11 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
// 10. If direct is true, then
if (direct == EvalMode::Direct) {
// a. Let thisEnvRec be GetThisEnvironment().
auto& this_environment_record = get_this_environment(vm);
auto this_environment_record = get_this_environment(vm);
// b. If thisEnvRec is a function Environment Record, then
if (is<FunctionEnvironment>(this_environment_record)) {
auto& this_function_environment_record = static_cast<FunctionEnvironment&>(this_environment_record);
if (is<FunctionEnvironment>(*this_environment_record)) {
auto& this_function_environment_record = static_cast<FunctionEnvironment&>(*this_environment_record);
// i. Let F be thisEnvRec.[[FunctionObject]].
auto& function = this_function_environment_record.function_object();

View file

@ -23,7 +23,7 @@ NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment&);
NonnullGCPtr<ObjectEnvironment> new_object_environment(Object&, bool is_with_environment, Environment*);
NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target);
NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer);
Environment& get_this_environment(VM&);
NonnullGCPtr<Environment> get_this_environment(VM&);
bool can_be_held_weakly(Value);
Object* get_super_constructor(VM&);
ThrowCompletionOr<Reference> make_super_property_reference(VM&, Value actual_this, PropertyKey const&, bool strict);

View file

@ -603,21 +603,21 @@ ThrowCompletionOr<Value> VM::resolve_this_binding()
auto& vm = *this;
// 1. Let envRec be GetThisEnvironment().
auto& environment = get_this_environment(vm);
auto environment = get_this_environment(vm);
// 2. Return ? envRec.GetThisBinding().
return TRY(environment.get_this_binding(vm));
return TRY(environment->get_this_binding(vm));
}
// 9.4.5 GetNewTarget ( ), https://tc39.es/ecma262/#sec-getnewtarget
Value VM::get_new_target()
{
// 1. Let envRec be GetThisEnvironment().
auto& env = get_this_environment(*this);
auto env = get_this_environment(*this);
// 2. Assert: envRec has a [[NewTarget]] field.
// 3. Return envRec.[[NewTarget]].
return verify_cast<FunctionEnvironment>(env).new_target();
return verify_cast<FunctionEnvironment>(*env).new_target();
}
// 9.4.5 GetGlobalObject ( ), https://tc39.es/ecma262/#sec-getglobalobject