From a3782782fa41bc8640480ff04755339410e5b5eb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 31 May 2024 15:12:33 +0200 Subject: [PATCH] LibJS: Remove two unused members from ExecutionContext --- Userland/Applications/Spreadsheet/Workbook.cpp | 2 +- .../Libraries/LibJS/Bytecode/Interpreter.cpp | 2 +- .../LibJS/Runtime/AbstractOperations.cpp | 2 +- .../LibJS/Runtime/ECMAScriptFunctionObject.cpp | 4 ++-- .../LibJS/Runtime/ExecutionContext.cpp | 17 ++++++++--------- .../Libraries/LibJS/Runtime/ExecutionContext.h | 12 +++--------- .../Libraries/LibJS/Runtime/NativeFunction.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/Realm.cpp | 2 +- .../Libraries/LibJS/Runtime/ShadowRealm.cpp | 2 +- .../LibJS/Runtime/ShadowRealmConstructor.cpp | 2 +- .../Libraries/LibJS/Runtime/WrappedFunction.cpp | 2 +- Userland/Libraries/LibJS/SourceTextModule.cpp | 4 ++-- Userland/Libraries/LibJS/SyntheticModule.cpp | 2 +- .../Libraries/LibWeb/Bindings/MainThreadVM.cpp | 6 +++--- .../LibWeb/HTML/Scripting/ModuleScript.cpp | 2 +- 15 files changed, 29 insertions(+), 36 deletions(-) diff --git a/Userland/Applications/Spreadsheet/Workbook.cpp b/Userland/Applications/Spreadsheet/Workbook.cpp index 8c73611265..e34dab241b 100644 --- a/Userland/Applications/Spreadsheet/Workbook.cpp +++ b/Userland/Applications/Spreadsheet/Workbook.cpp @@ -23,7 +23,7 @@ Workbook::Workbook(Vector>&& sheets, GUI::Window& parent_wi : m_sheets(move(sheets)) , m_vm(JS::VM::create().release_value_but_fixme_should_propagate_errors()) , m_root_execution_context(JS::create_simple_execution_context(m_vm)) - , m_main_execution_context(JS::ExecutionContext::create(m_vm->heap())) + , m_main_execution_context(JS::ExecutionContext::create()) , m_parent_window(parent_window) { auto& realm = *m_root_execution_context->realm; diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 6f519ce18b..8416bcda6a 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -186,7 +186,7 @@ ThrowCompletionOr Interpreter::run(Script& script_record, JS::GCPtr perform_eval(VM& vm, Value x, CallerMode strict_caller, // FIXME: We don't have this concept yet. // 20. Let evalContext be a new ECMAScript code execution context. - auto eval_context = ExecutionContext::create(vm.heap()); + auto eval_context = ExecutionContext::create(); // 21. Set evalContext's Function to null. // NOTE: This was done in the construction of eval_context. diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index d4176ec473..7a2e7c51e1 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -382,7 +382,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::internal_call(Value this_argu // 1. Let callerContext be the running execution context. // NOTE: No-op, kept by the VM in its execution context stack. - auto callee_context = ExecutionContext::create(heap()); + auto callee_context = ExecutionContext::create(); // Non-standard callee_context->arguments.ensure_capacity(max(arguments_list.size(), m_formal_parameters.size())); @@ -457,7 +457,7 @@ ThrowCompletionOr> ECMAScriptFunctionObject::internal_const this_argument = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::object_prototype, ConstructWithPrototypeTag::Tag)); } - auto callee_context = ExecutionContext::create(heap()); + auto callee_context = ExecutionContext::create(); // Non-standard callee_context->arguments.ensure_capacity(max(arguments_list.size(), m_formal_parameters.size())); diff --git a/Userland/Libraries/LibJS/Runtime/ExecutionContext.cpp b/Userland/Libraries/LibJS/Runtime/ExecutionContext.cpp index 139f10c401..6470fffc80 100644 --- a/Userland/Libraries/LibJS/Runtime/ExecutionContext.cpp +++ b/Userland/Libraries/LibJS/Runtime/ExecutionContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2024, Andreas Kling * Copyright (c) 2020-2021, Linus Groh * Copyright (c) 2022, Luke Wilde * @@ -15,12 +15,12 @@ namespace JS { class ExecutionContextAllocator { public: - NonnullOwnPtr allocate(Heap& heap) + NonnullOwnPtr allocate() { if (m_execution_contexts.is_empty()) - return adopt_own(*new ExecutionContext(heap)); + return adopt_own(*new ExecutionContext); void* slot = m_execution_contexts.take_last(); - return adopt_own(*new (slot) ExecutionContext(heap)); + return adopt_own(*new (slot) ExecutionContext); } void deallocate(void* ptr) { @@ -33,9 +33,9 @@ private: static NeverDestroyed s_execution_context_allocator; -NonnullOwnPtr ExecutionContext::create(Heap& heap) +NonnullOwnPtr ExecutionContext::create() { - return s_execution_context_allocator->allocate(heap); + return s_execution_context_allocator->allocate(); } void ExecutionContext::operator delete(void* ptr) @@ -43,8 +43,7 @@ void ExecutionContext::operator delete(void* ptr) s_execution_context_allocator->deallocate(ptr); } -ExecutionContext::ExecutionContext(Heap& heap) - : m_heap(heap) +ExecutionContext::ExecutionContext() { } @@ -54,7 +53,7 @@ ExecutionContext::~ExecutionContext() NonnullOwnPtr ExecutionContext::copy() const { - auto copy = create(m_heap); + auto copy = create(); copy->function = function; copy->realm = realm; copy->script_or_module = script_or_module; diff --git a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h index 81b095f341..2fade637fc 100644 --- a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h +++ b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2024, Andreas Kling * Copyright (c) 2020-2021, Linus Groh * Copyright (c) 2022, Luke Wilde * @@ -23,7 +23,7 @@ using ScriptOrModule = Variant, NonnullGCPtr // 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts struct ExecutionContext { - static NonnullOwnPtr create(Heap&); + static NonnullOwnPtr create(); [[nodiscard]] NonnullOwnPtr copy() const; ~ExecutionContext(); @@ -33,17 +33,11 @@ struct ExecutionContext { private: friend class ExecutionContextAllocator; - ExecutionContext(Heap&); - - IntrusiveListNode m_list_node; + ExecutionContext(); public: void operator delete(void* ptr); - Heap& m_heap; - - using List = IntrusiveList<&ExecutionContext::m_list_node>; - GCPtr function; // [[Function]] GCPtr realm; // [[Realm]] ScriptOrModule script_or_module; // [[ScriptOrModule]] diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index 4b14e44a3e..d04b89ef1e 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -121,7 +121,7 @@ ThrowCompletionOr NativeFunction::internal_call(Value this_argument, Read // NOTE: We don't support this concept yet. // 3. Let calleeContext be a new execution context. - auto callee_context = ExecutionContext::create(heap()); + auto callee_context = ExecutionContext::create(); // 4. Set the Function of calleeContext to F. callee_context->function = this; @@ -185,7 +185,7 @@ ThrowCompletionOr> NativeFunction::internal_construct(Reado // NOTE: We don't support this concept yet. // 3. Let calleeContext be a new execution context. - auto callee_context = ExecutionContext::create(heap()); + auto callee_context = ExecutionContext::create(); // 4. Set the Function of calleeContext to F. callee_context->function = this; diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp index 248330c80d..12ef4dab59 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.cpp +++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp @@ -42,7 +42,7 @@ ThrowCompletionOr> Realm::initialize_host_define auto realm = MUST_OR_THROW_OOM(Realm::create(vm)); // 2. Let newContext be a new execution context. - auto new_context = ExecutionContext::create(vm.heap()); + auto new_context = ExecutionContext::create(); // 3. Set the Function of newContext to null. new_context->function = nullptr; diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 97f153cb0e..cba817471f 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -143,7 +143,7 @@ ThrowCompletionOr perform_shadow_realm_eval(VM& vm, StringView source_tex // NOTE: We don't support this concept yet. // 9. Let evalContext be a new ECMAScript code execution context. - auto eval_context = ExecutionContext::create(vm.heap()); + auto eval_context = ExecutionContext::create(); // 10. Set evalContext's Function to null. eval_context->function = nullptr; diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp index ab5c32cbd1..10753c48d0 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp @@ -47,7 +47,7 @@ ThrowCompletionOr> ShadowRealmConstructor::construct(Functi auto realm = MUST_OR_THROW_OOM(Realm::create(vm)); // 5. Let context be a new execution context. - auto context = ExecutionContext::create(vm.heap()); + auto context = ExecutionContext::create(); // 6. Set the Function of context to null. context->function = nullptr; diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp index 601a18de4c..0b04092bd5 100644 --- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp @@ -62,7 +62,7 @@ ThrowCompletionOr WrappedFunction::internal_call(Value this_argument, Rea // NOTE: No-op, kept by the VM in its execution context stack. // 2. Let calleeContext be PrepareForWrappedFunctionCall(F). - auto callee_context = ExecutionContext::create(vm.heap()); + auto callee_context = ExecutionContext::create(); prepare_for_wrapped_function_call(*this, *callee_context); // 3. Assert: calleeContext is now the running execution context. diff --git a/Userland/Libraries/LibJS/SourceTextModule.cpp b/Userland/Libraries/LibJS/SourceTextModule.cpp index 6306914416..eaf04a23e1 100644 --- a/Userland/Libraries/LibJS/SourceTextModule.cpp +++ b/Userland/Libraries/LibJS/SourceTextModule.cpp @@ -107,7 +107,7 @@ SourceTextModule::SourceTextModule(Realm& realm, StringView filename, Script::Ho RefPtr default_export) : CyclicModule(realm, filename, has_top_level_await, move(requested_modules), host_defined) , m_ecmascript_code(move(body)) - , m_execution_context(ExecutionContext::create(realm.heap())) + , m_execution_context(ExecutionContext::create()) , m_import_entries(move(import_entries)) , m_local_export_entries(move(local_export_entries)) , m_indirect_export_entries(move(indirect_export_entries)) @@ -674,7 +674,7 @@ ThrowCompletionOr SourceTextModule::execute_module(VM& vm, GCPtris_strict_mode = true; diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp index a1689eef2a..7bcb2e0a49 100644 --- a/Userland/Libraries/LibJS/SyntheticModule.cpp +++ b/Userland/Libraries/LibJS/SyntheticModule.cpp @@ -81,7 +81,7 @@ ThrowCompletionOr SyntheticModule::evaluate(VM& vm) // FIXME: We don't have suspend yet. // 2. Let moduleContext be a new ECMAScript code execution context. - auto module_context = ExecutionContext::create(vm.heap()); + auto module_context = ExecutionContext::create(); // 3. Set the Function of moduleContext to null. // Note: This is the default value. diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index b32ee625ca..4dd6a8409e 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -292,7 +292,7 @@ ErrorOr initialize_main_thread_vm() // FIXME: We need to setup a dummy execution context in case a JS::NativeFunction is called when processing the job. // This is because JS::NativeFunction::call excepts something to be on the execution context stack to be able to get the caller context to initialize the environment. // Do note that the JS spec gives _no_ guarantee that the execution context stack has something on it if HostEnqueuePromiseJob was called with a null realm: https://tc39.es/ecma262/#job-preparedtoevaluatecode - dummy_execution_context = JS::ExecutionContext::create(s_main_thread_vm->heap()); + dummy_execution_context = JS::ExecutionContext::create(); dummy_execution_context->script_or_module = script_or_module; s_main_thread_vm->push_execution_context(*dummy_execution_context); } @@ -334,7 +334,7 @@ ErrorOr initialize_main_thread_vm() // 4. If active script is not null, set script execution context to a new JavaScript execution context, with its Function field set to null, // its Realm field set to active script's settings object's Realm, and its ScriptOrModule set to active script's record. if (script) { - script_execution_context = JS::ExecutionContext::create(s_main_thread_vm->heap()); + script_execution_context = JS::ExecutionContext::create(); script_execution_context->function = nullptr; script_execution_context->realm = &script->settings_object().realm(); if (is(script)) { @@ -523,7 +523,7 @@ ErrorOr initialize_main_thread_vm() // 5. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, completion). // NON-STANDARD: To ensure that LibJS can find the module on the stack, we push a new execution context. - auto module_execution_context = JS::ExecutionContext::create(realm.heap()); + auto module_execution_context = JS::ExecutionContext::create(); module_execution_context->realm = realm; if (module) module_execution_context->script_or_module = JS::NonnullGCPtr { *module }; diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp index c9ce50b228..571f3a08ee 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp @@ -148,7 +148,7 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting) VERIFY(record); // NON-STANDARD: To ensure that LibJS can find the module on the stack, we push a new execution context. - auto module_execution_context = JS::ExecutionContext::create(heap()); + auto module_execution_context = JS::ExecutionContext::create(); module_execution_context->realm = &settings.realm(); module_execution_context->script_or_module = JS::NonnullGCPtr { *record }; vm().push_execution_context(*module_execution_context);