Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specifi...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jan 2020 16:58:17 +0000 (16:58 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jan 2020 16:58:17 +0000 (16:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=205699

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaselined existing test now that more checks are passing.

* web-platform-tests/dom/idlharness.window-expected.txt:

Source/WebCore:

Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specification and
other browsers (tested Chrome 79 and Firefox 71). In particular, their parameter should not be
optional (or nullable).

No new tests, rebaselined existing test.

* dom/Document.cpp:
(WebCore::Document::createNSResolver):
* dom/Document.h:
* dom/Document.idl:
* xml/NativeXPathNSResolver.cpp:
(WebCore::NativeXPathNSResolver::NativeXPathNSResolver):
(WebCore::NativeXPathNSResolver::lookupNamespaceURI):
* xml/NativeXPathNSResolver.h:
(WebCore::NativeXPathNSResolver::create):
* xml/XPathEvaluator.cpp:
(WebCore::XPathEvaluator::createNSResolver):
* xml/XPathEvaluator.h:
* xml/XPathEvaluator.idl:
* xml/XPathResult.idl:

Source/WebKitLegacy/mac:

* DOM/DOMDocument.mm:
(-[DOMDocument createNSResolver:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254001 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/dom/idlharness.window-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/xml/NativeXPathNSResolver.cpp
Source/WebCore/xml/NativeXPathNSResolver.h
Source/WebCore/xml/XPathEvaluator.cpp
Source/WebCore/xml/XPathEvaluator.h
Source/WebCore/xml/XPathEvaluator.idl
Source/WebCore/xml/XPathResult.idl
Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/DOMDocument.mm

index b669851..bf734b0 100644 (file)
@@ -1,3 +1,14 @@
+2020-01-03  Chris Dumez  <cdumez@apple.com>
+
+        Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=205699
+
+        Reviewed by Alex Christensen.
+
+        Rebaselined existing test now that more checks are passing.
+
+        * web-platform-tests/dom/idlharness.window-expected.txt:
+
 2020-01-03  Cathie Chen  <cathiechen@igalia.com>
 
         Import WPT test cases for apect-ratio generated from attribute width and height
index feb3543..77b52e5 100644 (file)
@@ -1794,7 +1794,7 @@ PASS XPathResult interface: attribute singleNodeValue
 PASS XPathResult interface: attribute invalidIteratorState 
 PASS XPathResult interface: attribute snapshotLength 
 PASS XPathResult interface: operation iterateNext() 
-FAIL XPathResult interface: operation snapshotItem(unsigned long) assert_equals: property has wrong .length expected 1 but got 0
+PASS XPathResult interface: operation snapshotItem(unsigned long) 
 PASS XPathResult must be primary interface of document.evaluate("//*", document.body) 
 PASS Stringification of document.evaluate("//*", document.body) 
 PASS XPathResult interface: document.evaluate("//*", document.body) must inherit property "ANY_TYPE" with the proper type 
@@ -1840,16 +1840,14 @@ PASS XPathEvaluator interface: existence and properties of interface prototype o
 PASS XPathEvaluator interface: existence and properties of interface prototype object's "constructor" property 
 PASS XPathEvaluator interface: existence and properties of interface prototype object's @@unscopables property 
 PASS XPathEvaluator interface: operation createExpression(DOMString, XPathNSResolver) 
-FAIL XPathEvaluator interface: operation createNSResolver(Node) assert_equals: property has wrong .length expected 1 but got 0
+PASS XPathEvaluator interface: operation createNSResolver(Node) 
 PASS XPathEvaluator interface: operation evaluate(DOMString, Node, XPathNSResolver, unsigned short, XPathResult) 
 PASS XPathEvaluator must be primary interface of new XPathEvaluator() 
 PASS Stringification of new XPathEvaluator() 
 PASS XPathEvaluator interface: new XPathEvaluator() must inherit property "createExpression(DOMString, XPathNSResolver)" with the proper type 
 PASS XPathEvaluator interface: calling createExpression(DOMString, XPathNSResolver) on new XPathEvaluator() with too few arguments must throw TypeError 
 PASS XPathEvaluator interface: new XPathEvaluator() must inherit property "createNSResolver(Node)" with the proper type 
-FAIL XPathEvaluator interface: calling createNSResolver(Node) on new XPathEvaluator() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
-            fn.apply(obj, args);
-        }" did not throw
+PASS XPathEvaluator interface: calling createNSResolver(Node) on new XPathEvaluator() with too few arguments must throw TypeError 
 PASS XPathEvaluator interface: new XPathEvaluator() must inherit property "evaluate(DOMString, Node, XPathNSResolver, unsigned short, XPathResult)" with the proper type 
 PASS XPathEvaluator interface: calling evaluate(DOMString, Node, XPathNSResolver, unsigned short, XPathResult) on new XPathEvaluator() with too few arguments must throw TypeError 
 PASS Window interface: attribute event 
index de1377b..f7b65e5 100644 (file)
@@ -1,3 +1,31 @@
+2020-01-03  Chris Dumez  <cdumez@apple.com>
+
+        Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=205699
+
+        Reviewed by Alex Christensen.
+
+        Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specification and
+        other browsers (tested Chrome 79 and Firefox 71). In particular, their parameter should not be
+        optional (or nullable).
+
+        No new tests, rebaselined existing test.
+
+        * dom/Document.cpp:
+        (WebCore::Document::createNSResolver):
+        * dom/Document.h:
+        * dom/Document.idl:
+        * xml/NativeXPathNSResolver.cpp:
+        (WebCore::NativeXPathNSResolver::NativeXPathNSResolver):
+        (WebCore::NativeXPathNSResolver::lookupNamespaceURI):
+        * xml/NativeXPathNSResolver.h:
+        (WebCore::NativeXPathNSResolver::create):
+        * xml/XPathEvaluator.cpp:
+        (WebCore::XPathEvaluator::createNSResolver):
+        * xml/XPathEvaluator.h:
+        * xml/XPathEvaluator.idl:
+        * xml/XPathResult.idl:
+
 2020-01-03  Rob Buis  <rbuis@igalia.com>
 
         Implement "create a potential-CORS request"
index 5e6fd74..7623818 100644 (file)
@@ -5848,7 +5848,7 @@ ExceptionOr<Ref<XPathExpression>> Document::createExpression(const String& expre
     return m_xpathEvaluator->createExpression(expression, WTFMove(resolver));
 }
 
-Ref<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
+Ref<XPathNSResolver> Document::createNSResolver(Node& nodeResolver)
 {
     if (!m_xpathEvaluator)
         m_xpathEvaluator = XPathEvaluator::create();
index cd65a50..82497ac 100644 (file)
@@ -1043,7 +1043,7 @@ public:
 
     // XPathEvaluator methods
     WEBCORE_EXPORT ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
-    WEBCORE_EXPORT Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
+    WEBCORE_EXPORT Ref<XPathNSResolver> createNSResolver(Node& nodeResolver);
     WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node& contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
 
     bool hasNodesWithNonFinalStyle() const { return m_hasNodesWithNonFinalStyle; }
index 2bfadf6..3c841a6 100644 (file)
@@ -137,7 +137,7 @@ typedef (
 
     // XPath extensions (https://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator).
     [MayThrowException] XPathExpression createExpression(DOMString expression, optional XPathNSResolver? resolver);
-    XPathNSResolver createNSResolver(Node? nodeResolver);
+    XPathNSResolver createNSResolver(Node nodeResolver);
     [MayThrowException] XPathResult evaluate(DOMString expression, Node contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
 
     // Extensions from Pointer Lock API (https://www.w3.org/TR/pointerlock/#extensions-to-the-document-interface).
index 14f5194..ebf34b7 100644 (file)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-NativeXPathNSResolver::NativeXPathNSResolver(RefPtr<Node>&& node)
+NativeXPathNSResolver::NativeXPathNSResolver(Ref<Node>&& node)
     : m_node(WTFMove(node))
 {
 }
@@ -46,7 +46,7 @@ String NativeXPathNSResolver::lookupNamespaceURI(const String& prefix)
     if (prefix == "xml")
         return XMLNames::xmlNamespaceURI.get();
     
-    return m_node ? m_node->lookupNamespaceURI(prefix).string() : String();
+    return m_node->lookupNamespaceURI(prefix).string();
 }
 
 } // namespace WebCore
index 0264207..f875ae2 100644 (file)
@@ -34,14 +34,14 @@ class Node;
 
 class NativeXPathNSResolver : public XPathNSResolver {
 public:
-    static Ref<NativeXPathNSResolver> create(RefPtr<Node>&& node) { return adoptRef(*new NativeXPathNSResolver(WTFMove(node))); }
+    static Ref<NativeXPathNSResolver> create(Ref<Node>&& node) { return adoptRef(*new NativeXPathNSResolver(WTFMove(node))); }
     virtual ~NativeXPathNSResolver();
 
     String lookupNamespaceURI(const String& prefix) override;
 
 private:
-    explicit NativeXPathNSResolver(RefPtr<Node>&&);
-    RefPtr<Node> m_node;
+    explicit NativeXPathNSResolver(Ref<Node>&&);
+    Ref<Node> m_node;
 };
 
 } // namespace WebCore
index 25c0cbf..1c63e71 100644 (file)
@@ -41,7 +41,7 @@ ExceptionOr<Ref<XPathExpression>> XPathEvaluator::createExpression(const String&
     return XPathExpression::createExpression(expression, WTFMove(resolver));
 }
 
-Ref<XPathNSResolver> XPathEvaluator::createNSResolver(Node* nodeResolver)
+Ref<XPathNSResolver> XPathEvaluator::createNSResolver(Node& nodeResolver)
 {
     return NativeXPathNSResolver::create(nodeResolver);
 }
index 6c3f91c..7a98ffd 100644 (file)
@@ -40,7 +40,7 @@ public:
     static Ref<XPathEvaluator> create() { return adoptRef(*new XPathEvaluator); }
 
     ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
-    Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
+    Ref<XPathNSResolver> createNSResolver(Node& nodeResolver);
     ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node& contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
 
 private:
index f2bd6cc..e599c51 100644 (file)
@@ -23,7 +23,7 @@
 ] interface XPathEvaluator {
     [MayThrowException] XPathExpression createExpression(DOMString expression, optional XPathNSResolver? resolver);
 
-    XPathNSResolver createNSResolver(optional Node? nodeResolver);
+    XPathNSResolver createNSResolver(Node nodeResolver);
 
     [MayThrowException] XPathResult evaluate(DOMString expression, Node contextNode, optional XPathNSResolver? resolver, optional unsigned short type = 0, optional XPathResult? inResult);
 };
index 91efaf9..09ba4b5 100644 (file)
@@ -43,5 +43,5 @@
     readonly attribute unsigned long snapshotLength;
 
     [MayThrowException] Node iterateNext();
-    [MayThrowException] Node snapshotItem(optional unsigned long index = 0);
+    [MayThrowException] Node snapshotItem(unsigned long index);
 };
index 1d13178..f1a22d2 100644 (file)
@@ -1151,7 +1151,9 @@ WebKitDOMXPathNSResolver* webkit_dom_document_create_ns_resolver(WebKitDOMDocume
     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(nodeResolver), 0);
     WebCore::Document* item = WebKit::core(self);
     WebCore::Node* convertedNodeResolver = WebKit::core(nodeResolver);
-    RefPtr<WebCore::XPathNSResolver> gobjectResult = WTF::getPtr(item->createNSResolver(convertedNodeResolver));
+    if (!convertedNodeResolver)
+        return nullptr;
+    RefPtr<WebCore::XPathNSResolver> gobjectResult = WTF::getPtr(item->createNSResolver(*convertedNodeResolver));
     return WebKit::kit(gobjectResult.get());
 }
 
