Bug 1456035: Part 3.1 - Add temporary fallback XPCOMUtils.generateQI implementation for Android hostutils. r=me
authorKris Maglione <maglione.k@gmail.com>
Wed, 25 Apr 2018 14:26:05 -0700
changeset 469219 2add2de30c229733a3d0f11843695fcda818fe94
parent 469218 affc06c38acd82a0773dd09465c2602e636fc08e
child 469220 35fe513112642f7d2f9c99da61538db193701a94
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
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.1 - Add temporary fallback XPCOMUtils.generateQI implementation for Android hostutils. r=me MozReview-Commit-ID: IDs6Jyz5PyO
js/xpconnect/loader/XPCOMUtils.jsm
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -562,8 +562,49 @@ 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");
+
+// FIXME: Remove this when Android hostutils is updated to support
+// ChromeUtils.generateQI.
+if (ChromeUtils.generateQI) {
+  XPCOMUtils.generateQI = function(interfaces) {
+    return ChromeUtils.generateQI(interfaces.filter(i => i && i.name != "nsISupports"));
+  };
+} else {
+  /**
+   * Helper for XPCOMUtils.generateQI to avoid leaks - see bug 381651#c1
+   */
+  let 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;
+    };
+  };
+
+  XPCOMUtils.generateQI = function(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);
+  };
+}