forked from mirrors/gecko-dev
Bug 1881564 - Initialize module loader also for ServiceWorker to allow ChromeUtils.importESModule in DevTools ServiceWorker debugger global. r=yulia
Dynamic import is prevented by IsDynamicImportSupported, and now it now throws TypeError instead of Error, and related wpt passes with it. Differential Revision: https://phabricator.services.mozilla.com/D202494
This commit is contained in:
parent
763685f55f
commit
5f7c671736
7 changed files with 20 additions and 17 deletions
|
|
@ -517,9 +517,7 @@ already_AddRefed<WorkerScriptLoader> WorkerScriptLoader::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the module loader, if it has not been initialzied yet.
|
// Set up the module loader, if it has not been initialzied yet.
|
||||||
if (!aWorkerPrivate->IsServiceWorker()) {
|
self->InitModuleLoader();
|
||||||
self->InitModuleLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.forget();
|
return self.forget();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,15 @@ already_AddRefed<ModuleLoadRequest> WorkerModuleLoader::CreateDynamicImport(
|
||||||
return request.forget();
|
return request.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WorkerModuleLoader::IsDynamicImportSupported() {
|
||||||
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
|
if (workerPrivate->IsServiceWorker()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool WorkerModuleLoader::CanStartLoad(ModuleLoadRequest* aRequest,
|
bool WorkerModuleLoader::CanStartLoad(ModuleLoadRequest* aRequest,
|
||||||
nsresult* aRvOut) {
|
nsresult* aRvOut) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ class WorkerModuleLoader : public JS::loader::ModuleLoaderBase {
|
||||||
JS::Handle<JSString*> aSpecifier,
|
JS::Handle<JSString*> aSpecifier,
|
||||||
JS::Handle<JSObject*> aPromise) override;
|
JS::Handle<JSObject*> aPromise) override;
|
||||||
|
|
||||||
|
bool IsDynamicImportSupported() override;
|
||||||
|
|
||||||
bool CanStartLoad(ModuleLoadRequest* aRequest, nsresult* aRvOut) override;
|
bool CanStartLoad(ModuleLoadRequest* aRequest, nsresult* aRvOut) override;
|
||||||
|
|
||||||
// StartFetch is special for worker modules, as we need to move back to the
|
// StartFetch is special for worker modules, as we need to move back to the
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,12 @@ bool ModuleLoaderBase::HostImportModuleDynamically(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!loader->IsDynamicImportSupported()) {
|
||||||
|
JS_ReportErrorNumberASCII(aCx, js::GetErrorMessage, nullptr,
|
||||||
|
JSMSG_DYNAMIC_IMPORT_NOT_SUPPORTED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto result = loader->ResolveModuleSpecifier(script, specifier);
|
auto result = loader->ResolveModuleSpecifier(script, specifier);
|
||||||
if (result.isErr()) {
|
if (result.isErr()) {
|
||||||
JS::Rooted<JS::Value> error(aCx);
|
JS::Rooted<JS::Value> error(aCx);
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,8 @@ class ModuleLoaderBase : public nsISupports {
|
||||||
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript,
|
||||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) = 0;
|
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise) = 0;
|
||||||
|
|
||||||
|
virtual bool IsDynamicImportSupported() { return true; }
|
||||||
|
|
||||||
// Called when dynamic import started successfully.
|
// Called when dynamic import started successfully.
|
||||||
virtual void OnDynamicImportStarted(ModuleLoadRequest* aRequest) {}
|
virtual void OnDynamicImportStarted(ModuleLoadRequest* aRequest) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
[serviceworker.any.serviceworker.html]
|
|
||||||
[import() should not drain the microtask queue if it fails because it's used in a ServiceWorker]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
[no-dynamic-import.any.serviceworker.html]
|
|
||||||
expected:
|
|
||||||
if (os == "android") and fission: [OK, TIMEOUT]
|
|
||||||
[Module URL]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Another module URL]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Module data: URL]
|
|
||||||
expected: FAIL
|
|
||||||
Loading…
Reference in a new issue