Bug 1311726 - Only set "ProcessingScript" tag when executing; r=jonco

Previously, we were setting the ProcessingScriptTag for Module compilation as well as script
execution. This patch creates a helper function (GetGlobalWithContext) and removes a superfluous
setting of the "ProcessingScriptTag".

ProcessingScriptTag should be set when a script is executing, as it helps correct our behavior
around history replacement during JS execution: https://searchfox.org/mozilla-central/rev/e9cd2997be1071b9bb76fc14df0f01a2bd721c30/dom/base/LocationBase.cpp#223-231

Differential Revision: https://phabricator.services.mozilla.com/D132603
This commit is contained in:
Yulia Startsev
2021-12-08 16:57:15 +00:00
parent 29155c707c
commit 226b73f68a

View File

@@ -622,23 +622,9 @@ nsresult ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest) {
LOG(("ScriptLoadRequest (%p): Create module script", aRequest));
nsCOMPtr<nsIGlobalObject> globalObject;
nsCOMPtr<nsIScriptContext> context;
if (aRequest->GetWebExtGlobal()) {
globalObject = aRequest->GetWebExtGlobal();
} else {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal =
GetScriptGlobalObject(WebExtGlobal::Handled);
if (!scriptGlobal) {
return NS_ERROR_FAILURE;
}
context = scriptGlobal->GetScriptContext();
if (!context) {
return NS_ERROR_FAILURE;
}
globalObject = scriptGlobal;
nsCOMPtr<nsIGlobalObject> globalObject = GetGlobalForRequest(aRequest);
if (!globalObject) {
return NS_ERROR_FAILURE;
}
nsAutoMicroTask mt;
@@ -647,12 +633,6 @@ nsresult ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest) {
AutoEntryScript aes(globalObject, "CompileModule", true);
bool oldProcessingScriptTag = false;
if (context) {
oldProcessingScriptTag = context->GetProcessingScriptTag();
context->SetProcessingScriptTag(true);
}
nsresult rv;
{
JSContext* cx = aes.cx();
@@ -728,10 +708,6 @@ nsresult ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest) {
}
}
if (context) {
context->SetProcessingScriptTag(oldProcessingScriptTag);
}
LOG(("ScriptLoadRequest (%p): module script == %p", aRequest,
aRequest->mModuleScript.get()));