Bug 507047. Remove unnecessary toString override from COWs. r=jst
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 05 Aug 2009 14:39:05 +1200
changeset 31135 981030c48c4151d47af4497dc5af2fea24f0a809
parent 31134 60add17e8ed3b01ff2cfa6057dcdf524dce67933
child 31136 c9b642c7a69935ddb616af3c2b1abfa30f9d701a
push id8388
push userrocallahan@mozilla.com
push dateWed, 05 Aug 2009 02:43:46 +0000
treeherdermozilla-central@73e08f744e9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs507047
milestone1.9.2a1pre
Bug 507047. Remove unnecessary toString override from COWs. r=jst
js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
--- a/js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
+++ b/js/src/xpconnect/src/XPCChromeObjectWrapper.cpp
@@ -102,20 +102,16 @@ JSExtendedClass sXPC_COW_JSClass = {
   XPC_COW_Equality,
   nsnull,             // outerObject
   nsnull,             // innerObject
   XPC_COW_Iterator,
   XPC_COW_WrappedObject,
   JSCLASS_NO_RESERVED_MEMBERS
 };
 
-static JSBool
-XPC_COW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
-                 jsval *rval);
-
 // Throws an exception on context |cx|.
 static inline JSBool
 ThrowException(nsresult rv, JSContext *cx)
 {
   return XPCWrapper::ThrowException(rv, cx);
 }
 
 // Like GetWrappedObject, but works on other types of wrappers, too.
@@ -351,20 +347,16 @@ XPC_COW_DelProperty(JSContext *cx, JSObj
   // Deleting a property is safe.
   return XPCWrapper::DelProperty(cx, wrappedObj, id, vp);
 }
 
 static JSBool
 XPC_COW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
                          JSBool isSet)
 {
-  if (id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING)) {
-    return JS_TRUE;
-  }
-
   obj = GetWrapper(obj);
   if (!obj) {
     return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx);
   }
 
   XPCCallContext ccx(JS_CALLER, cx);
   if (!ccx.IsValid()) {
     return ThrowException(NS_ERROR_FAILURE, cx);
@@ -445,56 +437,32 @@ XPC_COW_NewResolve(JSContext *cx, JSObje
     return JS_TRUE;
   }
 
   XPCCallContext ccx(JS_CALLER, cx);
   if (!ccx.IsValid()) {
     return ThrowException(NS_ERROR_FAILURE, cx);
   }
 
-  if (id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING)) {
-    jsval oldSlotVal;
-    if (!::JS_GetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, &oldSlotVal) ||
-        !::JS_SetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot,
-                              INT_TO_JSVAL(JSVAL_TO_INT(oldSlotVal) |
-                                           FLAG_RESOLVING))) {
-      return JS_FALSE;
-    }
-
-    JSBool ok = JS_DefineFunction(cx, obj, "toString",
-                                  XPC_COW_toString, 0, 0) != nsnull;
-
-    if (ok && (ok = ::JS_SetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot,
-                                         oldSlotVal))) {
-      *objp = obj;
-    }
-
-    return ok;
-  }
-
   return XPCWrapper::NewResolve(cx, obj, JS_TRUE, wrappedObj, id, flags, objp);
 }
 
 static JSBool
 XPC_COW_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
 {
   // Don't do any work to convert to object.
   if (type == JSTYPE_OBJECT) {
     *vp = OBJECT_TO_JSVAL(obj);
     return JS_TRUE;
   }
 
   JSObject *wrappedObj = GetWrappedObject(cx, obj);
   if (!wrappedObj) {
     // Converting the prototype to something.
 
-    if (type == JSTYPE_STRING || type == JSTYPE_VOID) {
-      return XPC_COW_toString(cx, obj, 0, nsnull, vp);
-    }
-
     *vp = OBJECT_TO_JSVAL(obj);
     return JS_TRUE;
   }
 
   XPCCallContext ccx(JS_CALLER, cx);
   if (!ccx.IsValid()) {
     return ThrowException(NS_ERROR_FAILURE, cx);
   }
@@ -584,48 +552,16 @@ XPC_COW_Iterator(JSContext *cx, JSObject
 }
 
 static JSObject *
 XPC_COW_WrappedObject(JSContext *cx, JSObject *obj)
 {
   return GetWrappedObject(cx, obj);
 }
 
-static JSBool
-XPC_COW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
-                 jsval *rval)
-{
-  obj = GetWrapper(obj);
-  if (!obj) {
-    return ThrowException(NS_ERROR_UNEXPECTED, cx);
-  }
-
-  JSObject *wrappedObj = GetWrappedObject(cx, obj);
-  if (!wrappedObj) {
-    // Someone's calling toString on our prototype.
-    NS_NAMED_LITERAL_CSTRING(protoString, "[object XPCCrossOriginWrapper]");
-    JSString *str =
-      JS_NewStringCopyN(cx, protoString.get(), protoString.Length());
-    if (!str) {
-      return JS_FALSE;
-    }
-    *rval = STRING_TO_JSVAL(str);
-    return JS_TRUE;
-  }
-
-  XPCCallContext ccx(JS_CALLER, cx);
-  if (!ccx.IsValid()) {
-    return ThrowException(NS_ERROR_FAILURE, cx);
-  }
-
-  XPCWrappedNative *wn =
-    XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj);
-  return XPCWrapper::NativeToString(cx, wn, argc, argv, rval, JS_FALSE);
-}
-
 JSBool
 XPC_COW_WrapObject(JSContext *cx, JSObject *parent, jsval v, jsval *vp)
 {
   JSObject *wrapperObj =
     JS_NewObjectWithGivenProto(cx, &sXPC_COW_JSClass.base, NULL, parent);
   if (!wrapperObj) {
     return JS_FALSE;
   }