Bug 901162 - Inline ExecuteScript in the one caller. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Thu, 08 Aug 2013 16:51:34 -0700
changeset 141973 5ede20316d320042a4185a52fdbd2753bec9a336
parent 141972 a429d61544af5d00880a807966f097a62afffeec
child 141974 dacad5a4081141b0de7f63af3cd0799bbb7985c2
push id25076
push userryanvm@gmail.com
push dateFri, 09 Aug 2013 23:09:21 +0000
treeherdermozilla-central@cead6eb63964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs901162
milestone26.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 901162 - Inline ExecuteScript in the one caller. r=bz
content/xul/document/src/XULDocument.cpp
dom/base/nsIScriptContext.h
dom/base/nsJSEnvironment.cpp
dom/base/nsJSEnvironment.h
--- a/content/xul/document/src/XULDocument.cpp
+++ b/content/xul/document/src/XULDocument.cpp
@@ -86,16 +86,17 @@
 #include "nsXULPopupManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsURILoader.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ProcessingInstruction.h"
 #include "mozilla/dom/XULDocumentBinding.h"
 #include "mozilla/Preferences.h"
 #include "nsTextNode.h"
+#include "nsJSUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 //----------------------------------------------------------------------
 //
 // CIDs
 //
@@ -3633,19 +3634,32 @@ XULDocument::ExecuteScript(nsIScriptCont
                            JS::Handle<JSScript*> aScriptObject)
 {
     NS_PRECONDITION(aScriptObject != nullptr && aContext != nullptr, "null ptr");
     if (! aScriptObject || ! aContext)
         return NS_ERROR_NULL_POINTER;
 
     NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED);
 
+    if (!aContext->GetScriptsEnabled())
+        return NS_OK;
+
     // Execute the precompiled script with the given version
+    nsAutoMicroTask mt;
+    JSContext *cx = aContext->GetNativeContext();
+    AutoCxPusher pusher(cx);
     JSObject* global = mScriptGlobalObject->GetGlobalJSObject();
-    return aContext->ExecuteScript(aScriptObject, global);
+    xpc_UnmarkGrayObject(global);
+    xpc_UnmarkGrayScript(aScriptObject);
+    JSAutoCompartment ac(cx, global);
+    JS::Rooted<JS::Value> unused(cx);
+    if (!JS_ExecuteScript(cx, global, aScriptObject, unused.address()))
+        nsJSUtils::ReportPendingException(cx);
+    aContext->ScriptEvaluated(true);
+    return NS_OK;
 }
 
 nsresult
 XULDocument::ExecuteScript(nsXULPrototypeScript *aScript)
 {
     NS_PRECONDITION(aScript != nullptr, "null ptr");
     NS_ENSURE_TRUE(aScript, NS_ERROR_NULL_POINTER);
     NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED);
--- a/dom/base/nsIScriptContext.h
+++ b/dom/base/nsIScriptContext.h
@@ -60,33 +60,16 @@ public:
    */
   virtual nsresult EvaluateString(const nsAString& aScript,
                                   JS::Handle<JSObject*> aScopeObject,
                                   JS::CompileOptions& aOptions,
                                   bool aCoerceToString,
                                   JS::Value* aRetValue) = 0;
 
   /**
-   * Execute a precompiled script object.
-   *
-   * @param aScriptObject an object representing the script to be executed
-   * @param aScopeObject an object telling the scope in which to execute,
-   *                     or nullptr to use a default scope
-   * @param aRetValue the result of executing the script, may be null in
-   *                  which case no result string is computed
-   * @param aIsUndefined true if the result of executing the script is the
-   *                     undefined value, may be null for "don't care"
-   *
-   * @return NS_OK if the script was valid and got executed
-   *
-   */
-  virtual nsresult ExecuteScript(JSScript* aScriptObject,
-                                 JSObject* aScopeObject) = 0;
-
-  /**
    * Bind an already-compiled event handler function to the given
    * target.  Scripting languages with static scoping must re-bind the
    * scope chain for aHandler to begin (after the activation scope for
    * aHandler itself, typically) with aTarget's scope.
    *
    * The result of the bind operation is a new handler object, with
    * principals now set and scope set as above.  This is returned in
    * aBoundHandler.  When this function is called, aBoundHandler is
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -1253,67 +1253,16 @@ nsJSContext::EvaluateString(const nsAStr
                                    aOptions, aCoerceToString, aRetValue);
   }
 
   // ScriptEvaluated needs to come after we pop the stack
   ScriptEvaluated(true);
   return rv;
 }
 
-nsresult
-nsJSContext::ExecuteScript(JSScript* aScriptObject_,
-                           JSObject* aScopeObject_)
-{
-  JSAutoRequest ar(mContext);
-  JS::Rooted<JSObject*> aScopeObject(mContext, aScopeObject_);
-  JS::Rooted<JSScript*> aScriptObject(mContext, aScriptObject_);
-  NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
-
-  if (!mScriptsEnabled) {
-    return NS_OK;
-  }
-
-  nsAutoMicroTask mt;
-
-  if (!aScopeObject) {
-    aScopeObject = GetNativeGlobal();
-  }
-
-  xpc_UnmarkGrayScript(aScriptObject);
-  xpc_UnmarkGrayObject(aScopeObject);
-
-  // Push our JSContext on our thread's context stack, in case native code
-  // called from JS calls back into JS via XPConnect.
-  nsCxPusher pusher;
-  pusher.Push(mContext);
-
-  // Scope the JSAutoCompartment so that it gets destroyed before we pop the
-  // cx and potentially call JS_RestoreFrameChain.
-  {
-    JSAutoCompartment ac(mContext, aScopeObject);
-
-    // The result of evaluation, used only if there were no errors. This need
-    // not be a GC root currently, provided we run the GC only from the
-    // operation callback or from ScriptEvaluated.
-    JS::Rooted<JS::Value> val(mContext);
-    if (!JS_ExecuteScript(mContext, aScopeObject, aScriptObject, val.address())) {
-      ReportPendingException();
-    }
-  }
-
-  // Pop here, after JS_ValueToString and any other possible evaluation.
-  pusher.Pop();
-
-  // ScriptEvaluated needs to come after we pop the stack
-  ScriptEvaluated(true);
-
-  return NS_OK;
-}
-
-
 #ifdef DEBUG
 bool
 AtomIsEventHandlerName(nsIAtom *aName)
 {
   const PRUnichar *name = aName->GetUTF16String();
 
   const PRUnichar *cp;
   PRUnichar c;
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -45,19 +45,16 @@ public:
                                                          nsIScriptContext)
 
   virtual nsresult EvaluateString(const nsAString& aScript,
                                   JS::Handle<JSObject*> aScopeObject,
                                   JS::CompileOptions &aOptions,
                                   bool aCoerceToString,
                                   JS::Value* aRetValue) MOZ_OVERRIDE;
 
-  virtual nsresult ExecuteScript(JSScript* aScriptObject,
-                                 JSObject* aScopeObject) MOZ_OVERRIDE;
-
   virtual nsresult BindCompiledEventHandler(nsISupports *aTarget,
                                             JS::Handle<JSObject*> aScope,
                                             JS::Handle<JSObject*> aHandler,
                                             JS::MutableHandle<JSObject*> aBoundHandler) MOZ_OVERRIDE;
 
   virtual nsIScriptGlobalObject *GetGlobalObject() MOZ_OVERRIDE;
   inline nsIScriptGlobalObject *GetGlobalObjectRef() { return mGlobalObjectRef; }