Bug 867459: Root xpcshell.cpp r=terrence
authorDavid Zbarsky <dzbarsky@gmail.com>
Wed, 01 May 2013 18:43:53 -0400
changeset 141506 e1fe36ce89d100ea57b31768b7d0c8b00f2a034c
parent 141505 5aceec8a122219fecb8ea8900cce27c2b5a7086c
child 141507 9b1b9e61db7b18f51b5113866cf42a25bf577a02
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: Root xpcshell.cpp r=terrence
js/xpconnect/shell/xpcshell.cpp
--- a/js/xpconnect/shell/xpcshell.cpp
+++ b/js/xpconnect/shell/xpcshell.cpp
@@ -199,29 +199,29 @@ GetLocationProperty(JSContext *cx, JSHan
             absolutePath.Append(filenameString);
 
             rv = NS_NewLocalFile(absolutePath,
                                  false, getter_AddRefs(location));
         }
 
         if (location) {
             nsCOMPtr<nsIXPConnectJSObjectHolder> locationHolder;
-            JSObject *locationObj = NULL;
+            JS::Rooted<JSObject*> locationObj(cx, nullptr);
 
             bool symlink;
             // don't normalize symlinks, because that's kind of confusing
             if (NS_SUCCEEDED(location->IsSymlink(&symlink)) &&
                 !symlink)
                 location->Normalize();
             rv = xpc->WrapNative(cx, obj, location,
                                  NS_GET_IID(nsIFile),
                                  getter_AddRefs(locationHolder));
 
             if (NS_SUCCEEDED(rv) &&
-                NS_SUCCEEDED(locationHolder->GetJSObject(&locationObj))) {
+                NS_SUCCEEDED(locationHolder->GetJSObject(locationObj.address()))) {
                 vp.set(OBJECT_TO_JSVAL(locationObj));
             }
         }
     }
 
     return true;
 #endif
 }
@@ -444,17 +444,17 @@ Dump(JSContext *cx, unsigned argc, jsval
     fputs(bytes.ptr(), gOutFile);
     fflush(gOutFile);
     return true;
 }
 
 static JSBool
 Load(JSContext *cx, unsigned argc, jsval *vp)
 {
-    JSObject *obj = JS_THIS_OBJECT(cx, vp);
+    JS::Rooted<JSObject*> obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return false;
 
     jsval *argv = JS_ARGV(cx, vp);
     for (unsigned i = 0; i < argc; i++) {
         JSString *str = JS_ValueToString(cx, argv[i]);
         if (!str)
             return false;
@@ -473,18 +473,18 @@ Load(JSContext *cx, unsigned argc, jsval
                .setFileAndLine(filename.ptr(), 1)
                .setPrincipals(gJSPrincipals);
         JS::RootedObject rootedObj(cx, obj);
         JSScript *script = JS::Compile(cx, rootedObj, options, file);
         fclose(file);
         if (!script)
             return false;
 
-        jsval result;
-        if (!compileOnly && !JS_ExecuteScript(cx, obj, script, &result))
+        JS::Rooted<JS::Value> result(cx);
+        if (!compileOnly && !JS_ExecuteScript(cx, obj, script, result.address()))
             return false;
     }
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
     return true;
 }
 
 static JSBool
 Version(JSContext *cx, unsigned argc, jsval *vp)
@@ -677,18 +677,18 @@ SendCommand(JSContext* cx,
     return true;
 }
 
 static JSBool
 GetChildGlobalObject(JSContext* cx,
                      unsigned,
                      jsval* vp)
 {
-    JSObject* global;
-    if (XRE_GetChildGlobalObject(cx, &global)) {
+    JS::Rooted<JSObject*> global(cx);
+    if (XRE_GetChildGlobalObject(cx, global.address())) {
         JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(global));
         return true;
     }
     return false;
 }
 
 /*
  * JSContext option name to flag map. The option names are in alphabetical
@@ -850,17 +850,18 @@ JSClass global_class = {
     JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   nullptr
 };
 
 static JSBool
 env_setProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp)
 {
 /* XXX porting may be easy, but these don't seem to supply setenv by default */
 #if !defined XP_OS2 && !defined SOLARIS
-    JSString *idstr, *valstr;
+    JSString *valstr;
+    JS::Rooted<JSString*> idstr(cx);
     int rv;
 
     jsval idval;
     if (!JS_IdToValue(cx, id, &idval))
         return false;
 
     idstr = JS_ValueToString(cx, idval);
     valstr = JS_ValueToString(cx, vp);
@@ -995,21 +996,21 @@ my_GetErrorMessage(void *userRef, const 
 {
     if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
         return NULL;
 
     return &jsShell_ErrorFormatString[errorNumber];
 }
 
 static void
-ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
+ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, FILE *file,
             JSBool forceTTY)
 {
     JSScript *script;
-    jsval result;
+    JS::Rooted<JS::Value> result(cx);
     int lineno, startline;
     JSBool ok, hitEOF;
     char *bufp, buffer[4096];
     JSString *str;
 
     if (forceTTY) {
         file = stdin;
     } else
@@ -1034,20 +1035,19 @@ ProcessFile(JSContext *cx, JSObject *obj
         }
         ungetc(ch, file);
         DoBeginRequest(cx);
 
         JS::CompileOptions options(cx);
         options.setUTF8(true)
                .setFileAndLine(filename, 1)
                .setPrincipals(gJSPrincipals);
-        JS::RootedObject rootedObj(cx, obj);
-        script = JS::Compile(cx, rootedObj, options, file);
+        script = JS::Compile(cx, obj, options, file);
         if (script && !compileOnly)
-            (void)JS_ExecuteScript(cx, obj, script, &result);
+            (void)JS_ExecuteScript(cx, obj, script, result.address());
         DoEndRequest(cx);
 
         return;
     }
 
     /* It's an interactive filehandle; drop into read-eval-print loop. */
     lineno = 1;
     hitEOF = false;
@@ -1075,17 +1075,17 @@ ProcessFile(JSContext *cx, JSObject *obj
         /* Clear any pending exception from previous failed compiles.  */
         JS_ClearPendingException(cx);
         script = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
                                                strlen(buffer), "typein", startline);
         if (script) {
             JSErrorReporter older;
 
             if (!compileOnly) {
-                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);
                     JS_SetErrorReporter(cx, older);
                     JSAutoByteString bytes;
                     if (str && bytes.encodeLatin1(cx, str))
                         fprintf(gOutFile, "%s\n", bytes.ptr());
@@ -1096,17 +1096,17 @@ ProcessFile(JSContext *cx, JSObject *obj
         }
         DoEndRequest(cx);
     } while (!hitEOF && !gQuitting);
 
     fprintf(gOutFile, "\n");
 }
 
 static void
-Process(JSContext *cx, JSObject *obj, const char *filename, JSBool forceTTY)
+Process(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, JSBool forceTTY)
 {
     FILE *file;
 
     if (forceTTY || !filename || strcmp(filename, "-") == 0) {
         file = stdin;
     } else {
         file = fopen(filename, "r");
         if (!file) {
@@ -1163,22 +1163,22 @@ ProcessArgsForCompartment(JSContext *cx,
         case 'n':
             JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE);
             break;
         }
     }
 }
 
 static int
-ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc, XPCShellDirProvider* aDirProvider)
+ProcessArgs(JSContext *cx, JS::Handle<JSObject*> obj, char **argv, int argc, XPCShellDirProvider* aDirProvider)
 {
     const char rcfilename[] = "xpcshell.js";
     FILE *rcfile;
     int i;
-    JSObject *argsObj;
+    JS::Rooted<JSObject*> argsObj(cx);
     char *filename = NULL;
     JSBool isInteractive = true;
     JSBool forceTTY = false;
 
     rcfile = fopen(rcfilename, "r");
     if (rcfile) {
         printf("[loading '%s'...]\n", rcfilename);
         ProcessFile(cx, obj, rcfilename, rcfile, false);
@@ -1926,17 +1926,18 @@ main(int argc, char **argv, char **envp)
 
             nsAutoString workingDirectory;
             if (GetCurrentWorkingDirectory(workingDirectory))
                 gWorkingDirectory = &workingDirectory;
 
             JS_DefineProperty(cx, glob, "__LOCATION__", JSVAL_VOID,
                               GetLocationProperty, NULL, 0);
 
-            result = ProcessArgs(cx, glob, argv, argc, &dirprovider);
+            JS::Rooted<JSObject*> rootedGlob(cx, glob);
+            result = ProcessArgs(cx, rootedGlob, argv, argc, &dirprovider);
 
             JS_DropPrincipals(rt, gJSPrincipals);
             JS_SetAllNonReservedSlotsToUndefined(cx, glob);
             JS_GC(rt);
             xpc::danger::PopJSContext();
             JS_GC(rt);
         } //this scopes the JSAutoCrossCompartmentCall
         JS_EndRequest(cx);