Bug 1456035: Part 3 - Replace XPCOMUtils.generateQI with a stub for ChromeUtils.generateQI. r=mccr8
authorKris Maglione <maglione.k@gmail.com>
Sun, 22 Apr 2018 18:55:49 -0700
changeset 415714 affc06c38acd82a0773dd09465c2602e636fc08e
parent 415713 0102a61e38ae9c52d35b8239ccb24f48718a2b5b
child 415715 2add2de30c229733a3d0f11843695fcda818fe94
push id63245
push userapavel@mozilla.com
push dateThu, 26 Apr 2018 06:07:25 +0000
treeherderautoland@4da669897520 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1456035
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1456035: Part 3 - Replace XPCOMUtils.generateQI with a stub for ChromeUtils.generateQI. r=mccr8 MozReview-Commit-ID: HWnlxUQvxYZ
js/xpconnect/loader/XPCOMUtils.jsm
js/xpconnect/tests/unit/test_xpcomutils.js
toolkit/components/places/PlacesUtils.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;
-  };
-}
--- a/js/xpconnect/tests/unit/test_xpcomutils.js
+++ b/js/xpconnect/tests/unit/test_xpcomutils.js
@@ -42,17 +42,23 @@ add_test(function test_generateQI_string
 
 
 add_test(function test_generateCI()
 {
     const classID = Components.ID("562dae2e-7cff-432b-995b-3d4c03fa2b89");
     const classDescription = "generateCI test component";
     const flags = Ci.nsIClassInfo.DOM_OBJECT;
     var x = {
-        QueryInterface: XPCOMUtils.generateQI([]),
+        QueryInterface: function(iid) {
+            if (iid.equals(Ci.nsIClassInfo))
+                return this.classInfo;
+            if (iid.equals(Ci.nsISupports))
+                return this;
+            throw Cr.NS_ERROR_NO_INTERFACE;
+        },
         classInfo: XPCOMUtils.generateCI({classID: classID,
                                           interfaces: [],
                                           flags: flags,
                                           classDescription: classDescription})
     };
 
     try {
         var ci = x.QueryInterface(Ci.nsIClassInfo);
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -2679,17 +2679,17 @@ var GuidHelper = {
         },
         onItemRemoved:
         (aItemId, aParentId, aIndex, aItemTyep, aURI, aGuid, aParentGuid) => {
           this.guidsForIds.delete(aItemId);
           this.idsForGuids.delete(aGuid);
           this.updateCache(aParentId, aParentGuid);
         },
 
-        QueryInterface: XPCOMUtils.generateQI(Ci.nsINavBookmarkObserver),
+        QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]),
 
         onBeginUpdateBatch() {},
         onEndUpdateBatch() {},
         onItemChanged() {},
         onItemVisited() {},
         onItemMoved() {},
       };
       PlacesUtils.bookmarks.addObserver(this.observer);