Bug 1456035: Part 3 - Replace XPCOMUtils.generateQI with a stub for ChromeUtils.generateQI. r?mccr8 draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 22 Apr 2018 18:55:49 -0700
changeset 786393 74d0d8ee44442efb7f5f9f3b01b42d845d28f97f
parent 786392 53d1951499c93c9afd416ad827b62603752c7f62
child 786394 e0074c5c72fa7a2b0a328ca9d8377176fe5f1fea
child 786765 69ca4d64c851c6629e89fd31aa49b6e015388dba
push id107444
push usermaglione.k@gmail.com
push dateMon, 23 Apr 2018 04:22:11 +0000
reviewersmccr8
bugs1456035
milestone61.0a1
Bug 1456035: Part 3 - Replace XPCOMUtils.generateQI with a stub for ChromeUtils.generateQI. r?mccr8 MozReview-Commit-ID: HWnlxUQvxYZ
js/xpconnect/loader/XPCOMUtils.jsm
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -96,28 +96,17 @@ var XPCOMUtils = {
    * assigned to the 'QueryInterface' property of a JS object. When invoked on
    * that object, it checks if the given iid is listed in the |interfaces|
    * param, and if it is, returns |this| (the object it was called on).
    * If the JS object has a classInfo property it'll be returned for the
    * nsIClassInfo IID, generateCI can be used to generate the classInfo
    * property.
    */
   generateQI: function XPCU_generateQI(interfaces) {
-    /* Note that Ci[Ci.x] == Ci.x for all x */
-    let a = [];
-    if (interfaces) {
-      for (let i = 0; i < interfaces.length; i++) {
-        let iface = interfaces[i];
-        let name = (iface && iface.name) || String(iface);
-        if (name in Ci) {
-          a.push(name);
-        }
-      }
-    }
-    return makeQI(a);
+    return ChromeUtils.generateQI(interfaces);
   },
 
   /**
    * Generate a ClassInfo implementation for a component. The returned object
    * must be assigned to the 'classInfo' property of a JS object. The first and
    * only argument should be an object that contains a number of optional
    * properties: "interfaces", "contractID", "classDescription", "classID" and
    * "flags". The values of the properties will be returned as the values of the
@@ -573,26 +562,8 @@ var XPCOMUtils = {
 var XPCU_lazyPreferenceObserverQI = XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]);
 
 ChromeUtils.defineModuleGetter(this, "Services",
                                "resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(XPCOMUtils, "categoryManager",
                                    "@mozilla.org/categorymanager;1",
                                    "nsICategoryManager");
-
-/**
- * Helper for XPCOMUtils.generateQI to avoid leaks - see bug 381651#c1
- */
-function makeQI(interfaceNames) {
-  return function XPCOMUtils_QueryInterface(iid) {
-    if (iid.equals(Ci.nsISupports))
-      return this;
-    if (iid.equals(Ci.nsIClassInfo) && "classInfo" in this)
-      return this.classInfo;
-    for (let i = 0; i < interfaceNames.length; i++) {
-      if (Ci[interfaceNames[i]].equals(iid))
-        return this;
-    }
-
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  };
-}