Bug 1292253 - replace some Ci uses in view-helpers and TableWidget; r?gregtatum draft
authorTom Tromey <tom@tromey.com>
Tue, 09 Aug 2016 09:43:58 -0600
changeset 398683 a392221ec3c6902ef8fc1cdd24742a3e87c40279
parent 398621 613fec9a571e48c64918ebd0a8153096300ff992
child 527720 9c359e9e3c8ca48fd2e0fd461207329436aa88ea
push id25598
push userbmo:ttromey@mozilla.com
push dateTue, 09 Aug 2016 16:23:54 +0000
reviewersgregtatum
bugs1292253
milestone51.0a1
Bug 1292253 - replace some Ci uses in view-helpers and TableWidget; r?gregtatum MozReview-Commit-ID: JIs4wxNA3Eg
devtools/.eslintrc
devtools/client/shared/widgets/TableWidget.js
devtools/client/shared/widgets/view-helpers.js
devtools/shared/builtin-modules.js
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -6,23 +6,26 @@
     "atob": true,
     "btoa": true,
     "Components": true,
     "CSSRule": true,
     "clearInterval": true,
     "clearTimeout": true,
     "console": true,
     "CSS": true,
+    "DocumentFragment": true,
     "DOMParser": true,
     "dump": true,
+    "Element": true,
     "exports": true,
     "isWorker": true,
     "indexedDB": true,
     "loader": true,
     "module": true,
+    "Node": true,
     "reportError": true,
     "require": true,
     "setInterval": true,
     "setTimeout": true,
     "uneval": true,
     "URL": true,
     "WebSocket": true,
     "XMLHttpRequest": true,
--- a/devtools/client/shared/widgets/TableWidget.js
+++ b/devtools/client/shared/widgets/TableWidget.js
@@ -1,14 +1,13 @@
 /* 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/. */
 "use strict";
 
