Title: [238429] trunk
Revision
238429
Author
rn...@webkit.org
Date
2018-11-21 13:33:48 -0800 (Wed, 21 Nov 2018)

Log Message

Mutation observers doesn't get notified of character data mutation made by the parser
https://bugs.webkit.org/show_bug.cgi?id=191874

Reviewed by Antti Koivisto.

Source/WebCore:

Fixed the bug that CharacterData::parserAppendData was never notifying MutationObserver.

Test: fast/dom/MutationObserver/observe-parser-character-data-change.html

* dom/CharacterData.cpp:
(WebCore::CharacterData::parserAppendData):

LayoutTests:

Added a regression test.

* fast/dom/MutationObserver/observe-parser-character-data-change-expected.txt: Added.
* fast/dom/MutationObserver/observe-parser-character-data-change.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (238428 => 238429)


--- trunk/LayoutTests/ChangeLog	2018-11-21 19:10:49 UTC (rev 238428)
+++ trunk/LayoutTests/ChangeLog	2018-11-21 21:33:48 UTC (rev 238429)
@@ -1,3 +1,15 @@
+2018-11-21  Ryosuke Niwa  <rn...@webkit.org>
+
+        Mutation observers doesn't get notified of character data mutation made by the parser
+        https://bugs.webkit.org/show_bug.cgi?id=191874
+
+        Reviewed by Antti Koivisto.
+
+        Added a regression test.
+
+        * fast/dom/MutationObserver/observe-parser-character-data-change-expected.txt: Added.
+        * fast/dom/MutationObserver/observe-parser-character-data-change.html: Added.
+
 2018-11-21  Zalan Bujtas <za...@apple.com>
 
         [LFC][IFC] Border should be considered as non-breakable space

Added: trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change-expected.txt (0 => 238429)


--- trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change-expected.txt	2018-11-21 21:33:48 UTC (rev 238429)
@@ -0,0 +1,4 @@
+This tests observing the character data change by the HTML parser.
+
+PASS
+ab

Added: trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change.html (0 => 238429)


--- trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MutationObserver/observe-parser-character-data-change.html	2018-11-21 21:33:48 UTC (rev 238429)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This tests observing the character data change by the HTML parser.</p>
+<pre id="log"></pre>
+<div id="parent"><script>
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+const log = document.getElementById('log');
+
+document.write('a');
+let observer = new MutationObserver((mutations) => {
+    let result = 'PASS';
+    if (mutations.length != 1)
+        result = `FAIL - expected 1 mutation record but got ${mutations.length}`;
+    else if (mutations[0].type != 'characterData')
+        result = `FAIL - expected characterData mutation record but got ${mutations[0].type}`;
+    else if (mutations[0].oldValue != 'a')
+        result = `FAIL - expected oldValue to be "a" but got "${mutations[0].oldValue}"`;
+    log.textContent = result;
+});
+observer.observe(document.getElementById('parent'), {childList: true, subtree: true, characterData: true, characterDataOldValue: true});
+document.write('b');
+
+function fail() {
+    if (!log.textContent)
+        log.textContent = 'FAIL - did not receive a mutation record in time';
+}
+
+Promise.resolve().then(fail);
+window._onload_ = () => fail;
+
+</script></div>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (238428 => 238429)


--- trunk/Source/WebCore/ChangeLog	2018-11-21 19:10:49 UTC (rev 238428)
+++ trunk/Source/WebCore/ChangeLog	2018-11-21 21:33:48 UTC (rev 238429)
@@ -1,3 +1,17 @@
+2018-11-20  Ryosuke Niwa  <rn...@webkit.org>
+
+        Mutation observers doesn't get notified of character data mutation made by the parser
+        https://bugs.webkit.org/show_bug.cgi?id=191874
+
+        Reviewed by Antti Koivisto.
+
+        Fixed the bug that CharacterData::parserAppendData was never notifying MutationObserver.
+
+        Test: fast/dom/MutationObserver/observe-parser-character-data-change.html
+
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::parserAppendData):
+
 2018-11-21  Claudio Saavedra  <csaave...@igalia.com>
 
         [SOUP] Follow-up robustness improvements to the certificate decoder

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (238428 => 238429)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2018-11-21 19:10:49 UTC (rev 238428)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2018-11-21 21:33:48 UTC (rev 238429)
@@ -96,6 +96,7 @@
     if (!characterLengthLimit)
         return 0;
 
+    String oldData = m_data;
     if (string.is8Bit())
         m_data.append(string.characters8() + offset, characterLengthLimit);
     else
@@ -107,6 +108,10 @@
 
     notifyParentAfterChange(ContainerNode::ChildChangeSource::Parser);
 
+    auto mutationRecipients = MutationObserverInterestGroup::createForCharacterDataMutation(*this);
+    if (UNLIKELY(mutationRecipients))
+        mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacterData(*this, oldData));
+
     return characterLengthLimit;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to