Bug 1361900: Part 7 - Use the script preloader in content processes in subscript and component loaders. r?mccr8 draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 30 Apr 2017 21:53:49 -0700
changeset 577044 995219df7ebf66f3c34f3332ec4e35c846812df2
parent 577043 0e803b6361f6cd87ef1d8ba41d7eae82919f18b2
child 577045 d4845037b2c404574c4892420655fc88b47d1091
push id58588
push usermaglione.k@gmail.com
push dateFri, 12 May 2017 19:00:00 +0000
reviewersmccr8
bugs1361900
milestone55.0a1
Bug 1361900: Part 7 - Use the script preloader in content processes in subscript and component loaders. r?mccr8 MozReview-Commit-ID: 4b5XwORYlAz
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/loader/mozJSSubScriptLoader.cpp
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -678,38 +678,36 @@ mozJSComponentLoader::ObjectForLocation(
 
     bool writeToCache = false;
     StartupCache* cache = StartupCache::GetSingleton();
 
     nsAutoCString cachePath(kJSCachePrefix);
     rv = PathifyURI(aInfo.URI(), cachePath);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (cache) {
-        if (!mReuseLoaderGlobal) {
-            script = ScriptPreloader::GetSingleton().GetCachedScript(cx, cachePath);
-            if (!script) {
-                rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
-            }
-        } else {
-            rv = ReadCachedFunction(cache, cachePath, cx, mSystemPrincipal,
-                                    function.address());
+    if (!mReuseLoaderGlobal) {
+        script = ScriptPreloader::GetSingleton().GetCachedScript(cx, cachePath);
+        if (!script && cache) {
+            ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
         }
+    } else if (cache) {
+        ReadCachedFunction(cache, cachePath, cx, mSystemPrincipal,
+                           function.address());
+    }
 
-        if (NS_SUCCEEDED(rv)) {
-            LOG(("Successfully loaded %s from startupcache\n", nativePath.get()));
-        } else {
-            // This is ok, it just means the script is not yet in the
-            // cache. Could mean that the cache was corrupted and got removed,
-            // but either way we're going to write this out.
-            writeToCache = true;
-            // ReadCachedScript and ReadCachedFunction may have set a pending
-            // exception.
-            JS_ClearPendingException(cx);
-        }
+    if (script || function) {
+        LOG(("Successfully loaded %s from startupcache\n", nativePath.get()));
+    } else if (cache) {
+        // This is ok, it just means the script is not yet in the
+        // cache. Could mean that the cache was corrupted and got removed,
+        // but either way we're going to write this out.
+        writeToCache = true;
+        // ReadCachedScript and ReadCachedFunction may have set a pending
+        // exception.
+        JS_ClearPendingException(cx);
     }
 
     if (!script && !function) {
         // The script wasn't in the cache , so compile it now.
         LOG(("Slow loading %s\n", nativePath.get()));
 
         // Use lazy source if both of these conditions hold:
         //
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -692,20 +692,20 @@ mozJSSubScriptLoader::DoLoadSubScriptWit
 
     JSVersion version = JS_GetVersion(cx);
     nsAutoCString cachePath;
     cachePath.AppendPrintf("jssubloader/%d", version);
     PathifyURI(uri, cachePath);
 
     RootedFunction function(cx);
     RootedScript script(cx);
-    if (cache && !options.ignoreCache) {
+    if (!options.ignoreCache) {
         if (!options.wantReturnValue)
             script = ScriptPreloader::GetSingleton().GetCachedScript(cx, cachePath);
-        if (!script)
+        if (!script && cache)
             rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
         if (NS_FAILED(rv) || !script) {
             // ReadCachedScript may have set a pending exception.
             JS_ClearPendingException(cx);
         }
     }
 
     // If we are doing an async load, trigger it and bail out.