Title: [93762] trunk
Revision
93762
Author
[email protected]
Date
2011-08-24 23:58:33 -0700 (Wed, 24 Aug 2011)

Log Message

Implement an Event constructor.
https://bugs.webkit.org/show_bug.cgi?id=66756

Patch by Kentaro Hara <[email protected]> on 2011-08-24
Reviewed by Adam Barth.

The spec of the Event constructor is here:
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-constructor.
This patch added the Event constructor to EventConstructors.h using
_javascript_ implementation-independent macros. This patch also added the V8
implementation of these macros to V8EventConstructors.cpp.

Source/WebCore:

The bug 63878 has been implementing the Event constructors for JSC.
Our plan is to first implement all the Event constructors for V8
using EventConstructors.h proposed in the JSC patch, and then merge
the JSC patch with these V8 patches. In any case, we are going to split
the patches for V8 and those for JSC in order to avoid hard regression.

Test: fast/events/event-constructors.html

* WebCore.gypi: Added V8EventConstructors.cpp.
* WebCore.pro: Added V8EventConstructors.cpp.
* bindings/generic/EventConstructors.h: Added. The Event constructor. This is written using _javascript_ implementation-independent macros. The V8 implementation of these macros is written in bindings/v8/custom/V8EventConstructors.cpp.
* bindings/v8/OptionsObject.cpp:
(WebCore::OptionsObject::getKeyDouble): Returns the value of a given key of type double.
(WebCore::OptionsObject::getKey): Returns true whenever the given key is found, even if the value is null or undefined.
* bindings/v8/OptionsObject.h:
(WebCore::OptionsObject::getKeyValue): Returns the value of the given key. We need to overload getKeyValue() for all types required to EventConfiguration members.
* bindings/v8/custom/V8EventConstructors.cpp: Added. Implemented macros used in EventConstructors.h.
(WebCore::constructV8Event): The Event constructor.
* dom/Event.cpp:
(WebCore::EventConfiguration::EventConfiguration): A constructor of EventConfiguration.
(WebCore::Event::Event): A constructor of the Event class.
* dom/Event.h: Added EventConfiguration, which manages attributes of the Event class.
(WebCore::Event::create): A factory method of the Event class with EventConfiguration.
* dom/Event.idl: Added 'CanBeConstructed' and 'V8CustomConstructor'.

LayoutTests:

* fast/events/event-constructors-expected.txt: Added.
* fast/events/event-constructors.html: Added.
* platform/gtk/Skipped: Skipped event-constructors.html, since Event constructors are not yet implemented in JSC.
* platform/mac/Skipped: Ditto.
* platform/qt/Skipped: Ditto.
* platform/win/Skipped: Ditto.
* platform/wk2/Skipped: Ditto.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (93761 => 93762)


--- trunk/LayoutTests/ChangeLog	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/ChangeLog	2011-08-25 06:58:33 UTC (rev 93762)
@@ -1,5 +1,26 @@
 2011-08-24  Kentaro Hara  <[email protected]>
 
+        Implement an Event constructor.
+        https://bugs.webkit.org/show_bug.cgi?id=66756
+
+        Reviewed by Adam Barth.
+
+        The spec of the Event constructor is here:
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-constructor.
+        This patch added the Event constructor to EventConstructors.h using
+        _javascript_ implementation-independent macros. This patch also added the V8
+        implementation of these macros to V8EventConstructors.cpp.
+
+        * fast/events/event-constructors-expected.txt: Added.
+        * fast/events/event-constructors.html: Added.
+        * platform/gtk/Skipped: Skipped event-constructors.html, since Event constructors are not yet implemented in JSC.
+        * platform/mac/Skipped: Ditto.
+        * platform/qt/Skipped: Ditto.
+        * platform/win/Skipped: Ditto.
+        * platform/wk2/Skipped: Ditto.
+
+2011-08-24  Kentaro Hara  <[email protected]>
+
         Implement a keypath parser strictly following the specification
         https://bugs.webkit.org/show_bug.cgi?id=62288
 