-const {Ci} = require("chrome");
 const EventEmitter = require("devtools/shared/event-emitter");
 loader.lazyRequireGetter(this, "setNamedTimeout",
   "devtools/client/shared/widgets/view-helpers", true);
 loader.lazyRequireGetter(this, "clearNamedTimeout",
   "devtools/client/shared/widgets/view-helpers", true);
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const HTML_NS = "http://www.w3.org/1999/xhtml";
@@ -1345,27 +1344,27 @@ Column.prototype = {
   /**
    * Sorts the given items and returns the sorted list if the table was sorted
    * by this column.
    */
   sort: function (items) {
     // Only sort the array if we are sorting based on this column
     if (this.sorted == 1) {
       items.sort((a, b) => {
-        let val1 = (a[this.id] instanceof Ci.nsIDOMNode) ?
+        let val1 = (a[this.id] instanceof Node) ?
             a[this.id].textContent : a[this.id];
-        let val2 = (b[this.id] instanceof Ci.nsIDOMNode) ?
+        let val2 = (b[this.id] instanceof Node) ?
             b[this.id].textContent : b[this.id];
         return val1 > val2;
       });
     } else if (this.sorted > 1) {
       items.sort((a, b) => {
-        let val1 = (a[this.id] instanceof Ci.nsIDOMNode) ?
+        let val1 = (a[this.id] instanceof Node) ?
             a[this.id].textContent : a[this.id];
-        let val2 = (b[this.id] instanceof Ci.nsIDOMNode) ?
+        let val2 = (b[this.id] instanceof Node) ?
             b[this.id].textContent : b[this.id];
         return val2 > val1;
       });
     }
 
     if (this.selectedRow) {
       this.cells[this.items[this.selectedRow]].toggleClass("theme-selected");
     }
@@ -1499,28 +1498,28 @@ Cell.prototype = {
 
   set value(value) {
     this._value = value;
     if (value == null) {
       this.label.setAttribute("value", "");
       return;
     }
 
-    if (this.wrapTextInElements && !(value instanceof Ci.nsIDOMNode)) {
+    if (this.wrapTextInElements && !(value instanceof Node)) {
       let span = this.label.ownerDocument.createElementNS(HTML_NS, "span");
       span.textContent = value;
       value = span;
     }
 
-    if (!(value instanceof Ci.nsIDOMNode) &&
+    if (!(value instanceof Node) &&
         value.length > MAX_VISIBLE_STRING_SIZE) {
       value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026";
     }
 
-    if (value instanceof Ci.nsIDOMNode) {
+    if (value instanceof Node) {
       this.label.removeAttribute("value");
 
       while (this.label.firstChild) {
         this.label.removeChild(this.label.firstChild);
       }
 
       this.label.appendChild(value);
     } else {
--- a/devtools/client/shared/widgets/view-helpers.js
+++ b/devtools/client/shared/widgets/view-helpers.js
@@ -1,17 +1,15 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript 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/. */
 "use strict";
 
-const { Ci } = require("chrome");
-
 const PANE_APPEARANCE_DELAY = 50;
 const PAGE_SIZE_ITEM_COUNT_RATIO = 5;
 const WIDGET_FOCUSABLE_NODES = new Set(["vbox", "hbox"]);
 
 /**
  * Inheritance helpers from the addon SDK's core/heritage.
  * Remove these when all devtools are loadered.
  */
@@ -123,17 +121,17 @@ const ViewHelpers = exports.ViewHelpers 
    *        The name of the event.
    * @param any detail
    *        The data passed when initializing the event.
    * @return boolean
    *         True if the event was cancelled or a registered handler
    *         called preventDefault.
    */
   dispatchEvent: function (target, type, detail) {
-    if (!(target instanceof Ci.nsIDOMNode)) {
+    if (!(target instanceof Node)) {
       // Event cancelled.
       return true;
     }
     let document = target.ownerDocument || target;
     let dispatcher = target.ownerDocument ? target : document.documentElement;
 
     let event = document.createEvent("CustomEvent");
     event.initCustomEvent(type, true, true, detail);
@@ -185,19 +183,19 @@ const ViewHelpers = exports.ViewHelpers 
 
   /**
    * Checks if the specified object is an instance of a DOM node.
    *
    * @return boolean
    *         True if it's a node, false otherwise.
    */
   isNode: function (object) {
-    return object instanceof Ci.nsIDOMNode ||
-           object instanceof Ci.nsIDOMElement ||
-           object instanceof Ci.nsIDOMDocumentFragment;
+    return object instanceof Node ||
+           object instanceof Element ||
+           object instanceof DocumentFragment;
   },
 
   /**
    * Prevents event propagation when navigation keys are pressed.
    *
    * @param Event e
    *        The event to be prevented.
    */
@@ -787,22 +785,22 @@ const WidgetMethods = exports.WidgetMeth
       return;
     }
     let { _prebuiltNode: firstPrebuiltTarget, _target: firstTarget } = first;
     let { _prebuiltNode: secondPrebuiltTarget, _target: secondTarget } = second;
 
     // If the two items were constructed with prebuilt nodes as
     // DocumentFragments, then those DocumentFragments are now
     // empty and need to be reassembled.
-    if (firstPrebuiltTarget instanceof Ci.nsIDOMDocumentFragment) {
+    if (firstPrebuiltTarget instanceof DocumentFragment) {
       for (let node of firstTarget.childNodes) {
         firstPrebuiltTarget.appendChild(node.cloneNode(true));
       }
     }
-    if (secondPrebuiltTarget instanceof Ci.nsIDOMDocumentFragment) {
+    if (secondPrebuiltTarget instanceof DocumentFragment) {
       for (let node of secondTarget.childNodes) {
         secondPrebuiltTarget.appendChild(node.cloneNode(true));
       }
     }
 
     // 1. Get the indices of the two items to swap.
     let i = this._indexOfElement(firstTarget);
     let j = this._indexOfElement(secondTarget);
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -229,16 +229,20 @@ const globals = exports.globals = {
   },
 
   // Let new XMLHttpRequest do the right thing.
   XMLHttpRequest: function () {
     return Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
            .createInstance(Ci.nsIXMLHttpRequest);
   },
 
+  Node: Ci.nsIDOMNode,
+  Element: Ci.nsIDOMElement,
+  DocumentFragment: Ci.nsIDOMDocumentFragment,
+
   // Make sure `define` function exists.  This allows defining some modules
   // in AMD format while retaining CommonJS compatibility through this hook.
   // JSON Viewer needs modules in AMD format, as it currently uses RequireJS
   // from a content document and can't access our usual loaders.  So, any
   // modules shared with the JSON Viewer should include a define wrapper:
   //
   //   // Make this available to both AMD and CJS environments
   //   define(function(require, exports, module) {