Bug 569471 - Rename js_GetWrappedObject to JSObject::wrappedObject. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Tue, 01 Jun 2010 15:59:02 -0700
changeset 43261 97874793a87a57c951bee55c9ee7ab4c6cf84bc6
parent 43260 71a8c9b6136e7e1f29610b7a470a1b04e0a58135
child 43262 02485857682cfbc64db06158c41f86f519515412
push idunknown
push userunknown
push dateunknown
reviewersjorendorff
bugs569471
milestone1.9.3a5pre
Bug 569471 - Rename js_GetWrappedObject to JSObject::wrappedObject. r=jorendorff
js/src/jsapi.cpp
js/src/jsarray.cpp
js/src/jsdbgapi.cpp
js/src/jsgc.cpp
js/src/jsinterp.cpp
js/src/jsobj.cpp
js/src/jsobj.h
js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3756,17 +3756,17 @@ JS_NewArrayObject(JSContext *cx, jsint l
     CHECK_REQUEST(cx);
     /* NB: jsuint cast does ToUint32. */
     return js_NewArrayObject(cx, (jsuint)length, vector);
 }
 
 JS_PUBLIC_API(JSBool)
 JS_IsArrayObject(JSContext *cx, JSObject *obj)
 {
-    return js_GetWrappedObject(cx, obj)->isArray();
+    return obj->wrappedObject(cx)->isArray();
 }
 
 JS_PUBLIC_API(JSBool)
 JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp)
 {
     CHECK_REQUEST(cx);
     return js_GetLengthProperty(cx, obj, lengthp);
 }
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -594,17 +594,17 @@ js_HasLengthProperty(JSContext *cx, JSOb
 
     *lengthp = ValueIsLength(cx, tvr.addr());
     return !JSVAL_IS_NULL(tvr.value());
 }
 
 JSBool
 js_IsArrayLike(JSContext *cx, JSObject *obj, JSBool *answerp, jsuint *lengthp)
 {
-    JSObject *wrappedObj = js_GetWrappedObject(cx, obj);
+    JSObject *wrappedObj = obj->wrappedObject(cx);
 
     *answerp = wrappedObj->isArguments() || wrappedObj->isArray();
     if (!*answerp) {
         *lengthp = 0;
         return JS_TRUE;
     }
     return js_GetLengthProperty(cx, obj, lengthp);
 }
