diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3c960ae005..30554486e5 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -12941,10 +12941,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 43efe6f4e3..5182886256 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 db70cd924d..3445e1fd71 100644 --- a/dom/base/nsJSUtils.h +++ b/dom/base/nsJSUtils.h @@ -163,7 +163,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 01b03c3f27..0780601767 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2377,10 +2377,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.