mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
LibJS: Pass VM& to ECMAScriptFunctionObject [[Call]] helpers
This avoids fetching the VM from the Cell::private_data() repeatedly.
This commit is contained in:
parent
8a3c66d8a6
commit
403ae86fd9
Notes:
github-actions[bot]
2025-04-28 10:46:17 +00:00
Author: https://github.com/awesomekling
Commit: 403ae86fd9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4499
2 changed files with 15 additions and 21 deletions
|
@ -510,7 +510,7 @@ ThrowCompletionOr<Value> ECMAScriptFunctionObject::internal_call(ExecutionContex
|
||||||
|
|
||||||
// 2. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
|
// 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.
|
// 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.
|
// 3. Assert: calleeContext is now the running execution context.
|
||||||
VERIFY(&vm.running_execution_context() == &callee_context);
|
VERIFY(&vm.running_execution_context() == &callee_context);
|
||||||
|
@ -530,10 +530,10 @@ ThrowCompletionOr<Value> ECMAScriptFunctionObject::internal_call(ExecutionContex
|
||||||
|
|
||||||
// 5. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
|
// 5. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
|
||||||
if (uses_this())
|
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)).
|
// 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.
|
// 7. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
|
||||||
vm.pop_execution_context();
|
vm.pop_execution_context();
|
||||||
|
@ -596,7 +596,7 @@ ThrowCompletionOr<GC::Ref<Object>> ECMAScriptFunctionObject::internal_construct(
|
||||||
|
|
||||||
// 4. Let calleeContext be PrepareForOrdinaryCall(F, newTarget).
|
// 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.
|
// 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.
|
// 5. Assert: calleeContext is now the running execution context.
|
||||||
VERIFY(&vm.running_execution_context() == callee_context);
|
VERIFY(&vm.running_execution_context() == callee_context);
|
||||||
|
@ -605,7 +605,7 @@ ThrowCompletionOr<GC::Ref<Object>> ECMAScriptFunctionObject::internal_construct(
|
||||||
if (kind == ConstructorKind::Base) {
|
if (kind == ConstructorKind::Base) {
|
||||||
// a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
|
// a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
|
||||||
if (uses_this())
|
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)).
|
// b. Let initializeResult be Completion(InitializeInstanceElements(thisArgument, F)).
|
||||||
auto initialize_result = this_argument->initialize_instance_elements(*this);
|
auto initialize_result = this_argument->initialize_instance_elements(*this);
|
||||||
|
@ -624,7 +624,7 @@ ThrowCompletionOr<GC::Ref<Object>> ECMAScriptFunctionObject::internal_construct(
|
||||||
auto constructor_env = callee_context->lexical_environment;
|
auto constructor_env = callee_context->lexical_environment;
|
||||||
|
|
||||||
// 8. Let result be Completion(OrdinaryCallEvaluateBody(F, argumentsList)).
|
// 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.
|
// 9. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
|
||||||
vm.pop_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
|
// 10.2.1.1 PrepareForOrdinaryCall ( F, newTarget ), https://tc39.es/ecma262/#sec-prepareforordinarycall
|
||||||
ThrowCompletionOr<void> ECMAScriptFunctionObject::prepare_for_ordinary_call(ExecutionContext& callee_context, Object* new_target)
|
ThrowCompletionOr<void> ECMAScriptFunctionObject::prepare_for_ordinary_call(VM& vm, ExecutionContext& callee_context, Object* new_target)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
|
||||||
|
|
||||||
// Non-standard
|
// Non-standard
|
||||||
callee_context.is_strict_mode = is_strict_mode();
|
callee_context.is_strict_mode = is_strict_mode();
|
||||||
|
|
||||||
|
@ -755,10 +753,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::prepare_for_ordinary_call(Exec
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument ), https://tc39.es/ecma262/#sec-ordinarycallbindthis
|
// 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]].
|
// 1. Let thisMode be F.[[ThisMode]].
|
||||||
// If thisMode is lexical, return unused.
|
// If thisMode is lexical, return unused.
|
||||||
if (this_mode() == ThisMode::Lexical)
|
if (this_mode() == ThisMode::Lexical)
|
||||||
|
@ -908,9 +904,8 @@ template void async_function_start(VM&, PromiseCapability const&, GC::Function<C
|
||||||
|
|
||||||
// 10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList ), https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
// 10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList ), https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
||||||
// 15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody, https://tc39.es/ecma262/#sec-runtime-semantics-evaluatefunctionbody
|
// 15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody, https://tc39.es/ecma262/#sec-runtime-semantics-evaluatefunctionbody
|
||||||
Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body(VM& vm)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
|
||||||
auto& realm = *vm.current_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto result_and_frame = vm.bytecode_interpreter().run_executable(*m_bytecode_executable, {});
|
auto result_and_frame = vm.bytecode_interpreter().run_executable(*m_bytecode_executable, {});
|
||||||
|
|
|
@ -181,11 +181,6 @@ public:
|
||||||
|
|
||||||
friend class Bytecode::Generator;
|
friend class Bytecode::Generator;
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual bool is_strict_mode() const override { return shared_data().m_strict; }
|
|
||||||
|
|
||||||
virtual Completion ordinary_call_evaluate_body();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ECMAScriptFunctionObject(
|
ECMAScriptFunctionObject(
|
||||||
NonnullRefPtr<SharedFunctionInstanceData>,
|
NonnullRefPtr<SharedFunctionInstanceData>,
|
||||||
|
@ -193,14 +188,18 @@ private:
|
||||||
PrivateEnvironment* private_environment,
|
PrivateEnvironment* private_environment,
|
||||||
Object& prototype);
|
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; }
|
[[nodiscard]] bool function_environment_needed() const { return shared_data().m_function_environment_needed; }
|
||||||
SharedFunctionInstanceData const& shared_data() const { return m_shared_data; }
|
SharedFunctionInstanceData const& shared_data() const { return m_shared_data; }
|
||||||
|
|
||||||
virtual bool is_ecmascript_function_object() const override { return true; }
|
virtual bool is_ecmascript_function_object() const override { return true; }
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
ThrowCompletionOr<void> prepare_for_ordinary_call(ExecutionContext& callee_context, Object* new_target);
|
ThrowCompletionOr<void> prepare_for_ordinary_call(VM&, ExecutionContext& callee_context, Object* new_target);
|
||||||
void ordinary_call_bind_this(ExecutionContext&, Value this_argument);
|
void ordinary_call_bind_this(VM&, ExecutionContext&, Value this_argument);
|
||||||
|
|
||||||
NonnullRefPtr<SharedFunctionInstanceData> m_shared_data;
|
NonnullRefPtr<SharedFunctionInstanceData> m_shared_data;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue