Bug 839313: In js/src/shell/js.cpp, Use JS_SET_RVAL, instead of assigning to *vp. r=waldo
authorJim Blandy <jimb@mozilla.com>
Tue, 26 Feb 2013 11:48:44 -0800
changeset 123051 e150e804f9029ee1d10b4d6b936551d7531282d4
parent 123050 4c8b199ed597e46d62c812f4c68e4ae97e9aee15
child 123052 2b8d0b73600e58b722e5b8a0828e504eb61be248
push id23637
push userjblandy@mozilla.com
push dateTue, 26 Feb 2013 19:49:11 +0000
treeherdermozilla-inbound@2b8d0b73600e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs839313
milestone22.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 839313: In js/src/shell/js.cpp, Use JS_SET_RVAL, instead of assigning to *vp. r=waldo
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -643,32 +643,32 @@ MapContextOptionNameToFlag(JSContext* cx
 extern JSClass global_class;
 
 static JSBool
 Version(JSContext *cx, unsigned argc, jsval *vp)
 {
     jsval *argv = JS_ARGV(cx, vp);
     if (argc == 0 || JSVAL_IS_VOID(argv[0])) {
         /* Get version. */
-        *vp = INT_TO_JSVAL(JS_GetVersion(cx));
+        JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_GetVersion(cx)));
     } else {
         /* Set version. */
         int32_t v = -1;
         if (JSVAL_IS_INT(argv[0])) {
             v = JSVAL_TO_INT(argv[0]);
         } else if (JSVAL_IS_DOUBLE(argv[0])) {
             double fv = JSVAL_TO_DOUBLE(argv[0]);
             if (int32_t(fv) == fv)
                 v = int32_t(fv);
         }
         if (v < 0 || v > JSVERSION_LATEST) {
             JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_INVALID_ARGS, "version");
             return false;
         }
-        *vp = INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(v)));
+        JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(v))));
     }
     return true;
 }
 
 static JSBool
 RevertVersion(JSContext *cx, unsigned argc, jsval *vp)
 {
     js_RevertVersion(cx);
@@ -717,17 +717,17 @@ Options(JSContext *cx, unsigned argc, js
     if (!names) {
         JS_ReportOutOfMemory(cx);
         return false;
     }
     str = JS_NewStringCopyZ(cx, names);
     free(names);
     if (!str)
         return false;
-    *vp = STRING_TO_JSVAL(str);
+    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
     return true;
 }
 
 static JSBool
 Load(JSContext *cx, unsigned argc, jsval *vp)
 {
     RootedObject thisobj(cx, JS_THIS_OBJECT(cx, vp));
     if (!thisobj)
@@ -948,17 +948,17 @@ Evaluate(JSContext *cx, unsigned argc, j
             if (!smurl)
                 return false;
             jschar *smurl_copy = js_strdup(cx, smurl);
             if (!smurl_copy || !script->scriptSource()->setSourceMap(cx, smurl_copy, script->filename))
                 return false;
         }
         if (!JS_ExecuteScript(cx, global, script, vp)) {
             if (catchTermination && !JS_IsExceptionPending(cx)) {
-                *vp = StringValue(JS_NewStringCopyZ(cx, "terminated"));
+                JS_SET_RVAL(cx, vp, StringValue(JS_NewStringCopyZ(cx, "terminated")));
                 return true;
             }
             return false;
         }
     }
 
     return JS_WrapValue(cx, vp);
 }