@@ -2595,17 +2595,17 @@ array_concat(JSContext *cx, uintN argc, 
     for (i = 0; i <= argc; i++) {
         if (!JS_CHECK_OPERATION_LIMIT(cx))
             return false;
         v = argv[i];
         if (!JSVAL_IS_PRIMITIVE(v)) {
             JSObject *wobj;
 
             aobj = JSVAL_TO_OBJECT(v);
-            wobj = js_GetWrappedObject(cx, aobj);
+            wobj = aobj->wrappedObject(cx);
             if (wobj->isArray()) {
                 jsid id = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
                 if (!aobj->getProperty(cx, id, tvr.addr()))
                     return false;
                 alength = ValueIsLength(cx, tvr.addr());
                 if (JSVAL_IS_NULL(tvr.value()))
                     return false;
                 for (slot = 0; slot < alength; slot++) {
@@ -3036,17 +3036,17 @@ array_every(JSContext *cx, uintN argc, j
 }
 #endif
 
 static JSBool
 array_isArray(JSContext *cx, uintN argc, jsval *vp)
 {
     *vp = BOOLEAN_TO_JSVAL(argc > 0 &&
                            !JSVAL_IS_PRIMITIVE(vp[2]) &&
-                           js_GetWrappedObject(cx, JSVAL_TO_OBJECT(vp[2]))->isArray());
+                           JSVAL_TO_OBJECT(vp[2])->wrappedObject(cx)->isArray());
     return JS_TRUE;
 }
 
 static JSPropertySpec array_props[] = {
     {js_length_str,   -1,   JSPROP_SHARED | JSPROP_PERMANENT,
                             array_length_getter,    array_length_setter},
     {0,0,0,0,0}
 };
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -790,17 +790,17 @@ JS_SetWatchPoint(JSContext *cx, JSObject
     JSProperty *prop;
     JSScopeProperty *sprop;
     JSRuntime *rt;
     JSBool ok;
     JSWatchPoint *wp;
     JSPropertyOp watcher;
 
     origobj = obj;
-    obj = js_GetWrappedObject(cx, obj);
+    obj = obj->wrappedObject(cx);
     OBJ_TO_INNER_OBJECT(cx, obj);
     if (!obj)
         return JS_FALSE;
 
     AutoValueRooter idroot(cx);
     if (JSVAL_IS_INT(idval)) {
         propid = INT_JSVAL_TO_JSID(idval);
     } else {
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -3253,17 +3253,17 @@ js_SetProtoOrParentCheckingForCycles(JSC
     BeginGCSession(cx);
 
     bool cycle;
     {
         AutoUnlockGC unlock(rt);
 
         cycle = false;
         for (JSObject *obj2 = pobj; obj2;) {
-            obj2 = js_GetWrappedObject(cx, obj2);
+            obj2 = obj2->wrappedObject(cx);
             if (obj2 == obj) {
                 cycle = true;
                 break;
             }
             obj2 = (slot == JSSLOT_PARENT) ? obj2->getParent() : obj2->getProto();
         }
         if (!cycle) {
             if (slot == JSSLOT_PARENT)
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -981,18 +981,18 @@ js_StrictlyEqual(JSContext *cx, jsval lv
             return JSDOUBLE_COMPARE(ld, ==, rd, JS_FALSE);
         }
         if (ltag == JSVAL_OBJECT &&
             lval != rval &&
             !JSVAL_IS_NULL(lval) &&
             !JSVAL_IS_NULL(rval)) {
             JSObject *lobj, *robj;
 
-            lobj = js_GetWrappedObject(cx, JSVAL_TO_OBJECT(lval));
-            robj = js_GetWrappedObject(cx, JSVAL_TO_OBJECT(rval));
+            lobj = JSVAL_TO_OBJECT(lval)->wrappedObject(cx);
+            robj = JSVAL_TO_OBJECT(rval)->wrappedObject(cx);
             lval = OBJECT_TO_JSVAL(lobj);
             rval = OBJECT_TO_JSVAL(robj);
         }
         return lval == rval;
     }
     if (ltag == JSVAL_DOUBLE && JSVAL_IS_INT(rval)) {
         ld = *JSVAL_TO_DOUBLE(lval);
         rd = JSVAL_TO_INT(rval);
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -874,17 +874,17 @@ obj_toString(JSContext *cx, uintN argc, 
 
     obj = JS_THIS_OBJECT(cx, vp);
     if (!obj)
         return JS_FALSE;
     if (obj->isProxy()) {
         if (!GetProxyObjectClass(cx, obj, &clazz))
             return false;
     } else {
-        obj = js_GetWrappedObject(cx, obj);
+        obj = obj->wrappedObject(cx);
         clazz = obj->getClass()->name;
     }
     nchars = 9 + strlen(clazz);         /* 9 for "[object ]" */
     chars = (jschar *) cx->malloc((nchars + 1) * sizeof(jschar));
     if (!chars)
         return JS_FALSE;
 
     prefix = "[object ";
@@ -1078,29 +1078,29 @@ obj_eval(JSContext *cx, uintN argc, jsva
                              JSMSG_BAD_INDIRECT_CALL, js_eval_str);
         return JS_FALSE;
     }
 
     jsbytecode *callerPC = caller->pc(cx);
     bool indirectCall = (callerPC && *callerPC != JSOP_EVAL);
 
     /*
-     * This call to js_GetWrappedObject is safe because of the security checks
-     * we do below. However, the control flow below is confusing, so we double
-     * check. There are two cases:
+     * This call to JSObject::wrappedObject is safe because of the security
+     * checks we do below. However, the control flow below is confusing, so we
+     * double check. There are two cases:
      * - Direct call: This object is never used. So unwrapping can't hurt.
      * - Indirect call: If this object isn't already the scope chain (which
      *   we're guaranteed to be allowed to access) then we do a security
      *   check.
      */
     jsval *argv = JS_ARGV(cx, vp);
     JSObject *obj = JS_THIS_OBJECT(cx, vp);
     if (!obj)
         return JS_FALSE;
-    obj = js_GetWrappedObject(cx, obj);
+    obj = obj->wrappedObject(cx);
 
     /*
      * Ban all indirect uses of eval (global.foo = eval; global.foo(...)) and
      * calls that attempt to use a non-global object as the "with" object in
      * the former indirect case.
      */
     {
         JSObject *parent = obj->getParent();
@@ -1191,17 +1191,17 @@ obj_eval(JSContext *cx, uintN argc, jsva
              * NB: This means that native callers (who reach this point through
              * the C API) must use the two parameter form.
              */
             JS_ASSERT_IF(caller->argv, caller->callobj);
             scopeobj = callerScopeChain;
         }
 #endif
     } else {
-        scopeobj = js_GetWrappedObject(cx, scopeobj);
+        scopeobj = scopeobj->wrappedObject(cx);
         OBJ_TO_INNER_OBJECT(cx, scopeobj);
         if (!scopeobj)
             return JS_FALSE;
 
         if (!js_CheckPrincipalsAccess(cx, scopeobj,
                                       JS_StackFramePrincipals(cx, caller),
                                       cx->runtime->atomState.evalAtom))
             return JS_FALSE;
@@ -5551,17 +5551,17 @@ js_CheckAccess(JSContext *cx, JSObject *
 JSType
 js_TypeOf(JSContext *cx, JSObject *obj)
 {
     /*
      * Unfortunately we have wrappers that are native objects and thus don't
      * overwrite js_TypeOf (i.e. XPCCrossOriginWrapper), so we have to
      * unwrap here.
      */
-    obj = js_GetWrappedObject(cx, obj);
+    obj = obj->wrappedObject(cx);
 
     /*
      * ECMA 262, 11.4.3 says that any native object that implements
      * [[Call]] should be of type "function". However, RegExp is of
      * type "object", not "function", for Web compatibility.
      */
     if (obj->isCallable()) {
         return (obj->getClass() != &js_RegExpClass)
@@ -5723,17 +5723,17 @@ js_HasInstance(JSContext *cx, JSObject *
 JSBool
 js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
 {
     JSObject *obj2;
 
     *bp = JS_FALSE;
     if (JSVAL_IS_PRIMITIVE(v))
         return JS_TRUE;
-    obj2 = js_GetWrappedObject(cx, JSVAL_TO_OBJECT(v));
+    obj2 = JSVAL_TO_OBJECT(v)->wrappedObject(cx);
     while ((obj2 = obj2->getProto()) != NULL) {
         if (obj2 == obj) {
             *bp = JS_TRUE;
             break;
         }
     }
     return JS_TRUE;
 }
@@ -6293,30 +6293,26 @@ js_SetReservedSlot(JSContext *cx, JSObje
 
     obj->setSlot(slot, v);
     GC_POKE(cx, JS_NULL);
     JS_UNLOCK_SCOPE(cx, scope);
     return true;
 }
 
 JSObject *
-js_GetWrappedObject(JSContext *cx, JSObject *obj)
-{
-    JSClass *clasp;
-
-    clasp = obj->getClass();
+JSObject::wrappedObject(JSContext *cx) const
+{
+    JSClass *clasp = getClass();
     if (clasp->flags & JSCLASS_IS_EXTENDED) {
-        JSExtendedClass *xclasp;
-        JSObject *obj2;
-
-        xclasp = (JSExtendedClass *)clasp;
-        if (xclasp->wrappedObject && (obj2 = xclasp->wrappedObject(cx, obj)))
-            return obj2;
-    }
-    return obj;
+        if (JSObjectOp wrappedObject = reinterpret_cast<JSExtendedClass *>(clasp)->wrappedObject) {
+            if (JSObject *obj = wrappedObject(cx, const_cast<JSObject *>(this)))
+                return obj;
+        }
+    }
+    return const_cast<JSObject *>(this);
 }
 
 JSObject *
 JSObject::getGlobal()
 {
     JSObject *obj = this;
     while (JSObject *parent = obj->getParent())
         obj = parent;
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -671,16 +671,18 @@ struct JSObject {
                        uintN *attrsp) {
         return map->ops->checkAccess(cx, this, id, mode, vp, attrsp);
     }
 
     JSType typeOf(JSContext *cx) {
         return map->ops->typeOf(cx, this);
     }
 
+    JSObject *wrappedObject(JSContext *cx) const;
+
     /* These four are time-optimized to avoid stub calls. */
     JSObject *thisObject(JSContext *cx) {
         return map->ops->thisObject ? map->ops->thisObject(cx, this) : this;
     }
 
     void dropProperty(JSContext *cx, JSProperty *prop) {
         if (map->ops->dropProperty)
             map->ops->dropProperty(cx, this, prop);
--- a/js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
+++ b/js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
@@ -313,17 +313,17 @@ using namespace ChromeObjectWrapper;
 // Throws an exception on context |cx|.
 static inline JSBool
 ThrowException(nsresult rv, JSContext *cx)
 {
   return XPCWrapper::DoThrowException(rv, cx);
 }
 
 // Like GetWrappedObject, but works on other types of wrappers, too.
-// See also js_GetWrappedObject in jsobj.h.
+// See also JSObject::wrappedObject in jsobj.cpp.
 // TODO Move to XPCWrapper?
 static inline JSObject *
 GetWrappedJSObject(JSContext *cx, JSObject *obj)
 {
   JSClass *clasp = obj->getClass();
   if (!(clasp->flags & JSCLASS_IS_EXTENDED)) {
     return obj;
   }