Bug 1039162 (attempt 2) - Don't use |for each| in XPCOMUtils.jsm. r=mrbkap.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 Jul 2014 22:45:29 -0700
changeset 217141 e92292705a68f81f6300c55d29b964b58f68f9bf
parent 217140 129a1110eee7b9160e5d0eb29691a4d97dbce8a5
child 217142 4bafe35cfb6581bd57e6fec7330694f790208fba
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1039162
milestone33.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 1039162 (attempt 2) - Don't use |for each| in XPCOMUtils.jsm. r=mrbkap.
js/xpconnect/loader/XPCOMUtils.jsm
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -102,33 +102,48 @@ this.XPCOMUtils = {
    * 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 */
-    return makeQI([Ci[i].name for each (i in interfaces) if (Ci[i])]);
+    let a = [];
+    if (interfaces) {
+      for (let i = 0; i < interfaces.length; i++) {
+        let iface = interfaces[i];
+        if (Ci[iface]) {
+          a.push(Ci[iface].name);
+        }
+      }
+    }
+    return makeQI(a);
   },
 
   /**
    * 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
    * various properties of the nsIClassInfo implementation.
    */
   generateCI: function XPCU_generateCI(classInfo)
   {
     if (QueryInterface in classInfo)
       throw Error("In generateCI, don't use a component for generating classInfo");
     /* Note that Ci[Ci.x] == Ci.x for all x */
-    var _interfaces = [Ci[i] for each (i in classInfo.interfaces) if (Ci[i])];
+    let _interfaces = [];
+    for (let i = 0; i < classInfo.interfaces.length; i++) {
+      let iface = classInfo.interfaces[i];
+      if (Ci[iface]) {
+        _interfaces.push(Ci[iface]);
+      }
+    }
     return {
       getInterfaces: function XPCU_getInterfaces(countRef) {
         countRef.value = _interfaces.length;
         return _interfaces;
       },
       getHelperForLanguage: function XPCU_getHelperForLanguage(language) null,
       contractID: classInfo.contractID,
       classDescription: classInfo.classDescription,
@@ -139,17 +154,18 @@ this.XPCOMUtils = {
     };
   },
 
   /**
    * Generate a NSGetFactory function given an array of components.
    */
   generateNSGetFactory: function XPCU_generateNSGetFactory(componentsArray) {
     let classes = {};
-    for each (let component in componentsArray) {
+    for (let i = 0; i < componentsArray.length; i++) {
+        let component = componentsArray[i];
         if (!(component.prototype.classID instanceof Components.ID))
           throw Error("In generateNSGetFactory, classID missing or incorrect for component " + component);
 
         classes[component.prototype.classID] = this._getFactory(component);
     }
     return function NSGetFactory(cid) {
       let cidstring = cid.toString();
       if (cidstring in classes)
@@ -324,16 +340,16 @@ this.XPCOMUtils = {
  * 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 each(let interfaceName in interfaceNames) {
-      if (Ci[interfaceName].equals(iid))
+    for (let i = 0; i < interfaceNames.length; i++) {
+      if (Ci[interfaceNames[i]].equals(iid))
         return this;
     }
 
     throw Cr.NS_ERROR_NO_INTERFACE;
   };
 }