Bug 824864 - Remove nsIScriptContext::EvaluateString. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 16 Jan 2013 18:50:26 -0800
changeset 128982 22dc6532b40b06d9921dc4b366a0212838376b90
parent 128981 3cb7ad47f6d9409a343a18548bdecd966afb5218
child 128983 badfbc904df619eb05a11de038eed1c9975ee554
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs824864
milestone21.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 824864 - Remove nsIScriptContext::EvaluateString. r=bz
dom/base/nsIScriptContext.h
dom/base/nsJSEnvironment.cpp
dom/base/nsJSEnvironment.h
--- a/dom/base/nsIScriptContext.h
+++ b/dom/base/nsIScriptContext.h
@@ -60,47 +60,16 @@ class nsIScriptContext : public nsIScrip
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
 
   /**
    * Compile and execute a script.
    *
    * @param aScript a string representing the script to be executed
-   * @param aScopeObject a script object for the scope to execute in, or
-   *                     nullptr to use a default scope
-   * @param aPrincipal the principal the script should be evaluated with
-   * @param aOriginPrincipal the principal the script originates from.  If null,
-   *                         aPrincipal is used.
-   * @param aURL the URL or filename for error messages
-   * @param aLineNo the starting line number of the script for error messages
-   * @param aVersion the script language version to use when executing
-   * @param aRetValue the result of executing the script, or null for no result.
-   *        If this is a JS context, it's the caller's responsibility to
-   *        preserve aRetValue from GC across this call
-   * @param aIsUndefined true if the result of executing the script is the
-   *                     undefined value
-   *
-   * @return NS_OK if the script was valid and got executed
-   *
-   **/
-  virtual nsresult EvaluateString(const nsAString& aScript,
-                                  JSObject* aScopeObject,
-                                  nsIPrincipal *aPrincipal,
-                                  nsIPrincipal *aOriginPrincipal,
-                                  const char *aURL,
-                                  uint32_t aLineNo,
-                                  JSVersion aVersion,
-                                  nsAString *aRetValue,
-                                  bool* aIsUndefined) = 0;
-
-  /**
-   * Compile and execute a script.
-   *
-   * @param aScript a string representing the script to be executed
    * @param aScopeObject a script object for the scope to execute in.
    * @param aOptions an options object. You probably want to at least set
    *                 filename and line number. The principal is computed
    *                 internally, though 'originPrincipals' may be passed.
    * @param aCoerceToString if the return value is not JSVAL_VOID, convert it
    *                        to a string before returning.
    * @param aRetValue the result of executing the script.
    **/
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -1369,151 +1369,16 @@ error:
 nsIScriptObjectPrincipal*
 nsJSContext::GetObjectPrincipal()
 {
   nsCOMPtr<nsIScriptObjectPrincipal> prin = do_QueryInterface(GetGlobalObject());
   return prin;
 }
 
 nsresult
