Bug 678201 - Use CallArgs in Debugger.cpp. Part 6, add CallArgs to Object methods. r=luke.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 11 Aug 2011 16:58:14 -0500
changeset 75251 eec543e3c6448dddc5161d07f9b393884b47e790
parent 75250 7926c48bfe9798582a1560938fa06772c94e0511
child 75252 2e368c4a6b5c813c6bf71a4006589a4f3d46765b
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersluke
bugs678201
milestone8.0a1
Bug 678201 - Use CallArgs in Debugger.cpp. Part 6, add CallArgs to Object methods. r=luke.
js/src/vm/Debugger.cpp
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -2819,23 +2819,23 @@ Class DebuggerObject_class = {
     NULL,                 /* call        */
     NULL,                 /* construct   */
     NULL,                 /* xdrObject   */
     NULL,                 /* hasInstance */
     DebuggerObject_trace
 };
 
 static JSObject *
-DebuggerObject_checkThis(JSContext *cx, Value *vp, const char *fnname)
+DebuggerObject_checkThis(JSContext *cx, const CallArgs &args, const char *fnname)
 {
-    if (!vp[1].isObject()) {
+    if (!args.thisv().isObject()) {
         ReportObjectRequired(cx);
         return NULL;
     }
-    JSObject *thisobj = &vp[1].toObject();
+    JSObject *thisobj = &args.thisv().toObject();
     if (thisobj->clasp != &DebuggerObject_class) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
                              "Debugger.Object", fnname, thisobj->getClass()->name);
         return NULL;
     }
 
     /*
      * Forbid Debugger.Object.prototype, which is of class DebuggerObject_class
@@ -2845,91 +2845,99 @@ DebuggerObject_checkThis(JSContext *cx, 
     if (!thisobj->getPrivate()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
                              "Debugger.Object", fnname, "prototype object");
         return NULL;
     }
     return thisobj;
 }
 
-#define THIS_DEBUGOBJECT_REFERENT(cx, vp, fnname, obj)                        \
-    JSObject *obj = DebuggerObject_checkThis(cx, vp, fnname);                 \
+#define THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, fnname, args, obj)            \
+    CallArgs args = CallArgsFromVp(argc, vp);                                 \
+    JSObject *obj = DebuggerObject_checkThis(cx, args, fnname);               \
     if (!obj)                                                                 \
         return false;                                                         \
     obj = (JSObject *) obj->getPrivate();                                     \
     JS_ASSERT(obj)
 
-#define THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, fnname, dbg, obj)             \
-    JSObject *obj = DebuggerObject_checkThis(cx, vp, fnname);                 \
+#define THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, fnname, args, dbg, obj) \
+    CallArgs args = CallArgsFromVp(argc, vp);                                 \
+    JSObject *obj = DebuggerObject_checkThis(cx, args, fnname);               \
     if (!obj)                                                                 \
         return false;                                                         \
     Debugger *dbg = Debugger::fromChildJSObject(obj);                         \
     obj = (JSObject *) obj->getPrivate();                                     \
     JS_ASSERT(obj)
 
 static JSBool
 DebuggerObject_construct(JSContext *cx, uintN argc, Value *vp)
 {
     JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_CONSTRUCTOR, "Debugger.Object");
     return false;
 }
 
 static JSBool
 DebuggerObject_getProto(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "get proto", dbg, refobj);
-    vp->setObjectOrNull(refobj->getProto());
-    return dbg->wrapDebuggeeValue(cx, vp);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get proto", args, dbg, refobj);
+    Value protov = ObjectOrNullValue(refobj->getProto());
+    if (!dbg->wrapDebuggeeValue(cx, &protov))
+        return false;
+    args.rval() = protov;
+    return true;
 }
 
 static JSBool
 DebuggerObject_getClass(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_REFERENT(cx, vp, "get class", refobj);
+    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get class", args, refobj);
     const char *s = refobj->clasp->name;
     JSAtom *str = js_Atomize(cx, s, strlen(s));
     if (!str)
         return false;
-    vp->setString(str);
+    args.rval().setString(str);
     return true;
 }
 
 static JSBool
 DebuggerObject_getCallable(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_REFERENT(cx, vp, "get callable", refobj);
-    vp->setBoolean(refobj->isCallable());
+    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get callable", args, refobj);
+    args.rval().setBoolean(refobj->isCallable());
     return true;
 }
 
 static JSBool
 DebuggerObject_getName(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "get name", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get name", args, dbg, obj);
     if (!obj->isFunction()) {
-        vp->setUndefined();
+        args.rval().setUndefined();
         return true;
     }
 
     JSString *name = obj->getFunctionPrivate()->atom;
     if (!name) {
-        vp->setUndefined();
+        args.rval().setUndefined();
         return true;
     }
 
-    vp->setString(name);
-    return dbg->wrapDebuggeeValue(cx, vp);
+    Value namev = StringValue(name);
+    if (!dbg->wrapDebuggeeValue(cx, &namev))
+        return false;
+    args.rval() = namev;
+    return true;
 }
 
 static JSBool
 DebuggerObject_getParameterNames(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_REFERENT(cx, vp, "get parameterNames", obj);
+    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get parameterNames", args, obj);
     if (!obj->isFunction()) {
-        vp->setUndefined();
+        args.rval().setUndefined();
         return true;
     }
 
     const JSFunction *fun = obj->getFunctionPrivate();
     JSObject *result = NewDenseAllocatedArray(cx, fun->nargs, NULL);
     if (!result)
         return false;
 
@@ -2946,49 +2954,49 @@ DebuggerObject_getParameterNames(JSConte
                 result->setDenseArrayElement(i, name ? StringValue(name) : UndefinedValue());
             }
         }
     } else {
         for (size_t i = 0; i < fun->nargs; i++)
             result->setDenseArrayElement(i, UndefinedValue());
     }
 
-    vp->setObject(*result);
+    args.rval().setObject(*result);
     return true;
 }
 
 static JSBool
 DebuggerObject_getScript(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "get script", dbg, obj);
-
-    vp->setUndefined();
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get script", args, dbg, obj);
+
+    args.rval().setUndefined();
 
     if (!obj->isFunction())
         return true;
 
     JSFunction *fun = obj->getFunctionPrivate();
     if (!fun->isInterpreted())
         return true;
 
     JSObject *scriptObject = dbg->wrapFunctionScript(cx, fun);
     if (!scriptObject)
         return false;
 
-    vp->setObject(*scriptObject);
+    args.rval().setObject(*scriptObject);
     return true;
 }
 
 static JSBool
 DebuggerObject_getOwnPropertyDescriptor(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "getOwnPropertyDescriptor", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "getOwnPropertyDescriptor", args, dbg, obj);
 
     jsid id;
-    if (!ValueToId(cx, argc >= 1 ? vp[2] : UndefinedValue(), &id))
+    if (!ValueToId(cx, argc >= 1 ? args[0] : UndefinedValue(), &id))
         return false;
 
     /* Bug: This can cause the debuggee to run! */
     AutoPropertyDescriptorRooter desc(cx);
     {
         AutoCompartment ac(cx, obj);
         if (!ac.enter() || !cx->compartment->wrapId(cx, &id))
             return false;
@@ -3010,23 +3018,23 @@ DebuggerObject_getOwnPropertyDescriptor(
         if (desc.attrs & JSPROP_SETTER) {
             Value set = ObjectOrNullValue(CastAsObject(desc.setter));
             if (!dbg->wrapDebuggeeValue(cx, &set))
                 return false;
             desc.setter = CastAsStrictPropertyOp(set.toObjectOrNull());
         }
     }
 
-    return NewPropertyDescriptorObject(cx, &desc, vp);
+    return NewPropertyDescriptorObject(cx, &desc, &args.rval());
 }
 
 static JSBool
 DebuggerObject_getOwnPropertyNames(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "getOwnPropertyNames", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "getOwnPropertyNames", args, dbg, obj);
 
     AutoIdVector keys(cx);
     {
         AutoCompartment ac(cx, obj);
         if (!ac.enter())
             return false;
 
         if (!GetPropertyNames(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &keys))
@@ -3053,17 +3061,17 @@ DebuggerObject_getOwnPropertyNames(JSCon
              if (!dbg->wrapDebuggeeValue(cx, &vals[i]))
                  return false;
          }
     }
 
     JSObject *aobj = NewDenseCopiedArray(cx, vals.length(), vals.begin());
     if (!aobj)
         return false;