index 25ac956..1927510 100644 (file)
@@ -1,3 +1,13 @@
+2020-01-03  Chris Dumez  <cdumez@apple.com>
+
+        Align XPathEvaluator.createNSResolver() / XPathResult.snapshotItem() with the specification
+        https://bugs.webkit.org/show_bug.cgi?id=205699
+
+        Reviewed by Alex Christensen.
+
+        * DOM/DOMDocument.mm:
+        (-[DOMDocument createNSResolver:]):
+
 2019-12-22  Jeff Miller  <jeffm@apple.com>
 
         Update user-visible copyright strings to include 2020
index 590db50..7f675e2 100644 (file)
@@ -596,7 +596,10 @@ static RefPtr<WebCore::XPathNSResolver> wrap(id <DOMXPathNSResolver> resolver)
 - (id <DOMXPathNSResolver>)createNSResolver:(DOMNode *)nodeResolver
 {
     WebCore::JSMainThreadNullState state;
-    return kit(WTF::getPtr(IMPL->createNSResolver(core(nodeResolver))));
+    if (!nodeResolver)
+        return nullptr;
+
+    return kit(WTF::getPtr(IMPL->createNSResolver(*core(nodeResolver))));
 }
 
 - (DOMXPathResult *)evaluate:(NSString *)expression contextNode:(DOMNode *)contextNode resolver:(id <DOMXPathNSResolver>)resolver type:(unsigned short)type inResult:(DOMXPathResult *)inResult