-nsJSContext::EvaluateString(const nsAString& aScript,
-                            JSObject* aScopeObject,
-                            nsIPrincipal *aPrincipal,
-                            nsIPrincipal *aOriginPrincipal,
-                            const char *aURL,
-                            uint32_t aLineNo,
-                            JSVersion aVersion,
-                            nsAString *aRetValue,
-                            bool* aIsUndefined)
-{
-  SAMPLE_LABEL("JS", "EvaluateString");
-  NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
-
-  if (!mScriptsEnabled) {
-    if (aIsUndefined) {
-      *aIsUndefined = true;
-    }
-
-    if (aRetValue) {
-      aRetValue->Truncate();
-    }
-
-    return NS_OK;
-  }
-
-  nsAutoMicroTask mt;
-
-  if (!aScopeObject) {
-    aScopeObject = JS_GetGlobalObject(mContext);
-  }
-
-  xpc_UnmarkGrayObject(aScopeObject);
-
-  // Ignore the principal that was passed in, and just assert that it matches
-  // the one we pull off the global.
-  nsCOMPtr<nsIPrincipal> principal;
-  nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(GetGlobalObject());
-  if (!objPrincipal)
-    return NS_ERROR_FAILURE;
-  principal = objPrincipal->GetPrincipal();
-  if (!principal)
-    return NS_ERROR_FAILURE;
-#ifdef DEBUG
-  bool equal = false;
-  principal->Equals(aPrincipal, &equal);
-  MOZ_ASSERT(equal);
-  nsIPrincipal *scopeObjectPrincipal =
-    nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aScopeObject)));
-  equal = false;
-  principal->Equals(scopeObjectPrincipal, &equal);
-  MOZ_ASSERT(equal);
-#endif
-
-  bool ok = false;
-
-  nsresult rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Push our JSContext on the current thread's context stack so JS called
-  // from native code via XPConnect uses the right context.  Do this whether
-  // or not the SecurityManager said "ok", in order to simplify control flow
-  // below where we pop before returning.
-  nsCOMPtr<nsIJSContextStack> stack =
-           do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
-  if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // 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.
-  jsval val = JSVAL_VOID;
-  jsval* vp = aRetValue ? &val : NULL;
-
-  nsJSContext::TerminationFuncHolder holder(this);
-
-  ++mExecuteDepth;
-
-  // SecurityManager said "ok", but don't compile if aVersion is unknown.
-  // Since the caller is responsible for parsing the version strings, we just
-  // check it isn't JSVERSION_UNKNOWN.
-  if (ok && JSVersion(aVersion) != JSVERSION_UNKNOWN) {
-    XPCAutoRequest ar(mContext);
-    JSAutoCompartment ac(mContext, aScopeObject);
-
-    js::RootedObject rootedScope(mContext, aScopeObject);
-    JS::CompileOptions options(mContext);
-    options.setFileAndLine(aURL, aLineNo)
-           .setPrincipals(nsJSPrincipals::get(principal))
-           .setOriginPrincipals(nsJSPrincipals::get(aOriginPrincipal))
-           .setVersion(JSVersion(aVersion));
-    ok = JS::Evaluate(mContext, rootedScope, options,
-                      PromiseFlatString(aScript).get(),
-                      aScript.Length(), vp);
-
-    if (!ok) {
-      // Tell XPConnect about any pending exceptions. This is needed
-      // to avoid dropping JS exceptions in case we got here through
-      // nested calls through XPConnect.
-
-      ReportPendingException();
-    }
-  }
-
-  // If all went well, convert val to a string if one is wanted.
-  if (ok) {
-    XPCAutoRequest ar(mContext);
-    JSAutoCompartment ac(mContext, aScopeObject);
-    rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
-  }
-  else {
-    if (aIsUndefined) {
-      *aIsUndefined = true;
-    }
-
-    if (aRetValue) {
-      aRetValue->Truncate();
-    }
-  }
-
-  --mExecuteDepth;
-
-  // Pop here, after JS_ValueToString and any other possible evaluation.
-  if (NS_FAILED(stack->Pop(nullptr)))
-    rv = NS_ERROR_FAILURE;
-
-  // ScriptEvaluated needs to come after we pop the stack
-  ScriptEvaluated(true);
-
-  return rv;
-}
-
-nsresult
 nsJSContext::CompileScript(const PRUnichar* aText,
                            int32_t aTextLength,
                            nsIPrincipal *aPrincipal,
                            const char *aURL,
                            uint32_t aLineNo,
                            uint32_t aVersion,
                            nsScriptObjectHolder<JSScript>& aScriptObject,
                            bool aSaveSource /* = false */)
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -39,25 +39,16 @@ public:
   virtual ~nsJSContext();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSContext,
                                                          nsIScriptContext)
 
   virtual nsIScriptObjectPrincipal* GetObjectPrincipal();
 
-  virtual nsresult EvaluateString(const nsAString& aScript,
-                                  JSObject* aScopeObject,
-                                  nsIPrincipal *principal,
-                                  nsIPrincipal *originPrincipal,
-                                  const char *aURL,
-                                  uint32_t aLineNo,
-                                  JSVersion aVersion,
-                                  nsAString *aRetValue,
-                                  bool* aIsUndefined);
   virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
                                            JSObject& aScopeObject,
                                            JS::CompileOptions &aOptions,
                                            bool aCoerceToString,
                                            JS::Value& aRetValue);
 
   virtual nsresult CompileScript(const PRUnichar* aText,
                                  int32_t aTextLength,