Bug 1518075 - Add another check for null script because compilation can 'succeed' if scripting is disabled r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 21 Jan 2019 12:40:55 +0000
changeset 514710 d323b050b0ce2ae624fc09e8f7d204c5016d3f9e
parent 514709 48810cb8ba3fb643308bbf2c5400e1b42042ca45
child 514711 2668f097f56dff2258bfc62de51715d3627ae4d2
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1518075
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518075 - Add another check for null script because compilation can 'succeed' if scripting is disabled r=smaug
dom/base/nsGlobalWindowInner.cpp
dom/base/nsJSUtils.cpp
dom/base/nsJSUtils.h
dom/script/ScriptLoader.cpp
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -6001,20 +6001,21 @@ bool nsGlobalWindowInner::RunTimeoutHand
       options.setFileAndLine(filename, lineNo);
       options.setNoScriptRval(true);
       JS::Rooted<JSObject*> global(aes.cx(), FastGetGlobalJSObject());
       nsresult rv;
       {
         nsJSUtils::ExecutionContext exec(aes.cx(), global);
         rv = exec.Compile(options, handler->GetHandlerText());
 
-        if (rv == NS_OK) {
+        JSScript* script = exec.MaybeGetScript();
+        if (script) {
           LoadedScript* initiatingScript = handler->GetInitiatingScript();
           if (initiatingScript) {
-            initiatingScript->AssociateWithScript(exec.GetScript());
+            initiatingScript->AssociateWithScript(script);
           }
 
           rv = exec.ExecScript();
         }
       }
 
       if (rv == NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW_UNCATCHABLE) {
         abortIntervalHandler = true;
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -369,16 +369,20 @@ nsresult nsJSUtils::ExecutionContext::De
 
 JSScript* nsJSUtils::ExecutionContext::GetScript() {
 #ifdef DEBUG
   MOZ_ASSERT(!mSkip);
   MOZ_ASSERT(mScript);
   mScriptUsed = true;
 #endif
 
+  return MaybeGetScript();
+}
+
+JSScript* nsJSUtils::ExecutionContext::MaybeGetScript() {
   return mScript;
 }
 
 nsresult nsJSUtils::ExecutionContext::ExecScript() {
   if (mSkip) {
     return mRv;
   }
 
--- a/dom/base/nsJSUtils.h
+++ b/dom/base/nsJSUtils.h
@@ -170,16 +170,19 @@ class nsJSUtils {
 
     // Decode a BinAST encoded script contained in a buffer.
     nsresult DecodeBinAST(JS::CompileOptions& aCompileOptions,
                           const uint8_t* aBuf, size_t aLength);
 
     // Get a successfully compiled script.
     JSScript* GetScript();
 
+    // Get the compiled script if present, or nullptr.
+    JSScript* MaybeGetScript();
+
     // Execute the compiled script and ignore the return value.
     MOZ_MUST_USE nsresult ExecScript();
 
     // Execute the compiled script a get the return value.
     //
     // Copy the returned value into the mutable handle argument. In case of a
     // evaluation failure either during the execution or the conversion of the
     // result to a string, the nsresult is be set to the corresponding result
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2440,17 +2440,17 @@ class MOZ_RAII AutoSetProcessingScriptTa
   }
 
   ~AutoSetProcessingScriptTag() { mContext->SetProcessingScriptTag(mOldTag); }
 };
 
 static nsresult ExecuteCompiledScript(JSContext* aCx,
                                       ScriptLoadRequest* aRequest,
                                       nsJSUtils::ExecutionContext& aExec) {
-  JS::Rooted<JSScript*> script(aCx, aExec.GetScript());
+  JS::Rooted<JSScript*> script(aCx, aExec.MaybeGetScript());
   if (!script) {
     // Compilation succeeds without producing a script if scripting is
     // disabled for the global.
     return NS_OK;
   }
 
   // Create a ClassicScript object and associate it with the JSScript.
   RefPtr<ClassicScript> classicScript =