Bug 1342012 - Also associate classic scripts from the bytecode cache r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 03 Jan 2019 10:06:00 +0000
changeset 509510 34e605a49937a1a2e844bd1970229062727c8eed
parent 509509 c89629ed81defdd8968b1dd3cfd50c1bcd7eea24
child 509511 43a79c5e38f4da161cebfdda8572a2c796b3959d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1342012
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 1342012 - Also associate classic scripts from the bytecode cache r=smaug
dom/script/ScriptLoader.cpp
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2435,16 +2435,29 @@ class MOZ_RAII AutoSetProcessingScriptTa
   explicit AutoSetProcessingScriptTag(nsIScriptContext* aContext)
       : mContext(aContext), mOldTag(mContext->GetProcessingScriptTag()) {
     mContext->SetProcessingScriptTag(true);
   }
 
   ~AutoSetProcessingScriptTag() { mContext->SetProcessingScriptTag(mOldTag); }
 };
 
+static nsresult ExecuteCompiledScript(JSContext* aCx,
+                                      ScriptLoadRequest* aRequest,
+                                      nsJSUtils::ExecutionContext& aExec) {
+  JS::Rooted<JSScript*> script(aCx, aExec.GetScript());
+
+  // Create a ClassicScript object and associate it with the JSScript.
+  RefPtr<ClassicScript> classicScript = new ClassicScript(
+    aRequest->mFetchOptions, aRequest->mBaseURL);
+  classicScript->AssociateWithScript(script);
+
+  return aExec.ExecScript();
+}
+
 nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
   using namespace mozilla::Telemetry;
   MOZ_ASSERT(aRequest->IsReadyToRun());
 
   // We need a document to evaluate scripts.
   if (!mDocument) {
     return NS_ERROR_FAILURE;
   }
@@ -2543,24 +2556,28 @@ nsresult ScriptLoader::EvaluateScript(Sc
 
       if (NS_SUCCEEDED(rv)) {
         if (aRequest->IsBytecode()) {
           TRACE_FOR_TEST(aRequest->Element(), "scriptloader_execute");
           nsJSUtils::ExecutionContext exec(cx, global);
           if (aRequest->mOffThreadToken) {
             LOG(("ScriptLoadRequest (%p): Decode Bytecode & Join and Execute",
                  aRequest));
-            exec.JoinDecode(&aRequest->mOffThreadToken);
+            rv = exec.JoinDecode(&aRequest->mOffThreadToken);
           } else {
             LOG(("ScriptLoadRequest (%p): Decode Bytecode and Execute",
                  aRequest));
-            exec.Decode(options, aRequest->mScriptBytecode,
-                        aRequest->mBytecodeOffset);
+            rv = exec.Decode(options, aRequest->mScriptBytecode,
+                             aRequest->mBytecodeOffset);
           }
-          rv = exec.ExecScript();
+
+          if (rv == NS_OK) {
+            rv = ExecuteCompiledScript(cx, aRequest, exec);
+          }
+
           // We do not expect to be saving anything when we already have some
           // bytecode.
           MOZ_ASSERT(!aRequest->mCacheInfo);
         } else {
           MOZ_ASSERT(aRequest->IsSource());
           JS::Rooted<JSScript*> script(cx);
           bool encodeBytecode = ShouldCacheBytecode(aRequest);
 
@@ -2596,24 +2613,17 @@ nsresult ScriptLoader::EvaluateScript(Sc
                 } else {
                   rv = NS_ERROR_OUT_OF_MEMORY;
                 }
               }
             }
 
             if (rv == NS_OK) {
               script = exec.GetScript();
-
-              // Create a ClassicScript object and associate it with the
-              // JSScript.
-              RefPtr<ClassicScript> classicScript = new ClassicScript(
-                  aRequest->mFetchOptions, aRequest->mBaseURL);
-              classicScript->AssociateWithScript(script);
-
-              rv = exec.ExecScript();
+              rv = ExecuteCompiledScript(cx, aRequest, exec);
             }
           }
 
           // Queue the current script load request to later save the bytecode.
           if (script && encodeBytecode) {
             aRequest->SetScript(script);
             TRACE_FOR_TEST(aRequest->Element(), "scriptloader_encode");
             MOZ_ASSERT(aRequest->mBytecodeOffset ==