Title: [93951] trunk
Revision
93951
Author
[email protected]
Date
2011-08-28 16:58:25 -0700 (Sun, 28 Aug 2011)

Log Message

Add support for constructor syntax for Events
https://bugs.webkit.org/show_bug.cgi?id=63878

Reviewed by Oliver Hunt.

Source/WebCore: 

Add basic support for Event constructors, starting with just supporting
the constructor for the base Event class and just JSC support.  This lays
the infrastructure for the other events as well.

Test: fast/events/event-constructors.html

* GNUmakefile.list.am:
* UseJSC.cmake:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Add files.

* bindings/generic/EventConstructors.h: Added.
Add binding agnostic header that defines the Event initializers
using a macro based DSL.

* bindings/js/JSEventConstructors.cpp: Added.
(WebCore::convertValue):
(WebCore::tryGetProperty):
(WebCore::constructJSEventWithInitializer):
Add JSC implementation of Event initializer DSL.

* dom/Event.cpp:
(WebCore::EventInit::EventInit):
(WebCore::Event::Event):
* dom/Event.h:
(WebCore::Event::create):
Add Event initializer interface for base Event.

* dom/Event.idl:
Mark Event as having a custom constructor function.

LayoutTests: 

Add basic test for Event constructors.

* fast/events/constructors/event-constructors-expected.txt: Added.
* fast/events/constructors/event-constructors.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (93950 => 93951)


--- trunk/LayoutTests/ChangeLog	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/LayoutTests/ChangeLog	2011-08-28 23:58:25 UTC (rev 93951)
@@ -1,3 +1,15 @@
+2011-08-28  Sam Weinig  <[email protected]>
+
+        Add support for constructor syntax for Events
+        https://bugs.webkit.org/show_bug.cgi?id=63878
+
+        Reviewed by Oliver Hunt.
+
+        Add basic test for Event constructors.
+
+        * fast/events/constructors/event-constructors-expected.txt: Added.
+        * fast/events/constructors/event-constructors.html: Added.
+
 2011-08-27  Robert Hogan  <[email protected]>
 
         Don't rely on hardcoded position in absolute-appended-to-inline.html

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


--- trunk/LayoutTests/fast/events/constructors/event-constructors-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/constructors/event-constructors-expected.txt	2011-08-28 23:58:25 UTC (rev 93951)
@@ -0,0 +1,44 @@
+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('eventType')).bubbles is false
+PASS (new Event('eventType')).cancelable is false
+PASS (new Event('eventType', { bubbles: true, cancelable: true })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, cancelable: true })).cancelable is true
+PASS (new Event('eventType', { bubbles: true, cancelable: false })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, cancelable: false })).cancelable is false
+PASS (new Event('eventType', { bubbles: true, cancelable: undefined })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, cancelable: undefined })).cancelable is false
+PASS (new Event('eventType', { bubbles: true, cancelable: 0 })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, cancelable: 0 })).cancelable is false
+PASS (new Event('eventType', { bubbles: true })).bubbles is true
+PASS (new Event('eventType', { bubbles: true })).cancelable is false
+PASS (new Event('eventType', { })).bubbles is false
+PASS (new Event('eventType', { })).cancelable is false
+PASS (new Event('eventType', null)).bubbles is false
+PASS (new Event('eventType', null)).cancelable is false
+PASS (new Event('eventType', undefined)).bubbles is false
+PASS (new Event('eventType', undefined)).cancelable is false
+PASS (new Event('eventType', 0)).bubbles is false
+PASS (new Event('eventType', 0)).cancelable is false
+PASS (new Event('eventType', window)).bubbles is false
+PASS (new Event('eventType', window)).cancelable is false
+PASS (new Event('eventType', window)).bubbles is true
+PASS (new Event('eventType', window)).cancelable is false
+PASS (new Event('eventType', document)).bubbles is true
+PASS (new Event('eventType', document)).cancelable is false
+PASS (new Event('eventType', constructible)).bubbles is true
+PASS (new Event('eventType', constructible)).cancelable is false
+PASS (new Event('eventType', { bubbles: true, cancelable: true, other: true })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, cancelable: true, other: true })).cancelable is true
+PASS (new Event('eventType', { bubbles: true, get cancelable() { return true; } })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, get cancelable() { return true; } })).cancelable is true
+PASS (new Event('eventType', { bubbles: true, get cancelable() { return false; } })).bubbles is true
+PASS (new Event('eventType', { bubbles: true, get cancelable() { return false; } })).cancelable is false
+PASS new Event('eventType', { bubbles: true, get cancelable() { throw 'Custom Error'; } }) threw exception Custom Error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

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


