diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 4cba2c4a925e..8612458b6a01 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1606,6 +1606,16 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx, JS_SetPrivate(flat, nullptr); } + // Before proceeding, eagerly create any same-compartment security wrappers + // that the object might have. This forces us to take the 'WithWrapper' path + // while transplanting that handles this stuff correctly. + { + JSAutoEnterCompartment innerAC; + if (!innerAC.enter(ccx, aOldScope->GetGlobalJSObject()) || + !wrapper->GetSameCompartmentSecurityWrapper(ccx)) + return NS_ERROR_FAILURE; + } + { // scoped lock Native2WrappedNativeMap* oldMap = aOldScope->GetWrappedNativeMap(); Native2WrappedNativeMap* newMap = aNewScope->GetWrappedNativeMap(); @@ -1641,16 +1651,6 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx, (void) newMap->Add(wrapper); } - // Before proceeding, eagerly create any same-compartment security wrappers - // that the object might have. This forces us to take the 'WithWrapper' path - // while transplanting that handles this stuff correctly. - { - JSAutoEnterCompartment innerAC; - if (!innerAC.enter(ccx, aOldScope->GetGlobalJSObject()) || - !wrapper->GetSameCompartmentSecurityWrapper(ccx)) - return NS_ERROR_FAILURE; - } - JSObject *ww = wrapper->GetWrapper(); if (ww) { JSObject *newwrapper;