Bug 989373, part 5 - Eliminate |function| from subscript loader. r=kmag
authorAndrew McCreight <continuation@gmail.com>
Wed, 17 May 2017 09:21:54 -0700
changeset 359836 60a6e210bb3b8e3e09d6807d727ad63cd5b12901
parent 359835 d76a99d0f147a39e07083dc2b9e654a61dd0b276
child 359837 67231a14bdc916eb8a0b673e0eeb34ada188a3dc
push id31859
push userihsiao@mozilla.com
push dateMon, 22 May 2017 03:28:26 +0000
treeherdermozilla-central@367944041b55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs989373
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 989373, part 5 - Eliminate |function| from subscript loader. r=kmag Thanks to the previous patch, we never set any of the function arguments, so they can be removed, and various code for running functions can be deleted. MozReview-Commit-ID: BTIIyDtBPMR
js/xpconnect/loader/mozJSSubScriptLoader.cpp
js/xpconnect/loader/mozJSSubScriptLoader.h
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -128,18 +128,17 @@ static bool
 PrepareScript(nsIURI* uri,
               JSContext* cx,
               HandleObject targetObj,
               const char* uriStr,
               const nsAString& charset,
               const char* buf,
               int64_t len,
               bool wantReturnValue,
-              MutableHandleScript script,
-              MutableHandleFunction function)
+              MutableHandleScript script)
 {
     JS::CompileOptions options(cx);
     options.setFileAndLine(uriStr, 1)
            .setVersion(JSVERSION_LATEST)
            .setNoScriptRval(!wantReturnValue);
     if (!charset.IsVoid()) {
         char16_t* scriptBuf = nullptr;
         size_t scriptLength = 0;
@@ -172,40 +171,29 @@ PrepareScript(nsIURI* uri,
 
 static bool
 EvalScript(JSContext* cx,
            HandleObject targetObj,
            MutableHandleValue retval,
            nsIURI* uri,
            bool startupCache,
            bool preloadCache,
-           MutableHandleScript script,
-           HandleFunction function)
+           MutableHandleScript script)
 {
-    if (function) {
-        script.set(JS_GetFunctionScript(cx, function));
-    }
-
-    if (function) {
-        if (!JS_CallFunction(cx, targetObj, function, JS::HandleValueArray::empty(), retval)) {
+    if (JS_IsGlobalObject(targetObj)) {
+        if (!JS::CloneAndExecuteScript(cx, script, retval)) {
             return false;
         }
     } else {
-        if (JS_IsGlobalObject(targetObj)) {
-            if (!JS::CloneAndExecuteScript(cx, script, retval)) {
-                return false;
-            }
-        } else {
-            JS::AutoObjectVector envChain(cx);
-            if (!envChain.append(targetObj)) {
-                return false;
-            }
-            if (!JS::CloneAndExecuteScript(cx, envChain, script, retval)) {
-                return false;
-            }
+        JS::AutoObjectVector envChain(cx);
+        if (!envChain.append(targetObj)) {
+            return false;
+        }
+        if (!JS::CloneAndExecuteScript(cx, envChain, script, retval)) {
+            return false;
         }
     }
 
     JSAutoCompartment rac(cx, targetObj);
     if (!JS_WrapValue(cx, retval)) {
         return false;
     }
 
@@ -368,35 +356,34 @@ AsyncScriptLoader::OnStreamComplete(nsII
         return NS_OK;
     }
 
     if (aLength > INT32_MAX) {
         ReportError(cx, LOAD_ERROR_CONTENTTOOBIG, uri);
         return NS_OK;
     }
 
-    RootedFunction function(cx);
     RootedScript script(cx);
     nsAutoCString spec;
     nsresult rv = uri->GetSpec(spec);
     NS_ENSURE_SUCCESS(rv, rv);
 
     RootedObject targetObj(cx, mTargetObj);
 
     if (!PrepareScript(uri, cx, targetObj, spec.get(), mCharset,
                        reinterpret_cast<const char*>(aBuf), aLength,
-                       mWantReturnValue, &script, &function))
+                       mWantReturnValue, &script))
     {
         return NS_OK;
     }
 
     JS::Rooted<JS::Value> retval(cx);
     if (EvalScript(cx, targetObj, &retval, uri, mCache,
                    mCache && !mWantReturnValue,
-                   &script, function)) {
+                   &script)) {
         autoPromise.ResolvePromise(retval);
     }
 
     return NS_OK;
 }
 
 nsresult
 mozJSSubScriptLoader::ReadScriptAsync(nsIURI* uri,
@@ -462,21 +449,19 @@ mozJSSubScriptLoader::ReadScriptAsync(ns
 bool
 mozJSSubScriptLoader::ReadScript(nsIURI* uri,
                                  JSContext* cx,
                                  HandleObject targetObj,
                                  const nsAString& charset,
                                  const char* uriStr,
                                  nsIIOService* serv,
                                  bool wantReturnValue,
-                                 MutableHandleScript script,
-                                 MutableHandleFunction function)
+                                 MutableHandleScript script)
 {
     script.set(nullptr);
-    function.set(nullptr);
 
     // We create a channel and call SetContentType, to avoid expensive MIME type
     // lookups (bug 632490).
     nsCOMPtr<nsIChannel> chan;
     nsCOMPtr<nsIInputStream> instream;
     nsresult rv;
     rv = NS_NewChannel(getter_AddRefs(chan),
                        uri,
@@ -512,17 +497,17 @@ mozJSSubScriptLoader::ReadScript(nsIURI*
     }
 
     nsCString buf;
     rv = NS_ReadInputStreamToString(instream, buf, len);
     NS_ENSURE_SUCCESS(rv, false);
 
     return PrepareScript(uri, cx, targetObj, uriStr, charset,
                          buf.get(), len, wantReturnValue,
-                         script, function);
+                         script);
 }
 
 NS_IMETHODIMP
 mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
                                     HandleValue target,
                                     const nsAString& charset,
                                     JSContext* cx,
                                     MutableHandleValue retval)
@@ -662,17 +647,16 @@ mozJSSubScriptLoader::DoLoadSubScriptWit
         uriStr = tmp;
     }
 
     JSVersion version = JS_GetVersion(cx);
     nsAutoCString cachePath;
     cachePath.AppendPrintf("jssubloader/%d", version);
     PathifyURI(uri, cachePath);
 
-    RootedFunction function(cx);
     RootedScript script(cx);
     if (!options.ignoreCache) {
         if (!options.wantReturnValue)
             script = ScriptPreloader::GetSingleton().GetCachedScript(cx, cachePath);
         if (!script && cache)
             rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
         if (NS_FAILED(rv) || !script) {
             // ReadCachedScript may have set a pending exception.
@@ -686,25 +670,24 @@ mozJSSubScriptLoader::DoLoadSubScriptWit
                                options.wantReturnValue, !!cache, retval);
     }
 
     if (script) {
         // |script| came from the cache, so don't bother writing it
         // |back there.
         cache = nullptr;
     } else if (!ReadScript(uri, cx, targetObj, options.charset,
-                           static_cast<const char*>(uriStr.get()), serv,
-                           options.wantReturnValue, &script,
-                           &function)) {
+                        static_cast<const char*>(uriStr.get()), serv,
+                        options.wantReturnValue, &script)) {
         return NS_OK;
     }
 
     Unused << EvalScript(cx, targetObj, retval, uri, !!cache,
                          !ignoreCache && !options.wantReturnValue,
-                         &script, function);
+                         &script);
     return NS_OK;
 }
 
 /**
   * Let us compile scripts from a URI off the main thread.
   */
 
 class ScriptPrecompiler : public nsIIncrementalStreamLoaderObserver
--- a/js/xpconnect/loader/mozJSSubScriptLoader.h
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.h
@@ -32,18 +32,17 @@ public:
 
 private:
     virtual ~mozJSSubScriptLoader();
 
     bool ReadScript(nsIURI* uri, JSContext* cx, JS::HandleObject targetObj,
                     const nsAString& charset, const char* uriStr,
                     nsIIOService* serv,
                     bool wantReturnValue,
-                    JS::MutableHandleScript script,
-                    JS::MutableHandleFunction function);
+                    JS::MutableHandleScript script);
 
     nsresult ReadScriptAsync(nsIURI* uri,
                              JS::HandleObject targetObj,
                              const nsAString& charset,
                              nsIIOService* serv,
                              bool wantReturnValue,
                              bool cache,
                              JS::MutableHandleValue retval);