XMLHttpRequest's responseXML should be annotated with [Exposed=Window]
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Oct 2017 21:12:48 +0000 (21:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Oct 2017 21:12:48 +0000 (21:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177714

Patch by Sam Weinig <sam@webkit.org> on 2017-10-01
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js: Added.
* web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js: Added.
* web-platform-tests/XMLHttpRequest/resources/w3c-import.log:
* web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html: Added.
* web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html: Added.
* web-platform-tests/XMLHttpRequest/w3c-import.log:

    Import latest XMLHttpRequest tests that include tests for responseXML not
    being available in workers and setting a responseType of 'document' being
    a no-op in workers.

Source/WebCore:

Tests: imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html
       imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::responseXML):

    Replace returning null for non-document contexts with an assertion now
    that the bindings layer ensures this doesn't get called.

(WebCore::XMLHttpRequest::setResponseType):

    Match the spec and turn attempts to set a responseType of 'document' in
    non-documents contexts as a no-op.

* xml/XMLHttpRequest.idl:

    Address FIXME and annotate responseXML with [Exposed=Window] now that it
    is supported.

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/w3c-import.log
Source/WebCore/ChangeLog
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.idl

index 363a374..7abd5cb 100644 (file)
@@ -1,3 +1,21 @@
+2017-10-01  Sam Weinig  <sam@webkit.org>
+
+        XMLHttpRequest's responseXML should be annotated with [Exposed=Window]
+        https://bugs.webkit.org/show_bug.cgi?id=177714
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js: Added.
+        * web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js: Added.
+        * web-platform-tests/XMLHttpRequest/resources/w3c-import.log:
+        * web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html: Added.
+        * web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html: Added.
+        * web-platform-tests/XMLHttpRequest/w3c-import.log:
+
+            Import latest XMLHttpRequest tests that include tests for responseXML not
+            being available in workers and setting a responseType of 'document' being
+            a no-op in workers.
+
 2017-09-27  Chris Dumez  <cdumez@apple.com>
 
         cssFloat missing in CSSPropertyDeclaration.prototype
diff --git a/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js b/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js
new file mode 100644 (file)
index 0000000..37ba9bd
--- /dev/null
@@ -0,0 +1,9 @@
+self.importScripts('/resources/testharness.js');
+
+test(function() {
+    let xhr = new XMLHttpRequest();
+    xhr.responseType = "document";
+    assert_not_equals(xhr.responseType, "document");
+}, "Setting XMLHttpRequest responseType to 'document' in a worker should have no effect.");
+
+done();
diff --git a/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js b/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js
new file mode 100644 (file)
index 0000000..2f3fdf2
--- /dev/null
@@ -0,0 +1,9 @@
+self.importScripts('/resources/testharness.js');
+
+test(function() {
+    let xhr = new XMLHttpRequest();
+    assert_not_exists(xhr, "responseXML", "responseXML should not be available on instances.");
+    assert_not_exists(XMLHttpRequest.prototype, "responseXML", "responseXML should not be on the prototype.");
+}, "XMLHttpRequest's responseXML property should not be exposed in workers.");
+
+done();
index f0c6123..9aad346 100644 (file)
@@ -71,6 +71,8 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/redirect.py
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/requri.py
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/reset-token.py
+/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseType-document-in-worker.js
+/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/responseXML-unavailable-in-worker.js
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/send-after-setting-document-domain-window-1.htm
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/send-after-setting-document-domain-window-2.htm
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/resources/send-after-setting-document-domain-window-helper.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html b/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html
new file mode 100644 (file)
index 0000000..9a04320
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+    fetch_tests_from_worker(new Worker("resources/responseType-document-in-worker.js"));
+</script>
+</body>
+</html>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html b/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html
new file mode 100644 (file)
index 0000000..dcb4cb0
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+    fetch_tests_from_worker(new Worker("resources/responseXML-unavailable-in-worker.js"));
+</script>
+</body>
+</html>
index ab2cd50..5b7e0fc 100644 (file)
@@ -169,6 +169,8 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/response-json.htm
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/response-method.htm
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseText-status.html
+/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html
+/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responsetext-decoding.htm
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responsetype.html
 /LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responseurl.html
index 1dffcfb..a30ac85 100644 (file)
@@ -1,3 +1,29 @@
+2017-10-01  Sam Weinig  <sam@webkit.org>
+
+        XMLHttpRequest's responseXML should be annotated with [Exposed=Window]
+        https://bugs.webkit.org/show_bug.cgi?id=177714
+
+        Reviewed by Darin Adler.
+
+        Tests: imported/w3c/web-platform-tests/XMLHttpRequest/responseType-document-in-worker.html
+               imported/w3c/web-platform-tests/XMLHttpRequest/responseXML-unavailable-in-worker.html
+
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::responseXML):
+        
+            Replace returning null for non-document contexts with an assertion now
+            that the bindings layer ensures this doesn't get called.
+        
+        (WebCore::XMLHttpRequest::setResponseType):
+        
+            Match the spec and turn attempts to set a responseType of 'document' in
+            non-documents contexts as a no-op.
+        
+        * xml/XMLHttpRequest.idl:
+        
+            Address FIXME and annotate responseXML with [Exposed=Window] now that it
+            is supported.
+
 2017-09-30  Ryosuke Niwa  <rniwa@webkit.org>
 
         Don't reveal file URL when pasting an image
index dadf070..16fbcf2 100644 (file)
@@ -172,6 +172,8 @@ void XMLHttpRequest::didCacheResponse()
 
 ExceptionOr<Document*> XMLHttpRequest::responseXML()
 {
+    ASSERT(scriptExecutionContext()->isDocument());
+    
     if (m_responseType != ResponseType::EmptyString && m_responseType != ResponseType::Document)
         return Exception { InvalidStateError };
 
@@ -185,8 +187,7 @@ ExceptionOr<Document*> XMLHttpRequest::responseXML()
         // The W3C spec requires the final MIME type to be some valid XML type, or text/html.
         // If it is text/html, then the responseType of "document" must have been supplied explicitly.
         if ((m_response.isHTTP() && !responseIsXML() && !isHTML)
-            || (isHTML && m_responseType == ResponseType::EmptyString)
-            || scriptExecutionContext()->isWorkerGlobalScope()) {
+            || (isHTML && m_responseType == ResponseType::EmptyString)) {
             m_responseDocument = nullptr;
         } else {
             if (isHTML)
@@ -252,6 +253,9 @@ ExceptionOr<void> XMLHttpRequest::setTimeout(unsigned timeout)
 
 ExceptionOr<void> XMLHttpRequest::setResponseType(ResponseType type)
 {
+    if (!scriptExecutionContext()->isDocument() && type == ResponseType::Document)
+        return { };
+
     if (m_state >= LOADING)
         return Exception { InvalidStateError };
 
index 159a730..06bd7d3 100644 (file)
@@ -79,6 +79,5 @@ enum XMLHttpRequestResponseType {
     attribute XMLHttpRequestResponseType responseType;
     [CachedAttribute, CustomGetter] readonly attribute any response;
     readonly attribute USVString responseText;
-    // FIXME: responseXML should be annotated with [Exposed=Window].
-    readonly attribute Document? responseXML;
+    [Exposed=Window] readonly attribute Document? responseXML;
 };