--- trunk/LayoutTests/fast/events/constructors/event-constructors.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/constructors/event-constructors.html	2011-08-28 23:58:25 UTC (rev 93951)
@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<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.");
+
+function test(toEval, bubblesExpected, cancelableExpected)
+{
+    if (bubblesExpected) {
+        shouldBe("(" + toEval + ").bubbles", "true");
+    } else {
+        shouldBe("(" + toEval + ").bubbles", "false");
+    }
+
+    if (cancelableExpected) {
+        shouldBe("(" + toEval + ").cancelable", "true");
+    } else {
+        shouldBe("(" + toEval + ").cancelable", "false");
+    }
+}
+
+// No initializer passed.
+test("new Event('eventType')", false, false);
+
+// Both true.
+test("new Event('eventType', { bubbles: true, cancelable: true })", true, true);
+
+// One true, one false.
+test("new Event('eventType', { bubbles: true, cancelable: false })", true, false);
+
+// One explicitly undefined.
+test("new Event('eventType', { bubbles: true, cancelable: undefined })", true, false);
+
+// One a numeric value.
+test("new Event('eventType', { bubbles: true, cancelable: 0 })", true, false);
+
+// One missing.
+test("new Event('eventType', { bubbles: true })", true, false);
+
+// Empty initalizer.
+test("new Event('eventType', { })", false, false);
+
+// null initializer.
+test("new Event('eventType', null)", false, false);
+
+// Explicitly undefined initializer.
+test("new Event('eventType', undefined)", false, false);
+
+// A number as the initializer.
+// FIXME: Should this throw?
+test("new Event('eventType', 0)", false, false);
+
+// The window as the initializer.
+test("new Event('eventType', window)", false, false);
+
+// The window as the initializer, but with bubbles defined to true.
+var bubbles = true;
+test("new Event('eventType', window)", true, false);
+
+// One value defined on the prototype chain of a host object.
+Document.prototype.bubbles = true;
+test("new Event('eventType', document)", true, false);
+
+// One value defined on the prototype chain of a vanilla object.
+var Constructible = function() { }
+Constructible.prototype.bubbles = true;
+var constructible = new Constructible;
+test("new Event('eventType', constructible)", true, false);
+
+// Additional properties on the initializer
+test("new Event('eventType', { bubbles: true, cancelable: true, other: true })", true, true);
+
+// One getter returning true.
+test("new Event('eventType', { bubbles: true, get cancelable() { return true; } })", true, true);
+
+// One getter returning false.
+test("new Event('eventType', { bubbles: true, get cancelable() { return false; } })", true, false);
+
+// One getter throws an exeception.
+shouldThrow("new Event('eventType', { bubbles: true, get cancelable() { throw 'Custom Error'; } })")
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (93950 => 93951)


