Bug 1460735 part 1. Remove use of nsIDOMDocument in JS. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 29 May 2018 13:39:00 -0400
changeset 420250 3b36aa930a8a8286b24edf2deef3a92d4f76a6dc
parent 420249 f8c16ddfa41c992121da1a0290b2efbde023fc2a
child 420251 35a9ad46b395f60f04eb9abb3522781464f38e9d
push id103769
push userbzbarsky@mozilla.com
push dateTue, 29 May 2018 17:40:46 +0000
treeherdermozilla-inbound@35a9ad46b395 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1460735
milestone62.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 1460735 part 1. Remove use of nsIDOMDocument in JS. r=qdot There are some places where we have a thing which may not even be a node, and we end up hardcoding the value of DOCUMENT_NODE there, because "foo.nodeType == foo.DOCUMENT_NODE" will test true if foo is not a node: both sides will be undefined.
accessible/tests/mochitest/common.js
accessible/tests/mochitest/events.js
accessible/tests/mochitest/test_nsIAccessibleDocument.html
browser/base/content/content.js
browser/base/content/test/general/browser_tabfocus.js
browser/components/extensions/parent/ext-tabs.js
devtools/server/actors/object/previewers.js
dom/base/test/unit/head_xml.js
dom/base/test/unit/test_range.js
dom/base/test/unit/test_xml_parser.js
mobile/android/components/BrowserCLH.js
testing/marionette/element.js
testing/xpcshell/head.js
toolkit/content/contentAreaUtils.js
--- a/accessible/tests/mochitest/common.js
+++ b/accessible/tests/mochitest/common.js
@@ -39,17 +39,16 @@ const nsIAccessiblePivot = Ci.nsIAccessi
 const nsIAccessibleSelectable = Ci.nsIAccessibleSelectable;
 const nsIAccessibleTable = Ci.nsIAccessibleTable;
 const nsIAccessibleTableCell = Ci.nsIAccessibleTableCell;
 const nsIAccessibleTraversalRule = Ci.nsIAccessibleTraversalRule;
 const nsIAccessibleValue = Ci.nsIAccessibleValue;
 
 const nsIObserverService = Ci.nsIObserverService;
 
-const nsIDOMDocument = Ci.nsIDOMDocument;
 const nsIDOMNode = Ci.nsIDOMNode;
 const nsIDOMWindow = Ci.nsIDOMWindow;
 
 const nsIPropertyElement = Ci.nsIPropertyElement;
 
 // //////////////////////////////////////////////////////////////////////////////
 // OS detect
 
