Bug 708825 - set mIdentity to null if compartment enter fails. r=bholley a=akeybl
authorAndrew McCreight <amccreight@mozilla.com>
Fri, 09 Mar 2012 18:41:13 -0800
changeset 92017 8ea9983dc06325d078558809bd67967f937db3a6
parent 92016 ff9768ab37b77ff40721e66ac9abb9cb7fd14c43
child 92018 c77d34d9dc8c18ce8351a1eaa6602622f08b5537
push idunknown
push userunknown
push dateunknown
reviewersbholley, akeybl
bugs708825
milestone13.0a2
Bug 708825 - set mIdentity to null if compartment enter fails. r=bholley a=akeybl
js/xpconnect/src/XPCWrappedNative.cpp
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -839,17 +839,21 @@ XPCWrappedNative::Morph(XPCCallContext& 
 
     // We use an AutoMarkingPtr here because it is possible for JS gc to happen
     // after we have Init'd the wrapper but *before* we add it to the hashtable.
     // This would cause the mSet to get collected and we'd later crash. I've
     // *seen* this happen.
     AutoMarkingWrappedNativePtr wrapperMarker(ccx, wrapper);
 
     JSAutoEnterCompartment ac;
-    if (!ac.enter(ccx, existingJSObject) || !wrapper->Init(ccx, existingJSObject))
+    if (!ac.enter(ccx, existingJSObject)) {
+        wrapper->mIdentity = nsnull;
+        return NS_ERROR_FAILURE;
+    }
+    if (!wrapper->Init(ccx, existingJSObject))
         return NS_ERROR_FAILURE;
 
     nsresult rv;
     if (Interface && !wrapper->FindTearOff(ccx, Interface, false, &rv)) {
         NS_ASSERTION(NS_FAILED(rv), "returning NS_OK on failure");
         return rv;
     }