--- trunk/Source/WebCore/ChangeLog	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/ChangeLog	2011-08-28 23:58:25 UTC (rev 93951)
@@ -1,3 +1,45 @@
+2011-08-28  Sam Weinig  <[email protected]>
+
+        Add support for constructor syntax for Events
+        https://bugs.webkit.org/show_bug.cgi?id=63878
+
+        Reviewed by Oliver Hunt.
+
+        Add basic support for Event constructors, starting with just supporting
+        the constructor for the base Event class and just JSC support.  This lays
+        the infrastructure for the other events as well.
+
+        Test: fast/events/event-constructors.html
+
+        * GNUmakefile.list.am:
+        * UseJSC.cmake:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        Add files.
+
+        * bindings/generic/EventConstructors.h: Added.
+        Add binding agnostic header that defines the Event initializers
+        using a macro based DSL.
+
+        * bindings/js/JSEventConstructors.cpp: Added.
+        (WebCore::convertValue):
+        (WebCore::tryGetProperty):
+        (WebCore::constructJSEventWithInitializer):
+        Add JSC implementation of Event initializer DSL.
+
+        * dom/Event.cpp:
+        (WebCore::EventInit::EventInit):
+        (WebCore::Event::Event):
+        * dom/Event.h:
+        (WebCore::Event::create):
+        Add Event initializer interface for base Event.
+
+        * dom/Event.idl:
+        Mark Event as having a custom constructor function.
+
 2011-08-27  Andreas Kling  <[email protected]>
 
         SQLiteStatement::getColumnText() could construct WTF::String result more efficiently.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (93950 => 93951)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-08-28 23:58:25 UTC (rev 93951)
@@ -645,6 +645,7 @@
 	Source/WebCore/bindings/generic/BindingSecurityBase.cpp \
 	Source/WebCore/bindings/generic/BindingSecurityBase.h \
 	Source/WebCore/bindings/generic/BindingSecurity.h \
+	Source/WebCore/bindings/generic/EventConstructors.h \
 	Source/WebCore/bindings/generic/GenericBinding.h \
 	Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp \
 	Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h \
@@ -718,6 +719,7 @@
 	Source/WebCore/bindings/js/JSEntryCustom.cpp \
 	Source/WebCore/bindings/js/JSEntrySyncCustom.cpp \
 	Source/WebCore/bindings/js/JSEventCustom.cpp \
+	Source/WebCore/bindings/js/JSEventConstructors.cpp \
 	Source/WebCore/bindings/js/JSEventListener.cpp \
 	Source/WebCore/bindings/js/JSEventListener.h \
 	Source/WebCore/bindings/js/JSEventSourceCustom.cpp \

Modified: trunk/Source/WebCore/UseJSC.cmake (93950 => 93951)


--- trunk/Source/WebCore/UseJSC.cmake	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/UseJSC.cmake	2011-08-28 23:58:25 UTC (rev 93951)
@@ -50,6 +50,7 @@
     bindings/js/JSDocumentCustom.cpp
     bindings/js/JSElementCustom.cpp
     bindings/js/JSErrorHandler.cpp
+    bindings/js/JSEventConstructors.cpp
     bindings/js/JSEventCustom.cpp
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventSourceCustom.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (93950 => 93951)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-28 23:58:25 UTC (rev 93951)
@@ -1730,6 +1730,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',
@@ -1818,6 +1819,7 @@
             'bindings/js/JSEntrySyncCustom.cpp',
             'bindings/js/JSErrorHandler.cpp',
             'bindings/js/JSErrorHandler.h',
+            'bindings/js/JSEventConstructors.cpp',
             'bindings/js/JSEventCustom.cpp',
             'bindings/js/JSEventListener.cpp',
             'bindings/js/JSEventListener.h',

Modified: trunk/Source/WebCore/WebCore.pro (93950 => 93951)


--- trunk/Source/WebCore/WebCore.pro	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/WebCore.pro	2011-08-28 23:58:25 UTC (rev 93951)
@@ -274,6 +274,7 @@
         bindings/js/JSDocumentCustom.cpp \
         bindings/js/JSElementCustom.cpp \
         bindings/js/JSErrorHandler.cpp \
+        bindings/js/JSEventConstructors.cpp \
         bindings/js/JSEventCustom.cpp \
         bindings/js/JSEventListener.cpp \
         bindings/js/JSEventSourceCustom.cpp \
