1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:47:35 +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

@ -513,7 +513,7 @@ Completion SuperCall::execute(Interpreter& interpreter) const
auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function())); auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function()));
// 7. Let thisER be GetThisEnvironment(). // 7. Let thisER be GetThisEnvironment().
auto& this_er = verify_cast<FunctionEnvironment>(get_this_environment(vm)); auto& this_er = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
// 8. Perform ? thisER.BindThisValue(result). // 8. Perform ? thisER.BindThisValue(result).
TRY(this_er.bind_this_value(vm, result)); TRY(this_er.bind_this_value(vm, result));
@ -1430,10 +1430,10 @@ ThrowCompletionOr<Reference> MemberExpression::to_reference(Interpreter& interpr
// https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
if (is<SuperExpression>(object())) { if (is<SuperExpression>(object())) {
// 1. Let env be GetThisEnvironment(). // 1. Let env be GetThisEnvironment().
auto& environment = get_this_environment(vm); auto environment = get_this_environment(vm);
// 2. Let actualThis be ? env.GetThisBinding(). // 2. Let actualThis be ? env.GetThisBinding().
auto actual_this = TRY(environment.get_this_binding(vm)); auto actual_this = TRY(environment->get_this_binding(vm));
PropertyKey property_key; PropertyKey property_key;

View file

@ -682,7 +682,7 @@ ThrowCompletionOr<void> SuperCall::execute_impl(Bytecode::Interpreter& interpret
auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function())); auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function()));
// 7. Let thisER be GetThisEnvironment(). // 7. Let thisER be GetThisEnvironment().
auto& this_environment = verify_cast<FunctionEnvironment>(get_this_environment(vm)); auto& this_environment = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
// 8. Perform ? thisER.BindThisValue(result). // 8. Perform ? thisER.BindThisValue(result).
TRY(this_environment.bind_this_value(vm, result)); TRY(this_environment.bind_this_value(vm, result));

View file

@ -443,7 +443,7 @@ NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironm
} }
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment // 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. // 1. Let env be the running execution context's LexicalEnvironment.
// 2. Repeat, // 2. Repeat,
@ -483,12 +483,12 @@ bool can_be_held_weakly(Value value)
Object* get_super_constructor(VM& vm) Object* get_super_constructor(VM& vm)
{ {
// 1. Let envRec be GetThisEnvironment(). // 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. // 2. Assert: envRec is a function Environment Record.
// 3. Let activeFunction be envRec.[[FunctionObject]]. // 3. Let activeFunction be envRec.[[FunctionObject]].
// 4. Assert: activeFunction is an ECMAScript function object. // 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]](). // 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
auto* super_constructor = MUST(active_function.internal_get_prototype_of()); 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) ThrowCompletionOr<Reference> make_super_property_reference(VM& vm, Value actual_this, PropertyKey const& property_key, bool strict)
{ {
// 1. Let env be GetThisEnvironment(). // 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. // 2. Assert: env.HasSuperBinding() is true.
VERIFY(env.has_super_binding()); 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 // 10. If direct is true, then
if (direct == EvalMode::Direct) { if (direct == EvalMode::Direct) {
// a. Let thisEnvRec be GetThisEnvironment(). // 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 // b. If thisEnvRec is a function Environment Record, then
if (is<FunctionEnvironment>(this_environment_record)) { if (is<FunctionEnvironment>(*this_environment_record)) {
auto& this_function_environment_record = static_cast<FunctionEnvironment&>(this_environment_record); auto& this_function_environment_record = static_cast<FunctionEnvironment&>(*this_environment_record);
// i. Let F be thisEnvRec.[[FunctionObject]]. // i. Let F be thisEnvRec.[[FunctionObject]].
auto& function = this_function_environment_record.function_object(); 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<ObjectEnvironment> new_object_environment(Object&, bool is_with_environment, Environment*);
NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target); NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target);
NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer); 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); bool can_be_held_weakly(Value);
Object* get_super_constructor(VM&); Object* get_super_constructor(VM&);
ThrowCompletionOr<Reference> make_super_property_reference(VM&, Value actual_this, PropertyKey const&, bool strict); 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; auto& vm = *this;
// 1. Let envRec be GetThisEnvironment(). // 1. Let envRec be GetThisEnvironment().
auto& environment = get_this_environment(vm); auto environment = get_this_environment(vm);
// 2. Return ? envRec.GetThisBinding(). // 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 // 9.4.5 GetNewTarget ( ), https://tc39.es/ecma262/#sec-getnewtarget
Value VM::get_new_target() Value VM::get_new_target()
{ {
// 1. Let envRec be GetThisEnvironment(). // 1. Let envRec be GetThisEnvironment().
auto& env = get_this_environment(*this); auto env = get_this_environment(*this);
// 2. Assert: envRec has a [[NewTarget]] field. // 2. Assert: envRec has a [[NewTarget]] field.
// 3. Return envRec.[[NewTarget]]. // 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 // 9.4.5 GetGlobalObject ( ), https://tc39.es/ecma262/#sec-getglobalobject