Title: [113279] trunk
Revision
113279
Author
[email protected]
Date
2012-04-04 19:50:25 -0700 (Wed, 04 Apr 2012)

Log Message

[MutationObservers] implement takeRecords()
https://bugs.webkit.org/show_bug.cgi?id=83218

Reviewed by Ojan Vafai.

Source/WebCore:

This patch implements MutationObserver.takeRecords per the DOM4 spec.
takeRecords retrieves and clears any pending mutation records for
the observer.

Test: fast/mutation/takeRecords.html

* dom/WebKitMutationObserver.cpp:
(WebCore::WebKitMutationObserver::takeRecords):
(WebCore):
(WebCore::WebKitMutationObserver::deliver):
* dom/WebKitMutationObserver.h:
* dom/WebKitMutationObserver.idl:

LayoutTests:

* fast/mutation/takeRecords-expected.txt: Added.
* fast/mutation/takeRecords.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113278 => 113279)


--- trunk/LayoutTests/ChangeLog	2012-04-05 02:42:57 UTC (rev 113278)
+++ trunk/LayoutTests/ChangeLog	2012-04-05 02:50:25 UTC (rev 113279)
@@ -1,3 +1,13 @@
+2012-04-04  Rafael Weinstein  <[email protected]>
+
+        [MutationObservers] implement takeRecords()
+        https://bugs.webkit.org/show_bug.cgi?id=83218
+
+        Reviewed by Ojan Vafai.
+
+        * fast/mutation/takeRecords-expected.txt: Added.
+        * fast/mutation/takeRecords.html: Added.
+
 2012-04-04  Abhishek Arya  <[email protected]>
 
         Rebaseline for r113252.

Added: trunk/LayoutTests/fast/mutation/takeRecords-expected.txt (0 => 113279)


--- trunk/LayoutTests/fast/mutation/takeRecords-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/takeRecords-expected.txt	2012-04-05 02:50:25 UTC (rev 113279)
@@ -0,0 +1,24 @@
+Testing WebKitMutationObserver.takeRecords
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing takeRecords.
+...records are taken synchronously.
+PASS mutations.length is 2
+PASS mutations[0].type is "attributes"
+PASS mutations[0].target is subDiv
+PASS mutations[0].attributeName is "foo"
+PASS mutations[0].attributeNamespace is null
+PASS mutations[1].type is "characterData"
+PASS mutations[1].target is subDiv.firstChild
+...takeRecord took records, but did not clear transient observers
+PASS mutations.length is 1
+PASS mutations[0].type is "attributes"
+PASS mutations[0].target is subDiv
+PASS mutations[0].attributeName is "foo"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/mutation/takeRecords.html (0 => 113279)


--- trunk/LayoutTests/fast/mutation/takeRecords.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/takeRecords.html	2012-04-05 02:50:25 UTC (rev 113279)
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<title></title>
+</head>
+<body>
+<p id=description></p>
+<div id="console"></div>
+<script>
+
+window.jsTestIsAsync = true;
+var mutations;
+
+function testBasic() {
+    var observer;
+
+    function start() {
+        debug('Testing takeRecords.');
+
+        mutations = null;
+        div = document.createElement('div');
+        subDiv = div.appendChild(document.createElement('div'));
+        subDiv.innerHTML = 'hello, world';
+        observer = new WebKitMutationObserver(function(mutations) {
+            window.mutations = mutations;
+        });
+
+        observer.observe(div, {attributes: true, characterData: true, subtree: true});
+        subDiv.setAttribute('foo', 'bar');
+        subDiv.firstChild.textContent = 'goodbye!';
+        div.removeChild(subDiv);
+
+        mutations = observer.takeRecords();
+
+        debug('...records are taken synchronously.');
+
+        shouldBe('mutations.length', '2');
+        shouldBe('mutations[0].type', '"attributes"');
+        shouldBe('mutations[0].target', 'subDiv');
+        shouldBe('mutations[0].attributeName', '"foo"');
+        shouldBe('mutations[0].attributeNamespace', 'null');
+        shouldBe('mutations[1].type', '"characterData"');
+        shouldBe('mutations[1].target', 'subDiv.firstChild');
+
+        subDiv.setAttribute('foo', 'baz');
+        setTimeout(finish, 0);
+    }
+
+    function finish() {
+        debug('...takeRecord took records, but did not clear transient observers');
+
+        shouldBe('mutations.length', '1');
+        shouldBe('mutations[0].type', '"attributes"');
+        shouldBe('mutations[0].target', 'subDiv');
+        shouldBe('mutations[0].attributeName', '"foo"');
+        observer.disconnect();
+        debug('');
+        runNextTest();
+    }
+
+    start();
+}
+
+var tests = [testBasic];
+var testIndex = 0;
+
+function runNextTest() {
+    if (testIndex < tests.length)
+        tests[testIndex++]();
+    else
+        finishJSTest();
+}
+
+description('Testing WebKitMutationObserver.takeRecords');
+
+if (!window.WebKitMutationObserver)
+    testFailed('This test requires ENABLE(MUTATION_OBSERVERS)');
+else
+    runNextTest();
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (113278 => 113279)


