diff --git a/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 3eec2d9e1b4..c662f34580a 100644 --- a/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -510,7 +510,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::internal_call(ExecutionContex // 2. Let calleeContext be PrepareForOrdinaryCall(F, undefined). // NOTE: We throw if the end of the native stack is reached, so unlike in the spec this _does_ need an exception check. - TRY(prepare_for_ordinary_call(callee_context, nullptr)); + TRY(prepare_for_ordinary_call(vm, callee_context, nullptr)); // 3. Assert: calleeContext is now the running execution context. VERIFY(&vm.running_execution_context() == &callee_context); @@ -530,10 +530,10 @@ ThrowCompletionOr ECMAScriptFunctionObject::internal_call(ExecutionContex // 5. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument). if (uses_this()) - ordinary_call_bind_this(callee_context, this_argument); + ordinary_call_bind_this(vm, callee_context, this_argument); // 6. Let result be Completion(OrdinaryCallEvaluateBody(F, argumentsList)). - auto result = ordinary_call_evaluate_body(); + auto result = ordinary_call_evaluate_body(vm); // 7. Remove calleeContext from the execution context stack and restore callerContext as the running execution context. vm.pop_execution_context(); @@ -596,7 +596,7 @@ ThrowCompletionOr> ECMAScriptFunctionObject::internal_construct( // 4. Let calleeContext be PrepareForOrdinaryCall(F, newTarget). // NOTE: We throw if the end of the native stack is reached, so unlike in the spec this _does_ need an exception check. - TRY(prepare_for_ordinary_call(*callee_context, &new_target)); + TRY(prepare_for_ordinary_call(vm, *callee_context, &new_target)); // 5. Assert: calleeContext is now the running execution context. VERIFY(&vm.running_execution_context() == callee_context); @@ -605,7 +605,7 @@ ThrowCompletionOr> ECMAScriptFunctionObject::internal_construct( if (kind == ConstructorKind::Base) { // a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument). if (uses_this()) - ordinary_call_bind_this(*callee_context, this_argument); + ordinary_call_bind_this(vm, *callee_context, this_argument); // b. Let initializeResult be Completion(InitializeInstanceElements(thisArgument, F)). auto initialize_result = this_argument->initialize_instance_elements(*this); @@ -624,7 +624,7 @@ ThrowCompletionOr> ECMAScriptFunctionObject::internal_construct( auto constructor_env = callee_context->lexical_environment; // 8. Let result be Completion(OrdinaryCallEvaluateBody(F, argumentsList)). - auto result = ordinary_call_evaluate_body(); + auto result = ordinary_call_evaluate_body(vm); // 9. Remove calleeContext from the execution context stack and restore callerContext as the running execution context. vm.pop_execution_context(); @@ -705,10 +705,8 @@ void ECMAScriptFunctionObject::make_method(Object& home_object) } // 10.2.1.1 PrepareForOrdinaryCall ( F, newTarget ), https://tc39.es/ecma262/#sec-prepareforordinarycall -ThrowCompletionOr ECMAScriptFunctionObject::prepare_for_ordinary_call(ExecutionContext& callee_context, Object* new_target) +ThrowCompletionOr ECMAScriptFunctionObject::prepare_for_ordinary_call(VM& vm, ExecutionContext& callee_context, Object* new_target) { - auto& vm = this->vm(); - // Non-standard callee_context.is_strict_mode = is_strict_mode(); @@ -755,10 +753,8 @@ ThrowCompletionOr ECMAScriptFunctionObject::prepare_for_ordinary_call(Exec } // 10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument ), https://tc39.es/ecma262/#sec-ordinarycallbindthis -void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_context, Value this_argument) +void ECMAScriptFunctionObject::ordinary_call_bind_this(VM& vm, ExecutionContext& callee_context, Value this_argument) { - auto& vm = this->vm(); - // 1. Let thisMode be F.[[ThisMode]]. // If thisMode is lexical, return unused. if (this_mode() == ThisMode::Lexical) @@ -908,9 +904,8 @@ template void async_function_start(VM&, PromiseCapability const&, GC::Functionvm(); auto& realm = *vm.current_realm(); auto result_and_frame = vm.bytecode_interpreter().run_executable(*m_bytecode_executable, {}); diff --git a/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h b/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h index 920463c54fe..ac6c69dd9c5 100644 --- a/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h +++ b/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h @@ -181,11 +181,6 @@ public: friend class Bytecode::Generator; -protected: - virtual bool is_strict_mode() const override { return shared_data().m_strict; } - - virtual Completion ordinary_call_evaluate_body(); - private: ECMAScriptFunctionObject( NonnullRefPtr, @@ -193,14 +188,18 @@ private: PrivateEnvironment* private_environment, Object& prototype); + virtual bool is_strict_mode() const override { return shared_data().m_strict; } + + Completion ordinary_call_evaluate_body(VM&); + [[nodiscard]] bool function_environment_needed() const { return shared_data().m_function_environment_needed; } SharedFunctionInstanceData const& shared_data() const { return m_shared_data; } virtual bool is_ecmascript_function_object() const override { return true; } virtual void visit_edges(Visitor&) override; - ThrowCompletionOr prepare_for_ordinary_call(ExecutionContext& callee_context, Object* new_target); - void ordinary_call_bind_this(ExecutionContext&, Value this_argument); + ThrowCompletionOr prepare_for_ordinary_call(VM&, ExecutionContext& callee_context, Object* new_target); + void ordinary_call_bind_this(VM&, ExecutionContext&, Value this_argument); NonnullRefPtr m_shared_data;