Bug 1463016: Part 6 - Allow JS callers to Window constructors as IID. r?bz
There are still a few places where it's going to be hard to remove
getInterface(nsIDOMWindow) calls. Since native callers should not be using
XPCOM interfaces when dealing with DOM Windows and we ideally want to stop
implementing any stub interfaces on DOM objects, that makes things difficult.
This workaround allows us to pass DOM constructors, in particular Window
objects, in place of IIDs, and automatically convert them to native IIDs for
QueryInterface purposes.
I took the simple approach here, and hard coded the handling of the Window
prototype. That's the general approach a lot of the rest of XPCConvert takes,
and I don't immediately forsee us needing to add other interfaces in the
future, so it seems sufficient.
MozReview-Commit-ID: 6WT2SBHboHO
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -783,16 +783,26 @@ xpc_JSObjectToID(JSContext* cx, JSObject
if (obj && IS_WN_REFLECTOR(obj))
wrapper = XPCWrappedNative::Get(obj);
if (wrapper &&
(wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSID)) ||
wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSIID)) ||
wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSCID)))) {
return ((nsIJSID*)wrapper->GetIdentityObject())->GetID();
}
+ if (dom::IsDOMConstructor(obj)) {
+ const js::Class* clasp = js::GetObjectClass(obj);
+ auto iface = dom::DOMIfaceAndProtoJSClass::FromJSClass(clasp);
+ switch (iface->mPrototypeID) {
+ case dom::prototypes::id::Window:
+ return &NS_GET_IID(nsPIDOMWindowOuter);
+ default:
+ break;
+ }
+ }
return nullptr;
}
bool
xpc_JSObjectIsID(JSContext* cx, JSObject* obj)
{
MOZ_ASSERT(cx && obj, "bad param");
// NOTE: this call does NOT addref