Fix for bug 814821 (Dromaeo dom-traverse regression from bug 812333) - part 3: reorder castNativeFromWrapper. r=bz.

--HG--
extra : rebase_source : ad4c96a240140f56b1b451df3b57a4d5c47ee3ee
This commit is contained in:
Peter Van der Beken 2012-11-27 10:20:05 +01:00
parent f805d53dbb
commit 25dce7afd5

View File

@ -435,49 +435,43 @@ castNativeFromWrapper(JSContext *cx,
return nullptr;
}
*rv = NS_ERROR_XPC_BAD_CONVERT_JS;
nsISupports *native;
if (wrapper) {
native = wrapper->GetIdentityObject();
cur = wrapper->GetFlatJSObject();
if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) {
return nullptr;
native = nullptr;
} else if (lccx) {
lccx->SetWrapper(wrapper, tearoff);
}
} else if (cur) {
if (IS_SLIM_WRAPPER(cur)) {
native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));
if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) {
return nullptr;
}
} else if (protoDepth >= 0) {
const mozilla::dom::DOMClass* domClass;
mozilla::dom::DOMObjectSlot slot =
mozilla::dom::GetDOMClass(cur, domClass);
native = mozilla::dom::UnwrapDOMObject<nsISupports>(cur, slot);
if (!native ||
(uint32_t)domClass->mInterfaceChain[protoDepth] != protoID) {
return nullptr;
}
} else {
return nullptr;
} else if (cur && IS_SLIM_WRAPPER(cur)) {
native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));
if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) {
native = nullptr;
} else if (lccx) {
lccx->SetWrapper(cur);
}
} else if (cur && protoDepth >= 0) {
const mozilla::dom::DOMClass* domClass;
mozilla::dom::DOMObjectSlot slot =
mozilla::dom::GetDOMClass(cur, domClass);
native = mozilla::dom::UnwrapDOMObject<nsISupports>(cur, slot);
if (native &&
(uint32_t)domClass->mInterfaceChain[protoDepth] != protoID) {
native = nullptr;
}
} else {
return nullptr;
native = nullptr;
}
*pRef = nullptr;
*pVal = OBJECT_TO_JSVAL(cur);
if (lccx) {
if (wrapper)
lccx->SetWrapper(wrapper, tearoff);
else if (IS_SLIM_WRAPPER(cur))
lccx->SetWrapper(cur);
if (native) {
*pRef = nullptr;
*pVal = OBJECT_TO_JSVAL(cur);
*rv = NS_OK;
} else {
*rv = NS_ERROR_XPC_BAD_CONVERT_JS;
}
*rv = NS_OK;
return native;
}