Added: trunk/LayoutTests/fast/events/event-constructors-expected.txt (0 => 93762)


--- trunk/LayoutTests/fast/events/event-constructors-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/event-constructors-expected.txt	2011-08-25 06:58:33 UTC (rev 93762)
@@ -0,0 +1,21 @@
+This tests the constructors for all the event DOM classes that have them.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new Event() threw exception TypeError: Not enough arguments.
+PASS new Event(null).type is 'null'
+PASS new Event(undefined).type is 'undefined'
+PASS new Event('foo').type is 'foo'
+PASS new Event('foo', {}).type is 'foo'
+PASS new Event('foo', {'bubbles': false}).bubbles is false
+PASS new Event('foo', {'bubbles': true}).bubbles is true
+PASS new Event('foo', {'cancelable': false}).cancelable is false
+PASS new Event('foo', {'cancelable': true}).cancelable is true
+PASS new Event('foo', {'defaultPrevented': false}).defaultPrevented is false
+PASS new Event('foo', {'defaultPrevented': true}).defaultPrevented is true
+PASS new Event('foo', {'timeStamp': 1234}).timeStamp is 1234
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/fast/events/event-constructors-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/events/event-constructors.html (0 => 93762)


--- trunk/LayoutTests/fast/events/event-constructors.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/event-constructors.html	2011-08-25 06:58:33 UTC (rev 93762)
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("This tests the constructors for all the event DOM classes that have them.");
+
+shouldThrow("new Event()");
+shouldBe("new Event(null).type", "'null'");
+shouldBe("new Event(undefined).type", "'undefined'");
+shouldBe("new Event('foo').type", "'foo'");
+shouldBe("new Event('foo', {}).type", "'foo'");
+shouldBe("new Event('foo', {'bubbles': false}).bubbles", "false");
+shouldBe("new Event('foo', {'bubbles': true}).bubbles", "true");
+shouldBe("new Event('foo', {'cancelable': false}).cancelable", "false");
+shouldBe("new Event('foo', {'cancelable': true}).cancelable", "true");
+shouldBe("new Event('foo', {'defaultPrevented': false}).defaultPrevented", "false");
+shouldBe("new Event('foo', {'defaultPrevented': true}).defaultPrevented", "true");
+shouldBe("new Event('foo', {'timeStamp': 1234}).timeStamp", "1234");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/events/event-constructors.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/platform/gtk/Skipped (93761 => 93762)


--- trunk/LayoutTests/platform/gtk/Skipped	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/platform/gtk/Skipped	2011-08-25 06:58:33 UTC (rev 93762)
@@ -492,6 +492,10 @@
 fast/forms/select-script-onchange.html
 fast/html/tab-order.html
 
+# These tests require the implementation of Event constructors.
+# https://bugs.webkit.org/show_bug.cgi?id=63878
+fast/events/event-constructors.html
+
 # The box isn't empty after a test run with this test.
 # https://bugs.webkit.org/show_bug.cgi?id=53644
  editing/deleting/5408255.html

Modified: trunk/LayoutTests/platform/mac/Skipped (93761 => 93762)


--- trunk/LayoutTests/platform/mac/Skipped	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/platform/mac/Skipped	2011-08-25 06:58:33 UTC (rev 93762)
@@ -88,6 +88,10 @@
 # No button tracked
 fast/events/mouseover-button.html
 
+# These tests require the JSC implementation of Event constructors.
+# https://bugs.webkit.org/show_bug.cgi?id=63878
+fast/events/event-constructors.html
+
 # Skipped until https://bugs.webkit.org/show_bug.cgi?id=33923 is resolved.
 platform/mac/accessibility/change-notification-on-scroll.html
 

Modified: trunk/LayoutTests/platform/qt/Skipped (93761 => 93762)