@@ -1147,17 +1147,17 @@ ReadLine(JSContext *cx, unsigned argc, j
             return false;
         }
 
         buf = tmp;
     }
 
     /* Treat the empty string specially. */
     if (buflength == 0) {
-        *vp = feof(from) ? NullValue() : JS_GetEmptyStringValue(cx);
+        JS_SET_RVAL(cx, vp, feof(from) ? NullValue() : JS_GetEmptyStringValue(cx));
         JS_free(cx, buf);
         return true;
     }
 
     /* Shrink the buffer to the real size. */
     tmp = (char *) JS_realloc(cx, buf, buflength);
     if (!tmp) {
         JS_free(cx, buf);
@@ -1170,17 +1170,17 @@ ReadLine(JSContext *cx, unsigned argc, j
      * Turn buf into a JSString. Note that buflength includes the trailing null
      * character.
      */
     str = JS_NewStringCopyN(cx, buf, sawNewline ? buflength - 1 : buflength);
     JS_free(cx, buf);
     if (!str)
         return false;
 
-    *vp = STRING_TO_JSVAL(str);
+    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
     return true;
 }
 
 static JSBool
 PutStr(JSContext *cx, unsigned argc, jsval *vp)
 {
     jsval *argv;
     JSString *str;
@@ -1535,33 +1535,33 @@ LineToPC(JSContext *cx, unsigned argc, j
             return false;
         lineArg++;
     }
     if (!JS_ValueToECMAUint32(cx, JS_ARGV(cx, vp)[lineArg], &lineno))
         return false;
     pc = JS_LineNumberToPC(cx, script, lineno);
     if (!pc)
         return false;
-    *vp = INT_TO_JSVAL(pc - script->code);
+    JS_SET_RVAL(cx, vp, INT_TO_JSVAL(pc - script->code));
     return true;
 }
 
 static JSBool
 PCToLine(JSContext *cx, unsigned argc, jsval *vp)
 {
     RootedScript script(cx);
     int32_t i;
     unsigned lineno;
 
     if (!GetScriptAndPCArgs(cx, argc, JS_ARGV(cx, vp), &script, &i))
         return false;
     lineno = JS_PCToLineNumber(cx, script, script->code + i);
     if (!lineno)
         return false;
-    *vp = INT_TO_JSVAL(lineno);
+    JS_SET_RVAL(cx, vp, INT_TO_JSVAL(lineno));
     return true;
 }
 
 #ifdef DEBUG
 
 static void
 UpdateSwitchTableBounds(JSContext *cx, HandleScript script, unsigned offset,
                         unsigned *start, unsigned *end)
@@ -2140,17 +2140,17 @@ DumpObject(JSContext *cx, unsigned argc,
 static JSBool
 BuildDate(JSContext *cx, unsigned argc, jsval *vp)
 {
     char version[20] = "\n";
 #if JS_VERSION < 150
     sprintf(version, " for version %d\n", JS_VERSION);
 #endif
     fprintf(gOutFile, "built on %s at %s%s", __DATE__, __TIME__, version);
-    *vp = UndefinedValue();
+    JS_SET_RVAL(cx, vp, UndefinedValue());
     return true;
 }
 
 static JSBool
 Intern(JSContext *cx, unsigned argc, jsval *vp)
 {
     JSString *str = JS_ValueToString(cx, argc == 0 ? UndefinedValue() : vp[2]);
     if (!str)
@@ -2212,40 +2212,40 @@ Clone(JSContext *cx, unsigned argc, jsva
             return false;
     } else {
         parent = JS_GetParent(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
     }
 
     JSObject *clone = JS_CloneFunctionObject(cx, funobj, parent);
     if (!clone)
         return false;
-    *vp = OBJECT_TO_JSVAL(clone);
+    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(clone));
     return true;
 }
 
 static JSBool
 GetPDA(JSContext *cx, unsigned argc, jsval *vp)
 {
     RootedObject vobj(cx);
     bool ok;
     JSPropertyDescArray pda;
     JSPropertyDesc *pd;
     jsval v;
 
     if (!JS_ValueToObject(cx, argc == 0 ? UndefinedValue() : vp[2], vobj.address()))
         return false;
     if (!vobj) {
-        *vp = UndefinedValue();
+        JS_SET_RVAL(cx, vp, UndefinedValue());
         return true;
     }
 
     RootedObject aobj(cx, JS_NewArrayObject(cx, 0, NULL));
     if (!aobj)
         return false;
-    *vp = OBJECT_TO_JSVAL(aobj);
+    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(aobj));
 
     ok = !!JS_GetPropertyDescArray(cx, vobj, &pda);
     if (!ok)
         return false;
     pd = pda.array;
     RootedObject pdobj(cx);
     for (uint32_t i = 0; i < pda.length; i++, pd++) {
         pdobj = JS_NewObject(cx, NULL, NULL, NULL);
@@ -2275,28 +2275,28 @@ GetPDA(JSContext *cx, unsigned argc, jsv
 static JSBool
 GetSLX(JSContext *cx, unsigned argc, jsval *vp)
 {
     RootedScript script(cx);
 
     script = ValueToScript(cx, argc == 0 ? UndefinedValue() : vp[2]);
     if (!script)
         return false;
-    *vp = INT_TO_JSVAL(js_GetScriptLineExtent(script));
+    JS_SET_RVAL(cx, vp, INT_TO_JSVAL(js_GetScriptLineExtent(script)));
     return true;
 }
 
 static JSBool
 ToInt32(JSContext *cx, unsigned argc, jsval *vp)
 {
     int32_t i;
 
     if (!JS_ValueToInt32(cx, argc == 0 ? UndefinedValue() : vp[2], &i))
         return false;
-    *vp = JS_NumberValue(i);
+    JS_SET_RVAL(cx, vp, JS_NumberValue(i));
     return true;
 }
 
 static JSBool
 ThrowError(JSContext *cx, unsigned argc, jsval *vp)
 {
     JS_ReportError(cx, "This is an error");
     return false;
@@ -2510,17 +2510,17 @@ static JSBool
 ShapeOf(JSContext *cx, unsigned argc, JS::Value *vp)
 {
     JS::Value v;
     if (argc < 1 || !((v = JS_ARGV(cx, vp)[0]).isObject())) {
         JS_ReportError(cx, "shapeOf: object expected");
         return false;
     }
     JSObject *obj = &v.toObject();
-    *vp = JS_NumberValue((double) ((uintptr_t)obj->lastProperty() >> 3));
+    JS_SET_RVAL(cx, vp, JS_NumberValue((double) ((uintptr_t)obj->lastProperty() >> 3)));
     return true;
 }
 
 /*
  * If referent has an own property named id, copy that property to obj[id].
  * Since obj is native, this isn't totally transparent; properties of a
  * non-native referent may be simplified to data properties.
  */
@@ -2909,17 +2909,17 @@ SetTimeoutValue(JSContext *cx, double t)
     }
     return true;
 }
 
 static JSBool
 Timeout(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (argc == 0) {
-        *vp = JS_NumberValue(gTimeoutInterval);
+        JS_SET_RVAL(cx, vp, JS_NumberValue(gTimeoutInterval));
         return true;
     }
 
     if (argc > 2) {
         JS_ReportError(cx, "Wrong number of arguments");
         return false;
     }
 
@@ -2931,29 +2931,29 @@ Timeout(JSContext *cx, unsigned argc, js
         RootedValue value(cx, JS_ARGV(cx, vp)[1]);
         if (!value.isObject() || !value.toObject().isFunction()) {
             JS_ReportError(cx, "Second argument must be a timeout function");
             return false;
         }
         gTimeoutFunc = value;
     }
 
-    *vp = UndefinedValue();
+    JS_SET_RVAL(cx, vp, UndefinedValue());
     return SetTimeoutValue(cx, t);
 }
 
 static JSBool
 Elapsed(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (argc == 0) {
         double d = 0.0;
         JSShellContextData *data = GetContextData(cx);
         if (data)
             d = PRMJ_Now() - data->startTime;
-        *vp = JS_NumberValue(d);
+        JS_SET_RVAL(cx, vp, JS_NumberValue(d));
         return true;
     }
     JS_ReportError(cx, "Wrong number of arguments");
     return false;
 }
 
 static JSBool
 Parent(JSContext *cx, unsigned argc, jsval *vp)
@@ -2965,22 +2965,22 @@ Parent(JSContext *cx, unsigned argc, jsv
 
     jsval v = JS_ARGV(cx, vp)[0];
     if (JSVAL_IS_PRIMITIVE(v)) {
         JS_ReportError(cx, "Only objects have parents!");
         return false;
     }
 
     Rooted<JSObject*> parent(cx, JS_GetParent(&v.toObject()));
-    *vp = OBJECT_TO_JSVAL(parent);
+    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(parent));
 
     /* Outerize if necessary.  Embrace the ugliness! */
     if (parent) {
         if (JSObjectOp op = parent->getClass()->ext.outerObject)
-            *vp = OBJECT_TO_JSVAL(op(cx, parent));
+            JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(op(cx, parent)));
     }
 
     return true;
 }
 
 #ifdef XP_UNIX
 
 #include <fcntl.h>
@@ -3202,24 +3202,24 @@ Snarf(JSContext *cx, unsigned argc, jsva
             return false;
         JSBool match;
         if (!JS_StringEqualsAscii(cx, opt, "binary", &match))
             return false;
         if (match) {
             JSObject *obj;
             if (!(obj = FileAsTypedArray(cx, pathname)))
                 return false;
-            *vp = OBJECT_TO_JSVAL(obj);
+            JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
             return true;
         }
     }
 
     if (!(str = FileAsString(cx, pathname)))
         return false;
-    *vp = STRING_TO_JSVAL(str);
+    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
     return true;
 }
 
 static JSBool
 System(JSContext *cx, unsigned argc, jsval *vp)
 {
     JSString *str;
 
@@ -3233,17 +3233,17 @@ System(JSContext *cx, unsigned argc, jsv
     if (!str)
         return false;
     JSAutoByteString command(cx, str);
     if (!command)
         return false;
 
     int result = system(command.ptr());
 
-    *vp = Int32Value(result);
+    JS_SET_RVAL(cx, vp, Int32Value(result));
     return true;
 }
 
 static bool
 DecompileFunctionSomehow(JSContext *cx, unsigned argc, Value *vp,
                          JSString *(*decompiler)(JSContext *, JSFunction *, unsigned))
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -4173,19 +4173,19 @@ static JSBool
 its_get_customNative(JSContext *cx, unsigned argc, jsval *vp)
 {
     JSObject *obj = JS_THIS_OBJECT(cx, vp);
     if (!obj)
         return false;
 
     if (JS_GetClass(obj) == &its_class) {
         jsval *val = (jsval *) JS_GetPrivate(obj);
-        *vp = val ? *val : UndefinedValue();
+        JS_SET_RVAL(cx, vp, val ? *val : UndefinedValue());
     } else {
-        *vp = UndefinedValue();
+        JS_SET_RVAL(cx, vp, UndefinedValue());
     }
 
     return true;
 }
 
 static JSBool
 its_set_customNative(JSContext *cx, unsigned argc, jsval *vp)
 {
@@ -4526,17 +4526,17 @@ dom_genericMethod(JSContext *cx, unsigne
 static JSClass *GetDomClass();
 #endif
 
 static bool
 dom_get_x(JSContext* cx, JSHandleObject obj, void *self, JS::Value *vp)
 {
     JS_ASSERT(JS_GetClass(obj) == GetDomClass());
     JS_ASSERT(self == (void *)0x1234);
-    *vp = JS_NumberValue(double(3.14));
+    JS_SET_RVAL(cx, vp, JS_NumberValue(double(3.14)));
     return true;
 }
 
 static bool
 dom_set_x(JSContext* cx, JSHandleObject obj, void *self, JS::Value *argv)
 {
     JS_ASSERT(JS_GetClass(obj) == GetDomClass());
     JS_ASSERT(self == (void *)0x1234);
@@ -4623,17 +4623,17 @@ static JSClass *GetDomClass() {
 static JSBool
 dom_genericGetter(JSContext *cx, unsigned argc, JS::Value *vp)
 {
     js::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return false;
 
     if (JS_GetClass(obj) != &dom_class) {
-        *vp = UndefinedValue();
+        JS_SET_RVAL(cx, vp, UndefinedValue());
         return true;
     }
 
     JS::Value val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT);
 
     const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));
     MOZ_ASSERT(info->type == JSJitInfo::Getter);
     JSJitPropertyOp getter = info->op;
@@ -4645,41 +4645,41 @@ dom_genericSetter(JSContext* cx, unsigne
 {
     js::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return false;
 
     JS_ASSERT(argc == 1);
 
     if (JS_GetClass(obj) != &dom_class) {
-        *vp = UndefinedValue();
+        JS_SET_RVAL(cx, vp, UndefinedValue());
         return true;
     }
 
     JS::Value* argv = JS_ARGV(cx, vp);
     JS::Value val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT);
 
     const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));
     MOZ_ASSERT(info->type == JSJitInfo::Setter);
     JSJitPropertyOp setter = info->op;
     if (!setter(cx, obj, val.toPrivate(), argv))
         return false;
-    *vp = UndefinedValue();
+    JS_SET_RVAL(cx, vp, UndefinedValue());
     return true;
 }
 
 static JSBool
 dom_genericMethod(JSContext* cx, unsigned argc, JS::Value *vp)
 {
     js::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return false;
 
     if (JS_GetClass(obj) != &dom_class) {
-        *vp = UndefinedValue();
+        JS_SET_RVAL(cx, vp, UndefinedValue());
         return true;
     }
 
     JS::Value val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT);
 
     const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));
     MOZ_ASSERT(info->type == JSJitInfo::Method);
     JSJitMethodOp method = (JSJitMethodOp)info->op;