--- a/accessible/tests/mochitest/events.js
+++ b/accessible/tests/mochitest/events.js
@@ -1057,17 +1057,17 @@ function defineScenario(aInvoker, aEvent
 /**
  * Click invoker.
  */
 function synthClick(aNodeOrID, aCheckerOrEventSeq, aArgs) {
   this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq);
 
   this.invoke = function synthClick_invoke() {
     var targetNode = this.DOMNode;
-    if (targetNode instanceof nsIDOMDocument) {
+    if (targetNode.nodeType == targetNode.DOCUMENT_NODE) {
       targetNode =
         this.DOMNode.body ? this.DOMNode.body : this.DOMNode.documentElement;
     }
 
     // Scroll the node into view, otherwise synth click may fail.
     if (isHTMLElement(targetNode)) {
       targetNode.scrollIntoView(true);
     } else if (ChromeUtils.getClassName(targetNode) == "XULElement") {
--- a/accessible/tests/mochitest/test_nsIAccessibleDocument.html
+++ b/accessible/tests/mochitest/test_nsIAccessibleDocument.html
@@ -51,22 +51,22 @@ https://bugzilla.mozilla.org/show_bug.cg
            "Wrong mime type for document!");
 
         // DocAccessible::getDocType currently returns NS_ERROR_FAILURE.
         // See bug 442005. After fixing, please remove this comment and
         // uncomment the below two lines to enable the test.
 //        is(docAcc.docType, "HTML",
 //           "Wrong type of document!");
 
-        // Test for correct nsIDOMDocument retrieval.
+        // Test for correct Document retrieval.
         var domDoc = null;
         try {
-          domDoc = docAcc.DOMDocument.QueryInterface(nsIDOMDocument);
+          domDoc = docAcc.DOMDocument;
         } catch (e) {}
-        ok(domDoc, "no nsIDOMDocument for this doc accessible!");
+        ok(domDoc, "no Document for this doc accessible!");
         is(domDoc, document, "Document nodes do not match!");
 
         // Test for correct nsIDOMWindow retrieval.
         var domWindow = null;
         try {
           domWindow = docAcc.window.QueryInterface(nsIDOMWindow);
         } catch (e) {}
         ok(domWindow, "no nsIDOMWindow for this doc accessible!");
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -583,22 +583,18 @@ var AboutNetAndCertErrorListener = {
     }
   },
 
   onCaptivePortalFreed(msg) {
     content.dispatchEvent(new content.CustomEvent("AboutNetErrorCaptivePortalFreed"));
   },
 
   handleEvent(aEvent) {
-    let doc;
-    if (aEvent.originalTarget instanceof Ci.nsIDOMDocument) {
-      doc = aEvent.originalTarget;
-    } else {
-      doc = aEvent.originalTarget.ownerDocument;
-    }
+    // Documents have a null ownerDocument.
+    let doc = aEvent.originalTarget.ownerDocument || aEvent.originalTarget;
 
     if (!this.isAboutNetError(doc) && !this.isAboutCertError(doc)) {
       return;
     }
 
     switch (aEvent.type) {
     case "AboutNetErrorLoad":
       this.onPageLoad(aEvent.originalTarget, doc.defaultView);
--- a/browser/base/content/test/general/browser_tabfocus.js
+++ b/browser/base/content/test/general/browser_tabfocus.js
@@ -69,17 +69,17 @@ function focusInChild() {
 
   function eventListener(event) {
     // Stop the shim code from seeing this event process.
     event.stopImmediatePropagation();
 
     var id;
     if (event.target instanceof Ci.nsIDOMWindow)
       id = getWindowDocId(event.originalTarget) + "-window";
-    else if (event.target instanceof Ci.nsIDOMDocument)
+    else if (event.target.nodeType == event.target.DOCUMENT_NODE)
       id = getWindowDocId(event.originalTarget) + "-document";
     else
       id = event.originalTarget.id;
     sendSyncMessage("Browser:FocusChanged", { details: event.type + ": " + id });
   }
 
   addEventListener("focus", eventListener, true);
   addEventListener("blur", eventListener, true);
--- a/browser/components/extensions/parent/ext-tabs.js
+++ b/browser/components/extensions/parent/ext-tabs.js
@@ -961,18 +961,18 @@ this.tabs = class extends ExtensionAPI {
               zoomLevels.set(browser, getZoomLevel(browser));
             };
 
 
             let zoomListener = event => {
               let browser = event.originalTarget;
 
               // For non-remote browsers, this event is dispatched on the document
-              // rather than on the <browser>.
-              if (browser instanceof Ci.nsIDOMDocument) {
+              // rather than on the <browser>.  But either way we have a node here.
+              if (browser.nodeType == browser.DOCUMENT_NODE) {
                 browser = browser.docShell.chromeEventHandler;
               }
 
               let {gBrowser} = browser.ownerGlobal;
               let nativeTab = gBrowser.getTabForBrowser(browser);
               if (!nativeTab) {
                 // We only care about zoom events in the top-level browser of a tab.
                 return;
--- a/devtools/server/actors/object/previewers.js
+++ b/devtools/server/actors/object/previewers.js
@@ -608,17 +608,17 @@ previewers.Object = [
 
     let preview = grip.preview = {
       kind: "DOMNode",
       nodeType: rawObj.nodeType,
       nodeName: rawObj.nodeName,
       isConnected: rawObj.isConnected === true,
     };
 
-    if (rawObj instanceof Ci.nsIDOMDocument && rawObj.location) {
+    if (rawObj.nodeType == rawObj.DOCUMENT_NODE && rawObj.location) {
       preview.location = hooks.createValueGrip(rawObj.location.href);
     } 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));
--- a/dom/base/test/unit/head_xml.js
+++ b/dom/base/test/unit/head_xml.js
@@ -7,17 +7,16 @@
 const I                    = Ci;
 const C                    = Cc;
 
 const nsIFile         = I.nsIFile;
 const nsIProperties        = I.nsIProperties;
 const nsIFileInputStream   = I.nsIFileInputStream;
 const nsIInputStream       = I.nsIInputStream;
 
-const nsIDOMDocument       = I.nsIDOMDocument;
 const nsIDOMNode           = I.nsIDOMNode;
 
 Cu.importGlobalProperties(["DOMParser", "Element", "XMLSerializer"]);
 
 function getParser() {
   var parser = new DOMParser();
   parser.forceEnableXULXBL();
   return parser;
--- a/dom/base/test/unit/test_range.js
+++ b/dom/base/test/unit/test_range.js
@@ -172,17 +172,17 @@ function getRange(aSourceNode, aFragment
  * @param aPath The path to the local document.
  */
 function getParsedDocument(aPath) {
   return do_parse_document(aPath, "application/xml").then(processParsedDocument);
 }
 
 function processParsedDocument(doc) {
   Assert.ok(doc.documentElement.localName != "parsererror");
-  Assert.ok(doc instanceof Ci.nsIDOMDocument);
+  Assert.equal(ChromeUtils.getClassName(doc), "XMLDocument");
 
   // Clean out whitespace.
   var walker = doc.createTreeWalker(doc,
                                     NodeFilter.SHOW_TEXT |
                                     NodeFilter.SHOW_CDATA_SECTION,
                                     isWhitespace);
   while (walker.nextNode()) {
     var parent = walker.currentNode.parentNode;
@@ -442,17 +442,17 @@ function do_miscellaneous_tests(doc) {
   // XXX ajvincent if rv == WRONG_DOCUMENT_ERR, return false?
   do_check_false(baseRange.isPointInRange(startContainer, startOffset));
   do_check_false(baseRange.isPointInRange(startContainer, startOffset + 1));
   do_check_false(baseRange.isPointInRange(endContainer, endOffset));
   */
 
   // Requested by smaug:  A range involving a comment as a document child.
   doc = parser.parseFromString("<!-- foo --><foo/>", "application/xml");
-  Assert.ok(doc instanceof Ci.nsIDOMDocument);
+  Assert.equal(ChromeUtils.getClassName(doc), "XMLDocument");
   Assert.equal(doc.childNodes.length, 2);
   baseRange = doc.createRange();
   baseRange.setStart(doc.firstChild, 1);
   baseRange.setEnd(doc.firstChild, 2);
   var frag = baseRange.extractContents();
   Assert.equal(frag.childNodes.length, 1);
   Assert.ok(ChromeUtils.getClassName(frag.firstChild) == "Comment");
   Assert.equal(frag.firstChild.nodeType, frag.COMMENT_NODE);
--- a/dom/base/test/unit/test_xml_parser.js
+++ b/dom/base/test/unit/test_xml_parser.js
@@ -3,30 +3,30 @@ function run_test () {
     if (!tests[i][0].call()) {
       do_throw(tests[i][1]);
     }
   }
 }
 
 var tests = [
   [ test1, "Unable to parse basic XML document" ],
-  [ test2, "ParseXML doesn't return nsIDOMDocument" ],
+  [ test2, "ParseXML doesn't return Document" ],
   [ test3, "ParseXML return value's documentElement is not Element" ],
   [ test4, "" ],
   [ test5, "" ],
   [ test6, "" ],
   [ null ]
 ];
 
 function test1() {
   return ParseXML("<root/>");
 }
 
 function test2() {
-  return (ParseXML("<root/>") instanceof nsIDOMDocument);
+  return (ChromeUtils.getClassName(ParseXML("<root/>")) === "XMLDocument");
 }
 
 function test3() {
   return Element.isInstance(ParseXML("<root/>").documentElement);
 }
 
 function test4() {
   var doc = ParseXML("<root/>");
--- a/mobile/android/components/BrowserCLH.js
+++ b/mobile/android/components/BrowserCLH.js
@@ -111,17 +111,17 @@ BrowserCLH.prototype = {
             _ => Services.logins,
           ], 10000 /* 10 seconds maximum wait. */),
         });
         break;
       }
 
       case "chrome-document-interactive":
       case "content-document-interactive": {
-        let contentWin = subject.QueryInterface(Ci.nsIDOMDocument).defaultView;
+        let contentWin = subject.defaultView;
         let win = GeckoViewUtils.getChromeWindow(contentWin);
         let dispatcher = GeckoViewUtils.getDispatcherForWindow(win);
         if (!win || !dispatcher || win !== contentWin) {
           // Only attach to top-level windows.
           return;
         }
 
         GeckoViewUtils.addLazyEventListener(win, "click", {
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -354,17 +354,17 @@ function find_(container, strategy, sele
   let rootNode = container.shadowRoot || container.frame.document;
 
   if (!startNode) {
     switch (strategy) {
       // For anonymous nodes the start node needs to be of type
       // DOMElement, which will refer to :root in case of a DOMDocument.
       case element.Strategy.Anon:
       case element.Strategy.AnonAttribute:
-        if (rootNode instanceof Ci.nsIDOMDocument) {
+        if (rootNode.nodeType == rootNode.DOCUMENT_NODE) {
           startNode = rootNode.documentElement;
         }
         break;
 
       default:
         startNode = rootNode;
     }
   }
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -1000,17 +1000,17 @@ function do_load_manifest(path) {
 }
 
 /**
  * Parse a DOM document.
  *
  * @param aPath File path to the document.
  * @param aType Content type to use in DOMParser.
  *
- * @return nsIDOMDocument from the file.
+ * @return Document from the file.
  */
 function do_parse_document(aPath, aType) {
   switch (aType) {
     case "application/xhtml+xml":
     case "application/xml":
     case "text/xml":
       break;
 
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -175,34 +175,34 @@ function saveBrowser(aBrowser, aSkipProm
     onError(status) {
       throw new Components.Exception("saveBrowser failed asynchronously in startPersistence",
                                      status, stack);
     }
   });
 }
 
 // Saves a document; aDocument can be an nsIWebBrowserPersistDocument
-// (see saveBrowser, above) or an nsIDOMDocument.
+// (see saveBrowser, above) or a Document.
 //
-// aDocument can also be a CPOW for a remote nsIDOMDocument, in which
+// aDocument can also be a CPOW for a remote Document, in which
 // case "save as" modes that serialize the document's DOM are
 // unavailable.  This is a temporary measure for the "Save Frame As"
 // command (bug 1141337) and pre-e10s add-ons.
 function saveDocument(aDocument, aSkipPrompt) {
   if (!aDocument)
     throw "Must have a document when calling saveDocument";
 
   let contentDisposition = null;
   let cacheKey = 0;
 
   if (aDocument instanceof Ci.nsIWebBrowserPersistDocument) {
     // nsIWebBrowserPersistDocument exposes these directly.
     contentDisposition = aDocument.contentDisposition;
     cacheKey = aDocument.cacheKey;
-  } else if (aDocument instanceof Ci.nsIDOMDocument) {
+  } else if (aDocument.nodeType == 9 /* DOCUMENT_NODE */) {
     // Otherwise it's an actual nsDocument (and possibly a CPOW).
     // We want to use cached data because the document is currently visible.
     let ifreq =
       aDocument.defaultView
                .QueryInterface(Ci.nsIInterfaceRequestor);
 
     try {
       contentDisposition =
@@ -401,17 +401,17 @@ function internalSave(aURL, aDocument, a
     // If we're saving a document, and are saving either in complete mode or
     // as converted text, pass the document to the web browser persist component.
     // If we're just saving the HTML (second option in the list), send only the URI.
     let nonCPOWDocument =
       aDocument && !Cu.isCrossProcessWrapper(aDocument);
 
     let isPrivate = aIsContentWindowPrivate;
     if (isPrivate === undefined) {
-      isPrivate = aInitiatingDocument instanceof Ci.nsIDOMDocument
+      isPrivate = aInitiatingDocument.nodeType == 9 /* DOCUMENT_NODE */
         ? PrivateBrowsingUtils.isContentWindowPrivate(aInitiatingDocument.defaultView)
         : aInitiatingDocument.isPrivate;
     }
 
     var persistArgs = {
       sourceURI,
       sourceReferrer: aReferrer,
       sourceDocument: useSaveDocument ? aDocument : null,