--- trunk/LayoutTests/platform/qt/Skipped	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/platform/qt/Skipped	2011-08-25 06:58:33 UTC (rev 93762)
@@ -202,6 +202,10 @@
 # Font feature settings is not implemented.
 css3/font-feature-settings-rendering.html
 
+# These tests require the JSC implementation of Event constructors.
+# https://bugs.webkit.org/show_bug.cgi?id=63878
+fast/events/event-constructors.html
+
 # =========================================================================== #
 #       Drag and Drop Support in DRT.                                         #
 # =========================================================================== #

Modified: trunk/LayoutTests/platform/win/Skipped (93761 => 93762)


--- trunk/LayoutTests/platform/win/Skipped	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/platform/win/Skipped	2011-08-25 06:58:33 UTC (rev 93762)
@@ -148,6 +148,10 @@
 # No button tracked
 fast/events/mouseover-button.html
 
+# These tests require the JSC implementation of Event constructors.
+# https://bugs.webkit.org/show_bug.cgi?id=63878
+fast/events/event-constructors.html
+
 # The eqqivalent of option-tab doesn not exist in Boomer <rdar://problem/5137230>
 fast/events/frame-tab-focus.html
 fast/events/option-tab.html

Modified: trunk/LayoutTests/platform/wk2/Skipped (93761 => 93762)


--- trunk/LayoutTests/platform/wk2/Skipped	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/LayoutTests/platform/wk2/Skipped	2011-08-25 06:58:33 UTC (rev 93762)
@@ -1595,6 +1595,10 @@
 platform/mac/fast/text/rounding-hacks.html
 platform/mac/fast/text/rounding-hacks-expansion.html
 
+# These tests require the implementation of Event constructors.
+# https://bugs.webkit.org/show_bug.cgi?id=63878
+fast/events/event-constructors.html
+
 # Sometimes fails
 # http://webkit.org/b/58990
 editing/undo/undo-iframe-location-change.html

Modified: trunk/Source/WebCore/ChangeLog (93761 => 93762)


--- trunk/Source/WebCore/ChangeLog	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/ChangeLog	2011-08-25 06:58:33 UTC (rev 93762)
@@ -1,3 +1,41 @@
+2011-08-24  Kentaro Hara  <[email protected]>
+
+        Implement an Event constructor.
+        https://bugs.webkit.org/show_bug.cgi?id=66756
+
+        Reviewed by Adam Barth.
+
+        The spec of the Event constructor is here:
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-constructor.
+        This patch added the Event constructor to EventConstructors.h using
+        _javascript_ implementation-independent macros. This patch also added the V8
+        implementation of these macros to V8EventConstructors.cpp.
+
+        The bug 63878 has been implementing the Event constructors for JSC.
+        Our plan is to first implement all the Event constructors for V8
+        using EventConstructors.h proposed in the JSC patch, and then merge
+        the JSC patch with these V8 patches. In any case, we are going to split
+        the patches for V8 and those for JSC in order to avoid hard regression.
+
+        Test: fast/events/event-constructors.html
+
+        * WebCore.gypi: Added V8EventConstructors.cpp.
+        * WebCore.pro: Added V8EventConstructors.cpp.
+        * bindings/generic/EventConstructors.h: Added. The Event constructor. This is written using _javascript_ implementation-independent macros. The V8 implementation of these macros is written in bindings/v8/custom/V8EventConstructors.cpp.
+        * bindings/v8/OptionsObject.cpp:
+        (WebCore::OptionsObject::getKeyDouble): Returns the value of a given key of type double.
+        (WebCore::OptionsObject::getKey): Returns true whenever the given key is found, even if the value is null or undefined.
+        * bindings/v8/OptionsObject.h:
+        (WebCore::OptionsObject::getKeyValue): Returns the value of the given key. We need to overload getKeyValue() for all types required to EventConfiguration members.
+        * bindings/v8/custom/V8EventConstructors.cpp: Added. Implemented macros used in EventConstructors.h.
+        (WebCore::constructV8Event): The Event constructor.
+        * dom/Event.cpp:
+        (WebCore::EventConfiguration::EventConfiguration): A constructor of EventConfiguration.
+        (WebCore::Event::Event): A constructor of the Event class.
+        * dom/Event.h: Added EventConfiguration, which manages attributes of the Event class.
+        (WebCore::Event::create): A factory method of the Event class with EventConfiguration.
+        * dom/Event.idl: Added 'CanBeConstructed' and 'V8CustomConstructor'.
+
 2011-08-24  Philippe Normand  <[email protected]>
 
         [GTK] bump GStreamer requirement to 0.10.30

