Bug 505217 - Don't wrap slim wrappers in SOWs. r+sr=peterv
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 10 Aug 2009 16:01:42 -0700
changeset 31315 45832a03722d7892b210a429be704260051f02d8
parent 31314 9c54fecf8cfc0a5129fef8ca5cc99bf164ffba9f
child 31316 3c54e89da87da2b2ea2ed4cfb1a3306ba42ee35d
push id8488
push usermrbkap@mozilla.com
push dateMon, 10 Aug 2009 23:02:44 +0000
treeherdermozilla-central@505615255899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs505217
milestone1.9.2a2pre
Bug 505217 - Don't wrap slim wrappers in SOWs. r+sr=peterv
js/src/xpconnect/src/XPCSystemOnlyWrapper.cpp
--- a/js/src/xpconnect/src/XPCSystemOnlyWrapper.cpp
+++ b/js/src/xpconnect/src/XPCSystemOnlyWrapper.cpp
@@ -693,16 +693,23 @@ XPC_SOW_toString(JSContext *cx, JSObject
     XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj);
   return XPCWrapper::NativeToString(cx, wn, argc, argv, rval, JS_FALSE);
 }
 
 JSBool
 XPC_SOW_WrapObject(JSContext *cx, JSObject *parent, jsval v,
                    jsval *vp)
 {
+  // Slim wrappers don't expect to be wrapped, so morph them to fat wrappers
+  // if we're about to wrap one.
+  JSObject *innerObj = JSVAL_TO_OBJECT(v);
+  if (IS_SLIM_WRAPPER(innerObj) && !MorphSlimWrapper(cx, innerObj)) {
+    return ThrowException(NS_ERROR_FAILURE, cx);
+  }
+
   JSObject *wrapperObj =
     JS_NewObjectWithGivenProto(cx, &sXPC_SOW_JSClass.base, NULL, parent);
   if (!wrapperObj) {
     return JS_FALSE;
   }
 
   *vp = OBJECT_TO_JSVAL(wrapperObj);
   JSAutoTempValueRooter tvr(cx, *vp);