Diff
Modified: trunk/LayoutTests/ChangeLog (99610 => 99611)
--- trunk/LayoutTests/ChangeLog 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/LayoutTests/ChangeLog 2011-11-08 20:59:47 UTC (rev 99611)
@@ -1,3 +1,13 @@
+2011-11-08 Adam Klein <ad...@chromium.org>
+
+ WebKitMutationObserver.observe should raise a DOMException if passed invalid arguments
+ https://bugs.webkit.org/show_bug.cgi?id=71596
+
+ Reviewed by Ryosuke Niwa.
+
+ * fast/mutation/observe-exceptions-expected.txt:
+ * fast/mutation/observe-exceptions.html:
+
2011-11-08 Joshua Bell <jsb...@chromium.org>
IndexedDB: implement compound (array) key support
Modified: trunk/LayoutTests/fast/mutation/observe-exceptions-expected.txt (99610 => 99611)
--- trunk/LayoutTests/fast/mutation/observe-exceptions-expected.txt 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/LayoutTests/fast/mutation/observe-exceptions-expected.txt 2011-11-08 20:59:47 UTC (rev 99611)
@@ -9,6 +9,11 @@
PASS observer.observe(document.body) threw exception TypeError: Not enough arguments.
PASS observer.observe(document.body, null) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
PASS observer.observe(document.body, undefined) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
+PASS observer.observe(null, {attributes: true}) threw exception Error: NOT_FOUND_ERR: DOM Exception 8.
+PASS observer.observe(undefined, {attributes: true}) threw exception Error: NOT_FOUND_ERR: DOM Exception 8.
+PASS observer.observe(document.body, {subtree: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS observer.observe(document.body, {childList: true, attributeOldValue: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS observer.observe(document.body, {attributes: true, characterDataOldValue: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/mutation/observe-exceptions.html (99610 => 99611)
--- trunk/LayoutTests/fast/mutation/observe-exceptions.html 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/LayoutTests/fast/mutation/observe-exceptions.html 2011-11-08 20:59:47 UTC (rev 99611)
@@ -18,6 +18,13 @@
shouldThrow('observer.observe(document.body)');
shouldThrow('observer.observe(document.body, null)');
shouldThrow('observer.observe(document.body, undefined)');
+ 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})');
+ // FIXME: Uncomment the below when attributeFilter is supported.
+ //shouldThrow('observer.observe(document.body, {characterData: true, attributeFilter: ["id"]})');
}
description('Test that WebKitMutationObserver.observe throws exceptions appropriately');
Modified: trunk/Source/WebCore/ChangeLog (99610 => 99611)
--- trunk/Source/WebCore/ChangeLog 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/ChangeLog 2011-11-08 20:59:47 UTC (rev 99611)
@@ -1,3 +1,25 @@
+2011-11-08 Adam Klein <ad...@chromium.org>
+
+ WebKitMutationObserver.observe should raise a DOMException if passed invalid arguments
+ https://bugs.webkit.org/show_bug.cgi?id=71596
+
+ Reviewed by Ryosuke Niwa.
+
+ Adds two cases where WebKitMutationObserver.observe throws an exception:
+ - When passed a null Node*.
+ - When passed options that don't make sense, e.g.,
+ 'attributeOldValue' but not 'attributes'.
+
+ * bindings/js/JSWebKitMutationObserverCustom.cpp:
+ (WebCore::JSWebKitMutationObserver::observe):
+ * bindings/v8/custom/V8WebKitMutationObserverCustom.cpp:
+ (WebCore::V8WebKitMutationObserver::observeCallback):
+ * dom/WebKitMutationObserver.cpp:
+ (WebCore::WebKitMutationObserver::validateOptions):
+ (WebCore::WebKitMutationObserver::observe):
+ * dom/WebKitMutationObserver.h:
+ * dom/WebKitMutationObserver.idl:
+
2011-11-08 Joshua Bell <jsb...@chromium.org>
IndexedDB: implement compound (array) key support
Modified: trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp (99610 => 99611)
--- trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp 2011-11-08 20:59:47 UTC (rev 99611)
@@ -93,7 +93,10 @@
if (exec->hadException())
return jsUndefined();
- impl()->observe(target, options);
+ ExceptionCode ec = 0;
+ impl()->observe(target, options, ec);
+ if (ec)
+ setDOMException(exec, ec);
return jsUndefined();
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp (99610 => 99611)
--- trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp 2011-11-08 20:59:47 UTC (rev 99611)
@@ -103,7 +103,10 @@
if (optionsObject.get("characterDataOldValue", option) && option)
options |= WebKitMutationObserver::CharacterDataOldValue;
- imp->observe(target, options);
+ ExceptionCode ec = 0;
+ imp->observe(target, options, ec);
+ if (ec)
+ V8Proxy::setDOMException(ec);
return v8::Handle<v8::Value>();
}
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.cpp (99610 => 99611)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.cpp 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.cpp 2011-11-08 20:59:47 UTC (rev 99611)
@@ -35,6 +35,7 @@
#include "WebKitMutationObserver.h"
#include "Document.h"
+#include "ExceptionCode.h"
#include "MutationCallback.h"
#include "MutationObserverRegistration.h"
#include "MutationRecord.h"
@@ -58,8 +59,28 @@
ASSERT(m_registrations.isEmpty());
}
-void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options)
+bool WebKitMutationObserver::validateOptions(MutationObserverOptions options)
{
+ return (options & (Attributes | CharacterData | ChildList))
+ && ((options & Attributes) || !(options & AttributeOldValue))
+ // FIXME: Uncomment the line below once attributeFilter is supported.
+ // && ((options & Attributes) || !(options & AttributeFilter))
+ && ((options & CharacterData) || !(options & CharacterDataOldValue));
+}
+
+void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options, ExceptionCode& ec)
+{
+ if (!node) {
+ ec = NOT_FOUND_ERR;
+ return;
+ }
+
+ if (!validateOptions(options)) {
+ // FIXME: Revisit this once the spec specifies the exception type; SYNTAX_ERR may not be appropriate.
+ ec = SYNTAX_ERR;
+ return;
+ }
+
MutationObserverRegistration* registration = node->registerMutationObserver(this);
registration->resetObservation(options);
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.h (99610 => 99611)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.h 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.h 2011-11-08 20:59:47 UTC (rev 99611)
@@ -33,6 +33,7 @@
#if ENABLE(MUTATION_OBSERVERS)
+#include "ExceptionCode.h"
#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
@@ -75,7 +76,7 @@
~WebKitMutationObserver();
- void observe(Node*, MutationObserverOptions);
+ void observe(Node*, MutationObserverOptions, ExceptionCode&);
void disconnect();
void observationStarted(MutationObserverRegistration*);
void observationEnded(MutationObserverRegistration*);
@@ -85,6 +86,8 @@
WebKitMutationObserver(PassRefPtr<MutationCallback>);
void deliver();
+ static bool validateOptions(MutationObserverOptions);
+
RefPtr<MutationCallback> m_callback;
Vector<RefPtr<MutationRecord> > m_records;
HashSet<MutationObserverRegistration*> m_registrations;
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.idl (99610 => 99611)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.idl 2011-11-08 20:53:55 UTC (rev 99610)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.idl 2011-11-08 20:59:47 UTC (rev 99611)
@@ -34,7 +34,8 @@
CanBeConstructed,
CustomConstructor
] WebKitMutationObserver {
- [Custom] void observe(in Node target, in MutationObserverOptions options);
+ [Custom] void observe(in Node target, in MutationObserverOptions options)
+ raises(DOMException);
void disconnect();
};
}