Modified: trunk/Source/WebCore/WebCore.gypi (93761 => 93762)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-25 06:58:33 UTC (rev 93762)
@@ -1729,6 +1729,7 @@
             'bindings/generic/BindingSecurity.h',
             'bindings/generic/BindingSecurityBase.cpp',
             'bindings/generic/BindingSecurityBase.h',
+            'bindings/generic/EventConstructors.h',
             'bindings/generic/GenericBinding.h',
             'bindings/generic/RuntimeEnabledFeatures.cpp',
             'bindings/generic/RuntimeEnabledFeatures.h',
@@ -2141,6 +2142,7 @@
             'bindings/v8/custom/V8ElementCustom.cpp',
             'bindings/v8/custom/V8EntryCustom.cpp',
             'bindings/v8/custom/V8EntrySyncCustom.cpp',
+            'bindings/v8/custom/V8EventConstructors.cpp',
             'bindings/v8/custom/V8EventCustom.cpp',
             'bindings/v8/custom/V8EventSourceConstructor.cpp',
             'bindings/v8/custom/V8FileReaderCustom.cpp',

Modified: trunk/Source/WebCore/WebCore.pro (93761 => 93762)


--- trunk/Source/WebCore/WebCore.pro	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/WebCore.pro	2011-08-25 06:58:33 UTC (rev 93762)
@@ -164,6 +164,7 @@
         bindings/v8/custom/V8DocumentCustom.cpp \
         bindings/v8/custom/V8DocumentLocationCustom.cpp \
         bindings/v8/custom/V8ElementCustom.cpp \
+        bindings/v8/custom/V8EventConstructors.cpp \
         bindings/v8/custom/V8EventCustom.cpp \
         bindings/v8/custom/V8EventSourceConstructor.cpp \
         bindings/v8/custom/V8FileReaderCustom.cpp \

Added: trunk/Source/WebCore/bindings/generic/EventConstructors.h (0 => 93762)


--- trunk/Source/WebCore/bindings/generic/EventConstructors.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/generic/EventConstructors.h	2011-08-25 06:58:33 UTC (rev 93762)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EventConstructors_h
+#define EventConstructors_h
+
+namespace WebCore {
+
+#define SETUP_EVENT_CONFIGURATION_FOR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \
+    DICTIONARY_START(Event) \
+    FILL_PROPERTY(bubbles) \
+    FILL_PROPERTY(cancelable) \
+    FILL_PROPERTY(defaultPrevented) \
+    FILL_PROPERTY(timeStamp) \
+    DICTIONARY_END(Event)
+
+#define SETUP_EVENT_CONFIGURATION_FOR_ALL_EVENTS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \
+    SETUP_EVENT_CONFIGURATION_FOR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY)
+
+} // namespace WebCore
+
+#endif // EventConstructors_h
Property changes on: trunk/Source/WebCore/bindings/generic/EventConstructors.h
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/bindings/v8/OptionsObject.cpp (93761 => 93762)


--- trunk/Source/WebCore/bindings/v8/OptionsObject.cpp	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/bindings/v8/OptionsObject.cpp	2011-08-25 06:58:33 UTC (rev 93762)
@@ -89,6 +89,19 @@
     return true;
 }
 
