зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1658160 - Give shell workers a module loader r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D86568
This commit is contained in:
Родитель
1e945cc264
Коммит
282eb17b37
|
@ -538,6 +538,8 @@ bool shell::dumpEntrainedVariables = false;
|
|||
bool shell::OOM_printAllocationCount = false;
|
||||
#endif
|
||||
|
||||
UniqueChars shell::processWideModuleLoadPath;
|
||||
|
||||
static bool SetTimeoutValue(JSContext* cx, double t);
|
||||
|
||||
static void KillWatchdog(JSContext* cx);
|
||||
|
@ -4131,6 +4133,7 @@ static void WorkerMain(WorkerInput* input) {
|
|||
});
|
||||
|
||||
sc->isWorker = true;
|
||||
|
||||
JS_SetContextPrivate(cx, sc);
|
||||
JS_SetGrayGCRootsTracer(cx, TraceGrayRoots, nullptr);
|
||||
SetWorkerContextOptions(cx);
|
||||
|
@ -4168,6 +4171,16 @@ static void WorkerMain(WorkerInput* input) {
|
|||
|
||||
JSAutoRealm ar(cx, global);
|
||||
|
||||
JS::ConstUTF8CharsZ path(processWideModuleLoadPath.get(), strlen(processWideModuleLoadPath.get()));
|
||||
RootedString moduleLoadPath(cx, JS_NewStringCopyUTF8Z(cx, path));
|
||||
if (!moduleLoadPath) {
|
||||
return;
|
||||
}
|
||||
sc->moduleLoader = js::MakeUnique<ModuleLoader>();
|
||||
if (!sc->moduleLoader || !sc->moduleLoader->init(cx, moduleLoadPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
JS::CompileOptions options(cx);
|
||||
options.setFileAndLine("<string>", 1).setIsRunOnce(true);
|
||||
|
||||
|
@ -10084,6 +10097,12 @@ static MOZ_MUST_USE bool ProcessArgs(JSContext* cx, OptionParser* op) {
|
|||
return false;
|
||||
}
|
||||
|
||||
processWideModuleLoadPath = JS_EncodeStringToUTF8(cx, moduleLoadPath);
|
||||
if (!processWideModuleLoadPath) {
|
||||
MOZ_ASSERT(cx->isExceptionPending());
|
||||
return false;
|
||||
}
|
||||
|
||||
sc->moduleLoader = js::MakeUnique<ModuleLoader>();
|
||||
if (!sc->moduleLoader || !sc->moduleLoader->init(cx, moduleLoadPath)) {
|
||||
return false;
|
||||
|
|
|
@ -158,6 +158,8 @@ extern bool dumpEntrainedVariables;
|
|||
extern bool OOM_printAllocationCount;
|
||||
#endif
|
||||
|
||||
extern UniqueChars processWideModuleLoadPath;
|
||||
|
||||
// Alias the global dstName to namespaceObj.srcName. For example, if dstName is
|
||||
// "snarf", namespaceObj represents "os.file", and srcName is "readFile", then
|
||||
// this is equivalent to the JS code:
|
||||
|
|
Загрузка…
Ссылка в новой задаче