--- trunk/Source/WebCore/ChangeLog	2012-04-05 02:42:57 UTC (rev 113278)
+++ trunk/Source/WebCore/ChangeLog	2012-04-05 02:50:25 UTC (rev 113279)
@@ -1,3 +1,23 @@
+2012-04-04  Rafael Weinstein  <[email protected]>
+
+        [MutationObservers] implement takeRecords()
+        https://bugs.webkit.org/show_bug.cgi?id=83218
+
+        Reviewed by Ojan Vafai.
+
+        This patch implements MutationObserver.takeRecords per the DOM4 spec.
+        takeRecords retrieves and clears any pending mutation records for
+        the observer.
+
+        Test: fast/mutation/takeRecords.html
+
+        * dom/WebKitMutationObserver.cpp:
+        (WebCore::WebKitMutationObserver::takeRecords):
+        (WebCore):
+        (WebCore::WebKitMutationObserver::deliver):
+        * dom/WebKitMutationObserver.h:
+        * dom/WebKitMutationObserver.idl:
+
 2012-04-04  Shinya Kawanaka  <[email protected]>
 
         Shadow DOM is exposed in JS.

Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.cpp (113278 => 113279)


--- trunk/Source/WebCore/dom/WebKitMutationObserver.cpp	2012-04-05 02:42:57 UTC (rev 113278)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.cpp	2012-04-05 02:50:25 UTC (rev 113279)
@@ -100,6 +100,13 @@
     node->document()->addMutationObserverTypes(registration->mutationTypes());
 }
 
+Vector<RefPtr<MutationRecord> > WebKitMutationObserver::takeRecords()
+{
+    Vector<RefPtr<MutationRecord> > records;
+    records.swap(m_records);
+    return records;
+}
+
 void WebKitMutationObserver::disconnect()
 {
     m_records.clear();
@@ -140,7 +147,7 @@
     if (m_records.isEmpty())
         return;
 
-    MutationRecordArray records;
+    Vector<RefPtr<MutationRecord> > records;
     records.swap(m_records);
 
     for (HashSet<MutationObserverRegistration*>::iterator iter = m_registrations.begin(); iter != m_registrations.end(); ++iter)

Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.h (113278 => 113279)


--- trunk/Source/WebCore/dom/WebKitMutationObserver.h	2012-04-05 02:42:57 UTC (rev 113278)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.h	2012-04-05 02:50:25 UTC (rev 113279)
@@ -79,6 +79,7 @@
     ~WebKitMutationObserver();
 
     void observe(Node*, MutationObserverOptions, const HashSet<AtomicString>& attributeFilter, ExceptionCode&);
+    Vector<RefPtr<MutationRecord> > takeRecords();
     void disconnect();
     void observationStarted(MutationObserverRegistration*);
     void observationEnded(MutationObserverRegistration*);

Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.idl (113278 => 113279)


--- trunk/Source/WebCore/dom/WebKitMutationObserver.idl	2012-04-05 02:42:57 UTC (rev 113278)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.idl	2012-04-05 02:50:25 UTC (rev 113279)
@@ -36,6 +36,7 @@
     ] WebKitMutationObserver {
         [Custom] void observe(in Node target, in MutationObserverOptions options)
             raises(DOMException);
+        sequence<MutationRecord> takeRecords();
         void disconnect();
     };
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to