LibJS+LibWeb: Calculate count of regs+consts+locals before EC allocation

This is a preparation step before joining arguments vector into vector
of registers+constants+locals.
This commit is contained in:
Aliaksandr Kalenik 2025-04-22 21:49:41 +02:00 committed by Andreas Kling
commit 80a8040794
Notes: github-actions[bot] 2025-04-24 08:32:54 +00:00
14 changed files with 144 additions and 107 deletions

View file

@ -281,7 +281,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 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();
dummy_execution_context = JS::ExecutionContext::create(0);
dummy_execution_context->script_or_module = script_or_module;
vm.push_execution_context(*dummy_execution_context);
}
@ -324,7 +324,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 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 realm, and its ScriptOrModule set to active script's record.
if (script) {
script_execution_context = JS::ExecutionContext::create();
script_execution_context = JS::ExecutionContext::create(0);
script_execution_context->function = nullptr;
script_execution_context->realm = &script->realm();
if (is<HTML::ClassicScript>(script)) {
@ -585,7 +585,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 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();
auto module_execution_context = JS::ExecutionContext::create(0);
module_execution_context->realm = realm;
if (module)
module_execution_context->script_or_module = GC::Ref { *module };