Bug 1310211 - remove usage of deprecated Iterator in computed.js;r=tromey draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 17 Oct 2016 14:39:49 +0200
changeset 426034 5672f1ac86079c2fa0b4e6037da255f7e630ed6e
parent 425967 94b0fddf96b43942bdd851a3275042909ea37e09
child 534069 159a87789261a8617c07ec60d6f670a211037a3a
push id32592
push userjdescottes@mozilla.com
push dateMon, 17 Oct 2016 16:43:22 +0000
reviewerstromey
bugs1310211
milestone52.0a1
Bug 1310211 - remove usage of deprecated Iterator in computed.js;r=tromey MozReview-Commit-ID: AF6fPEBfrr3
devtools/.eslintrc
devtools/client/inspector/computed/computed.js
devtools/shared/builtin-modules.js
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -24,17 +24,16 @@
     "reportError": true,
     "require": true,
     "setInterval": true,
     "setTimeout": true,
     "uneval": true,
     "URL": true,
     "WebSocket": true,
     "XMLHttpRequest": true,
-    "_Iterator": true,
   },
   "rules": {
     // These are the rules that have been configured so far to match the
     // devtools coding style.
 
     // Rules from the mozilla plugin
     "mozilla/mark-test-function-used": 1,
     "mozilla/no-aArgs": 1,
--- a/devtools/client/inspector/computed/computed.js
+++ b/devtools/client/inspector/computed/computed.js
@@ -1,16 +1,14 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* globals StopIteration */
-
 "use strict";
 
 const ToolDefinitions = require("devtools/client/definitions").Tools;
 const CssLogic = require("devtools/shared/inspector/css-logic");
 const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
 const promise = require("promise");
 const defer = require("devtools/shared/defer");
 const Services = require("Services");
@@ -34,41 +32,48 @@ const FILTER_CHANGED_TIMEOUT = 150;
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 
 /**
  * Helper for long-running processes that should yield occasionally to
  * the mainloop.
  *
  * @param {Window} win
  *        Timeouts will be set on this window when appropriate.
- * @param {Generator} generator
- *        Will iterate this generator.
+ * @param {Array} array
+ *        The array of items to process.
  * @param {Object} options
  *        Options for the update process:
  *          onItem {function} Will be called with the value of each iteration.
  *          onBatch {function} Will be called after each batch of iterations,
  *            before yielding to the main loop.
  *          onDone {function} Will be called when iteration is complete.
  *          onCancel {function} Will be called if the process is canceled.
  *          threshold {int} How long to process before yielding, in ms.
  */
-function UpdateProcess(win, generator, options) {
+function UpdateProcess(win, array, options) {
   this.win = win;
-  this.iter = _Iterator(generator);
+  this.index = 0;
+  this.array = array;
+
   this.onItem = options.onItem || function () {};
   this.onBatch = options.onBatch || function () {};
   this.onDone = options.onDone || function () {};
   this.onCancel = options.onCancel || function () {};
   this.threshold = options.threshold || 45;
 
   this.canceled = false;
 }
 
 UpdateProcess.prototype = {
   /**
+   * Error thrown when the array of items to process is empty.
+   */
+  ERROR_ITERATION_DONE: new Error("UpdateProcess iteration done"),
+
+  /**
    * Schedule a new batch on the main loop.
    */
   schedule: function () {
     if (this.canceled) {
       return;
     }
     this._timeout = setTimeout(this._timeoutHandler.bind(this), 0);
   },
@@ -87,38 +92,48 @@ UpdateProcess.prototype = {
   },
 
   _timeoutHandler: function () {
     this._timeout = null;
     try {
       this._runBatch();
       this.schedule();
     } catch (e) {
-      if (e instanceof StopIteration) {
+      if (e === this.ERROR_ITERATION_DONE) {
         this.onBatch();
         this.onDone();
         return;
       }
       console.error(e);
       throw e;
     }
   },
 
   _runBatch: function () {
     let time = Date.now();
     while (!this.canceled) {
-      // Continue until iter.next() throws...
-      let next = this.iter.next();
-      this.onItem(next[1]);
+      let next = this._next();
+      this.onItem(next);
       if ((Date.now() - time) > this.threshold) {
         this.onBatch();
         return;
       }
     }
-  }
+  },
+
+  /**
+   * Returns the item at the current index and increases the index.
+   * If all items have already been processed, will throw ERROR_ITERATION_DONE.
+   */
+  _next: function () {
+    if (this.index < this.array.length) {
+      return this.array[this.index++];
+    }
+    throw this.ERROR_ITERATION_DONE;
+  },
 };
 
 /**
  * CssComputedView is a panel that manages the display of a table
  * sorted by style. There should be one instance of CssComputedView
  * per style display (of which there will generally only be one).
  *
  * @param {Inspector} inspector
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -214,17 +214,16 @@ defineLazyGetter(exports.modules, "FileR
 // List of all custom globals exposed to devtools modules.
 // Changes here should be mirrored to devtools/.eslintrc.
 const globals = exports.globals = {
   isWorker: false,
   reportError: Cu.reportError,
   atob: atob,
   btoa: btoa,
   URL,
-  _Iterator: Iterator,
   loader: {
     lazyGetter: defineLazyGetter,
     lazyImporter: defineLazyModuleGetter,
     lazyServiceGetter: defineLazyServiceGetter,
     lazyRequireGetter: lazyRequireGetter,
     id: null // Defined by Loader.jsm
   },