зеркало из https://github.com/mozilla/gecko-dev.git
Bug 999297 - Simplify xpc::HasInstance. r=bz
This commit is contained in:
Родитель
8ad042014e
Коммит
1686fcd58d
|
@ -493,45 +493,24 @@ xpc::HasInstance(JSContext *cx, HandleObject objArg, const nsID *iid, bool *bp)
|
|||
if (!obj)
|
||||
return NS_OK;
|
||||
|
||||
if (IsDOMObject(obj)) {
|
||||
// Not all DOM objects implement nsISupports. But if they don't,
|
||||
// there's nothing to do in this HasInstance hook.
|
||||
nsISupports *identity = UnwrapDOMObjectToISupports(obj);
|
||||
if (!identity)
|
||||
return NS_OK;;
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
identity->QueryInterface(*iid, getter_AddRefs(supp));
|
||||
*bp = supp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mozilla::jsipc::JavaScriptParent::IsCPOW(obj))
|
||||
return mozilla::jsipc::JavaScriptParent::InstanceOf(obj, iid, bp);
|
||||
|
||||
MOZ_ASSERT(IS_WN_REFLECTOR(obj));
|
||||
XPCWrappedNative* other_wrapper = XPCWrappedNative::Get(obj);
|
||||
if (!other_wrapper)
|
||||
nsISupports *identity = UnwrapReflectorToISupports(obj);
|
||||
if (!identity)
|
||||
return NS_OK;
|
||||
|
||||
// We'll trust the interface set of the wrapper if this is known
|
||||
// to be an interface that the objects *expects* to be able to
|
||||
// handle.
|
||||
if (other_wrapper->HasInterfaceNoQI(*iid)) {
|
||||
*bp = true;
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
identity->QueryInterface(*iid, getter_AddRefs(supp));
|
||||
*bp = supp;
|
||||
|
||||
// Otherwise, we'll end up Querying the native object to be sure.
|
||||
XPCCallContext ccx(JS_CALLER, cx);
|
||||
|
||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||
iface = XPCNativeInterface::GetNewOrUsed(iid);
|
||||
|
||||
nsresult findResult = NS_OK;
|
||||
if (iface && other_wrapper->FindTearOff(iface, false, &findResult))
|
||||
*bp = true;
|
||||
if (NS_FAILED(findResult) && findResult != NS_ERROR_NO_INTERFACE)
|
||||
return findResult;
|
||||
// Our old HasInstance implementation operated by invoking FindTearOff on
|
||||
// XPCWrappedNatives, and various bits of chrome JS came to depend on
|
||||
// |instanceof| doing an implicit QI if it succeeds. Do a drive-by QI to
|
||||
// preserve that behavior. This is just a compatibility hack, so we don't
|
||||
// really care if it fails.
|
||||
if (IS_WN_REFLECTOR(obj))
|
||||
(void) XPCWrappedNative::Get(obj)->FindTearOff(*iid);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -1431,6 +1431,14 @@ XPCWrappedNative::FindTearOff(XPCNativeInterface* aInterface,
|
|||
return to;
|
||||
}
|
||||
|
||||
XPCWrappedNativeTearOff*
|
||||
XPCWrappedNative::FindTearOff(const nsIID& iid) {
|
||||
AutoJSContext cx;
|
||||
AutoMarkingNativeInterfacePtr iface(cx);
|
||||
iface = XPCNativeInterface::GetNewOrUsed(&iid);
|
||||
return iface ? FindTearOff(iface) : nullptr;
|
||||
}
|
||||
|
||||
nsresult
|
||||
XPCWrappedNative::InitTearOff(XPCWrappedNativeTearOff* aTearOff,
|
||||
XPCNativeInterface* aInterface,
|
||||
|
|
|
@ -2093,6 +2093,8 @@ public:
|
|||
XPCWrappedNativeTearOff* FindTearOff(XPCNativeInterface* aInterface,
|
||||
bool needJSObject = false,
|
||||
nsresult* pError = nullptr);
|
||||
XPCWrappedNativeTearOff* FindTearOff(const nsIID& iid);
|
||||
|
||||
void Mark() const
|
||||
{
|
||||
mSet->Mark();
|
||||
|
|
Загрузка…
Ссылка в новой задаче