mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-03 14:28:39 +09:00
Issue #618 - Simplify module resolve hook to be a function pointer
This is an ahead-of time port to try and address #1624. This is based on BZ 1461751 and Jon Coppeard's work in it.
This commit is contained in:
parent
976239c8d0
commit
34db761758
10 changed files with 76 additions and 74 deletions
|
|
@ -274,6 +274,7 @@ struct ShellContext
|
|||
JS::PersistentRooted<JobQueue> jobQueue;
|
||||
ExclusiveData<ShellAsyncTasks> asyncTasks;
|
||||
bool drainingJobQueue;
|
||||
JS::PersistentRootedFunction moduleResolveHook;
|
||||
|
||||
/*
|
||||
* Watchdog thread state.
|
||||
|
|
@ -439,7 +440,8 @@ ShellContext::ShellContext(JSContext* cx)
|
|||
exitCode(0),
|
||||
quitting(false),
|
||||
readLineBufPos(0),
|
||||
spsProfilingStackSize(0)
|
||||
spsProfilingStackSize(0),
|
||||
moduleResolveHook(cx)
|
||||
{}
|
||||
|
||||
static ShellContext*
|
||||
|
|
@ -4030,13 +4032,34 @@ SetModuleResolveHook(JSContext* cx, unsigned argc, Value* vp)
|
|||
return false;
|
||||
}
|
||||
|
||||
RootedFunction hook(cx, &args[0].toObject().as<JSFunction>());
|
||||
Rooted<GlobalObject*> global(cx, cx->global());
|
||||
global->setModuleResolveHook(hook);
|
||||
ShellContext* sc = GetShellContext(cx);
|
||||
sc->moduleResolveHook = &args[0].toObject().as<JSFunction>();
|
||||
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSObject*
|
||||
CallModuleResolveHook(JSContext* cx, HandleObject module, HandleString specifier)
|
||||
{
|
||||
ShellContext* sc = GetShellContext(cx);
|
||||
|
||||
JS::AutoValueArray<2> args(cx);
|
||||
args[0].setObject(*module);
|
||||
args[1].setString(specifier);
|
||||
|
||||
RootedValue result(cx);
|
||||
if (!JS_CallFunction(cx, nullptr, sc->moduleResolveHook, args, &result))
|
||||
return nullptr;
|
||||
|
||||
if (!result.isObject() || !result.toObject().is<ModuleObject>()) {
|
||||
JS_ReportErrorASCII(cx, "Module resolve hook did not return Module object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &result.toObject();
|
||||
}
|
||||
|
||||
static bool
|
||||
GetModuleLoadPath(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
|
|
@ -7962,6 +7985,8 @@ main(int argc, char** argv, char** envp)
|
|||
|
||||
js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
|
||||
|
||||
JS::SetModuleResolveHook(cx->runtime(), CallModuleResolveHook);
|
||||
|
||||
result = Shell(cx, &op, envp);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue