diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index e5f0744c2..d19ea5224 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -12881,10 +12881,11 @@ nsGlobalWindow::RunTimeoutHandler(Timeout* aTimeout, nsJSUtils::ExecutionContext exec(aes.cx(), global); rv = exec.Compile(options, handler->GetHandlerText()); - if (rv == NS_OK) { + JS::Rooted script(aes.cx(), exec.GetScript()); + if (script) { LoadedScript* initiatingScript = handler->GetInitiatingScript(); if (initiatingScript) { - initiatingScript->AssociateWithScript(exec.GetScript()); + initiatingScript->AssociateWithScript(script); } rv = exec.ExecScript(); diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 8d2d0b37d..a7e3073c9 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -315,8 +315,11 @@ nsJSUtils::ExecutionContext::JoinDecode(void **aOffThreadToken) } JSScript* nsJSUtils::ExecutionContext::GetScript() { + if (mSkip) { + return nullptr; + } + #ifdef DEBUG - MOZ_ASSERT(!mSkip); MOZ_ASSERT(mScript); mScriptUsed = true; #endif diff --git a/dom/base/nsJSUtils.h b/dom/base/nsJSUtils.h index c36290f90..c7d4f291c 100644 --- a/dom/base/nsJSUtils.h +++ b/dom/base/nsJSUtils.h @@ -164,7 +164,10 @@ public: // thread. nsresult JoinDecode(void** aOffThreadToken); - // Get a successfully compiled script. + // Get the compiled script if present, or nullptr. + // + // Compilation may succeed without producing a script when scripting is disabled for the global. Causes for this can + // be the global pref or dynamic change when script execution in a global is terminated due to max_script_run_time. JSScript* GetScript(); // Execute the compiled script and ignore the return value. diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 96f9cdda5..607b21865 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2396,10 +2396,7 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) rv = exec.Compile(options, srcBuf); } if (rv == NS_OK) { - JS::Rooted script(cx); - script = exec.GetScript(); - - // With scripts disabled GetScript() will return nullptr + JS::Rooted script(cx, exec.GetScript()); if (script) { // Create a ClassicScript object and associate it with the // JSScript.