-    vp->setObject(*aobj);
+    args.rval().setObject(*aobj);
     return true;
 }
 
 static bool
 CheckArgCompartment(JSContext *cx, JSObject *obj, const Value &v,
                     const char *methodname, const char *propname)
 {
     if (v.isObject() && v.toObject().compartment() != obj->compartment()) {
@@ -3106,24 +3114,24 @@ WrapIdAndPropDesc(JSContext *cx, JSObjec
            comp->wrap(cx, &desc->get) &&
            comp->wrap(cx, &desc->set) &&
            (!obj->isProxy() || desc->makeObject(cx));
 }
 
 static JSBool
 DebuggerObject_defineProperty(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "defineProperty", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "defineProperty", args, dbg, obj);
     REQUIRE_ARGC("Debugger.Object.defineProperty", 2);
 
     jsid id;
-    if (!ValueToId(cx, vp[2], &id))
+    if (!ValueToId(cx, args[0], &id))
         return JS_FALSE;
 
-    const Value &descval = vp[3];
+    const Value &descval = args[1];
     AutoPropDescArrayRooter descs(cx);
     PropDesc *desc = descs.append();
     if (!desc || !desc->initialize(cx, descval, false))
         return false;
 
     desc->pd.setUndefined();
     if (!UnwrapPropDesc(cx, dbg, obj, desc))
         return false;
@@ -3134,26 +3142,26 @@ DebuggerObject_defineProperty(JSContext 
             return false;
 
         ErrorCopier ec(ac, dbg->toJSObject());
         bool dummy;
         if (!DefineProperty(cx, obj, id, *desc, true, &dummy))
             return false;
     }
 
-    vp->setUndefined();
+    args.rval().setUndefined();
     return true;
 }
 
 static JSBool
 DebuggerObject_defineProperties(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "defineProperties", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "defineProperties", args, dbg, obj);
     REQUIRE_ARGC("Debugger.Object.defineProperties", 1);
-    JSObject *props = ToObject(cx, &vp[2]);
+    JSObject *props = ToObject(cx, &args[0]);
     if (!props)
         return false;
 
     AutoIdVector ids(cx);
     AutoPropDescArrayRooter descs(cx);
     if (!ReadPropertyDescriptors(cx, props, false, &ids, &descs))
         return false;
     size_t n = ids.length();
@@ -3175,47 +3183,47 @@ DebuggerObject_defineProperties(JSContex
         ErrorCopier ec(ac, dbg->toJSObject());
         for (size_t i = 0; i < n; i++) {
             bool dummy;
             if (!DefineProperty(cx, obj, ids[i], descs[i], true, &dummy))
                 return false;
         }
     }
 
-    vp->setUndefined();
+    args.rval().setUndefined();
     return true;
 }
 
 /*
  * This does a non-strict delete, as a matter of API design. The case where the
  * property is non-configurable isn't necessarily exceptional here.
  */
 static JSBool
 DebuggerObject_deleteProperty(JSContext *cx, uintN argc, Value *vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "deleteProperty", dbg, obj);
