Bug 1452183 part 2. Stop using nsIDOMDocumentFragment in JS. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 17 Apr 2018 21:13:03 -0400
changeset 414213 f4872ef01b2387fbd3fe86355a2fe12c33ebf042
parent 414212 a437a5c0f2ae18cc3ed35f8d6db47f3873d0d3ec
child 414214 9420e22ee07852d0d5e9b4cea7cce1ec4c860c81
push id33861
push userccoroiu@mozilla.com
push dateWed, 18 Apr 2018 10:50:38 +0000
treeherdermozilla-central@4af4ae0aee55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1452183
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 1452183 part 2. Stop using nsIDOMDocumentFragment in JS. r=mccr8
devtools/client/shared/widgets/view-helpers.js
devtools/server/actors/object/previewers.js
devtools/shared/builtin-modules.js
dom/base/test/unit/test_range.js
--- a/devtools/client/shared/widgets/view-helpers.js
+++ b/devtools/client/shared/widgets/view-helpers.js
@@ -1,15 +1,16 @@
 /* -*- 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 {Cu} = require("chrome");
 const {KeyCodes} = require("devtools/client/shared/keycodes");
 
 const PANE_APPEARANCE_DELAY = 50;
 const PAGE_SIZE_ITEM_COUNT_RATIO = 5;
 const WIDGET_FOCUSABLE_NODES = new Set(["vbox", "hbox"]);
 
 var namedTimeoutsStore = new Map();
 
@@ -164,17 +165,17 @@ 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 Node ||
            object instanceof Element ||
-           object instanceof DocumentFragment;
+           Cu.getClassName(object) == "DocumentFragment";
   },
 
   /**
    * Prevents event propagation when navigation keys are pressed.
    *
    * @param Event e
    *        The event to be prevented.
    */
@@ -782,22 +783,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 DocumentFragment) {
+    if (Cu.getClassName(firstPrebuiltTarget) == "DocumentFragment") {
       for (let node of firstTarget.childNodes) {
         firstPrebuiltTarget.appendChild(node.cloneNode(true));
       }
     }
-    if (secondPrebuiltTarget instanceof DocumentFragment) {
+    if (Cu.getClassName(secondPrebuiltTarget) == "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/server/actors/object/previewers.js
+++ b/devtools/server/actors/object/previewers.js
@@ -601,17 +601,17 @@ previewers.Object = [
       kind: "DOMNode",
       nodeType: rawObj.nodeType,
       nodeName: rawObj.nodeName,
       isConnected: rawObj.isConnected === true,
     };
 
     if (rawObj instanceof Ci.nsIDOMDocument && rawObj.location) {
       preview.location = hooks.createValueGrip(rawObj.location.href);
-    } else if (rawObj instanceof Ci.nsIDOMDocumentFragment) {
+    } else if (obj.class == "DocumentFragment") {
       preview.childNodesLength = rawObj.childNodes.length;
 
       if (hooks.getGripDepth() < 2) {
         preview.childNodes = [];
         for (let node of rawObj.childNodes) {
           let actor = hooks.createValueGrip(obj.makeDebuggeeValue(node));
           preview.childNodes.push(actor);
           if (preview.childNodes.length == OBJECT_PREVIEW_MAX_ITEMS) {
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -257,17 +257,16 @@ exports.globals = {
   //     ... code ...
   //   });
   //
   // Bug 1248830 will work out a better plan here for our content module
   // loading needs, especially as we head towards devtools.html.
   define(factory) {
     factory(this.require, this.exports, this.module);
   },
-  DocumentFragment: Ci.nsIDOMDocumentFragment,
   Element: Ci.nsIDOMElement,
   FormData,
   isWorker: false,
   loader: {
     lazyGetter: defineLazyGetter,
     lazyImporter: defineLazyModuleGetter,
     lazyServiceGetter: defineLazyServiceGetter,
     lazyRequireGetter: lazyRequireGetter,
--- a/dom/base/test/unit/test_range.js
+++ b/dom/base/test/unit/test_range.js
@@ -51,17 +51,17 @@ function dumpFragment(aFragment) {
  * fragment as context node.
  *
  * @param aContextNode The context node to apply the XPath to.
  * @param aPath        The XPath to use.
  *
  * @return nsIDOMNode  The target node retrieved from the XPath.
  */
 function evalXPathInDocumentFragment(aContextNode, aPath) {
-  Assert.ok(aContextNode instanceof Ci.nsIDOMDocumentFragment);
+  Assert.equal(ChromeUtils.getClassName(aContextNode), "DocumentFragment");
   Assert.ok(aContextNode.childNodes.length > 0);
   if (aPath == ".") {
     return aContextNode;
   }
 
   // Separate the fragment's xpath lookup from the rest.
   var firstSlash = aPath.indexOf("/");
   if (firstSlash == -1) {
@@ -144,17 +144,17 @@ function evalXPathInDocumentFragment(aCo
  *
  * @param aSourceNode <source/> element with range information.
  * @param aFragment   DocumentFragment generated with getFragment().
  *
  * @return Range object.
  */
 function getRange(aSourceNode, aFragment) {
   Assert.ok(aSourceNode instanceof Ci.nsIDOMElement);
-  Assert.ok(aFragment instanceof Ci.nsIDOMDocumentFragment);
+  Assert.equal(ChromeUtils.getClassName(aFragment), "DocumentFragment");
   var doc = aSourceNode.ownerDocument;
 
   var containerPath = aSourceNode.getAttribute("startContainer");
   var startContainer = evalXPathInDocumentFragment(aFragment, containerPath);
   var startOffset = Number(aSourceNode.getAttribute("startOffset"));
 
   containerPath = aSourceNode.getAttribute("endContainer");
   var endContainer = evalXPathInDocumentFragment(aFragment, containerPath);