From e785c66f91f6cc04235703142c1b07a6cf458bfb Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 15 Dec 2022 20:07:13 +0000 Subject: [PATCH] LibJS: Convert get_this_environment() to NonnullGCPtr --- Userland/Libraries/LibJS/AST.cpp | 6 +++--- Userland/Libraries/LibJS/Bytecode/Op.cpp | 2 +- .../Libraries/LibJS/Runtime/AbstractOperations.cpp | 14 +++++++------- .../Libraries/LibJS/Runtime/AbstractOperations.h | 2 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 17ed5936e5a..22d554b5c2d 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -513,7 +513,7 @@ Completion SuperCall::execute(Interpreter& interpreter) const auto result = TRY(construct(vm, static_cast(*func), move(arg_list), &new_target.as_function())); // 7. Let thisER be GetThisEnvironment(). - auto& this_er = verify_cast(get_this_environment(vm)); + auto& this_er = verify_cast(*get_this_environment(vm)); // 8. Perform ? thisER.BindThisValue(result). TRY(this_er.bind_this_value(vm, result)); @@ -1430,10 +1430,10 @@ ThrowCompletionOr MemberExpression::to_reference(Interpreter& interpr // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation if (is(object())) { // 1. Let env be GetThisEnvironment(). - auto& environment = get_this_environment(vm); + auto environment = get_this_environment(vm); // 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; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 3ba225cad40..8799b39c31a 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -682,7 +682,7 @@ ThrowCompletionOr SuperCall::execute_impl(Bytecode::Interpreter& interpret auto result = TRY(construct(vm, static_cast(*func), move(arg_list), &new_target.as_function())); // 7. Let thisER be GetThisEnvironment(). - auto& this_environment = verify_cast(get_this_environment(vm)); + auto& this_environment = verify_cast(*get_this_environment(vm)); // 8. Perform ? thisER.BindThisValue(result). TRY(this_environment.bind_this_value(vm, result)); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index f24e6cc3f6f..4db6c8529b4 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -443,7 +443,7 @@ NonnullGCPtr new_private_environment(VM& vm, PrivateEnvironm } // 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment -Environment& get_this_environment(VM& vm) +NonnullGCPtr 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(env).function_object(); + auto& active_function = verify_cast(*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 make_super_property_reference(VM& vm, Value actual_this, PropertyKey const& property_key, bool strict) { // 1. Let env be GetThisEnvironment(). - auto& env = verify_cast(get_this_environment(vm)); + auto& env = verify_cast(*get_this_environment(vm)); // 2. Assert: env.HasSuperBinding() is true. VERIFY(env.has_super_binding()); @@ -548,11 +548,11 @@ ThrowCompletionOr 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(this_environment_record)) { - auto& this_function_environment_record = static_cast(this_environment_record); + if (is(*this_environment_record)) { + auto& this_function_environment_record = static_cast(*this_environment_record); // i. Let F be thisEnvRec.[[FunctionObject]]. auto& function = this_function_environment_record.function_object(); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 5d300573970..4a9ea38d34d 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -23,7 +23,7 @@ NonnullGCPtr new_declarative_environment(Environment&); NonnullGCPtr new_object_environment(Object&, bool is_with_environment, Environment*); NonnullGCPtr new_function_environment(ECMAScriptFunctionObject&, Object* new_target); NonnullGCPtr new_private_environment(VM& vm, PrivateEnvironment* outer); -Environment& get_this_environment(VM&); +NonnullGCPtr get_this_environment(VM&); bool can_be_held_weakly(Value); Object* get_super_constructor(VM&); ThrowCompletionOr make_super_property_reference(VM&, Value actual_this, PropertyKey const&, bool strict); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index a65f8cbb06c..c325456d64c 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -603,21 +603,21 @@ ThrowCompletionOr 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(env).new_target(); + return verify_cast(*env).new_target(); } // 9.4.5 GetGlobalObject ( ), https://tc39.es/ecma262/#sec-getglobalobject