-    Value arg = argc > 0 ? vp[2] : UndefinedValue();
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "deleteProperty", args, dbg, obj);
+    Value arg = argc > 0 ? args[0] : UndefinedValue();
     jsid id;
     if (!ValueToId(cx, arg, &id))
         return false;
 
     AutoCompartment ac(cx, obj);
     if (!ac.enter() || !cx->compartment->wrapId(cx, &id))
         return false;
 
     ErrorCopier ec(ac, dbg->toJSObject());
-    return obj->deleteProperty(cx, id, vp, false);
+    return obj->deleteProperty(cx, id, &args.rval(), false);
 }
 
 enum SealHelperOp { Seal, Freeze, PreventExtensions };
 
 static JSBool
 DebuggerObject_sealHelper(JSContext *cx, uintN argc, Value *vp, SealHelperOp op, const char *name)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, name, dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, name, args, dbg, obj);
 
     AutoCompartment ac(cx, obj);
     if (!ac.enter())
         return false;
 
     ErrorCopier ec(ac, dbg->toJSObject());
     bool ok;
     if (op == Seal) {
@@ -3226,18 +3234,18 @@ DebuggerObject_sealHelper(JSContext *cx,
         JS_ASSERT(op == PreventExtensions);
         if (!obj->isExtensible())
             return true;
         AutoIdVector props(cx);
         ok = obj->preventExtensions(cx, &props);
     }
     if (!ok)
         return false;
-    vp->setUndefined();
-    return ok;
+    args.rval().setUndefined();
+    return true;
 }
 
 static JSBool
 DebuggerObject_seal(JSContext *cx, uintN argc, Value *vp)
 {
     return DebuggerObject_sealHelper(cx, argc, vp, Seal, "seal");
 }
 
