Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.
Depends on D147326
Differential Revision: https://phabricator.services.mozilla.com/D147329
This commit is contained in:
@@ -258,7 +258,12 @@ void LoadAllScripts(WorkerPrivate* aWorkerPrivate,
|
||||
return;
|
||||
}
|
||||
|
||||
loader->CreateScriptRequests(aScriptURLs, aDocumentEncoding, aIsMainScript);
|
||||
bool ok = loader->CreateScriptRequests(aScriptURLs, aDocumentEncoding,
|
||||
aIsMainScript);
|
||||
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (loader->DispatchLoadScripts()) {
|
||||
syncLoop.Run();
|
||||
@@ -427,14 +432,29 @@ void WorkerScriptLoader::InitModuleLoader() {
|
||||
->InitModuleLoader(moduleLoader);
|
||||
}
|
||||
|
||||
void WorkerScriptLoader::CreateScriptRequests(
|
||||
bool WorkerScriptLoader::CreateScriptRequests(
|
||||
const nsTArray<nsString>& aScriptURLs,
|
||||
const mozilla::Encoding* aDocumentEncoding, bool aIsMainScript) {
|
||||
// If a worker has been loaded as a module worker, ImportScripts calls are
|
||||
// disallowed -- then the operation is invalid.
|
||||
//
|
||||
// 10.3.1 Importing scripts and libraries.
|
||||
// Step 1. If worker global scope's type is "module", throw a TypeError
|
||||
// exception.
|
||||
if (!aIsMainScript &&
|
||||
mWorkerRef->Private()->WorkerType() == WorkerType::Module) {
|
||||
mRv.ThrowTypeError(
|
||||
"Using `ImportScripts` inside a Module Worker is "
|
||||
"disallowed.");
|
||||
return false;
|
||||
}
|
||||
for (const nsString& scriptURL : aScriptURLs) {
|
||||
RefPtr<ScriptLoadRequest> request =
|
||||
CreateScriptLoadRequest(scriptURL, aDocumentEncoding, aIsMainScript);
|
||||
mLoadingRequests.AppendElement(request);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
nsTArray<RefPtr<ThreadSafeRequestHandle>> WorkerScriptLoader::GetLoadingList() {
|
||||
|
||||
Reference in New Issue
Block a user