diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp b/chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp index e2d5fec85cb..06e610a33f4 100644 --- a/chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp +++ b/chromium/third_party/WebKit/Source/core/dom/MutationObserver.cpp @@ -40,9 +40,7 @@ #include "core/dom/MutationObserverRegistration.h" #include "core/dom/MutationRecord.h" #include "core/dom/Node.h" -#include "wtf/HashSet.h" #include "wtf/MainThread.h" -#include "wtf/Vector.h" namespace WebCore { @@ -55,13 +53,13 @@ struct MutationObserver::ObserverLessThan { } }; -PassRefPtr<MutationObserver> MutationObserver::create(PassRefPtr<MutationCallback> callback) +PassRefPtr<MutationObserver> MutationObserver::create(PassOwnPtr<MutationCallback> callback) { ASSERT(isMainThread()); return adoptRef(new MutationObserver(callback)); } -MutationObserver::MutationObserver(PassRefPtr<MutationCallback> callback) +MutationObserver::MutationObserver(PassOwnPtr<MutationCallback> callback) : m_callback(callback) , m_priority(s_observerPriority++) { @@ -73,45 +71,65 @@ MutationObserver::~MutationObserver() ASSERT(m_registrations.isEmpty()); } -bool MutationObserver::validateOptions(MutationObserverOptions options) -{ - return (options & (Attributes | CharacterData | ChildList)) - && ((options & Attributes) || !(options & AttributeOldValue)) - && ((options & Attributes) || !(options & AttributeFilter)) - && ((options & CharacterData) || !(options & CharacterDataOldValue)); -} - -void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionState& es) +void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionState& exceptionState) { if (!node) { - es.throwDOMException(NotFoundError); + exceptionState.throwDOMException(NotFoundError, "The provided node was null."); return; } - static const struct { - const char* name; - MutationObserverOptions value; - } booleanOptions[] = { - { "childList", ChildList }, - { "attributes", Attributes }, - { "characterData", CharacterData }, - { "subtree", Subtree }, - { "attributeOldValue", AttributeOldValue }, - { "characterDataOldValue", CharacterDataOldValue } - }; MutationObserverOptions options = 0; - 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; - } + + bool attributeOldValue = false; + bool attributeOldValuePresent = optionsDictionary.get("attributeOldValue", attributeOldValue); + if (attributeOldValue) + options |= AttributeOldValue; HashSet<AtomicString> attributeFilter; - if (optionsDictionary.get("attributeFilter", attributeFilter)) + bool attributeFilterPresent = optionsDictionary.get("attributeFilter", attributeFilter); + if (attributeFilterPresent) options |= AttributeFilter; - if (!validateOptions(options)) { - es.throwDOMException(SyntaxError); + bool attributes = false; + bool attributesPresent = optionsDictionary.get("attributes", attributes); + if (attributes || (!attributesPresent && (attributeOldValuePresent || attributeFilterPresent))) + options |= Attributes; + + bool characterDataOldValue = false; + bool characterDataOldValuePresent = optionsDictionary.get("characterDataOldValue", characterDataOldValue); + if (characterDataOldValue) + options |= CharacterDataOldValue; + + bool characterData = false; + bool characterDataPresent = optionsDictionary.get("characterData", characterData); + if (characterData || (!characterDataPresent && characterDataOldValuePresent)) + options |= CharacterData; + + bool childListValue = false; + if (optionsDictionary.get("childList", childListValue) && childListValue) + options |= ChildList; + + bool subtreeValue = false; + if (optionsDictionary.get("subtree", subtreeValue) && subtreeValue) + options |= Subtree; + + if (!(options & Attributes)) { + if (options & AttributeOldValue) { + exceptionState.throwDOMException(TypeError, "The options object may only set 'attributeOldValue' to true when 'attributes' is true or not present."); + return; + } + if (options & AttributeFilter) { + exceptionState.throwDOMException(TypeError, "The options object may only set 'attributeFilter' when 'attributes' is true or not present."); + return; + } + } + if (!((options & CharacterData) || !(options & CharacterDataOldValue))) { + exceptionState.throwDOMException(TypeError, "The options object may only set 'characterDataOldValue' to true when 'characterData' is true or not present."); + return; + } + + if (!(options & (Attributes | CharacterData | ChildList))) { + exceptionState.throwDOMException(TypeError, "The options object must set at least one of 'attributes', 'characterData', or 'childList' to true."); return; } @@ -182,7 +200,7 @@ HashSet<Node*> MutationObserver::getObservedNodes() const bool MutationObserver::canDeliver() { - return !m_callback->scriptExecutionContext()->activeDOMObjectsAreSuspended(); + return !m_callback->executionContext()->activeDOMObjectsAreSuspended(); } void MutationObserver::deliver() |