Skip to content
Permalink
Browse files
MutationObserver should accept attributeFilter, attributeOldValue, an…
…d characterDataOldValue on their own

https://bugs.webkit.org/show_bug.cgi?id=148716

Reviewed by Chris Dumez.

Source/WebCore:

According to DOM4 [1], MutationObserver accepts characterDataOldValue, attributeOldValue and attributeFilter options
on their own when characterData and attributes options are omitted. It throws only when characterData and attributes
options are explicitly set to false.

Fixed our implementation accordingly. Existing tests as well as ones imported from W3C covers this.

[1] http://www.w3.org/TR/2015/WD-dom-20150618/#interface-mutationobserver

* dom/MutationObserver.cpp:
(WebCore::MutationObserver::observe):

LayoutTests:

Updated the expected results.

Also added test cases to make sure explicitly setting attributes and characterData options to false along
with attributeOldValue, attributeFilter, and characterDataOldValue would throw.

* fast/dom/MutationObserver/observe-exceptions-expected.txt:
* fast/dom/MutationObserver/observe-exceptions.html:
* http/tests/w3c/dom/nodes/MutationObserver-attributes-expected.txt:
* http/tests/w3c/dom/nodes/MutationObserver-characterData-expected.txt:


Canonical link: https://commits.webkit.org/166849@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rniwa committed Sep 3, 2015
1 parent 3011bc3 commit 19b46b013a7063dde62f1b146c6b1827062ae363
Showing 7 changed files with 60 additions and 12 deletions.
@@ -1,3 +1,20 @@
2015-09-02 Ryosuke Niwa <rniwa@webkit.org>

MutationObserver should accept attributeFilter, attributeOldValue, and characterDataOldValue on their own
https://bugs.webkit.org/show_bug.cgi?id=148716

Reviewed by Chris Dumez.

Updated the expected results.

Also added test cases to make sure explicitly setting attributes and characterData options to false along
with attributeOldValue, attributeFilter, and characterDataOldValue would throw.

* fast/dom/MutationObserver/observe-exceptions-expected.txt:
* fast/dom/MutationObserver/observe-exceptions.html:
* http/tests/w3c/dom/nodes/MutationObserver-attributes-expected.txt:
* http/tests/w3c/dom/nodes/MutationObserver-characterData-expected.txt:

2015-09-02 Ryosuke Niwa <rniwa@webkit.org>

