diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index d934e86716..080705174e 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -2210,6 +2210,11 @@ ReparentWrapper(JSContext* aCx, JS::Handle aObjArg, ErrorResult& aErr js::GetReservedOrProxyPrivateSlot(aObj, DOM_OBJECT_SLOT)); js::SetReservedOrProxyPrivateSlot(aObj, DOM_OBJECT_SLOT, JS::PrivateValue(nullptr)); + aObj = xpc::TransplantObject(aCx, aObj, newobj); + if (!aObj) { + MOZ_CRASH(); + } + nsWrapperCache* cache = nullptr; CallQueryInterface(native, &cache); bool preserving = cache->PreservingWrapper(); @@ -2217,20 +2222,6 @@ ReparentWrapper(JSContext* aCx, JS::Handle aObjArg, ErrorResult& aErr cache->SetWrapper(aObj); cache->SetPreservingWrapper(preserving); - aObj = xpc::TransplantObject(aCx, aObj, newobj); - if (!aObj) { - MOZ_CRASH(); - } - - // Update the wrapper cache again if transplanting didn't use newobj but - // returned some other object. - if (aObj != newobj) { - preserving = cache->PreservingWrapper(); - cache->SetPreservingWrapper(false); - cache->SetWrapper(aObj); - cache->SetPreservingWrapper(preserving); - } - if (propertyHolder) { JS::Rooted copyTo(aCx); if (isProxy) {