Bug 1812628 - put worker modules behind a flag; r=jonco

Differential Revision: https://phabricator.services.mozilla.com/D168129
This commit is contained in:
Yulia Startsev
2023-02-01 15:30:15 +00:00
parent 3502913cd7
commit fa1b00145f
2 changed files with 25 additions and 1 deletions

View File

@@ -155,6 +155,7 @@ nsresult ChannelFromScriptURL(
// We must have a loadGroup with a load context for the principal to
// traverse the channel correctly.
MOZ_ASSERT(loadGroup);
MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(loadGroup, principal));
@@ -234,7 +235,12 @@ void LoadAllScripts(WorkerPrivate* aWorkerPrivate,
return;
}
if (aIsMainScript) {
if (aWorkerPrivate->WorkerType() == WorkerType::Module) {
if (!StaticPrefs::dom_workers_modules_enabled()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
MOZ_ASSERT(aIsMainScript);
// Module Load
RefPtr<JS::loader::ScriptLoadRequest> mainScript = loader->GetMainScript();
if (mainScript && mainScript->IsModuleRequest()) {
@@ -245,6 +251,7 @@ void LoadAllScripts(WorkerPrivate* aWorkerPrivate,
return;
}
}
if (loader->DispatchLoadScripts()) {
syncLoop.Run();
}
@@ -485,6 +492,10 @@ WorkerScriptLoader::WorkerScriptLoader(
mController = global->GetController();
// Set up the module loader, if it has not been yet.
// TODO: Implement this for classic scripts when dynamic imports are added.
if (!StaticPrefs::dom_workers_modules_enabled()) {
return;
}
if (aWorkerPrivate->WorkerType() == WorkerType::Module) {
InitModuleLoader();
}
@@ -533,6 +544,9 @@ bool WorkerScriptLoader::CreateScriptRequests(
for (const nsString& scriptURL : aScriptURLs) {
RefPtr<ScriptLoadRequest> request =
CreateScriptLoadRequest(scriptURL, aDocumentEncoding, aIsMainScript);
if (!request) {
return false;
}
mLoadingRequests.AppendElement(request);
}
@@ -618,6 +632,10 @@ already_AddRefed<ScriptLoadRequest> WorkerScriptLoader::CreateScriptLoadRequest(
// implementation, so we are defaulting the fetchOptions object defined
// above. This behavior is handled fully in GetModuleSecFlags.
if (!StaticPrefs::dom_workers_modules_enabled()) {
mRv.ThrowTypeError("Modules in workers are currently disallowed.");
return nullptr;
}
RefPtr<WorkerModuleLoader::ModuleLoaderBase> moduleLoader =
GetGlobal()->GetModuleLoader(nullptr);