From 26c21fba8e73d5d43ff1883bfbf18627308857b6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 6 Dec 2023 11:14:41 +0100 Subject: [PATCH] LibJS: Use LoadRequestedModules in the ad-hoc module loading path This ensures that modules go through the expected state transitions, fixing hundreds of test262 tests. --- Userland/Libraries/LibJS/Runtime/VM.cpp | 30 ++----------------------- Userland/Libraries/LibJS/Runtime/VM.h | 2 +- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 89d06ad663..6f99bfdc93 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -746,36 +746,10 @@ ThrowCompletionOr VM::link_and_eval_module(Badge, S return link_and_eval_module(module); } -ThrowCompletionOr VM::link_and_eval_module(Module& module) +ThrowCompletionOr VM::link_and_eval_module(CyclicModule& module) { auto filename = module.filename(); - - auto module_or_end = m_loaded_modules.find_if([&](StoredModule const& stored_module) { - return stored_module.module.ptr() == &module; - }); - - StoredModule* stored_module; - - if (module_or_end.is_end()) { - dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Warning introducing module via link_and_eval_module {}", module.filename()); - if (m_loaded_modules.size() > 0) - dbgln("Warning: Using multiple modules as entry point can lead to unexpected results"); - - m_loaded_modules.empend( - ImportedModuleReferrer { NonnullGCPtr { verify_cast(module) } }, - module.filename(), - DeprecatedString {}, // Null type - module, - true); - stored_module = &m_loaded_modules.last(); - } else { - stored_module = module_or_end.operator->(); - if (stored_module->has_once_started_linking) { - dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Module already has started linking once {}", module.filename()); - return {}; - } - stored_module->has_once_started_linking = true; - } + module.load_requested_modules(nullptr); dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking module {}", filename); auto linked_or_error = module.link(*this); diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 3fe0bdd90c..c7514d301f 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -268,7 +268,7 @@ private: ThrowCompletionOr iterator_binding_initialization(BindingPattern const& binding, IteratorRecord& iterator_record, Environment* environment); void load_imported_module(ImportedModuleReferrer, ModuleRequest const&, GCPtr, ImportedModulePayload); - ThrowCompletionOr link_and_eval_module(Module& module); + ThrowCompletionOr link_and_eval_module(CyclicModule&); void set_well_known_symbols(WellKnownSymbols well_known_symbols) { m_well_known_symbols = move(well_known_symbols); }