Simplify code now that Value is copyable
authorLuke Wagner <lw@mozilla.com>
Thu, 10 Jun 2010 10:09:05 -0700
changeset 52799 f36479b000c6f64ddd037d2f7e76600e3fe8d6cd
parent 52798 182561db34fd5e0edc4d959ccc7b5afaa4b2ef2c
child 52800 e315d1ab94af4203e98c6aecefe7310e88033515
child 52809 2deed859377af2c6dbe9c7ebac0bafa69a8ee5a3
child 52810 5a6f4d2c74f652cc7221ababc442aae20b625621
push idunknown
push userunknown
push dateunknown
milestone1.9.3a5pre
Simplify code now that Value is copyable
js/src/jsapi.cpp
js/src/jsexn.cpp
js/src/jsfun.cpp
js/src/jsobj.cpp
js/src/jsops.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3852,18 +3852,17 @@ JS_CloneFunctionObject(JSContext *cx, JS
         JS_ASSERT(parent);
     }
 
     if (funobj->getClass() != &js_FunctionClass) {
         /*
          * We cannot clone this object, so fail (we used to return funobj, bad
          * idea, but we changed incompatibly to teach any abusers a lesson!).
          */
-        Value v;
-        v.setObject(*funobj);
+        Value v = ObjectTag(*funobj);
         js_ReportIsNotFunction(cx, &v, 0);
         return NULL;
     }
 
     JSFunction *fun = GET_FUNCTION_PRIVATE(cx, funobj);
     JSObject *clone = CloneFunctionObject(cx, fun, parent);
     if (!clone)
         return NULL;
