Bug 1463016: Part 6 - Allow JS callers to Window constructors as IID. r?bz draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 20 May 2018 18:53:57 -0700
changeset 797630 826ba2f7c7df1f70f014090ed08b68a1db970355
parent 797629 2d6bbf5a4b3e24733ca9547aff852974aaff92d3
child 797631 665b4dc9674e11d0ff94b6da23d52746948d375a
push id110518
push usermaglione.k@gmail.com
push dateMon, 21 May 2018 02:57:23 +0000
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;
 xpc_JSObjectIsID(JSContext* cx, JSObject* obj)
     MOZ_ASSERT(cx && obj, "bad param");
     // NOTE: this call does NOT addref