Bug 1361900: Part 7 - Use the script preloader in content processes in subscript and component loaders. r?mccr8
MozReview-Commit-ID: 4b5XwORYlAz
--- 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.