Skip to content
Permalink
Browse files
[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.


Canonical link: https://commits.webkit.org/96820@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109058 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ajklein committed Feb 28, 2012
1 parent 3fb12a4 commit e07cfcc4b6432052c02cd3a6bc5ce584747b2fc7
Showing 5 changed files with 86 additions and 0 deletions.
@@ -1,3 +1,13 @@
2012-02-27 Adam Klein <adamk@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 <beidson@apple.com>

<rdar://problem/10924993> and https://bugs.webkit.org/show_bug.cgi?id=79725
@@ -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

@@ -0,0 +1,45 @@
<!DOCTYPE html>
<script src="../js/resources/js-test-pre.js"></script>
<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="../js/resources/js-test-post.js"></script>
@@ -1,3 +1,16 @@
2012-02-27 Adam Klein <adamk@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 <adamk@chromium.org>

Always notify subtree of removal in ContainerNode::removeChildren
@@ -89,6 +89,7 @@ void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options

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::enqueueMutationRecord(PassRefPtr<MutationRecord> mu

void WebKitMutationObserver::deliver()
{
if (m_records.isEmpty())
return;

MutationRecordArray records;
records.swap(m_records);

0 comments on commit e07cfcc

Please sign in to comment.