Support dynamic import

The static `import` should be prefered over the dynamic but it might be
usefull when loading an object from a json file.
This commit is contained in:
phosit
2025-01-15 22:08:06 +01:00
committed by phosit
parent 252df0a1db
commit a40caaffc4
5 changed files with 82 additions and 9 deletions
+6 -2
View File
@@ -154,14 +154,18 @@ ScriptContext::ScriptContext(int contextSize, uint32_t heapGrowthBytesGCTrigger)
JS::SetJobQueue(m_cx, m_JobQueue.get());
JS::SetPromiseRejectionTrackerCallback(m_cx, &Script::UnhandledRejectedPromise);
JS::SetModuleResolveHook(JS_GetRuntime(m_cx), &Script::ModuleLoader::ResolveHook);
JSRuntime* runtime{JS_GetRuntime(m_cx)};
JS::SetModuleResolveHook(runtime, &Script::ModuleLoader::ResolveHook);
JS::SetModuleDynamicImportHook(runtime, &Script::ModuleLoader::DynamicImportHook);
}
ScriptContext::~ScriptContext()
{
ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be active (initialized and not yet shut down) when destroying a ScriptContext!");
JS::SetModuleResolveHook(JS_GetRuntime(m_cx), nullptr);
JSRuntime* runtime{JS_GetRuntime(m_cx)};
JS::SetModuleDynamicImportHook(runtime, nullptr);
JS::SetModuleResolveHook(runtime, nullptr);
// Switch back to normal performance mode to avoid assertion in debug mode.
js::gc::SetPerformanceHint(m_cx, js::gc::PerformanceHint::Normal);