Title: [109058] trunk
Revision
109058
Author
ad...@chromium.org
Date
2012-02-27 18:34:20 -0800 (Mon, 27 Feb 2012)

Log Message

[MutationObservers] Clear pending mutation records on disconnect()
https://bugs.webkit.org/show_bug.cgi?id=78639

Reviewed by Ojan Vafai.

Source/WebCore:

Test: fast/mutation/disconnect-cancel-pending.html

* dom/WebKitMutationObserver.cpp:
(WebCore::WebKitMutationObserver::disconnect): Clear pending records.
(WebCore::WebKitMutationObserver::deliver): Avoid calling the callback if no records are pending delivery.

LayoutTests:

* fast/mutation/disconnect-cancel-pending-expected.txt: Added.
* fast/mutation/disconnect-cancel-pending.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (109057 => 109058)


--- trunk/LayoutTests/ChangeLog	2012-02-28 02:14:37 UTC (rev 109057)
+++ trunk/LayoutTests/ChangeLog	2012-02-28 02:34:20 UTC (rev 109058)
@@ -1,3 +1,13 @@
+2012-02-27  Adam Klein  <ad...@chromium.org>
+
+        [MutationObservers] Clear pending mutation records on disconnect()
+        https://bugs.webkit.org/show_bug.cgi?id=78639
+
+        Reviewed by Ojan Vafai.
+
+        * fast/mutation/disconnect-cancel-pending-expected.txt: Added.
+        * fast/mutation/disconnect-cancel-pending.html: Added.
+
 2012-02-27  Brady Eidson  <beid...@apple.com>
 
         <rdar://problem/10924993> and https://bugs.webkit.org/show_bug.cgi?id=79725

Added: trunk/LayoutTests/fast/mutation/disconnect-cancel-pending-expected.txt (0 => 109058)


--- trunk/LayoutTests/fast/mutation/disconnect-cancel-pending-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/disconnect-cancel-pending-expected.txt	2012-02-28 02:34:20 UTC (rev 109058)
@@ -0,0 +1,14 @@
+Test that WebKitMutationObserver.disconnect cancels pending delivery
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Disconnecting should cancel any pending delivery...
+PASS mutations is null
+...and re-observing should not see any of the previously-generated records.
+PASS mutations.length is 1
+PASS mutations[0].attributeName is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/mutation/disconnect-cancel-pending.html (0 => 109058)


--- trunk/LayoutTests/fast/mutation/disconnect-cancel-pending.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/disconnect-cancel-pending.html	2012-02-28 02:34:20 UTC (rev 109058)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<script src=""
+<script>
+description('Test that WebKitMutationObserver.disconnect cancels pending delivery');
+
+window.jsTestIsAsync = true;
+var mutations;
+var observer;
+
+function start() {
+    mutations = null;
+    div = document.createElement('div');
+
+    observer = new WebKitMutationObserver(function(m) {
+        mutations = m;
+    });
+
+    observer.observe(div, { attributes: true });
+    div.setAttribute('foo', 'bar');
+    observer.disconnect();
+    setTimeout(next, 0);
+}
+
+function next() {
+    debug('Disconnecting should cancel any pending delivery...');
+    shouldBeNull('mutations');
+    observer.observe(div, { attributes: true });
+    div.setAttribute('bar', 'baz');
+    setTimeout(finish, 0);
+}
+
+function finish() {
+    debug('...and re-observing should not see any of the previously-generated records.');
+    shouldBe('mutations.length', '1');
+    shouldBe('mutations[0].attributeName', '"bar"');
+    finishJSTest();
+}
+
+if (!window.WebKitMutationObserver)
+    testFailed('This test requires ENABLE(MUTATION_OBSERVERS)');
+else
+    start();
+
+</script>
+<script src=""

Modified: trunk/Source/WebCore/ChangeLog (109057 => 109058)


--- trunk/Source/WebCore/ChangeLog	2012-02-28 02:14:37 UTC (rev 109057)
+++ trunk/Source/WebCore/ChangeLog	2012-02-28 02:34:20 UTC (rev 109058)
@@ -1,5 +1,18 @@
 2012-02-27  Adam Klein  <ad...@chromium.org>
 
+        [MutationObservers] Clear pending mutation records on disconnect()
+        https://bugs.webkit.org/show_bug.cgi?id=78639
+
+        Reviewed by Ojan Vafai.
+
+        Test: fast/mutation/disconnect-cancel-pending.html
+
+        * dom/WebKitMutationObserver.cpp:
+        (WebCore::WebKitMutationObserver::disconnect): Clear pending records.
+        (WebCore::WebKitMutationObserver::deliver): Avoid calling the callback if no records are pending delivery.
+
+2012-02-27  Adam Klein  <ad...@chromium.org>
+
         Always notify subtree of removal in ContainerNode::removeChildren
         https://bugs.webkit.org/show_bug.cgi?id=79316
 

Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.cpp (109057 => 109058)


--- trunk/Source/WebCore/dom/WebKitMutationObserver.cpp	2012-02-28 02:14:37 UTC (rev 109057)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.cpp	2012-02-28 02:34:20 UTC (rev 109058)
@@ -89,6 +89,7 @@
 
 void WebKitMutationObserver::disconnect()
 {
+    m_records.clear();
     HashSet<MutationObserverRegistration*> registrations(m_registrations);
     for (HashSet<MutationObserverRegistration*>::iterator iter = registrations.begin(); iter != registrations.end(); ++iter)
         (*iter)->unregister();
@@ -123,6 +124,9 @@
 
 void WebKitMutationObserver::deliver()
 {
+    if (m_records.isEmpty())
+        return;
+
     MutationRecordArray records;
     records.swap(m_records);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to