Bug 1435666 - Part 3: Remove nsIDOMXPathResult. r=bz draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 05 Feb 2018 11:39:18 +0800
changeset 751958 07b5e02160708671cb9cf707938e97fb97c783d2
parent 751957 328f48d0fb3b30704df99942d568eaa7d870ccc2
child 751959 f3f41445a5d4cb62b296bb9ee313808c1aa8c6db
push id98105
push userbmo:cam@mcc.id.au
push dateWed, 07 Feb 2018 07:54:04 +0000
reviewersbz
bugs1435666
milestone60.0a1
Bug 1435666 - Part 3: Remove nsIDOMXPathResult. r=bz MozReview-Commit-ID: 9j6dUlanNTi
browser/components/sessionstore/test/browser_248970_b_perwindowpb.js
browser/components/sessionstore/test/content-forms.js
devtools/client/sourceeditor/tern/browser.js
devtools/client/webconsole/webconsole.js
devtools/server/actors/webconsole/utils.js
dom/base/test/unit/test_range.js
dom/interfaces/xpath/moz.build
dom/interfaces/xpath/nsIDOMXPathResult.idl
mobile/android/tests/browser/chrome/test_session_form_data.html
testing/marionette/doc/api/element.js.html
testing/marionette/element.js
toolkit/modules/sessionstore/FormData.jsm
xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
--- a/browser/components/sessionstore/test/browser_248970_b_perwindowpb.js
+++ b/browser/components/sessionstore/test/browser_248970_b_perwindowpb.js
@@ -36,17 +36,17 @@ function test() {
     try {
       return aLambda() || true;
     } catch (ex) { }
     return false;
   }
 
   function getElementByXPath(aTab, aQuery) {
     let doc = aTab.linkedBrowser.contentDocument;
-    let xptype = Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
+    let xptype = doc.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE;
     return doc.evaluate(aQuery, doc, null, xptype, null).singleNodeValue;
   }
 
   function setFormValue(aTab, aQuery, aValue) {
     let node = getElementByXPath(aTab, aQuery);
     if (typeof aValue == "string")
       node.value = aValue;
     else if (typeof aValue == "boolean")
--- a/browser/components/sessionstore/test/content-forms.js
+++ b/browser/components/sessionstore/test/content-forms.js
@@ -24,17 +24,17 @@ function queryElement(data) {
     return doc.getElementById(data.id);
   }
 
   if (data.hasOwnProperty("selector")) {
     return doc.querySelector(data.selector);
   }
 
   if (data.hasOwnProperty("xpath")) {
-    let xptype = Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
+    let xptype = doc.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE;
     return doc.evaluate(data.xpath, doc, null, xptype, null).singleNodeValue;
   }
 
   throw new Error("couldn't query element");
 }
 
 function dispatchUIEvent(input, type) {
   let event = input.ownerDocument.createEvent("UIEvents");
--- a/devtools/client/sourceeditor/tern/browser.js
+++ b/devtools/client/sourceeditor/tern/browser.js
@@ -1425,32 +1425,32 @@ module.exports = {
       "invalidIteratorState": {
         "!type": "bool",
         "!url": "https://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript",
         "!doc": "This document describes the interface for using XPath in JavaScript internally, in extensions, and from websites. Mozilla implements a fair amount of the DOM 3 XPath. Which means that XPath expressions can be run against both HTML and XML documents."
       },
       "numberValue": {
         "!type": "number",
         "!url": "https://developer.mozilla.org/en/docs/XPathResult",
-        "!doc": "Refer to nsIDOMXPathResult for more detail."
+        "!doc": "Refer to XPathResult for more detail."
       },
       "resultType": {
         "!type": "number",
         "!url": "https://developer.mozilla.org/en/docs/DOM/document.evaluate",
         "!doc": "Returns an XPathResult based on an XPath expression and other given parameters."
       },
       "singleNodeValue": {
         "!type": "+Element",
         "!url": "https://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript",
         "!doc": "This document describes the interface for using XPath in JavaScript internally, in extensions, and from websites. Mozilla implements a fair amount of the DOM 3 XPath. Which means that XPath expressions can be run against both HTML and XML documents."
       },
       "snapshotLength": {
         "!type": "number",
         "!url": "https://developer.mozilla.org/en/docs/XPathResult",
-        "!doc": "Refer to nsIDOMXPathResult for more detail."
+        "!doc": "Refer to XPathResult for more detail."
       },
       "stringValue": {
         "!type": "string",
         "!url": "https://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript",
         "!doc": "This document describes the interface for using XPath in JavaScript internally, in extensions, and from websites. Mozilla implements a fair amount of the DOM 3 XPath. Which means that XPath expressions can be run against both HTML and XML documents."
       },
       "iterateNext": {
         "!type": "fn()",
@@ -1468,17 +1468,17 @@ module.exports = {
       "UNORDERED_NODE_ITERATOR_TYPE": "number",
       "ORDERED_NODE_ITERATOR_TYPE": "number",
       "UNORDERED_NODE_SNAPSHOT_TYPE": "number",
       "ORDERED_NODE_SNAPSHOT_TYPE": "number",
       "ANY_UNORDERED_NODE_TYPE": "number",
       "FIRST_ORDERED_NODE_TYPE": "number"
     },
     "!url": "https://developer.mozilla.org/en/docs/XPathResult",
-    "!doc": "Refer to nsIDOMXPathResult for more detail."
+    "!doc": "Refer to XPathResult for more detail."
   },
   "ClientRect": {
     "!type": "fn()",
     "prototype": {
       "top": {
         "!type": "number",
         "!url": "https://developer.mozilla.org/en/docs/DOM/element.getClientRects",
         "!doc": "Top of the box, in pixels, relative to the viewport."
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -978,22 +978,19 @@ WebConsoleFrame.prototype = {
 
     // Look for message nodes (".message") with the given preference key
     // (filter="error", filter="cssparser", etc.) and add or remove the
     // "filtered-by-type" class, which turns on or off the display.
 
     let attribute = !WORKERTYPES_PREFKEYS.includes(prefKey)
                       ? "filter" : "workerType";
 
-    let xpath = ".//*[contains(@class, 'message') and " +
-      "@" + attribute + "='" + prefKey + "']";
-    let result = doc.evaluate(xpath, outputNode, null,
-      Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
-    for (let i = 0; i < result.snapshotLength; i++) {
-      let node = result.snapshotItem(i);
+    let selector = "[" + attribute + "='" + prefKey + "'].message";
+    let result = outputNode.querySelectorAll(selector);
+    for (let node of result) {
       if (state) {
         node.classList.remove("filtered-by-type");
       } else {
         node.classList.add("filtered-by-type");
       }
     }
   },
 
--- a/devtools/server/actors/webconsole/utils.js
+++ b/devtools/server/actors/webconsole/utils.js
@@ -367,17 +367,17 @@ WebConsoleCommands._registerOriginal("$x
   let nodes = new owner.window.Array();
 
   // Not waiving Xrays, since we want the original Document.evaluate function,
   // instead of anything that's been redefined.
   let doc = owner.window.document;
   context = context || doc;
 
   let results = doc.evaluate(xPath, context, null,
-                             Ci.nsIDOMXPathResult.ANY_TYPE, null);
+                             owner.window.XPathResult.ANY_TYPE, null);
   let node;
   while ((node = results.iterateNext())) {
     nodes.push(node);
   }
 
   return nodes;
 });
 
--- a/dom/base/test/unit/test_range.js
+++ b/dom/base/test/unit/test_range.js
@@ -1,15 +1,15 @@
 /* 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/. */
 
 const C_i = Components.interfaces;
 
-const UNORDERED_TYPE = C_i.nsIDOMXPathResult.ANY_UNORDERED_NODE_TYPE;
+const UNORDERED_TYPE = 8; // XPathResult.ANY_UNORDERED_NODE_TYPE
 
 /**
  * Determine if the data node has only ignorable white-space.
  *
  * @return NodeFilter.FILTER_SKIP if it does.
  * @return NodeFilter.FILTER_ACCEPT otherwise.
  */
 function isWhitespace(aNode) {
--- a/dom/interfaces/xpath/moz.build
+++ b/dom/interfaces/xpath/moz.build
@@ -4,13 +4,12 @@
 # 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/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "XSLT")
 
 XPIDL_SOURCES += [
     'nsIDOMXPathEvaluator.idl',
-    'nsIDOMXPathResult.idl',
 ]
 
 XPIDL_MODULE = 'dom_xpath'
 
deleted file mode 100644
--- a/dom/interfaces/xpath/nsIDOMXPathResult.idl
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-/**
- * Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
- */
-
-#include "nsISupports.idl"
-
-[uuid(75506f84-b504-11d5-a7f2-ca108ab8b6fc)]
-interface nsIDOMXPathResult : nsISupports
-{
-  // XPathResultType
-  const unsigned short      ANY_TYPE                       = 0;
-  const unsigned short      NUMBER_TYPE                    = 1;
-  const unsigned short      STRING_TYPE                    = 2;
-  const unsigned short      BOOLEAN_TYPE                   = 3;
-  const unsigned short      UNORDERED_NODE_ITERATOR_TYPE   = 4;
-  const unsigned short      ORDERED_NODE_ITERATOR_TYPE     = 5;
-  const unsigned short      UNORDERED_NODE_SNAPSHOT_TYPE   = 6;
-  const unsigned short      ORDERED_NODE_SNAPSHOT_TYPE     = 7;
-  const unsigned short      ANY_UNORDERED_NODE_TYPE        = 8;
-  const unsigned short      FIRST_ORDERED_NODE_TYPE        = 9;
-};
--- a/mobile/android/tests/browser/chrome/test_session_form_data.html
+++ b/mobile/android/tests/browser/chrome/test_session_form_data.html
@@ -41,17 +41,17 @@ function queryElement(contentWindow, dat
     return doc.getElementById(data.id);
   }
 
   if (data.hasOwnProperty("selector")) {
     return doc.querySelector(data.selector);
   }
 
   if (data.hasOwnProperty("xpath")) {
-    let xptype = Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
+    let xptype = XPathResult.FIRST_ORDERED_NODE_TYPE;
     return doc.evaluate(data.xpath, doc, null, xptype, null).singleNodeValue;
   }
 
   throw new Error("couldn't query element");
 }
 
 function dispatchUIEvent(input, type) {
   let event = input.ownerDocument.createEvent("UIEvents");
--- a/testing/marionette/doc/api/element.js.html
+++ b/testing/marionette/doc/api/element.js.html
@@ -48,20 +48,19 @@ this.EXPORTED_SYMBOLS = [
   "ChromeWebElement",
   "ContentWebElement",
   "ContentWebFrame",
   "ContentWebWindow",
   "element",
   "WebElement",
 ];
 
-const {
-  FIRST_ORDERED_NODE_TYPE,
-  ORDERED_NODE_ITERATOR_TYPE,
-} = Ci.nsIDOMXPathResult;
+const ORDERED_NODE_ITERATOR_TYPE = 5;
+const FIRST_ORDERED_NODE_TYPE = 9;
+
 const ELEMENT_NODE = 1;
 const DOCUMENT_NODE = 9;
 
 const XBLNS = "http://www.mozilla.org/xbl";
 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 /** XUL elements that support checked property. */
 const XUL_CHECKED_ELS = new Set([
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -20,20 +20,19 @@ this.EXPORTED_SYMBOLS = [
   "ChromeWebElement",
   "ContentWebElement",
   "ContentWebFrame",
   "ContentWebWindow",
   "element",
   "WebElement",
 ];
 
-const {
-  FIRST_ORDERED_NODE_TYPE,
-  ORDERED_NODE_ITERATOR_TYPE,
-} = Ci.nsIDOMXPathResult;
+const ORDERED_NODE_ITERATOR_TYPE = 5;
+const FIRST_ORDERED_NODE_TYPE = 9;
+
 const ELEMENT_NODE = 1;
 const DOCUMENT_NODE = 9;
 
 const XBLNS = "http://www.mozilla.org/xbl";
 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 /** XUL elements that support checked property. */
 const XUL_CHECKED_ELS = new Set([
--- a/toolkit/modules/sessionstore/FormData.jsm
+++ b/toolkit/modules/sessionstore/FormData.jsm
@@ -115,17 +115,17 @@ var FormDataInternal = {
     "xhtml": "http://www.w3.org/1999/xhtml",
     "xul": "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   },
 
   /**
    * Resolves an XPath query generated by node.generateXPath.
    */
   resolve(aDocument, aQuery) {
-    let xptype = Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
+    let xptype = aDocument.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE;
     return aDocument.evaluate(aQuery, aDocument, this.resolveNS.bind(this), xptype, null).singleNodeValue;
   },
 
   /**
    * Namespace resolver for the above XPath resolver.
    */
   resolveNS(aPrefix) {
     return this.namespaceURIs[aPrefix] || null;
@@ -168,17 +168,17 @@ var FormDataInternal = {
    * @return object
    *         Form data encoded in an object.
    */
   collect({document: doc}) {
     let formNodes = doc.evaluate(
       this.restorableFormNodesXPath,
       doc,
       this.resolveNS.bind(this),
-      Ci.nsIDOMXPathResult.UNORDERED_NODE_ITERATOR_TYPE, null
+      doc.defaultView.XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null
     );
 
     let node;
     let ret = {};
 
     // Limit the number of XPath expressions for performance reasons. See
     // bug 477564.
     const MAX_TRAVERSED_XPATHS = 100;
--- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
@@ -61,17 +61,16 @@
 #include "nsIDOMText.h"
 #include "nsIDOMTimeRanges.h"
 #include "nsIDOMTransitionEvent.h"
 #include "nsIDOMUIEvent.h"
 #include "nsIDOMValidityState.h"
 #include "nsIDOMWheelEvent.h"
 #include "nsIDOMXMLDocument.h"
 #include "nsIDOMXPathEvaluator.h"
-#include "nsIDOMXPathResult.h"
 #include "nsIDOMXULCommandEvent.h"
 #include "nsIDOMXULElement.h"
 #include "nsIFrameLoader.h"
 #include "nsIListBoxObject.h"
 #include "nsIMenuBoxObject.h"
 #include "nsIScrollBoxObject.h"
 #include "nsISelection.h"
 #include "nsITreeBoxObject.h"
@@ -158,17 +157,16 @@
 #include "mozilla/dom/UIEventBinding.h"
 #include "mozilla/dom/ValidityStateBinding.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include "mozilla/dom/XMLDocumentBinding.h"
 #include "mozilla/dom/XMLHttpRequestEventTargetBinding.h"
 #include "mozilla/dom/XMLHttpRequestUploadBinding.h"
 #include "mozilla/dom/XMLSerializerBinding.h"
 #include "mozilla/dom/XPathEvaluatorBinding.h"
-#include "mozilla/dom/XPathResultBinding.h"
 #include "mozilla/dom/XULCommandEventBinding.h"
 #include "mozilla/dom/XULDocumentBinding.h"
 #include "mozilla/dom/XULElementBinding.h"
 
 using namespace mozilla;
 
 struct ComponentsInterfaceShimEntry {
   constexpr
@@ -285,17 +283,16 @@ const ComponentsInterfaceShimEntry kComp
   DEFINE_SHIM(UIEvent),
   DEFINE_SHIM(ValidityState),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIWebBrowserPersistable, FrameLoader),
   DEFINE_SHIM(WheelEvent),
   DEFINE_SHIM(XMLDocument),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestEventTarget, XMLHttpRequestEventTarget),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestUpload, XMLHttpRequestUpload),
   DEFINE_SHIM(XPathEvaluator),
-  DEFINE_SHIM(XPathResult),
   DEFINE_SHIM(XULCommandEvent),
   DEFINE_SHIM(XULElement),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsISelection, Selection),
 };
 
 #undef DEFINE_SHIM
 #undef DEFINE_SHIM_WITH_CUSTOM_INTERFACE