@@ -1235,6 +1236,7 @@
     accessibility/AXObjectCache.h \
     bindings/ScriptControllerBase.h \
     bindings/generic/ActiveDOMCallback.h \
+    bindings/generic/EventConstructors.h \
     bindings/generic/RuntimeEnabledFeatures.h
 
 v8 {

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (93950 => 93951)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-28 23:58:25 UTC (rev 93951)
@@ -58397,6 +58397,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\bindings\generic\EventConstructors.h"
+					>
+				</File>
+				<File
 					RelativePath="..\bindings\generic\GenericBinding.h"
 					>
 				</File>
@@ -61009,6 +61013,58 @@
 					>
 				</File>
 				<File
+					RelativePath="..\bindings\js\JSEventConstructors.cpp"
+					>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_All|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Production|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
 					RelativePath="..\bindings\js\JSEventCustom.cpp"
 					>
 					<FileConfiguration

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (93950 => 93951)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-28 23:58:25 UTC (rev 93951)
@@ -5243,6 +5243,8 @@
 		BCE1C4400D9830F4003B02F2 /* JSLocationCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */; };
 		BCE3BEC20D222B1D007E06E4 /* TagNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE3BEC00D222B1D007E06E4 /* TagNodeList.cpp */; };
 		BCE3BEC30D222B1D007E06E4 /* TagNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE3BEC10D222B1D007E06E4 /* TagNodeList.h */; };
+		BCE43897140B0051005E437E /* EventConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE43896140B0051005E437E /* EventConstructors.h */; };
+		BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE43899140B0073005E437E /* JSEventConstructors.cpp */; };
 		BCE4413312F748E2009B84B8 /* RenderCombineText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE4413112F748E2009B84B8 /* RenderCombineText.cpp */; };
 		BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE4413212F748E2009B84B8 /* RenderCombineText.h */; };
 		BCE4413612F7490B009B84B8 /* FontWidthVariant.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE4413512F7490B009B84B8 /* FontWidthVariant.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11960,6 +11962,8 @@
 		BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSLocationCustom.cpp; sourceTree = "<group>"; };
 		BCE3BEC00D222B1D007E06E4 /* TagNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagNodeList.cpp; sourceTree = "<group>"; };
 		BCE3BEC10D222B1D007E06E4 /* TagNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagNodeList.h; sourceTree = "<group>"; };
+		BCE43896140B0051005E437E /* EventConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EventConstructors.h; path = generic/EventConstructors.h; sourceTree = "<group>"; };
+		BCE43899140B0073005E437E /* JSEventConstructors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEventConstructors.cpp; sourceTree = "<group>"; };
 		BCE4413112F748E2009B84B8 /* RenderCombineText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderCombineText.cpp; sourceTree = "<group>"; };
 		BCE4413212F748E2009B84B8 /* RenderCombineText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderCombineText.h; sourceTree = "<group>"; };
 		BCE4413512F7490B009B84B8 /* FontWidthVariant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontWidthVariant.h; sourceTree = "<group>"; };
@@ -18463,6 +18467,7 @@
 				A622A8F5122C44A600A785B3 /* BindingSecurity.h */,
 				A622A8F6122C44A600A785B3 /* BindingSecurityBase.cpp */,
 				A622A8F7122C44A600A785B3 /* BindingSecurityBase.h */,
+				BCE43896140B0051005E437E /* EventConstructors.h */,
 				A622A8F9122C44A600A785B3 /* GenericBinding.h */,
 			);
 			name = generic;
@@ -18529,6 +18534,7 @@
 				65E0E9431133C89F00B4CB10 /* JSDOMWrapper.h */,
 				F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */,
 				F3D461471161D53200CA0D09 /* JSErrorHandler.h */,