@@ -4091,18 +4090,17 @@ JS_DefineFunctions(JSContext *cx, JSObje
             if (!fun)
                 return JS_FALSE;
             fun->u.n.extra = (uint16)fs->extra;
 
             /*
              * As jsapi.h notes, fs must point to storage that lives as long
              * as fun->object lives.
              */
-            Value priv;
-            priv.setPrivate(fs);
+            Value priv = PrivateTag(fs);
             if (!js_SetReservedSlot(cx, FUN_OBJECT(fun), 0, priv))
                 return JS_FALSE;
         }
 
         JS_ASSERT(!(flags & JSFUN_FAST_NATIVE) ||
                   (uint16)(fs->extra >> 16) <= fs->nargs);
         fun = JS_DefineFunction(cx, obj, fs->name, fs->call, fs->nargs, flags);
         if (!fun)
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -280,18 +280,17 @@ InitExnPrivate(JSContext *cx, JSObject *
     older = JS_SetErrorReporter(cx, NULL);
     state = JS_SaveExceptionState(cx);
 
     callerid = ATOM_TO_JSID(cx->runtime->atomState.callerAtom);
     stackDepth = 0;
     valueCount = 0;
     for (fp = js_GetTopStackFrame(cx); fp; fp = fp->down) {
         if (fp->fun && fp->argv) {
-            Value v;
-            v.setNull();
+            Value v = NullTag();
             if (checkAccess &&
                 !checkAccess(cx, fp->callee(), callerid, JSACC_READ, &v)) {
                 break;
             }
             valueCount += fp->argc;
         }
         ++stackDepth;
     }
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -1941,19 +1941,18 @@ js_fun_apply(JSContext *cx, uintN argc, 
         return js_fun_call(cx, argc, vp);
     }
 
     LeaveTrace(cx);
 
     JSObject *obj = ComputeThisObjectFromVp(cx, vp);
     if (!obj)
         return JS_FALSE;
-    Value fval;
-    fval = vp[1];
-
+
+    Value fval = vp[1];
     if (!js_IsCallable(fval)) {
         JSString *str = js_ValueToString(cx, fval);
         if (str) {
             const char *bytes = js_GetStringBytes(cx, str);
 
             if (bytes) {
                 JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                      JSMSG_INCOMPATIBLE_PROTO,
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -2124,18 +2124,17 @@ DefinePropertyOnObject(JSContext *cx, JS
             return JS_FALSE;
 
         Value tmp = UndefinedTag();
         return js_DefineProperty(cx, obj, desc.id, &tmp,
                                  desc.getter(), desc.setter(), desc.attrs);
     }
 
     /* 8.12.9 steps 5-6 (note 5 is merely a special case of 6). */
-    Value v;
-    v.setUndefined();
+    Value v = UndefinedTag();
 
     /*
      * In the special case of shared permanent properties, the "own" property
      * can be found on a different object.  In that case the returned property
      * might not be native, except: the shared permanent property optimization
      * is not applied if the objects have different classes (bug 320854), as
      * must be enforced by js_HasOwnProperty for the JSScopeProperty cast below
      * to be safe.
@@ -5313,21 +5312,20 @@ js_DeleteProperty(JSContext *cx, JSObjec
     JS_UNLOCK_OBJ(cx, obj);
 
     return ok && js_SuppressDeletedProperty(cx, obj, id);
 }
 
 JSBool
 js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp)
 {
-    Value v;
-    v.setObject(*obj);
+    JS_ASSERT(hint != JSTYPE_OBJECT && hint != JSTYPE_FUNCTION);
+
+    Value v = ObjectTag(*obj);
     if (hint == JSTYPE_STRING) {
-    JS_ASSERT(hint != JSTYPE_OBJECT && hint != JSTYPE_FUNCTION);
-
         /*
          * Optimize for String objects with standard toString methods. Support
          * new String(...) instances whether mutated to have their own scope or
          * not, as well as direct String.prototype references.
          */
         if (obj->getClass() == &js_StringClass) {
             jsid toStringId = ATOM_TO_JSID(cx->runtime->atomState.toStringAtom);
 
--- a/js/src/jsops.cpp
+++ b/js/src/jsops.cpp
@@ -630,18 +630,17 @@ BEGIN_CASE(JSOP_SWAP)
     lref.swap(rref);
 }
 END_CASE(JSOP_SWAP)
 
 BEGIN_CASE(JSOP_PICK)
 {
     jsint i = regs.pc[1];
     JS_ASSERT(regs.sp - (i+1) >= fp->base());
-    Value lval;
-    lval = regs.sp[-(i+1)];
+    Value lval = regs.sp[-(i+1)];
     memmove(regs.sp - (i+1), regs.sp - i, sizeof(Value)*i);
     regs.sp[-1] = lval;
 }
 END_CASE(JSOP_PICK)
 
 #define NATIVE_GET(cx,obj,pobj,sprop,getHow,vp)                               \
     JS_BEGIN_MACRO                                                            \
         if (sprop->hasDefaultGetter()) {                                      \
@@ -1696,18 +1695,17 @@ BEGIN_CASE(JSOP_LENGTH)
         goto do_getprop_with_lval;
     }
 END_CASE(JSOP_LENGTH)
 
 }
 
 BEGIN_CASE(JSOP_CALLPROP)
 {
-    Value lval;
-    lval = regs.sp[-1];
+    Value lval = regs.sp[-1];
 
     Value objv;
     if (lval.isObject()) {
         objv = lval;
     } else {
         JSProtoKey protoKey;
         if (lval.isString()) {
             protoKey = JSProto_String;
@@ -2654,18 +2652,17 @@ BEGIN_CASE(JSOP_LOOKUPSWITCH)
     /*
      * JSOP_LOOKUPSWITCH and JSOP_LOOKUPSWITCHX are never used if any atom
      * index in it would exceed 64K limit.
      */
     JS_ASSERT(!fp->imacpc);
     JS_ASSERT(atoms == script->atomMap.vector);
     jsbytecode *pc2 = regs.pc;
 
-    Value lval;
-    lval = regs.sp[-1];
+    Value lval = regs.sp[-1];
     regs.sp--;
 
     if (!lval.isPrimitive())
         goto end_lookup_switch;
 
     pc2 += off;
     jsint npairs;
     npairs = (jsint) GET_UINT16(pc2);
@@ -2939,18 +2936,17 @@ BEGIN_CASE(JSOP_SETGVAR)
          */
 #ifdef JS_TRACER
         if (TRACE_RECORDER(cx))
             AbortRecording(cx, "SETGVAR with NULL slot");
 #endif
         JSAtom *atom;
         LOAD_ATOM(0, atom);
         jsid id = ATOM_TO_JSID(atom);
-        Value rval;
-        rval = rref;
+        Value rval = rref;
         if (!obj->setProperty(cx, id, &rval))
             goto error;
     } else {
         uint32 slot = (uint32)lref.asInt32();
         JS_LOCK_OBJ(cx, obj);
         JSScope *scope = obj->scope();
         if (!scope->methodWriteBarrier(cx, slot, rref)) {
             JS_UNLOCK_SCOPE(cx, scope);
@@ -3096,18 +3092,17 @@ BEGIN_CASE(JSOP_DEFFUN)
     /*
      * Protect obj from any GC hiding below JSObject::setProperty or
      * JSObject::defineProperty.  All paths from here must flow through the
      * fp->scopeChain code below the parent->defineProperty call.
      */
     MUST_FLOW_THROUGH("restore_scope");
     fp->scopeChain = obj;
 
-    Value rval;
-    rval.setFunObj(*obj);
+    Value rval = FunObjTag(*obj);
 
     /*
      * ECMA requires functions defined when entering Eval code to be
      * impermanent.
      */
     uintN attrs = (fp->flags & JSFRAME_EVAL)
                   ? JSPROP_ENUMERATE
                   : JSPROP_ENUMERATE | JSPROP_PERMANENT;
@@ -3197,18 +3192,17 @@ BEGIN_CASE(JSOP_DEFFUN_DBGFC)
     LOAD_FUNCTION(0);
 
     JSObject *obj = (op == JSOP_DEFFUN_FC)
                     ? js_NewFlatClosure(cx, fun)
                     : js_NewDebuggableFlatClosure(cx, fun);
     if (!obj)
         goto error;
 
-    Value rval;
-    rval.setFunObj(*obj);
+    Value rval = FunObjTag(*obj);
 
     uintN attrs = (fp->flags & JSFRAME_EVAL)
                   ? JSPROP_ENUMERATE
                   : JSPROP_ENUMERATE | JSPROP_PERMANENT;
 
     uintN flags = JSFUN_GSFLAG2ATTR(fun->flags);
     if (flags) {
         attrs |= flags | JSPROP_SHARED;
@@ -3579,18 +3573,17 @@ BEGIN_CASE(JSOP_ENDINIT)
 }
 END_CASE(JSOP_ENDINIT)
 
 BEGIN_CASE(JSOP_INITPROP)
 BEGIN_CASE(JSOP_INITMETHOD)
 {
     /* Load the property's initial value into rval. */
     JS_ASSERT(regs.sp - fp->base() >= 2);
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
 
     /* Load the object being initialized into lval/obj. */
     JSObject *obj = &regs.sp[-2].asObject();
     JS_ASSERT(obj->isNative());
     JS_ASSERT(!obj->getClass()->reserveSlots);
 
     JSScope *scope = obj->scope();
 
@@ -3777,18 +3770,17 @@ BEGIN_CASE(JSOP_USESHARP)
 }
 END_CASE(JSOP_USESHARP)
 
 BEGIN_CASE(JSOP_SHARPINIT)
 {
     uint32 slot = GET_UINT16(regs.pc);
     JS_ASSERT(slot + 1 < fp->script->nfixed);
     Value *vp = &fp->slots()[slot];
-    Value rval;
-    rval = vp[1];
+    Value rval = vp[1];
 
     /*
      * We peek ahead safely here because empty initialisers get zero
      * JSOP_SHARPINIT ops, and non-empty ones get two: the first comes
      * immediately after JSOP_NEWINIT followed by one or more property
      * initialisers; and the second comes directly before JSOP_ENDINIT.
      */
     if (regs.pc[JSOP_SHARPINIT_LENGTH] != JSOP_ENDINIT) {
@@ -3987,30 +3979,28 @@ BEGIN_CASE(JSOP_QNAMEPART)
 }
 END_CASE(JSOP_QNAMEPART)
 
 BEGIN_CASE(JSOP_QNAMECONST)
 {
     JSAtom *atom;
     LOAD_ATOM(0, atom);
     Value rval = StringTag(ATOM_TO_STRING(atom));
-    Value lval;
-    lval = regs.sp[-1];
+    Value lval = regs.sp[-1];
     JSObject *obj = js_ConstructXMLQNameObject(cx, lval, rval);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_QNAMECONST)
 
 BEGIN_CASE(JSOP_QNAME)
 {
-    Value rval, lval;
-    rval = regs.sp[-1];
-    lval = regs.sp[-2];
+    Value rval = regs.sp[-1];
+    Value lval = regs.sp[-2];
     JSObject *obj = js_ConstructXMLQNameObject(cx, lval, rval);
     if (!obj)
         goto error;
     regs.sp--;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_QNAME)
 
@@ -4034,19 +4024,18 @@ BEGIN_CASE(JSOP_TOATTRVAL)
         goto error;
     regs.sp[-1].setString(str);
 }
 END_CASE(JSOP_TOATTRVAL)
 
 BEGIN_CASE(JSOP_ADDATTRNAME)
 BEGIN_CASE(JSOP_ADDATTRVAL)
 {
-    Value rval, lval;
-    rval = regs.sp[-1];
-    lval = regs.sp[-2];
+    Value rval = regs.sp[-1];
+    Value lval = regs.sp[-2];
     JSString *str = lval.asString();
     JSString *str2 = rval.asString();
     str = js_AddAttributePart(cx, op == JSOP_ADDATTRNAME, str, str2);
     if (!str)
         goto error;
     regs.sp--;
     regs.sp[-1].setString(str);
 }
@@ -4063,33 +4052,31 @@ BEGIN_CASE(JSOP_BINDXMLNAME)
     regs.sp[-1].setObjectOrNull(obj);
     PUSH_COPY(ID_TO_VALUE(id));
 }
 END_CASE(JSOP_BINDXMLNAME)
 
 BEGIN_CASE(JSOP_SETXMLNAME)
 {
     JSObject *obj = &regs.sp[-3].asObject();
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     jsid id;
     FETCH_ELEMENT_ID(obj, -2, id);
     if (!obj->setProperty(cx, id, &rval))
         goto error;
     rval = regs.sp[-1];
     regs.sp -= 2;
     regs.sp[-1] = rval;
 }
 END_CASE(JSOP_SETXMLNAME)
 
 BEGIN_CASE(JSOP_CALLXMLNAME)
 BEGIN_CASE(JSOP_XMLNAME)
 {
-    Value lval;
-    lval = regs.sp[-1];
+    Value lval = regs.sp[-1];
     JSObject *obj;
     jsid id;
     if (!js_FindXMLProperty(cx, lval, &obj, &id))
         goto error;
     Value rval;
     if (!obj->getProperty(cx, id, &rval))
         goto error;
     regs.sp[-1] = rval;
@@ -4155,51 +4142,47 @@ BEGIN_CASE(JSOP_ENDFILTER)
         BRANCH(len);
     }
     regs.sp--;
 }
 END_CASE(JSOP_ENDFILTER);
 
 BEGIN_CASE(JSOP_TOXML)
 {
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     JSObject *obj = js_ValueToXMLObject(cx, rval);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_TOXML)
 
 BEGIN_CASE(JSOP_TOXMLLIST)
 {
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     JSObject *obj = js_ValueToXMLListObject(cx, rval);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_TOXMLLIST)
 
 BEGIN_CASE(JSOP_XMLTAGEXPR)
 {
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     JSString *str = js_ValueToString(cx, rval);
     if (!str)
         goto error;
     regs.sp[-1].setString(str);
 }
 END_CASE(JSOP_XMLTAGEXPR)
 
 BEGIN_CASE(JSOP_XMLELTEXPR)
 {
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     JSString *str;
     if (IsXML(rval)) {
         str = js_ValueToXMLString(cx, rval);
     } else {
         str = js_ValueToString(cx, rval);
         if (str)
             str = js_EscapeElementValue(cx, str);
     }
@@ -4244,18 +4227,17 @@ BEGIN_CASE(JSOP_XMLCOMMENT)
 }
 END_CASE(JSOP_XMLCOMMENT)
 
 BEGIN_CASE(JSOP_XMLPI)
 {
     JSAtom *atom;
     LOAD_ATOM(0, atom);
     JSString *str = ATOM_TO_STRING(atom);
-    Value rval;
-    rval = regs.sp[-1];
+    Value rval = regs.sp[-1];
     JSString *str2 = rval.asString();
     JSObject *obj = js_NewXMLSpecialObject(cx, JSXML_CLASS_PROCESSING_INSTRUCTION, str, str2);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_XMLPI)