Bug 867459: Rooting fixes for ipc r=terrence
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 03 May 2013 17:49:47 -0400
changeset 141747 eb47a4845d4fe57cb781a254c8e2045b2f311eb2
parent 141746 bfe5c0296c3b6b1fbe8536e658c4be19d9009f24
child 141748 b97f5f39fd8b9e95966bf5f0c7eceb21be5bf244
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs867459
milestone23.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 867459: Rooting fixes for ipc r=terrence
ipc/testshell/TestShellParent.cpp
ipc/testshell/XPCShellEnvironment.cpp
--- a/ipc/testshell/TestShellParent.cpp
+++ b/ipc/testshell/TestShellParent.cpp
@@ -87,17 +87,17 @@ TestShellCommandParent::SetCallback(JSCo
 
 JSBool
 TestShellCommandParent::RunCallback(const nsString& aResponse)
 {
   NS_ENSURE_TRUE(*mCallback.ToJSValPtr() != JSVAL_NULL && mCx, JS_FALSE);
 
   JSAutoRequest ar(mCx);
 
-  JSObject* global = JS_GetGlobalObject(mCx);
+  JS::Rooted<JSObject*> global(mCx, JS_GetGlobalObject(mCx));
   NS_ENSURE_TRUE(global, JS_FALSE);
 
   JSAutoCompartment ac(mCx, global);
 
   JSString* str = JS_NewUCStringCopyN(mCx, aResponse.get(), aResponse.Length());
   NS_ENSURE_TRUE(str, JS_FALSE);
 
   JS::Value argv[] = { STRING_TO_JSVAL(str) };
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -273,19 +273,19 @@ Dump(JSContext *cx,
     return JS_TRUE;
 }
 
 static JSBool
 Load(JSContext *cx,
      unsigned argc,
      JS::Value *vp)
 {
-    JS::Value result;
+    JS::Rooted<JS::Value> result(cx);
 
-    JSObject *obj = JS_THIS_OBJECT(cx, vp);
+    JS::Rooted<JSObject*> obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return JS_FALSE;
 
     JS::Value *argv = JS_ARGV(cx, vp);
     for (unsigned i = 0; i < argc; i++) {
         JSString *str = JS_ValueToString(cx, argv[i]);
         if (!str)
             return JS_FALSE;
@@ -304,17 +304,17 @@ Load(JSContext *cx,
                .setPrincipals(Environment(cx)->GetPrincipal());
         JS::RootedObject rootedObj(cx, obj);
         JSScript *script = JS::Compile(cx, rootedObj, options, file);
         fclose(file);
         if (!script)
             return JS_FALSE;
 
         if (!Environment(cx)->ShouldCompileOnly() &&
-            !JS_ExecuteScript(cx, obj, script, &result)) {
+            !JS_ExecuteScript(cx, obj, script, result.address())) {
             return JS_FALSE;
         }
     }
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
     return JS_TRUE;
 }
 
 static JSBool
@@ -518,27 +518,27 @@ typedef enum JSShellErrNum
 #include "jsshell.msg"
 #undef MSG_DEF
     JSShellErr_Limit
 #undef MSGDEF
 } JSShellErrNum;
 
 static void
 ProcessFile(JSContext *cx,
-            JSObject *obj,
+            JS::Handle<JSObject*> obj,
             const char *filename,
             FILE *file,
             JSBool forceTTY)
 {
     XPCShellEnvironment* env = Environment(cx);
     nsCxPusher pusher;
     pusher.Push(env->GetContext());
 
     JSScript *script;
-    JS::Value result;
+    JS::Rooted<JS::Value> result(cx);
     int lineno, startline;
     JSBool ok, hitEOF;
     char *bufp, buffer[4096];
     JSString *str;
 
     if (forceTTY) {
         file = stdin;
     }
@@ -566,20 +566,19 @@ ProcessFile(JSContext *cx,
 
         JSAutoRequest ar(cx);
         JSAutoCompartment ac(cx, obj);
 
         JS::CompileOptions options(cx);
         options.setUTF8(true)
                .setFileAndLine(filename, 1)
                .setPrincipals(env->GetPrincipal());
-        JS::RootedObject rootedObj(cx, obj);
-        JSScript* script = JS::Compile(cx, rootedObj, options, file);
+        JSScript* script = JS::Compile(cx, obj, options, file);
         if (script && !env->ShouldCompileOnly())
-            (void)JS_ExecuteScript(cx, obj, script, &result);
+            (void)JS_ExecuteScript(cx, obj, script, result.address());
 
         return;
     }
 
     /* It's an interactive filehandle; drop into read-eval-print loop. */
     lineno = 1;
     hitEOF = JS_FALSE;
     do {
@@ -609,17 +608,17 @@ ProcessFile(JSContext *cx,
         JS_ClearPendingException(cx);
         script =
             JS_CompileScriptForPrincipals(cx, obj, env->GetPrincipal(), buffer,
                                           strlen(buffer), "typein", startline);
         if (script) {
             JSErrorReporter older;
 
             if (!env->ShouldCompileOnly()) {
-                ok = JS_ExecuteScript(cx, obj, script, &result);
+                ok = JS_ExecuteScript(cx, obj, script, result.address());
                 if (ok && result != JSVAL_VOID) {
                     /* Suppress error reports from JS_ValueToString(). */
                     older = JS_SetErrorReporter(cx, NULL);
                     str = JS_ValueToString(cx, result);
                     JSAutoByteString bytes;
                     if (str)
                         bytes.encodeLatin1(cx, str);
                     JS_SetErrorReporter(cx, older);
@@ -1022,18 +1021,18 @@ XPCShellEnvironment::Init()
                                               principal, 0,
                                               JS::SystemZone,
                                               getter_AddRefs(holder));
     if (NS_FAILED(rv)) {
         NS_ERROR("InitClassesWithNewWrappedGlobal failed!");
         return false;
     }
 
-    JSObject *globalObj;
-    rv = holder->GetJSObject(&globalObj);
+    JS::Rooted<JSObject*> globalObj(cx);
+    rv = holder->GetJSObject(globalObj.address());
     if (NS_FAILED(rv)) {
         NS_ERROR("Failed to get global JSObject!");
         return false;
     }
 
     backstagePass->SetGlobalObject(globalObj);
 
     {
@@ -1067,34 +1066,34 @@ XPCShellEnvironment::EvaluateString(cons
   XPCShellEnvironment* env = Environment(mCx);
   nsCxPusher pusher;
   pusher.Push(env->GetContext());
 
   JSAutoRequest ar(mCx);
 
   JS_ClearPendingException(mCx);
 
-  JSObject* global = GetGlobalObject();
+  JS::Rooted<JSObject*> global(mCx, GetGlobalObject());
   JSAutoCompartment ac(mCx, global);
 
   JSScript* script =
       JS_CompileUCScriptForPrincipals(mCx, global, GetPrincipal(),
                                       aString.get(), aString.Length(),
                                       "typein", 0);
   if (!script) {
      return false;
   }
 
   if (!ShouldCompileOnly()) {
       if (aResult) {
           aResult->Truncate();
       }
 
-      JS::Value result;
-      JSBool ok = JS_ExecuteScript(mCx, global, script, &result);
+      JS::Rooted<JS::Value> result(mCx);
+      JSBool ok = JS_ExecuteScript(mCx, global, script, result.address());
       if (ok && result != JSVAL_VOID) {
           JSErrorReporter old = JS_SetErrorReporter(mCx, NULL);
           JSString* str = JS_ValueToString(mCx, result);
           nsDependentJSString depStr;
           if (str)
               depStr.init(mCx, str);
           JS_SetErrorReporter(mCx, old);