Bug 1217038 - Remove for-each and legacy array comprehension from accessible/. r=yzen
authorTooru Fujisawa <arai_a@mac.com>
Sun, 18 Oct 2015 23:21:31 +0900
changeset 304354 bca12d6bccc2deabe18cbba72b96fcc71981e143
parent 304353 bceff5c97cf5a4b122398e1114bfbb061765f0e3
child 304355 05bb7ca32591b299a15588ac01440ad9a91f67f8
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1217038
milestone44.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 1217038 - Remove for-each and legacy array comprehension from accessible/. r=yzen
accessible/jsat/Gestures.jsm
accessible/jsat/OutputGenerator.jsm
accessible/jsat/Presentation.jsm
accessible/jsat/Utils.jsm
accessible/tests/mochitest/jsat/jsatcommon.js
accessible/tests/mochitest/jsat/test_live_regions.html
--- a/accessible/jsat/Gestures.jsm
+++ b/accessible/jsat/Gestures.jsm
@@ -912,28 +912,28 @@ Swipe.prototype.compile = function Swipe
   let type = this.type;
   let detail = compileDetail(type, this.points,
     {x1: 'startX', y1: 'startY', x2: 'x', y2: 'y'});
   let deltaX = detail.deltaX;
   let deltaY = detail.deltaY;
   let edge = EDGE * Utils.dpi;
   if (Math.abs(deltaX) > Math.abs(deltaY)) {
     // Horizontal swipe.
-    let startPoints = [touch.x1 for (touch of detail.touches)];
+    let startPoints = detail.touches.map(touch => touch.x1);
     if (deltaX > 0) {
       detail.type = type + 'right';
       detail.edge = Math.min.apply(null, startPoints) <= edge;
     } else {
       detail.type = type + 'left';
       detail.edge =
         Utils.win.screen.width - Math.max.apply(null, startPoints) <= edge;
     }
   } else {
     // Vertical swipe.
-    let startPoints = [touch.y1 for (touch of detail.touches)];
+    let startPoints = detail.touches.map(touch => touch.y1);
     if (deltaY > 0) {
       detail.type = type + 'down';
       detail.edge = Math.min.apply(null, startPoints) <= edge;
     } else {
       detail.type = type + 'up';
       detail.edge =
         Utils.win.screen.height - Math.max.apply(null, startPoints) <= edge;
     }
--- a/accessible/jsat/OutputGenerator.jsm
+++ b/accessible/jsat/OutputGenerator.jsm
@@ -62,21 +62,23 @@ var OutputGenerator = {
                !(nameRule & IGNORE_EXPLICIT_NAME))));
     };
 
     let contextStart = this._getContextStart(aContext);
 
     if (this.outputOrder === OUTPUT_DESC_FIRST) {
       contextStart.forEach(addOutput);
       addOutput(aContext.accessible);
-      [addOutput(node) for // jshint ignore:line
-        (node of aContext.subtreeGenerator(true, ignoreSubtree))]; // jshint ignore:line
+      for (let node of aContext.subtreeGenerator(true, ignoreSubtree)) {
+        addOutput(node);
+      }
     } else {
-      [addOutput(node) for // jshint ignore:line
-        (node of aContext.subtreeGenerator(false, ignoreSubtree))]; // jshint ignore:line
+      for (let node of aContext.subtreeGenerator(false, ignoreSubtree)) {
+        addOutput(node);
+      }
       addOutput(aContext.accessible);
 
       // If there are any documents in new ancestry, find a first one and place
       // it in the beginning of the utterance.
       let doc, docIndex = contextStart.findIndex(
         ancestor => ancestor.role === Roles.DOCUMENT);
 
       if (docIndex > -1) {
--- a/accessible/jsat/Presentation.jsm
+++ b/accessible/jsat/Presentation.jsm
@@ -679,92 +679,89 @@ BraillePresenter.prototype.textSelection
 this.Presentation = { // jshint ignore:line
   get presenters() {
     delete this.presenters;
     let presenterMap = {
       'mobile/android': [VisualPresenter, AndroidPresenter],
       'b2g': [VisualPresenter, B2GPresenter],
       'browser': [VisualPresenter, B2GPresenter, AndroidPresenter]
     };
-    this.presenters = [new P() for (P of presenterMap[Utils.MozBuildApp])]; // jshint ignore:line
+    this.presenters = presenterMap[Utils.MozBuildApp].map(P => new P());
     return this.presenters;
   },
 
   get displayedAccessibles() {
     delete this.displayedAccessibles;
     this.displayedAccessibles = new WeakMap();
     return this.displayedAccessibles;
   },
 
   pivotChanged: function Presentation_pivotChanged(
     aPosition, aOldPosition, aReason, aStartOffset, aEndOffset, aIsUserInput) {
     let context = new PivotContext(
       aPosition, aOldPosition, aStartOffset, aEndOffset);
     this.displayedAccessibles.set(context.accessible.document.window, context);
 
-    return [p.pivotChanged(context, aReason, aIsUserInput)
-      for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.pivotChanged(context, aReason, aIsUserInput));
   },
 
   actionInvoked: function Presentation_actionInvoked(aObject, aActionName) {
-    return [p.actionInvoked(aObject, aActionName) // jshint ignore:line
-      for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.actionInvoked(aObject, aActionName));
   },
 
   textChanged: function Presentation_textChanged(aAccessible, aIsInserted,
                                     aStartOffset, aLength, aText,
                                     aModifiedText) {
-    return [p.textChanged(aAccessible, aIsInserted, aStartOffset, aLength, // jshint ignore:line
-      aText, aModifiedText) for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.textChanged(aAccessible, aIsInserted,
+                                                  aStartOffset, aLength,
+                                                  aText, aModifiedText));
   },
 
   textSelectionChanged: function textSelectionChanged(aText, aStart, aEnd,
                                                       aOldStart, aOldEnd,
                                                       aIsFromUserInput) {
-    return [p.textSelectionChanged(aText, aStart, aEnd, aOldStart, aOldEnd, // jshint ignore:line
-      aIsFromUserInput) for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.textSelectionChanged(aText, aStart, aEnd,
+                                                           aOldStart, aOldEnd,
+                                                           aIsFromUserInput));
   },
 
   nameChanged: function nameChanged(aAccessible) {
-    return [ p.nameChanged(aAccessible) for (p of this.presenters) ]; // jshint ignore:line
+    return this.presenters.map(p => p.nameChanged(aAccessible));
   },
 
   valueChanged: function valueChanged(aAccessible) {
-    return [ p.valueChanged(aAccessible) for (p of this.presenters) ]; // jshint ignore:line
+    return this.presenters.map(p => p.valueChanged(aAccessible));
   },
 
   tabStateChanged: function Presentation_tabStateChanged(aDocObj, aPageState) {
-    return [p.tabStateChanged(aDocObj, aPageState) // jshint ignore:line
-      for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.tabStateChanged(aDocObj, aPageState));
   },
 
   viewportChanged: function Presentation_viewportChanged(aWindow) {
     let context = this.displayedAccessibles.get(aWindow);
-    return [p.viewportChanged(aWindow, context) // jshint ignore:line
-      for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.viewportChanged(aWindow, context));
   },
 
   editingModeChanged: function Presentation_editingModeChanged(aIsEditing) {
-    return [p.editingModeChanged(aIsEditing) for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.editingModeChanged(aIsEditing));
   },
 
   announce: function Presentation_announce(aAnnouncement) {
     // XXX: Typically each presenter uses the UtteranceGenerator,
     // but there really isn't a point here.
-    return [p.announce(UtteranceGenerator.genForAnnouncement(aAnnouncement)) // jshint ignore:line
-      for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.announce(UtteranceGenerator.genForAnnouncement(aAnnouncement)));
   },
 
   noMove: function Presentation_noMove(aMoveMethod) {
-    return [p.noMove(aMoveMethod) for each (p in this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.noMove(aMoveMethod));
   },
 
   liveRegion: function Presentation_liveRegion(aAccessible, aIsPolite, aIsHide,
     aModifiedText) {
     let context;
     if (!aModifiedText) {
       context = new PivotContext(aAccessible, null, -1, -1, true,
         aIsHide ? true : false);
     }
-    return [p.liveRegion(context, aIsPolite, aIsHide, aModifiedText) // jshint ignore:line
-      for (p of this.presenters)]; // jshint ignore:line
+    return this.presenters.map(p => p.liveRegion(context, aIsPolite, aIsHide,
+                                                 aModifiedText));
   }
 };
--- a/accessible/jsat/Utils.jsm
+++ b/accessible/jsat/Utils.jsm
@@ -206,21 +206,20 @@ this.Utils = { // jshint ignore:line
     this.isContentProcess =
       Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
     return this.isContentProcess;
   },
 
   localize: function localize(aOutput) {
     let outputArray = Array.isArray(aOutput) ? aOutput : [aOutput];
     let localized =
-      [this.stringBundle.get(details) for (details of outputArray)]; // jshint ignore:line
+      outputArray.map(details => this.stringBundle.get(details));
     // Clean up the white space.
-    let trimmed;
-    return [trimmed for (word of localized) if (word && // jshint ignore:line
-      (trimmed = word.trim()))]; // jshint ignore:line
+    return localized.filter(word => word).map(word => word.trim()).
+      filter(trimmed => trimmed);
   },
 
   get stringBundle() {
     delete this.stringBundle;
     let bundle = Services.strings.createBundle(
       'chrome://global/locale/AccessFu.properties');
     this.stringBundle = {
       get: function stringBundle_get(aDetails = {}) {
@@ -829,19 +828,19 @@ PivotContext.prototype = {
 
   /*
    * This is a list of the accessible's ancestry up to the common ancestor
    * of the accessible and the old accessible. It is useful for giving the
    * user context as to where they are in the heirarchy.
    */
   get newAncestry() {
     if (!this._newAncestry) {
-      this._newAncestry = this._ignoreAncestry ? [] : [currentAncestor for ( // jshint ignore:line
-        [index, currentAncestor] of Iterator(this.currentAncestry)) if ( // jshint ignore:line
-          currentAncestor !== this.oldAncestry[index])]; // jshint ignore:line
+      this._newAncestry = this._ignoreAncestry ? [] :
+        this.currentAncestry.filter(
+          (currentAncestor, i) => currentAncestor !== this.oldAncestry[i]);
     }
     return this._newAncestry;
   },
 
   /*
    * Traverse the accessible's subtree in pre or post order.
    * It only includes the accessible's visible chidren.
    * Note: needSubtree is a function argument that can be used to determine
@@ -857,19 +856,23 @@ PivotContext.prototype = {
       if (this._includeInvisible) {
         include = true;
       } else {
         include = !Utils.isHidden(child);
       }
       if (include) {
         if (aPreorder) {
           yield child;
-          [yield node for (node of this._traverse(child, aPreorder, aStop))]; // jshint ignore:line
+          for (let node of this._traverse(child, aPreorder, aStop)) {
+            yield node;
+          }
         } else {
-          [yield node for (node of this._traverse(child, aPreorder, aStop))]; // jshint ignore:line
+          for (let node of this._traverse(child, aPreorder, aStop)) {
+            yield node;
+          }
           yield child;
         }
       }
       child = child.nextSibling;
     }
   },
 
   /**
@@ -981,25 +984,23 @@ PivotContext.prototype = {
     cellInfo.rowExtent = cellInfo.current.rowExtent;
     cellInfo.columnExtent = cellInfo.current.columnExtent;
     cellInfo.columnIndex = cellInfo.current.columnIndex;
     cellInfo.rowIndex = cellInfo.current.rowIndex;
 
     cellInfo.columnHeaders = [];
     if (cellInfo.columnChanged && cellInfo.current.role !==
       Roles.COLUMNHEADER) {
-      cellInfo.columnHeaders = [headers for (headers of getHeaders( // jshint ignore:line
-        cellInfo.current.columnHeaderCells))];
+      cellInfo.columnHeaders = [...getHeaders(cellInfo.current.columnHeaderCells)];
     }
     cellInfo.rowHeaders = [];
     if (cellInfo.rowChanged &&
         (cellInfo.current.role === Roles.CELL ||
          cellInfo.current.role === Roles.MATHML_CELL)) {
-      cellInfo.rowHeaders = [headers for (headers of getHeaders( // jshint ignore:line
-        cellInfo.current.rowHeaderCells))];
+      cellInfo.rowHeaders = [...getHeaders(cellInfo.current.rowHeaderCells)];
     }
 
     this._cells.set(domNode, cellInfo);
     return cellInfo;
   },
 
   get bounds() {
     if (!this._bounds) {
--- a/accessible/tests/mochitest/jsat/jsatcommon.js
+++ b/accessible/tests/mochitest/jsat/jsatcommon.js
@@ -161,17 +161,17 @@ var AccessFuTest = {
     prefs.push.apply(prefs, aAdditionalPrefs);
 
     SpecialPowers.pushPrefEnv({ 'set': prefs }, function () {
       if (AccessFuTest._waitForExplicitFinish) {
         // Run all test functions asynchronously.
         AccessFuTest.nextTest();
       } else {
         // Run all test functions synchronously.
-        [testFunc() for (testFunc of gTestFuncs)]; // jshint ignore:line
+        gTestFuncs.forEach(testFunc => testFunc());
         AccessFuTest.finish();
       }
     });
   }
 };
 
 function AccessFuContentTest(aFuncResultPairs) {
   this.queue = aFuncResultPairs;
--- a/accessible/tests/mochitest/jsat/test_live_regions.html
+++ b/accessible/tests/mochitest/jsat/test_live_regions.html
@@ -60,100 +60,98 @@
       expected: {
         "eventType": "liveregion-change",
         "data": [{"string": "hidden"}, "I will be hidden"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [hide(id) for (id of ["to_hide1", "to_hide2", "to_hide3", "to_hide4"])];
+        ["to_hide1", "to_hide2", "to_hide3", "to_hide4"].forEach(id => hide(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": [{"string": "hidden"}, "I will be hidden"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [hide(id) for (id of ["to_hide_descendant1", "to_hide_descendant2",
-          "to_hide_descendant3", "to_hide_descendant4"])];
+        ["to_hide_descendant1", "to_hide_descendant2",
+         "to_hide_descendant3", "to_hide_descendant4"].forEach(id => hide(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [show(id) for (id of ["to_show1", "to_show2", "to_show3", "to_show4"])];
+        ["to_show1", "to_show2", "to_show3", "to_show4"].forEach(id => show(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [show(id) for (id of ["to_show_descendant1", "to_show_descendant2",
-          "to_show_descendant3", "to_show_descendant4"])];
+        ["to_show_descendant1", "to_show_descendant2",
+         "to_show_descendant3", "to_show_descendant4"].forEach(id => show(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": [{"string": "hidden"}, "I will be hidden"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [ariaHide(id) for (id of ["to_hide5", "to_hide6", "to_hide7",
-          "to_hide8", "to_hide9"])];
+        ["to_hide5", "to_hide6", "to_hide7", "to_hide8", "to_hide9"].forEach(id => ariaHide(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": [{"string": "hidden"}, "I will be hidden"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [ariaHide(id) for (id of ["to_hide_descendant5", "to_hide_descendant6",
-          "to_hide_descendant7", "to_hide_descendant8"])];
+        ["to_hide_descendant5", "to_hide_descendant6",
+         "to_hide_descendant7", "to_hide_descendant8"].forEach(id => ariaHide(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [ariaShow(id) for (id of ["to_show5", "to_show6", "to_show7",
-          "to_show8", "to_show9"])];
+        ["to_show5", "to_show6", "to_show7", "to_show8", "to_show9"].forEach(id => ariaShow(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": true
         }
       },
       action: function action() {
-        [ariaShow(id) for (id of ["to_show_descendant5", "to_show_descendant6",
-          "to_show_descendant7", "to_show_descendant8"])];
+        ["to_show_descendant5", "to_show_descendant6",
+         "to_show_descendant7", "to_show_descendant8"].forEach(id => ariaShow(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": [{"string": "hidden"}, "I will be hidden"],
         "options": {
           "enqueue": false
         }
@@ -176,29 +174,28 @@
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": false
         }
       },
       action: function action() {
-        [show(id) for (id of ["to_show_live_off", "to_show_live_assertive"])];
+        ["to_show_live_off", "to_show_live_assertive"].forEach(id => show(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["I will be shown"],
         "options": {
           "enqueue": false
         }
       },
       action: function action() {
-        [ariaShow(id) for (id of ["to_show_live_off2",
-          "to_show_live_assertive2"])];
+        ["to_show_live_off2", "to_show_live_assertive2"].forEach(id => ariaShow(id));
       }
     }, {
       expected: {
         "eventType": "liveregion-change",
         "data": ["Text Added"],
         "options": {
           "enqueue": false
         }
@@ -467,9 +464,9 @@
     <div aria-live="assertive" aria-relevant="text">
       <p id="text_add_descendant2"></p>
     </div>
     <div aria-live="polite" aria-relevant="all">
       <p id="text_remove_descendant2">Descendant Text Removed</p>
     </div>
   </div>
 </body>
-</html>
\ No newline at end of file
+</html>