Fix for bug 604362 (Don't rewrap XPCWrappedNatives that don't have classinfo). r=mrbkap, a=blocking
authorPeter Van der Beken <peterv@propagandism.org>
Sat, 16 Oct 2010 01:43:53 -0700
changeset 55947 f9f10c04dceb103e774f79f3a8d60e5a697bb4c9
parent 55946 bd3e354ddb1ade7fd584c51811497c046e744e92
child 55949 a61ca0dfe56b37420f450597f276c998a319d79a
push id16349
push userpvanderbeken@mozilla.com
push dateSat, 16 Oct 2010 20:16:22 +0000
treeherdermozilla-central@f9f10c04dceb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, blocking
bugs604362
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 604362 (Don't rewrap XPCWrappedNatives that don't have classinfo). r=mrbkap, a=blocking
js/src/xpconnect/tests/unit/test_bug604362.js
js/src/xpconnect/wrappers/WrapperFactory.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/xpconnect/tests/unit/test_bug604362.js
@@ -0,0 +1,12 @@
+function run_test() {
+  var Cc = Components.classes;
+  var Ci = Components.interfaces;
+  var sp = Cc["@mozilla.org/systemprincipal;1"].
+           createInstance(Ci.nsIPrincipal);
+  var s = Components.utils.Sandbox(sp);
+  s.a = [];
+  s.Cu = Components.utils;
+  s.C = Components;
+  s.do_check_neq = do_check_neq;
+  Components.utils.evalInSandbox("do_check_neq(Cu.import, undefined);", s);
+}
--- a/js/src/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/src/xpconnect/wrappers/WrapperFactory.cpp
@@ -103,16 +103,21 @@ WrapperFactory::PrepareForWrapping(JSCon
     // those objects in a security wrapper, then we need to hand back the
     // wrapper for the new scope instead. Also, global objects don't move
     // between scopes so for those we also want to return the wrapper. So...
     if (!IS_WN_WRAPPER(obj) || !obj->getParent())
         return DoubleWrap(cx, obj, flags);
 
     XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
 
+    // If the object doesn't have classinfo we want to return the same
+    // XPCWrappedNative so that we keep the same set of interfaces.
+    if (!wn->GetClassInfo())
+        return DoubleWrap(cx, obj, flags);
+
     // We know that DOM objects only allow one object, we can return early.
     if (wn->HasProto() && wn->GetProto()->ClassIsDOMObject())
         return DoubleWrap(cx, obj, flags);
 
     XPCCallContext ccx(JS_CALLER, cx, obj);
     if (NATIVE_HAS_FLAG(&ccx, WantPreCreate)) {
         // We have a precreate hook. This object might enforce that we only
         // ever create JS object for it.