Ignore document.open/write after the active parser has been aborted
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Oct 2019 23:02:32 +0000 (23:02 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Oct 2019 23:02:32 +0000 (23:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203028

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline WPT test that is now passing.

* web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window-expected.txt:

Source/WebCore:

Ignore document.open/write after the active parser has been aborted, as per:
- https://github.com/whatwg/html/pull/4907

Test: imported/blink/fast/loader/document-write-after-location-change.html

* dom/Document.cpp:
(WebCore::Document::open):
(WebCore::Document::cancelParsing):
(WebCore::Document::implicitOpen):
(WebCore::Document::write):
* dom/Document.h:

LayoutTests:

Import test from blink.

* imported/blink/fast/loader/document-write-after-location-change-expected.txt: Added.
* imported/blink/fast/loader/document-write-after-location-change.html: Added.
* imported/blink/fast/loader/resources/pass-and-notify-done.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/imported/blink/fast/loader/document-write-after-location-change-expected.txt [new file with mode: 0644]
LayoutTests/imported/blink/fast/loader/document-write-after-location-change.html [new file with mode: 0644]
LayoutTests/imported/blink/fast/loader/resources/pass-and-notify-done.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h

index d6f7f4c..ff87f86 100644 (file)
@@ -1,3 +1,16 @@
+2019-10-23  Chris Dumez  <cdumez@apple.com>
+
+        Ignore document.open/write after the active parser has been aborted
+        https://bugs.webkit.org/show_bug.cgi?id=203028
+
+        Reviewed by Geoffrey Garen.
+
+        Import test from blink.
+
+        * imported/blink/fast/loader/document-write-after-location-change-expected.txt: Added.
+        * imported/blink/fast/loader/document-write-after-location-change.html: Added.
+        * imported/blink/fast/loader/resources/pass-and-notify-done.html: Added.
+
 2019-10-23  Russell Epstein  <repstein@apple.com>
 
         REGRESSION (r250936?) [ iOS ]: Layout Test http/tests/IndexedDB/storage-limit-1.https.html is a Flaky Failure (203275)
diff --git a/LayoutTests/imported/blink/fast/loader/document-write-after-location-change-expected.txt b/LayoutTests/imported/blink/fast/loader/document-write-after-location-change-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/imported/blink/fast/loader/document-write-after-location-change.html b/LayoutTests/imported/blink/fast/loader/document-write-after-location-change.html
new file mode 100644 (file)
index 0000000..565ad14
--- /dev/null
@@ -0,0 +1,11 @@
+<body>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+location.replace("resources/pass-and-notify-done.html");
+document.open();
+document.write("This should not cancel the navigation");
+</script>
+</body>
diff --git a/LayoutTests/imported/blink/fast/loader/resources/pass-and-notify-done.html b/LayoutTests/imported/blink/fast/loader/resources/pass-and-notify-done.html
new file mode 100644 (file)
index 0000000..d61dc36
--- /dev/null
@@ -0,0 +1,6 @@
+<body>
+PASS
+<script>
+if (window.testRunner)
+  testRunner.notifyDone()
+</script>
index c168c84..8e7a0a2 100644 (file)
@@ -1,3 +1,14 @@
+2019-10-23  Chris Dumez  <cdumez@apple.com>
+
+        Ignore document.open/write after the active parser has been aborted
+        https://bugs.webkit.org/show_bug.cgi?id=203028
+
+        Reviewed by Geoffrey Garen.
+
+        Rebaseline WPT test that is now passing.
+
+        * web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window-expected.txt:
+
 2019-10-23  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [SVG2] Fix SVGElement to conform with SVG2
index aa653fc..bd0dc91 100644 (file)
@@ -1,4 +1,4 @@
 
-FAIL document.open() after parser is aborted assert_false: child document should not be empty expected false got true
-FAIL async document.open() after parser is aborted assert_false: child document should not be empty expected false got true
+PASS document.open() after parser is aborted 
+PASS async document.open() after parser is aborted 
 
index e2077ae..d526365 100644 (file)
@@ -1,3 +1,22 @@
+2019-10-23  Chris Dumez  <cdumez@apple.com>
+
+        Ignore document.open/write after the active parser has been aborted
+        https://bugs.webkit.org/show_bug.cgi?id=203028
+
+        Reviewed by Geoffrey Garen.
+
+        Ignore document.open/write after the active parser has been aborted, as per:
+        - https://github.com/whatwg/html/pull/4907
+
+        Test: imported/blink/fast/loader/document-write-after-location-change.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::open):
+        (WebCore::Document::cancelParsing):
+        (WebCore::Document::implicitOpen):
+        (WebCore::Document::write):
+        * dom/Document.h:
+
 2019-10-23  Andy Estes  <aestes@apple.com>
 
         [Quick Look] Move PreviewConverter from platform/network/ to platform/
index 0ea1d86..954aa29 100644 (file)
@@ -2732,6 +2732,9 @@ ExceptionOr<void> Document::open(Document* responsibleDocument)
     if (m_ignoreOpensDuringUnloadCount)
         return { };
 
+    if (m_activeParserWasAborted)
+        return { };
+
     if (m_frame) {
         if (ScriptableDocumentParser* parser = scriptableDocumentParser()) {
             if (parser->isParsing()) {
@@ -2801,6 +2804,9 @@ void Document::cancelParsing()
     if (!m_parser)
         return;
 
+    if (m_parser->processingData())
+        m_activeParserWasAborted = true;
+
     // We have to clear the parser to avoid possibly triggering
     // the onload handler when closing as a side effect of a cancel-style
     // change, such as opening a new document or closing the window while
@@ -2815,7 +2821,7 @@ void Document::implicitOpen()
 
     setCompatibilityMode(DocumentCompatibilityMode::NoQuirksMode);
 
-    cancelParsing();
+    detachParser();
     m_parser = createParser();
 
     if (hasActiveParserYieldToken())
@@ -3085,6 +3091,9 @@ Seconds Document::timeSinceDocumentCreation() const
 
 ExceptionOr<void> Document::write(Document* responsibleDocument, SegmentedString&& text)
 {
+    if (m_activeParserWasAborted)
+        return { };
+
     NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth);
 
     m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionIsTooDeep;
index b7b67d5..f937d79 100644 (file)
@@ -1962,6 +1962,7 @@ private:
 
     MutationObserverOptions m_mutationObserverTypes { 0 };
 
+    bool m_activeParserWasAborted { false };
     bool m_writeRecursionIsTooDeep { false };
     bool m_wellFormed { false };
     bool m_createRenderers { true };