+				BCE43899140B0073005E437E /* JSEventConstructors.cpp */,
 				BC60901E0E91B8EC000C68B5 /* JSEventTarget.cpp */,
 				BC60901D0E91B8EC000C68B5 /* JSEventTarget.h */,
 				3314ACE910892086000F0E56 /* JSExceptionBase.cpp */,
@@ -23409,6 +23415,7 @@
 				DF9AFD7213FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.h in Headers */,
 				93500F3213FDE3BE0099EC24 /* NSScrollerImpDetails.h in Headers */,
 				D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
+				BCE43897140B0051005E437E /* EventConstructors.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -26214,6 +26221,7 @@
 				FD23A12513F5FA5900F67001 /* JSMediaElementAudioSourceNode.cpp in Sources */,
 				1A1414B513A0F0500019996C /* WebKitFontFamilyNames.cpp in Sources */,
 				DF9AFD7313FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.mm in Sources */,
+				BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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


--- trunk/Source/WebCore/bindings/generic/EventConstructors.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/generic/EventConstructors.h	2011-08-28 23:58:25 UTC (rev 93951)
@@ -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 INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \
+    \
+    DICTIONARY_START(Event) \
+        FILL_PROPERTY(bubbles) \
+        FILL_PROPERTY(cancelable) \
+    DICTIONARY_END(Event)
+
+
+#define INSTANTIATE_ALL_EVENT_INITIALIZING_CONSTRUCTORS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \
+    INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \
+
+} // namespace WebCore
+
+#endif // EventConstructors_h

Modified: trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp (93950 => 93951)


--- trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2011-08-28 23:58:25 UTC (rev 93951)
@@ -72,6 +72,7 @@
 #include "JSDocumentCustom.cpp"
 #include "JSElementCustom.cpp"
 #include "JSErrorHandler.cpp"
+#include "JSEventConstructors.cpp"
 #include "JSEventCustom.cpp"
 #include "JSEventListener.cpp"
 #include "JSEventSourceCustom.cpp"

Added: trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp (0 => 93951)


--- trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSEventConstructors.cpp	2011-08-28 23:58:25 UTC (rev 93951)
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "EventConstructors.h"
+
+#include "Event.h"
+#include "JSEvent.h"
+#include <runtime/Error.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+static void convertValue(ExecState* exec, JSValue value, bool& result)
+{
+    result = value.toBoolean(exec);
+}
+
+template <typename Result>
+static bool tryGetProperty(ExecState* exec, JSObject* initializerObject, const char* propertyName, Result& result)
+{
+    Identifier identifier(exec, propertyName);
+    PropertySlot slot(initializerObject);
+    if (initializerObject->getPropertySlot(exec, identifier, slot)) {
+        if (exec->hadException())
+            return false;
+
+        JSValue value = slot.getValue(exec, identifier);
+        
+        convertValue(exec, value, result);
+
+        if (exec->hadException())
+            return false;
+    }
+    
+    return true;
+}
+
+template<typename Constructor, typename EventType, typename EventInitType>
+static EncodedJSValue constructJSEventWithInitializer(ExecState* exec, bool (*filler)(EventInitType&, ExecState*, JSObject*))
+{
+    Constructor* jsConstructor = static_cast<Constructor*>(exec->callee());
+
+    ScriptExecutionContext* executionContext = jsConstructor->scriptExecutionContext();
+    if (!executionContext)
+        return throwVMError(exec, createReferenceError(exec, "Constructor associated execution context is unavailable"));
+
+    AtomicString eventType = ustringToAtomicString(exec->argument(0).toString(exec));
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    EventInitType eventInit;
+
+    JSValue initializerValue = exec->argument(1);
+    if (!initializerValue.isUndefinedOrNull()) {
+        // Given the above test, this will always yield an object.
+        JSObject* initializerObject = initializerValue.toObject(exec);
+
+        // Attempt to fill in the EventInit.
+        if (!filler(eventInit, exec, initializerObject))
+            return JSValue::encode(jsUndefined());
+    }
+
+    RefPtr<EventType> event = EventType::create(eventType, eventInit);
+    return JSValue::encode(toJS(exec, jsConstructor->globalObject(), event.get()));
+}
+
+#define DICTIONARY_START(Event) \
+    static bool fill##Event##Init(Event##Init& eventInit, ExecState* exec, JSObject* initializerObject) \
+    {
+
+#define DICTIONARY_END(Event) \
+        return true; \
+    } \
+    \
+    EncodedJSValue JSC_HOST_CALL JS##Event##Constructor::constructJS##Event(ExecState* exec) \
+    { \
+        return constructJSEventWithInitializer<JS##Event##Constructor, Event, Event##Init>(exec, fill##Event##Init); \
+    }
+
+#define FILL_PARENT_PROPERTIES(parent) \
+    if (!fill##parent##Init(eventInit, exec, initializerObject)) \
+        return false;
+
+#define FILL_PROPERTY(propertyName) \
+    if (!tryGetProperty(exec, initializerObject, #propertyName, eventInit.propertyName)) \
+        return false;
+
+INSTANTIATE_ALL_EVENT_INITIALIZING_CONSTRUCTORS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY)
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/dom/Event.cpp (93950 => 93951)


--- trunk/Source/WebCore/dom/Event.cpp	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/dom/Event.cpp	2011-08-28 23:58:25 UTC (rev 93951)
@@ -22,15 +22,22 @@
 
 #include "config.h"
 #include "Event.h"
+
 #include "EventDispatcher.h"
 #include "EventTarget.h"
-
 #include "UserGestureIndicator.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
 
+EventInit::EventInit()
+    : bubbles(false)
+    , cancelable(false)
+{
+}
+
+
 Event::Event()
     : m_canBubble(false)
     , m_cancelable(false)
@@ -60,6 +67,21 @@
 {
 }
 
+Event::Event(const AtomicString& eventType, const EventInit& initializer)
+    : m_type(eventType)
+    , m_canBubble(initializer.bubbles)
+    , m_cancelable(initializer.cancelable)
+    , m_propagationStopped(false)
+    , m_immediatePropagationStopped(false)
+    , m_defaultPrevented(false)
+    , m_defaultHandled(false)
+    , m_cancelBubble(false)
+    , m_eventPhase(0)
+    , m_currentTarget(0)
+    , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
+{
+}
+
 Event::~Event()
 {
 }

Modified: trunk/Source/WebCore/dom/Event.h (93950 => 93951)


--- trunk/Source/WebCore/dom/Event.h	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/dom/Event.h	2011-08-28 23:58:25 UTC (rev 93951)
@@ -34,6 +34,13 @@
     class EventTarget;
     class EventDispatcher;
 
+    struct EventInit {
+        EventInit();
+        
+        bool bubbles;
+        bool cancelable;
+    };
+
     class Event : public RefCounted<Event> {
     public:
         enum PhaseType { 
@@ -69,6 +76,12 @@
         {
             return adoptRef(new Event(type, canBubble, cancelable));
         }
+
+        static PassRefPtr<Event> create(const AtomicString& type, const EventInit& initializer)
+        {
+            return adoptRef(new Event(type, initializer));
+        }
+
         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& type, const EventInit&);
 
         virtual void receivedTarget();
         bool dispatched() const { return m_target; }

Modified: trunk/Source/WebCore/dom/Event.idl (93950 => 93951)


--- trunk/Source/WebCore/dom/Event.idl	2011-08-28 19:24:40 UTC (rev 93950)
+++ trunk/Source/WebCore/dom/Event.idl	2011-08-28 23:58:25 UTC (rev 93951)
@@ -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
@@ -23,6 +23,8 @@
     // Introduced in DOM Level 2:
     interface [
         CustomToJS,
+        CanBeConstructed,
+        CustomConstructFunction,
         NoStaticTables,
         Polymorphic
     ] Event {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to