+bool OptionsObject::getKeyDouble(const String& key, double& value) const
+{
+    v8::Local<v8::Value> v8Value;
+    if (!getKey(key, v8Value))
+        return false;
+
+    v8::Local<v8::Number> v8Number = v8Value->ToNumber();
+    if (v8Number.IsEmpty())
+        return false;
+    value = v8Number->Value();
+    return true;
+}
+
 bool OptionsObject::getKeyString(const String& key, String& value) const
 {
     v8::Local<v8::Value> v8Value;

Modified: trunk/Source/WebCore/bindings/v8/OptionsObject.h (93761 => 93762)


--- trunk/Source/WebCore/bindings/v8/OptionsObject.h	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/bindings/v8/OptionsObject.h	2011-08-25 06:58:33 UTC (rev 93762)
@@ -47,9 +47,27 @@
     bool getKeyInt32(const String& key, int32_t& value) const;
     bool getKeyString(const String& key, String& value) const;
     bool getKeyStringWithUndefinedOrNullCheck(const String& key, String& value) const;
+    bool getKeyDouble(const String& key, double& value) const;
     PassRefPtr<DOMStringList> getKeyDOMStringList(const String& key) const;
     PassRefPtr<IDBKeyRange> getKeyKeyRange(const String& key) const;
 
+     bool getKeyValue(const String& key, bool& value) const
+     {
+         return getKeyBool(key, value);
+     }
+     bool getKeyValue(const String& key, int32_t& value) const
+     {
+         return getKeyInt32(key, value);
+     }
+     bool getKeyValue(const String& key, double& value) const
+     {
+         return getKeyDouble(key, value);
+     }
+     bool getKeyValue(const String& key, String& value) const
+     {
+         return getKeyString(key, value);
+     }
+
 private:
     bool getKey(const String& key, v8::Local<v8::Value>&) const;
 

Added: trunk/Source/WebCore/bindings/v8/custom/V8EventConstructors.cpp (0 => 93762)


--- trunk/Source/WebCore/bindings/v8/custom/V8EventConstructors.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/custom/V8EventConstructors.cpp	2011-08-25 06:58:33 UTC (rev 93762)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EventConstructors.h"
+
+#include "Document.h"
+#include "DocumentFragment.h"
+#include "Node.h"
+
+#include "OptionsObject.h"
+#include "V8Binding.h"
+#include "V8BindingMacros.h"
+#include "V8Document.h"
+#include "V8Event.h"
+#include "V8Node.h"
+#include "V8Proxy.h"
+
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+
+template<typename EventType, typename EventConfigurationType>
+static v8::Handle<v8::Value> constructV8Event(const v8::Arguments& args, bool (*filler)(EventConfigurationType&, const OptionsObject&), WrapperTypeInfo* info)
+{
+    INC_STATS("DOM.Event.Constructor");
+
+    if (!args.IsConstructCall())
+        return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
+
+    if (args.Length() < 1)
+        return throwError("Not enough arguments", V8Proxy::TypeError);
+
+    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]);
+    EventConfigurationType eventConfiguration;
+    if (args.Length() >= 2) {
+        EXCEPTION_BLOCK(OptionsObject, options, args[1]);
+        if (!filler(eventConfiguration, options))
+            return v8::Undefined();
+    }
+
+    RefPtr<EventType> event = EventType::create(type, eventConfiguration);
+
+    V8DOMWrapper::setDOMWrapper(args.Holder(), info, event.get());
+    return toV8(event.release(), args.Holder());
+}
+
+#define DICTIONARY_START(EventType) \
+    static bool fill##EventType##Configuration(Event##Configuration& eventConfiguration, const OptionsObject& options) \
+    {
+
+#define DICTIONARY_END(EventType) \
+        return true; \
+    } \
+     \
+    v8::Handle<v8::Value> V8##EventType::constructorCallback(const v8::Arguments& args) \
+    { \
+      return constructV8Event<EventType, EventType##Configuration>(args, fill##EventType##Configuration, &info); \
+    }
+
+#define FILL_PARENT_PROPERTIES(parentEventType) \
+    if (!fill##parentEventType##Configuration(eventConfiguration)) \
+        return false;
+
+#define FILL_PROPERTY(propertyName) \
+    options.getKeyValue(#propertyName, eventConfiguration.propertyName); // This can fail but it is OK.
+
+SETUP_EVENT_CONFIGURATION_FOR_ALL_EVENTS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY)
+
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/bindings/v8/custom/V8EventConstructors.cpp
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/dom/Event.cpp (93761 => 93762)


--- trunk/Source/WebCore/dom/Event.cpp	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/dom/Event.cpp	2011-08-25 06:58:33 UTC (rev 93762)
@@ -31,6 +31,14 @@
 
 namespace WebCore {
 
+EventConfiguration::EventConfiguration()
+    : bubbles(false)
+    , cancelable(false)
+    , defaultPrevented(false)
+    , timeStamp(0)
+{
+}
+
 Event::Event()
     : m_canBubble(false)
     , m_cancelable(false)
@@ -60,6 +68,21 @@
 {
 }
 
+Event::Event(const AtomicString& eventType, const EventConfiguration& eventConfiguration)
+    : m_type(eventType)
+    , m_canBubble(eventConfiguration.bubbles)
+    , m_cancelable(eventConfiguration.cancelable)
+    , m_propagationStopped(false)
+    , m_immediatePropagationStopped(false)
+    , m_defaultPrevented(eventConfiguration.defaultPrevented)
+    , m_defaultHandled(false)
+    , m_cancelBubble(false)
+    , m_eventPhase(0)
+    , m_currentTarget(0)
+    , m_createTime(static_cast<DOMTimeStamp>(eventConfiguration.timeStamp))
+{
+}
+
 Event::~Event()
 {
 }

Modified: trunk/Source/WebCore/dom/Event.h (93761 => 93762)


--- trunk/Source/WebCore/dom/Event.h	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/dom/Event.h	2011-08-25 06:58:33 UTC (rev 93762)
@@ -34,6 +34,15 @@
     class EventTarget;
     class EventDispatcher;
 
+    struct EventConfiguration {
+        EventConfiguration();
+
+        bool bubbles;
+        bool cancelable;
+        bool defaultPrevented;
+        double timeStamp;
+    };
+
     class Event : public RefCounted<Event> {
     public:
         enum PhaseType { 
@@ -69,6 +78,10 @@
         {
             return adoptRef(new Event(type, canBubble, cancelable));
         }
+        static PassRefPtr<Event> create(const AtomicString& type, const EventConfiguration& eventConfiguration)
+        {
+            return adoptRef(new Event(type, eventConfiguration));
+        }
         virtual ~Event();
 
         void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
@@ -176,6 +189,7 @@
     protected:
         Event();
         Event(const AtomicString& type, bool canBubble, bool cancelable);
+        Event(const AtomicString&, const EventConfiguration&);
 
         virtual void receivedTarget();
         bool dispatched() const { return m_target; }

Modified: trunk/Source/WebCore/dom/Event.idl (93761 => 93762)


--- trunk/Source/WebCore/dom/Event.idl	2011-08-25 06:06:29 UTC (rev 93761)
+++ trunk/Source/WebCore/dom/Event.idl	2011-08-25 06:58:33 UTC (rev 93762)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009, 2011 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <[email protected]>
  *
  * This library is free software; you can redistribute it and/or
@@ -24,7 +24,9 @@
     interface [
         CustomToJS,
         NoStaticTables,
-        Polymorphic
+        Polymorphic,
+        CanBeConstructed,
+        V8CustomConstructor
     ] Event {
 
         // DOM PhaseType
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to