Bug 1367515 - Use ::mozilla::Maybe to de-duplicate the loop of ScriptLoader::GiveUpBytecodeEncoding r=nbp
authorStanley Ye <stanleyye1996@gmail.com>
Tue, 06 Jun 2017 23:49:54 -0700
changeset 362649 3666d91a4263
parent 362648 eb977b3751ca
child 362650 f302f3481aaa
push id91136
push usercbook@mozilla.com
push dateWed, 07 Jun 2017 08:38:58 +0000
treeherdermozilla-inbound@7ad815515bd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1367515
milestone55.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 1367515 - Use ::mozilla::Maybe to de-duplicate the loop of ScriptLoader::GiveUpBytecodeEncoding r=nbp
dom/script/ScriptLoader.cpp
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2294,39 +2294,36 @@ ScriptLoader::EncodeRequestBytecode(JSCo
 void
 ScriptLoader::GiveUpBytecodeEncoding()
 {
   // Ideally we prefer to properly end the incremental encoder, such that we
   // would not keep a large buffer around.  If we cannot, we fallback on the
   // removal of all request from the current list and these large buffers would
   // be removed at the same time as the source object.
   nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
+  Maybe<AutoEntryScript> aes;
+
   if (globalObject) {
     nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext();
     if (context) {
-      AutoEntryScript aes(globalObject, "give-up bytecode encoding", true);
-      JS::RootedScript script(aes.cx());
-      while (!mBytecodeEncodingQueue.isEmpty()) {
-        RefPtr<ScriptLoadRequest> request = mBytecodeEncodingQueue.StealFirst();
-        LOG(("ScriptLoadRequest (%p): Cannot serialize bytecode", request.get()));
-        TRACE_FOR_TEST_NONE(request->mElement, "scriptloader_bytecode_failed");
-        script.set(request->mScript);
-        Unused << JS::FinishIncrementalEncoding(aes.cx(), script,
-                                                request->mScriptBytecode);
-        request->mScriptBytecode.clearAndFree();
-        request->DropBytecodeCacheReferences();
-      }
-      return;
+      aes.emplace(globalObject, "give-up bytecode encoding", true);
     }
   }
 
   while (!mBytecodeEncodingQueue.isEmpty()) {
     RefPtr<ScriptLoadRequest> request = mBytecodeEncodingQueue.StealFirst();
     LOG(("ScriptLoadRequest (%p): Cannot serialize bytecode", request.get()));
     TRACE_FOR_TEST_NONE(request->mElement, "scriptloader_bytecode_failed");
+
+    if (aes.isSome()) {
+      JS::RootedScript script(aes->cx(), request->mScript);
+      Unused << JS::FinishIncrementalEncoding(aes->cx(), script,
+                                              request->mScriptBytecode);
+    }
+
     request->mScriptBytecode.clearAndFree();
     request->DropBytecodeCacheReferences();
   }
 }
 
 bool
 ScriptLoader::HasPendingRequests()
 {