@@ -3252,34 +3260,34 @@ DebuggerObject_preventExtensions(JSConte
 {
     return DebuggerObject_sealHelper(cx, argc, vp, PreventExtensions, "preventExtensions");
 }
 
 static JSBool
 DebuggerObject_isSealedHelper(JSContext *cx, uintN argc, Value *vp, SealHelperOp op,
                               const char *name)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, name, dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, name, args, dbg, obj);
 
     AutoCompartment ac(cx, obj);
     if (!ac.enter())
         return false;
 
     ErrorCopier ec(ac, dbg->toJSObject());
     bool r;
     if (op == Seal) {
         if (!obj->isSealed(cx, &r))
             return false;
     } else if (op == Freeze) {
         if (!obj->isFrozen(cx, &r))
             return false;
     } else {
         r = obj->isExtensible();
     }
-    vp->setBoolean(r);
+    args.rval().setBoolean(r);
     return true;
 }
 
 static JSBool
 DebuggerObject_isSealed(JSContext *cx, uintN argc, Value *vp)
 {
     return DebuggerObject_isSealedHelper(cx, argc, vp, Seal, "isSealed");
 }
@@ -3296,57 +3304,57 @@ DebuggerObject_isExtensible(JSContext *c
     return DebuggerObject_isSealedHelper(cx, argc, vp, PreventExtensions, "isExtensible");
 }
 
 enum ApplyOrCallMode { ApplyMode, CallMode };
 
 static JSBool
 ApplyOrCall(JSContext *cx, uintN argc, Value *vp, ApplyOrCallMode mode)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, vp, "apply", dbg, obj);
+    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "apply", args, dbg, obj);
 
     /*
      * Any JS exceptions thrown must be in the debugger compartment, so do
      * sanity checks and fallible conversions before entering the debuggee.
      */
     Value calleev = ObjectValue(*obj);
     if (!obj->isCallable()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
                              "Debugger.Object", "apply", obj->getClass()->name);
         return false;
     }
 
     /*
      * Unwrap Debugger.Objects. This happens in the debugger's compartment since
      * that is where any exceptions must be reported.
      */
-    Value thisv = argc > 0 ? vp[2] : UndefinedValue();
+    Value thisv = argc > 0 ? args[0] : UndefinedValue();
     if (!dbg->unwrapDebuggeeValue(cx, &thisv))
         return false;
     uintN callArgc = 0;
     Value *callArgv = NULL;
     AutoValueVector argv(cx);
     if (mode == ApplyMode) {
-        if (argc >= 2 && !vp[3].isNullOrUndefined()) {
-            if (!vp[3].isObject()) {
+        if (argc >= 2 && !args[1].isNullOrUndefined()) {
+            if (!args[1].isObject()) {
                 JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_APPLY_ARGS,
                                      js_apply_str);
                 return false;
             }
-            JSObject *argsobj = &vp[3].toObject();
+            JSObject *argsobj = &args[1].toObject();
             if (!js_GetLengthProperty(cx, argsobj, &callArgc))
                 return false;
             callArgc = uintN(JS_MIN(callArgc, StackSpace::ARGS_LENGTH_MAX));
             if (!argv.growBy(callArgc) || !GetElements(cx, argsobj, callArgc, argv.begin()))
                 return false;
             callArgv = argv.begin();
         }
     } else {
         callArgc = argc > 0 ? uintN(JS_MIN(argc - 1, StackSpace::ARGS_LENGTH_MAX)) : 0;
-        callArgv = vp + 3;
+        callArgv = args.argv() + 1;
     }
     for (uintN i = 0; i < callArgc; i++) {
         if (!dbg->unwrapDebuggeeValue(cx, &callArgv[i]))
             return false;
     }
 
     /*
      * Enter the debuggee compartment and rewrap all input value for that compartment.
@@ -3357,21 +3365,21 @@ ApplyOrCall(JSContext *cx, uintN argc, V
         return false;
     for (uintN i = 0; i < callArgc; i++) {
         if (!cx->compartment->wrap(cx, &callArgv[i]))
             return false;
     }
 
     /*
      * Call the function. Use newCompletionValue to return to the debugger
-     * compartment and populate *vp.
+     * compartment and populate args.rval().
      */
     Value rval;
     bool ok = ExternalInvoke(cx, thisv, calleev, callArgc, callArgv, &rval);
-    return dbg->newCompletionValue(ac, ok, rval, vp);
+    return dbg->newCompletionValue(ac, ok, rval, &args.rval());
 }
 
 static JSBool
 DebuggerObject_apply(JSContext *cx, uintN argc, Value *vp)
 {
     return ApplyOrCall(cx, argc, vp, ApplyMode);
 }