diff --git a/source/scriptinterface/ModuleLoader.cpp b/source/scriptinterface/ModuleLoader.cpp index 7d02c3293d..2460d401f2 100644 --- a/source/scriptinterface/ModuleLoader.cpp +++ b/source/scriptinterface/ModuleLoader.cpp @@ -421,17 +421,17 @@ ModuleLoader::Result::iterator& ModuleLoader::Result::iterator::operator++(int) } ModuleLoader::Result::Result(const ScriptRequest& rq, const VfsPath& modulePath): - m_Cx{rq.cx}, - m_Loader{rq.GetScriptInterface().GetModuleLoader()}, + m_Script{rq.GetScriptInterface()}, m_ModulePath{modulePath}, - m_Storage{rq, m_Loader, *this, m_ModulePath} + m_Storage{rq, m_Script.GetModuleLoader(), *this, m_ModulePath} { } ModuleLoader::Result::~Result() { - const auto modIter = m_Loader.m_Registry.find(m_ModulePath); - if (modIter == m_Loader.m_Registry.end()) + ModuleLoader::RegistryType& registry{m_Script.GetModuleLoader().m_Registry}; + const auto modIter = registry.find(m_ModulePath); + if (modIter == registry.end()) return; std::get<1>(*modIter).RemoveRequester(this); @@ -450,7 +450,7 @@ ModuleLoader::Result::~Result() void ModuleLoader::Result::Resume() { if (m_Storage.IsWaiting()) - m_Storage = ModuleLoader::Future{m_Cx, m_Loader, *this, m_ModulePath}; + m_Storage = ModuleLoader::Future{m_Script, m_Script.GetModuleLoader(), *this, m_ModulePath}; } ModuleLoader::ModuleLoader(ModuleLoader::AllowModuleFunc allowModule): diff --git a/source/scriptinterface/ModuleLoader.h b/source/scriptinterface/ModuleLoader.h index c819d786f4..d0b0870435 100644 --- a/source/scriptinterface/ModuleLoader.h +++ b/source/scriptinterface/ModuleLoader.h @@ -29,6 +29,7 @@ #include class ScriptContext; +class ScriptInterface; class ScriptRequest; namespace Script @@ -166,8 +167,7 @@ public: void Resume(); private: - JSContext* m_Cx; - ModuleLoader& m_Loader; + const ScriptInterface& m_Script; VfsPath m_ModulePath; Future m_Storage; }; diff --git a/source/scriptinterface/tests/test_Module.h b/source/scriptinterface/tests/test_Module.h index 800daddf4d..b9417cbbba 100644 --- a/source/scriptinterface/tests/test_Module.h +++ b/source/scriptinterface/tests/test_Module.h @@ -686,10 +686,18 @@ public: TS_ASSERT_STR_NOT_CONTAINS(logger.GetOutput(), "blah blah blah"); } - void test_ResultDestructionAfterScriptRequestDestruction() + void test_HotloadAfterScriptRequestDestruction() { ScriptInterface script{"Test", "Test", g_ScriptContext, AllowAllPredicate}; - auto _ = script.GetModuleLoader().LoadModule(ScriptRequest{script}, "empty.js"); + auto result = script.GetModuleLoader().LoadModule(ScriptRequest{script}, "empty.js"); + g_ScriptContext->RunJobs(); + auto iter = result.begin(); + TS_ASSERT(iter->IsDone()); + + ++iter; + ClearFromCache("empty.js"); + g_ScriptContext->RunJobs(); + TS_ASSERT(iter->IsDone()); } void test_RestrictionNoPredicate()