Diff
Modified: trunk/Source/WebCore/ChangeLog (120899 => 120900)
--- trunk/Source/WebCore/ChangeLog 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/ChangeLog 2012-06-21 04:18:51 UTC (rev 120900)
@@ -1,3 +1,25 @@
+2012-06-20 Adam Klein <[email protected]>
+
+ Use Dictionary in MutationObserver.observe to kill custom code
+ https://bugs.webkit.org/show_bug.cgi?id=89629
+
+ Reviewed by Ryosuke Niwa.
+
+ Move code for dictionary parsing in MutationObserver.observe
+ that used to be duplicated (with different implementations)
+ in JSC and V8 bindings into WebKitMutationObserver.cpp, using
+ the new Dictionary interface.
+
+ No new tests, no change in behavior.
+
+ * bindings/js/JSWebKitMutationObserverCustom.cpp:
+ * bindings/v8/custom/V8WebKitMutationObserverCustom.cpp:
+ * dom/WebKitMutationObserver.cpp:
+ (WebCore::WebKitMutationObserver::observe):
+ * dom/WebKitMutationObserver.h:
+ (WebCore):
+ * dom/WebKitMutationObserver.idl:
+
2012-06-20 Sheriff Bot <[email protected]>
Unreviewed, rolling out r120889.
Modified: trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp (120899 => 120900)
--- trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp 2012-06-21 04:18:51 UTC (rev 120900)
@@ -34,15 +34,9 @@
#include "JSWebKitMutationObserver.h"
-#include "ExceptionCode.h"
-#include "JSDictionary.h"
#include "JSMutationCallback.h"
-#include "JSNode.h"
-#include "Node.h"
#include "WebKitMutationObserver.h"
#include <runtime/Error.h>
-#include <wtf/HashSet.h>
-#include <wtf/text/AtomicString.h>
using namespace JSC;
@@ -64,59 +58,6 @@
return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), WebKitMutationObserver::create(callback.release()))));
}
-struct BooleanOption {
- const char* name;
- MutationObserverOptions value;
-};
-
-static const BooleanOption booleanOptions[] = {
- { "childList", WebKitMutationObserver::ChildList },
- { "attributes", WebKitMutationObserver::Attributes },
- { "characterData", WebKitMutationObserver::CharacterData },
- { "subtree", WebKitMutationObserver::Subtree },
- { "attributeOldValue", WebKitMutationObserver::AttributeOldValue },
- { "characterDataOldValue", WebKitMutationObserver::CharacterDataOldValue }
-};
-
-static const size_t numBooleanOptions = sizeof(booleanOptions) / sizeof(BooleanOption);
-
-JSValue JSWebKitMutationObserver::observe(ExecState* exec)
-{
- if (exec->argumentCount() < 2)
- return throwError(exec, createNotEnoughArgumentsError(exec));
- Node* target = toNode(exec->argument(0));
- if (exec->hadException())
- return jsUndefined();
-
- JSObject* optionsObject = exec->argument(1).getObject();
- if (!optionsObject) {
- setDOMException(exec, TYPE_MISMATCH_ERR);
- return jsUndefined();
- }
-
- JSDictionary dictionary(exec, optionsObject);
- MutationObserverOptions options = 0;
- for (unsigned i = 0; i < numBooleanOptions; ++i) {
- bool option = false;
- if (!dictionary.tryGetProperty(booleanOptions[i].name, option))
- return jsUndefined();
- if (option)
- options |= booleanOptions[i].value;
- }
-
- HashSet<AtomicString> attributeFilter;
- if (!dictionary.tryGetProperty("attributeFilter", attributeFilter))
- return jsUndefined();
- if (!attributeFilter.isEmpty())
- options |= WebKitMutationObserver::AttributeFilter;
-
- ExceptionCode ec = 0;
- impl()->observe(target, options, attributeFilter, ec);
- if (ec)
- setDOMException(exec, ec);
- return jsUndefined();
-}
-
} // namespace WebCore
#endif // ENABLE(MUTATION_OBSERVERS)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp (120899 => 120900)
--- trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp 2012-06-21 04:18:51 UTC (rev 120900)
@@ -34,20 +34,14 @@
#include "V8WebKitMutationObserver.h"
-#include "Dictionary.h"
-#include "ExceptionCode.h"
#include "V8Binding.h"
#include "V8BindingMacros.h"
#include "V8DOMWrapper.h"
#include "V8MutationCallback.h"
-#include "V8Node.h"
#include "V8Proxy.h"
#include "V8Utilities.h"
#include "WebKitMutationObserver.h"
-#include <wtf/HashSet.h>
-#include <wtf/text/AtomicString.h>
-
namespace WebCore {
v8::Handle<v8::Value> V8WebKitMutationObserver::constructorCallback(const v8::Arguments& args)
@@ -79,43 +73,6 @@
return args.Holder();
}
-v8::Handle<v8::Value> V8WebKitMutationObserver::observeCallback(const v8::Arguments& args)
-{
- INC_STATS("DOM.WebKitMutationObserver.observe");
- if (args.Length() < 2)
- return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
- WebKitMutationObserver* imp = V8WebKitMutationObserver::toNative(args.Holder());
- EXCEPTION_BLOCK(Node*, target, V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0);
-
- if (!args[1]->IsObject())
- return throwError(TYPE_MISMATCH_ERR, args.GetIsolate());
-
- Dictionary optionsObject(args[1]);
- unsigned options = 0;
- HashSet<AtomicString> attributeFilter;
- bool option;
- if (optionsObject.get("childList", option) && option)
- options |= WebKitMutationObserver::ChildList;
- if (optionsObject.get("attributes", option) && option)
- options |= WebKitMutationObserver::Attributes;
- if (optionsObject.get("attributeFilter", attributeFilter))
- options |= WebKitMutationObserver::AttributeFilter;
- if (optionsObject.get("characterData", option) && option)
- options |= WebKitMutationObserver::CharacterData;
- if (optionsObject.get("subtree", option) && option)
- options |= WebKitMutationObserver::Subtree;
- if (optionsObject.get("attributeOldValue", option) && option)
- options |= WebKitMutationObserver::AttributeOldValue;
- if (optionsObject.get("characterDataOldValue", option) && option)
- options |= WebKitMutationObserver::CharacterDataOldValue;
-
- ExceptionCode ec = 0;
- imp->observe(target, options, attributeFilter, ec);
- if (ec)
- return V8Proxy::setDOMException(ec, args.GetIsolate());
- return v8::Handle<v8::Value>();
-}
-
} // namespace WebCore
#endif // ENABLE(MUTATION_OBSERVERS)
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.cpp (120899 => 120900)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.cpp 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.cpp 2012-06-21 04:18:51 UTC (rev 120900)
@@ -34,6 +34,7 @@
#include "WebKitMutationObserver.h"
+#include "Dictionary.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "MutationCallback.h"
@@ -81,15 +82,41 @@
&& ((options & CharacterData) || !(options & CharacterDataOldValue));
}
-void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options, const HashSet<AtomicString>& attributeFilter, ExceptionCode& ec)
+void WebKitMutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionCode& ec)
{
if (!node) {
ec = NOT_FOUND_ERR;
return;
}
+ if (optionsDictionary.isUndefinedOrNull()) {
+ ec = TYPE_MISMATCH_ERR;
+ return;
+ }
+
+ static const struct {
+ const char* name;
+ MutationObserverOptions value;
+ } booleanOptions[] = {
+ { "childList", WebKitMutationObserver::ChildList },
+ { "attributes", WebKitMutationObserver::Attributes },
+ { "characterData", WebKitMutationObserver::CharacterData },
+ { "subtree", WebKitMutationObserver::Subtree },
+ { "attributeOldValue", WebKitMutationObserver::AttributeOldValue },
+ { "characterDataOldValue", WebKitMutationObserver::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;
+ }
+
+ HashSet<AtomicString> attributeFilter;
+ if (optionsDictionary.get("attributeFilter", attributeFilter))
+ options |= WebKitMutationObserver::AttributeFilter;
+
if (!validateOptions(options)) {
- // FIXME: Revisit this once the spec specifies the exception type; SYNTAX_ERR may not be appropriate.
ec = SYNTAX_ERR;
return;
}
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.h (120899 => 120900)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.h 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.h 2012-06-21 04:18:51 UTC (rev 120900)
@@ -43,6 +43,7 @@
namespace WebCore {
+class Dictionary;
class MutationCallback;
class MutationObserverRegistration;
class MutationRecord;
@@ -78,7 +79,7 @@
~WebKitMutationObserver();
- void observe(Node*, MutationObserverOptions, const HashSet<AtomicString>& attributeFilter, ExceptionCode&);
+ void observe(Node*, const Dictionary&, ExceptionCode&);
Vector<RefPtr<MutationRecord> > takeRecords();
void disconnect();
void observationStarted(MutationObserverRegistration*);
Modified: trunk/Source/WebCore/dom/WebKitMutationObserver.idl (120899 => 120900)
--- trunk/Source/WebCore/dom/WebKitMutationObserver.idl 2012-06-21 02:03:44 UTC (rev 120899)
+++ trunk/Source/WebCore/dom/WebKitMutationObserver.idl 2012-06-21 04:18:51 UTC (rev 120900)
@@ -34,7 +34,7 @@
CustomConstructor,
ConstructorParameters=1
] WebKitMutationObserver {
- [Custom] void observe(in Node target, in MutationObserverOptions options)
+ void observe(in Node target, in Dictionary options)
raises(DOMException);
sequence<MutationRecord> takeRecords();
void disconnect();