diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 183fd8d2a7..0443013e1f 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -3262,10 +3262,10 @@ Completion MetaProperty::execute(Interpreter& interpreter) const auto script_or_module = interpreter.vm().get_active_script_or_module(); // 2. Assert: module is a Source Text Module Record. - VERIFY(script_or_module.has>()); - VERIFY(script_or_module.get>()); - VERIFY(is(*script_or_module.get>())); - auto& module = static_cast(*script_or_module.get>()); + VERIFY(script_or_module.has>()); + VERIFY(script_or_module.get>()); + VERIFY(is(*script_or_module.get>())); + auto& module = static_cast(*script_or_module.get>()); // 3. Let importMeta be module.[[ImportMeta]]. auto* import_meta = module.import_meta(); diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp index 61a9e84de3..4a2b4f70d0 100644 --- a/Userland/Libraries/LibJS/CyclicModule.cpp +++ b/Userland/Libraries/LibJS/CyclicModule.cpp @@ -17,6 +17,14 @@ CyclicModule::CyclicModule(Realm& realm, StringView filename, bool has_top_level { } +void CyclicModule::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_cycle_root); + for (auto* module : m_async_parent_modules) + visitor.visit(module); +} + // 16.2.1.5.1 Link ( ), https://tc39.es/ecma262/#sec-moduledeclarationlinking ThrowCompletionOr CyclicModule::link(VM& vm) { @@ -106,7 +114,7 @@ ThrowCompletionOr CyclicModule::inner_module_linking(VM& vm, Vectormake_weak_ptr(), required)); + auto required_module = TRY(vm.host_resolve_imported_module(NonnullGCPtr(*this), required)); // b. Set index to ? InnerModuleLinking(requiredModule, stack, index). index = TRY(required_module->inner_module_linking(vm, stack, index)); @@ -305,7 +313,7 @@ ThrowCompletionOr CyclicModule::inner_module_evaluation(VM& vm, Vectormake_weak_ptr(), required)).ptr(); + auto* required_module = MUST(vm.host_resolve_imported_module(NonnullGCPtr(*this), required)).ptr(); // b. NOTE: Link must be completed successfully prior to invoking this method, so every requested module is guaranteed to resolve successfully. // c. Set index to ? InnerModuleEvaluation(requiredModule, stack, index). diff --git a/Userland/Libraries/LibJS/CyclicModule.h b/Userland/Libraries/LibJS/CyclicModule.h index 2f66b5d977..2c710d51a8 100644 --- a/Userland/Libraries/LibJS/CyclicModule.h +++ b/Userland/Libraries/LibJS/CyclicModule.h @@ -25,6 +25,8 @@ enum class ModuleStatus { // 16.2.1.5 Cyclic Module Records, https://tc39.es/ecma262/#sec-cyclic-module-records class CyclicModule : public Module { + JS_CELL(CyclicModule, Module); + public: // Note: Do not call these methods directly unless you are HostResolveImportedModule. // Badges cannot be used because other hosts must be able to call this (and it is called recursively) @@ -34,6 +36,8 @@ public: protected: CyclicModule(Realm& realm, StringView filename, bool has_top_level_await, Vector requested_modules); + virtual void visit_edges(Cell::Visitor&) override; + virtual ThrowCompletionOr inner_module_linking(VM& vm, Vector& stack, u32 index) override; virtual ThrowCompletionOr inner_module_evaluation(VM& vm, Vector& stack, u32 index) override; @@ -50,7 +54,7 @@ protected: Optional m_dfs_index; // [[DFSIndex]] Optional m_dfs_ancestor_index; // [[DFSAncestorIndex]] Vector m_requested_modules; // [[RequestedModules]] - CyclicModule* m_cycle_root; // [[CycleRoot]] + CyclicModule* m_cycle_root { nullptr }; // [[CycleRoot]] bool m_has_top_level_await { false }; // [[HasTLA]] bool m_async_evaluation { false }; // [[AsyncEvaluation]] Optional m_top_level_capability; // [[TopLevelCapability]] diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index a708d87d2c..20bdc1bc86 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -54,7 +54,7 @@ ThrowCompletionOr Interpreter::run(Script& script_record) script_context.realm = &script_record.realm(); // 5. Set the ScriptOrModule of scriptContext to scriptRecord. - script_context.script_or_module = script_record.make_weak_ptr(); + script_context.script_or_module = NonnullGCPtr