1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 09:00:46 +00:00

LibJS: Remove two unused members from ExecutionContext

This commit is contained in:
Andreas Kling 2024-05-31 15:12:33 +02:00
parent f5cacf25e1
commit a3782782fa
15 changed files with 29 additions and 36 deletions

View File

@ -23,7 +23,7 @@ Workbook::Workbook(Vector<NonnullRefPtr<Sheet>>&& 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<JS::GlobalObject>(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;

View File

@ -186,7 +186,7 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record, JS::GCPtr<Envir
auto& global_environment = script_record.realm().global_environment();
// 2. Let scriptContext be a new ECMAScript code execution context.
auto script_context = ExecutionContext::create(vm.heap());
auto script_context = ExecutionContext::create();
// 3. Set the Function of scriptContext to null.
// NOTE: This was done during execution context construction.

View File

@ -644,7 +644,7 @@ ThrowCompletionOr<Value> 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.

View File

@ -382,7 +382,7 @@ ThrowCompletionOr<Value> 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<NonnullGCPtr<Object>> ECMAScriptFunctionObject::internal_const
this_argument = TRY(ordinary_create_from_constructor<Object>(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()));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2024, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
*
@ -15,12 +15,12 @@ namespace JS {
class ExecutionContextAllocator {
public:
NonnullOwnPtr<ExecutionContext> allocate(Heap& heap)
NonnullOwnPtr<ExecutionContext> 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<ExecutionContextAllocator> s_execution_context_allocator;
NonnullOwnPtr<ExecutionContext> ExecutionContext::create(Heap& heap)
NonnullOwnPtr<ExecutionContext> 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> ExecutionContext::copy() const
{
auto copy = create(m_heap);
auto copy = create();
copy->function = function;
copy->realm = realm;
copy->script_or_module = script_or_module;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2024, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
*
@ -23,7 +23,7 @@ using ScriptOrModule = Variant<Empty, NonnullGCPtr<Script>, NonnullGCPtr<Module>
// 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
struct ExecutionContext {
static NonnullOwnPtr<ExecutionContext> create(Heap&);
static NonnullOwnPtr<ExecutionContext> create();
[[nodiscard]] NonnullOwnPtr<ExecutionContext> copy() const;
~ExecutionContext();
@ -33,17 +33,11 @@ struct ExecutionContext {
private:
friend class ExecutionContextAllocator;
ExecutionContext(Heap&);
IntrusiveListNode<ExecutionContext> m_list_node;
ExecutionContext();
public:
void operator delete(void* ptr);
Heap& m_heap;
using List = IntrusiveList<&ExecutionContext::m_list_node>;
GCPtr<FunctionObject> function; // [[Function]]
GCPtr<Realm> realm; // [[Realm]]
ScriptOrModule script_or_module; // [[ScriptOrModule]]

View File

@ -121,7 +121,7 @@ ThrowCompletionOr<Value> 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<NonnullGCPtr<Object>> 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;

View File

@ -42,7 +42,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> 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;

View File

@ -143,7 +143,7 @@ ThrowCompletionOr<Value> 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;

View File

@ -47,7 +47,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> 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;

View File

@ -62,7 +62,7 @@ ThrowCompletionOr<Value> 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.

View File

@ -107,7 +107,7 @@ SourceTextModule::SourceTextModule(Realm& realm, StringView filename, Script::Ho
RefPtr<ExportStatement const> 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<void> SourceTextModule::execute_module(VM& vm, GCPtr<PromiseCa
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] SourceTextModule::execute_module({}, PromiseCapability @ {})", filename(), capability.ptr());
// 1. Let moduleContext be a new ECMAScript code execution context.
auto module_context = ExecutionContext::create(vm.heap());
auto module_context = ExecutionContext::create();
// Note: This is not in the spec but we require it.
module_context->is_strict_mode = true;

View File

@ -81,7 +81,7 @@ ThrowCompletionOr<Promise*> 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.

View File

@ -292,7 +292,7 @@ ErrorOr<void> 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<void> 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<HTML::ClassicScript>(script)) {
@ -523,7 +523,7 @@ ErrorOr<void> 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 };

View File

@ -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<JS::Module> { *record };
vm().push_execution_context(*module_execution_context);