Node.textContent = undefined should be equivalent to textContent = ""
@@ -12,9 +12,12 @@ PASS observer.observe(document.body, undefined) threw exception Error: SyntaxErr
PASS observer.observe(null, {attributes: true}) threw exception Error: NotFoundError: DOM Exception 8.
PASS observer.observe(undefined, {attributes: true}) threw exception Error: NotFoundError: DOM Exception 8.
PASS observer.observe(document.body, {subtree: true}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {childList: true, attributeOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {attributes: true, characterDataOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {characterData: true, attributeFilter: ["id"]}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {childList: true, attributeOldValue: true}) did not throw exception.
PASS observer.observe(document.body, {attributes: true, characterDataOldValue: true}) did not throw exception.
PASS observer.observe(document.body, {characterData: true, attributeFilter: ["id"]}) did not throw exception.
PASS observer.observe(document.body, {attributes: false, attributeOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {attributes: false, attributeFilter: ["id"]}) threw exception Error: SyntaxError: DOM Exception 12.
PASS observer.observe(document.body, {characterData: false, characterDataOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
PASS successfullyParsed is true

TEST COMPLETE
@@ -21,9 +21,13 @@
shouldThrow('observer.observe(null, {attributes: true})');
shouldThrow('observer.observe(undefined, {attributes: true})');
shouldThrow('observer.observe(document.body, {subtree: true})');
shouldThrow('observer.observe(document.body, {childList: true, attributeOldValue: true})');
shouldThrow('observer.observe(document.body, {attributes: true, characterDataOldValue: true})');
shouldThrow('observer.observe(document.body, {characterData: true, attributeFilter: ["id"]})');
shouldNotThrow('observer.observe(document.body, {childList: true, attributeOldValue: true})');
shouldNotThrow('observer.observe(document.body, {attributes: true, characterDataOldValue: true})');
shouldNotThrow('observer.observe(document.body, {characterData: true, attributeFilter: ["id"]})');

shouldThrow('observer.observe(document.body, {attributes: false, attributeOldValue: true})');
shouldThrow('observer.observe(document.body, {attributes: false, attributeFilter: ["id"]})');
shouldThrow('observer.observe(document.body, {characterData: false, characterDataOldValue: true})');
}

description('Test that WebKitMutationObserver.observe throws exceptions appropriately');
@@ -40,7 +40,7 @@ PASS attributes Element.removeAttributeNS: removal no mutation
PASS attributes Element.removeAttributeNS: prefixed attribute removal no mutation
PASS attributes/attributeFilter Element.id/Element.className: update mutation
PASS attributes/attributeFilter Element.id/Element.className: multiple filter update mutation
FAIL attributeOldValue alone Element.id: update mutation SyntaxError: DOM Exception 12
FAIL attributeFilter alone Element.id/Element.className: multiple filter update mutation SyntaxError: DOM Exception 12
PASS attributeOldValue alone Element.id: update mutation
PASS attributeFilter alone Element.id/Element.className: multiple filter update mutation
PASS childList false: no childList mutation

@@ -23,5 +23,5 @@ PASS Range (r80) is created
PASS characterData Range.extractContents: child and data removal mutation
PASS Range (r81) is created
PASS characterData Range.extractContents: child and data removal mutation (2)
FAIL characterData/characterDataOldValue alone Text.data: simple mutation SyntaxError: DOM Exception 12
PASS characterData/characterDataOldValue alone Text.data: simple mutation

@@ -1,3 +1,21 @@
2015-09-02 Ryosuke Niwa <rniwa@webkit.org>

MutationObserver should accept attributeFilter, attributeOldValue, and characterDataOldValue on their own
https://bugs.webkit.org/show_bug.cgi?id=148716

Reviewed by Chris Dumez.

According to DOM4 [1], MutationObserver accepts characterDataOldValue, attributeOldValue and attributeFilter options
on their own when characterData and attributes options are omitted. It throws only when characterData and attributes
options are explicitly set to false.

Fixed our implementation accordingly. Existing tests as well as ones imported from W3C covers this.

[1] http://www.w3.org/TR/2015/WD-dom-20150618/#interface-mutationobserver

* dom/MutationObserver.cpp:
(WebCore::MutationObserver::observe):

2015-09-02 Andreas Kling <akling@apple.com>

ScrollbarThemes should be returned by reference.
@@ -82,15 +82,13 @@ void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
MutationObserverOptions value;
} booleanOptions[] = {
{ "childList", ChildList },
{ "attributes", Attributes },
{ "characterData", CharacterData },
{ "subtree", Subtree },
{ "attributeOldValue", AttributeOldValue },
{ "characterDataOldValue", CharacterDataOldValue }
};
MutationObserverOptions options = 0;
bool value = false;
for (unsigned i = 0; i < sizeof(booleanOptions) / sizeof(booleanOptions[0]); ++i) {
bool value = false;
if (optionsDictionary.get(booleanOptions[i].name, value) && value)
options |= booleanOptions[i].value;
}
@@ -99,6 +97,14 @@ void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
if (optionsDictionary.get("attributeFilter", attributeFilter))
options |= AttributeFilter;

bool attributesOptionIsSet = optionsDictionary.get("attributes", value);
if ((attributesOptionIsSet && value) || (!attributesOptionIsSet && (options & (AttributeFilter | AttributeOldValue))))
options |= Attributes;

bool characterDataOptionIsSet = optionsDictionary.get("characterData", value);
if ((characterDataOptionIsSet && value) || (!characterDataOptionIsSet && (options & CharacterDataOldValue)))
options |= CharacterData;

if (!validateOptions(options)) {
ec = SYNTAX_ERR;
return;

0 comments on commit 19b46b0

Please sign in to comment.