Title: [233443] trunk
Revision
233443
Author
[email protected]
Date
2018-07-02 15:54:32 -0700 (Mon, 02 Jul 2018)

Log Message

Generate event and event target interface types directly instead of via macros
https://bugs.webkit.org/show_bug.cgi?id=187215

Reviewed by Chris Dumez.

Made make_event_factory.pl directly generate EventInterface enum values and toJSNewlyCreated for Event,
and EventTargetInterface enum values and toJS for EventTarget. Removed the code to generate EventFactory::create
since it was never even compiled or used anywhere.

This patch faithfully replicates what the macro used to generate but we should consider always generating either
toJS or toJSNewlyCreated for both interfaces in the future.

No new tests since there should be no observable behavioral changes.

* DerivedSources.make: Generate EventTargetFactory.cpp, which is used to generate toJS function for EventTarget.
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSEventCustom.cpp:
(WebCore::toJSNewlyCreated): Deleted. Now generated directly in EventFactory.cpp.
* bindings/js/JSEventTargetCustom.cpp:
(WebCore::JSEventTarget::toWrapped): Removed the use of TRY_TO_UNWRAP_WITH_INTERFACE.
(WebCore::toJS): Deleted. Now generated directly in EventFactory.cpp.
* bindings/scripts/InFilesCompiler.pm:
(generateInterfacesHeader): Use #pragma once. Generate enum values directly. Added the support for suffixing
each type name with namespace for EventTarget.
* dom/Event.h: Removed the declaration of EventInterface enum. It's now directly generated in EventInterfaces.h
* dom/EventNames.in: Generate toJSNewlyCreated.
* dom/EventTarget.h: Removed the declaration of EventTargetInterface as it's now done in EventTargetInterfaces.h.
* dom/EventTargetFactory.in: Generate toJS.
* dom/make_event_factory.pl:
(defaultParameters): Added two new options. factoryFunction specifies whether toJS or toJSNewlyCreated is generated,
and useNamespaceAsSuffix specifies whether each entry should be suffixed by the namespace (used by EventTarget).
(generateCode): Added a missing semicolon.
(generateImplementation): Removed the early exit for EventTarget since we now need to generate its toJS function.
Replaced the code to generate EventFactory::create by the one to generate toJS / toJSNewlyCreated.

Modified Paths

Removed Paths

  • trunk/jstests/stress/

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (233442 => 233443)


--- trunk/Source/WebCore/CMakeLists.txt	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/CMakeLists.txt	2018-07-02 22:54:32 UTC (rev 233443)
@@ -1896,12 +1896,14 @@
 list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/HTMLNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/HTMLElementFactory.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/JSHTMLElementWrapperFactory.cpp)
 
 
-GENERATE_EVENT_FACTORY(${WEBCORE_DIR}/dom/EventNames.in EventInterfaces.h)
+GENERATE_EVENT_FACTORY(${WEBCORE_DIR}/dom/EventNames.in Event)
 list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/EventInterfaces.h)
+list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/EventFactory.cpp)
 
 
-GENERATE_EVENT_FACTORY(${WEBCORE_DIR}/dom/EventTargetFactory.in EventTargetInterfaces.h)
+GENERATE_EVENT_FACTORY(${WEBCORE_DIR}/dom/EventTargetFactory.in EventTarget)
 list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/EventTargetInterfaces.h)
+list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/EventTargetFactory.cpp)
 
 
 GENERATE_SETTINGS_MACROS(${WEBCORE_DIR}/page/Settings.yaml Settings.h)

Modified: trunk/Source/WebCore/ChangeLog (233442 => 233443)


--- trunk/Source/WebCore/ChangeLog	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/ChangeLog	2018-07-02 22:54:32 UTC (rev 233443)
@@ -1,3 +1,41 @@
+2018-06-29  Ryosuke Niwa  <[email protected]>
+
+        Generate event and event target interface types directly instead of via macros
+        https://bugs.webkit.org/show_bug.cgi?id=187215
+
+        Reviewed by Chris Dumez.
+
+        Made make_event_factory.pl directly generate EventInterface enum values and toJSNewlyCreated for Event,
+        and EventTargetInterface enum values and toJS for EventTarget. Removed the code to generate EventFactory::create
+        since it was never even compiled or used anywhere.
+
+        This patch faithfully replicates what the macro used to generate but we should consider always generating either
+        toJS or toJSNewlyCreated for both interfaces in the future.
+
+        No new tests since there should be no observable behavioral changes.
+
+        * DerivedSources.make: Generate EventTargetFactory.cpp, which is used to generate toJS function for EventTarget.
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSEventCustom.cpp:
+        (WebCore::toJSNewlyCreated): Deleted. Now generated directly in EventFactory.cpp.
+        * bindings/js/JSEventTargetCustom.cpp:
+        (WebCore::JSEventTarget::toWrapped): Removed the use of TRY_TO_UNWRAP_WITH_INTERFACE.
+        (WebCore::toJS): Deleted. Now generated directly in EventFactory.cpp.
+        * bindings/scripts/InFilesCompiler.pm:
+        (generateInterfacesHeader): Use #pragma once. Generate enum values directly. Added the support for suffixing
+        each type name with namespace for EventTarget.
+        * dom/Event.h: Removed the declaration of EventInterface enum. It's now directly generated in EventInterfaces.h
+        * dom/EventNames.in: Generate toJSNewlyCreated.
+        * dom/EventTarget.h: Removed the declaration of EventTargetInterface as it's now done in EventTargetInterfaces.h.
+        * dom/EventTargetFactory.in: Generate toJS.
+        * dom/make_event_factory.pl:
+        (defaultParameters): Added two new options. factoryFunction specifies whether toJS or toJSNewlyCreated is generated,
+        and useNamespaceAsSuffix specifies whether each entry should be suffixed by the namespace (used by EventTarget).
+        (generateCode): Added a missing semicolon.
+        (generateImplementation): Removed the early exit for EventTarget since we now need to generate its toJS function.
+        Replaced the code to generate EventFactory::create by the one to generate toJS / toJSNewlyCreated.
+
 2018-07-02  Zalan Bujtas  <[email protected]>
 
         HTML widget displays blank when playing on page

Modified: trunk/Source/WebCore/DerivedSources.make (233442 => 233443)


--- trunk/Source/WebCore/DerivedSources.make	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/DerivedSources.make	2018-07-02 22:54:32 UTC (rev 233443)
@@ -1396,8 +1396,8 @@
 
 EVENT_TARGET_FACTORY = EventTargetFactory.in $(ADDITIONAL_EVENT_TARGET_FACTORY)
 
-all : EventTargetHeaders.h EventTargetInterfaces.h
-EventTargetHeaders%h EventTargetInterfaces%h : dom/make_event_factory.pl $(EVENT_TARGET_FACTORY)
+all : EventTargetFactory.cpp EventTargetHeaders.h EventTargetInterfaces.h
+EventTargetFactory%cpp EventTargetHeaders%h EventTargetInterfaces%h : dom/make_event_factory.pl $(EVENT_TARGET_FACTORY)
 	$(PERL) $< $(addprefix --input , $(filter-out $(WebCore)/dom/make_event_factory.pl, $^))
 
 # --------

Modified: trunk/Source/WebCore/Sources.txt (233442 => 233443)


--- trunk/Source/WebCore/Sources.txt	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/Sources.txt	2018-07-02 22:54:32 UTC (rev 233443)
@@ -2361,6 +2361,8 @@
 
 CSSValueKeywords.cpp
 ColorData.cpp
+EventFactory.cpp
+EventTargetFactory.cpp
 HTMLElementFactory.cpp
 HTMLEntityTable.cpp
 MathMLElementFactory.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (233442 => 233443)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-07-02 22:54:32 UTC (rev 233443)
@@ -10843,6 +10843,7 @@
 		9B6C41521344949000085B62 /* StringWithDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringWithDirection.h; sourceTree = "<group>"; };
 		9B714E1E1C91166900AC0E92 /* EventPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventPath.cpp; sourceTree = "<group>"; };
 		9B714E1F1C91166900AC0E92 /* EventPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventPath.h; sourceTree = "<group>"; };
+		9B85530520E733B5009EEF4F /* EventTargetFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EventTargetFactory.cpp; path = EventTargetFactory.cpp; sourceTree = "<group>"; };
 		9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderCocoa.mm; sourceTree = "<group>"; };
 		9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogicalSelectionOffsetCaches.h; sourceTree = "<group>"; };
 		9BA827781F06156500F71E75 /* NavigationDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationDisabler.h; sourceTree = "<group>"; };
@@ -10853,6 +10854,7 @@
 		9BC5F9DF1D5AAF6A002B749D /* JSCustomElementRegistryCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomElementRegistryCustom.cpp; sourceTree = "<group>"; };
 		9BC6C21913CCC97B008E0337 /* HTMLTextFormControlElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLTextFormControlElement.h; sourceTree = "<group>"; };
 		9BC6C21A13CCC97B008E0337 /* HTMLTextFormControlElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTextFormControlElement.cpp; sourceTree = "<group>"; };
+		9BCCCA5320E7095D0068FB03 /* EventFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventFactory.cpp; sourceTree = "<group>"; };
 		9BD0BF9112A42BF50072FD43 /* ScopedEventQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedEventQueue.h; sourceTree = "<group>"; };
 		9BD0BF9212A42BF50072FD43 /* ScopedEventQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScopedEventQueue.cpp; sourceTree = "<group>"; };
 		9BD1F6801F0462B8001C9CDD /* LayoutDisallowedScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutDisallowedScope.h; sourceTree = "<group>"; };
@@ -18888,8 +18890,10 @@
 				6565814809D13043000E61D7 /* CSSValueKeywords.h */,
 				E334825E1DC93AA0009C9544 /* DOMJITAbstractHeapRepository.h */,
 				E1C6CFC21746D293007B87A1 /* DOMWindowConstructors.idl */,
+				9BCCCA5320E7095D0068FB03 /* EventFactory.cpp */,
 				970B72A5145008EB00F00A37 /* EventHeaders.h */,
 				970B7289144FFAC600F00A37 /* EventInterfaces.h */,
+				9B85530520E733B5009EEF4F /* EventTargetFactory.cpp */,
 				97AA3CA3145237CC003E1DA6 /* EventTargetHeaders.h */,
 				97AA3CA4145237CC003E1DA6 /* EventTargetInterfaces.h */,
 				A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */,

Modified: trunk/Source/WebCore/WebCoreMacros.cmake (233442 => 233443)


--- trunk/Source/WebCore/WebCoreMacros.cmake	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/WebCoreMacros.cmake	2018-07-02 22:54:32 UTC (rev 233443)
@@ -159,11 +159,12 @@
 endmacro()
 
 
-macro(GENERATE_EVENT_FACTORY _infile _outfile)
+macro(GENERATE_EVENT_FACTORY _infile _namespace)
     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
+    set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Interfaces.h ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Factory.cpp)
 
     add_custom_command(
-        OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
+        OUTPUT  ${_outputfiles}
         MAIN_DEPENDENCY ${_infile}
         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
         COMMAND ${PERL_EXECUTABLE} ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}

Modified: trunk/Source/WebCore/bindings/js/JSEventCustom.cpp (233442 => 233443)


--- trunk/Source/WebCore/bindings/js/JSEventCustom.cpp	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/bindings/js/JSEventCustom.cpp	2018-07-02 22:54:32 UTC (rev 233443)
@@ -42,19 +42,6 @@
 namespace WebCore {
 using namespace JSC;
 
-#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
-    case interfaceName##InterfaceType: \
-        return createWrapper<interfaceName>(globalObject, WTFMove(event));
-
-JSValue toJSNewlyCreated(ExecState*, JSDOMGlobalObject* globalObject, Ref<Event>&& event)
-{
-    switch (event->eventInterface()) {
-        DOM_EVENT_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)
-    }
-
-    return createWrapper<Event>(globalObject, WTFMove(event));
-}
-
 JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, Event& event)
 {
     return wrap(state, globalObject, event);

Modified: trunk/Source/WebCore/bindings/js/JSEventTargetCustom.cpp (233442 => 233443)


--- trunk/Source/WebCore/bindings/js/JSEventTargetCustom.cpp	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/bindings/js/JSEventTargetCustom.cpp	2018-07-02 22:54:32 UTC (rev 233443)
@@ -40,37 +40,19 @@
 namespace WebCore {
 using namespace JSC;
 
-#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
-    case interfaceName##EventTargetInterfaceType: \
-        return toJS(exec, globalObject, static_cast<interfaceName&>(target));
-
-JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget& target)
-{
-    switch (target.eventTargetInterface()) {
-    DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)
-    }
-
-    ASSERT_NOT_REACHED();
-    return jsNull();
-}
-
-#undef TRY_TO_WRAP_WITH_INTERFACE
-
-#define TRY_TO_UNWRAP_WITH_INTERFACE(interfaceName) \
-    if (value.inherits<JS##interfaceName>(vm)) \
-        return &jsCast<JS##interfaceName*>(asObject(value))->wrapped();
-
 EventTarget* JSEventTarget::toWrapped(VM& vm, JSValue value)
 {
-    TRY_TO_UNWRAP_WITH_INTERFACE(WindowProxy)
-    TRY_TO_UNWRAP_WITH_INTERFACE(DOMWindow)
-    TRY_TO_UNWRAP_WITH_INTERFACE(WorkerGlobalScope)
-    TRY_TO_UNWRAP_WITH_INTERFACE(EventTarget)
+    if (value.inherits<JSWindowProxy>(vm))
+        return &jsCast<JSWindowProxy*>(asObject(value))->wrapped();
+    if (value.inherits<JSDOMWindow>(vm))
+        return &jsCast<JSDOMWindow*>(asObject(value))->wrapped();
+    if (value.inherits<JSWorkerGlobalScope>(vm))
+        return &jsCast<JSWorkerGlobalScope*>(asObject(value))->wrapped();
+    if (value.inherits<JSEventTarget>(vm))
+        return &jsCast<JSEventTarget*>(asObject(value))->wrapped();
     return nullptr;
 }
 
-#undef TRY_TO_UNWRAP_WITH_INTERFACE
-
 std::unique_ptr<JSEventTargetWrapper> jsEventTargetCast(VM& vm, JSValue thisValue)
 {
     if (auto* target = jsDynamicCast<JSEventTarget*>(vm, thisValue))

Modified: trunk/Source/WebCore/bindings/scripts/InFilesCompiler.pm (233442 => 233443)


--- trunk/Source/WebCore/bindings/scripts/InFilesCompiler.pm	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/bindings/scripts/InFilesCompiler.pm	2018-07-02 22:54:32 UTC (rev 233443)
@@ -193,6 +193,7 @@
 
     my $F;
     my $namespace = $parsedParameters{"namespace"};
+    my $useNamespaceAsSuffix = $parsedParameters{"useNamespaceAsSuffix"};
     my $outputFile = "$outputDir/${namespace}Interfaces.h";
 
     open F, ">$outputFile" or die "Failed to open file: $!";
@@ -199,8 +200,7 @@
 
     print F license();
 
-    print F "#ifndef ${namespace}Interfaces_h\n";
-    print F "#define ${namespace}Interfaces_h\n";
+    print F "#pragma once\n";
     print F "\n";
 
     my %unconditionalInterfaces = ();
@@ -222,36 +222,35 @@
 
     my $macroStyledNamespace = $object->toMacroStyle($namespace);
 
+    print F "namespace WebCore {\n";
+    print F "\n";
+    print F "enum ${namespace}Interface {\n";
+
+    my $suffix = "InterfaceType";
+    if ($useNamespaceAsSuffix eq "true") {
+        $suffix = $namespace . $suffix;
+    }
+
+    my $count = 1;
     for my $conditional (sort keys %interfacesByConditional) {
         my $preferredConditional = $object->preferredConditional($conditional);
         print F "#if " . $object->conditionalStringFromAttributeValue($conditional) . "\n";
-        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro) \\\n";
-
         for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) {
             next if defined($unconditionalInterfaces{$interface});
-            print F "    macro($interface) \\\n";
+            print F "    ${interface}${suffix} = $count,\n";
+            $count++;
         }
-
-        print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional\n";
-        print F "#else\n";
-        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro)\n";
         print F "#endif\n";
-        print F "\n";
     }
 
-    print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH(macro) \\\n";
-    print F "    \\\n";
     for my $interface (sort keys %unconditionalInterfaces) {
-            print F "    macro($interface) \\\n";
+        print F "    ${interface}${suffix} = $count,\n";
+        $count++;
     }
-    print F "    \\\n";
-    for my $conditional (sort keys %interfacesByConditional) {
-        my $preferredConditional = $object->preferredConditional($conditional);
-        print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro) \\\n";
-    }
 
+    print F "};\n";
     print F "\n";
-    print F "#endif // ${namespace}Interfaces_h\n";
+    print F "} // namespace WebCore\n";
 
     close F;
 }

Modified: trunk/Source/WebCore/dom/Event.h (233442 => 233443)


--- trunk/Source/WebCore/dom/Event.h	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/dom/Event.h	2018-07-02 22:54:32 UTC (rev 233443)
@@ -38,14 +38,6 @@
 class EventTarget;
 class ScriptExecutionContext;
 
-enum EventInterface {
-
-#define DOM_EVENT_INTERFACE_DECLARE(name) name##InterfaceType,
-DOM_EVENT_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE)
-#undef DOM_EVENT_INTERFACE_DECLARE
-
-};
-
 class Event : public ScriptWrappable, public RefCounted<Event> {
 public:
     enum class IsTrusted { No, Yes };

Modified: trunk/Source/WebCore/dom/EventNames.in (233442 => 233443)


--- trunk/Source/WebCore/dom/EventNames.in	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/dom/EventNames.in	2018-07-02 22:54:32 UTC (rev 233443)
@@ -1,4 +1,6 @@
 namespace="Event"
+factoryFunction=toNewlyCreated
+useNamespaceAsSuffix=false
 
 Event
 Events interfaceName=Event

Modified: trunk/Source/WebCore/dom/EventTarget.h (233442 => 233443)


--- trunk/Source/WebCore/dom/EventTarget.h	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/dom/EventTarget.h	2018-07-02 22:54:32 UTC (rev 233443)
@@ -50,14 +50,6 @@
     bool isFiringEventListeners { false };
 };
 
-enum EventTargetInterface {
-
-#define DOM_EVENT_INTERFACE_DECLARE(name) name##EventTargetInterfaceType,
-DOM_EVENT_TARGET_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE)
-#undef DOM_EVENT_INTERFACE_DECLARE
-
-};
-
 class EventTarget : public ScriptWrappable {
 public:
     void ref() { refEventTarget(); }

Modified: trunk/Source/WebCore/dom/EventTargetFactory.in (233442 => 233443)


--- trunk/Source/WebCore/dom/EventTargetFactory.in	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/dom/EventTargetFactory.in	2018-07-02 22:54:32 UTC (rev 233443)
@@ -1,4 +1,6 @@
 namespace="EventTarget"
+factoryFunction=toJS
+useNamespaceAsSuffix=true
 
 AbortSignal
 ApplePaySession conditional=APPLE_PAY

Modified: trunk/Source/WebCore/dom/make_event_factory.pl (233442 => 233443)


--- trunk/Source/WebCore/dom/make_event_factory.pl	2018-07-02 22:47:20 UTC (rev 233442)
+++ trunk/Source/WebCore/dom/make_event_factory.pl	2018-07-02 22:54:32 UTC (rev 233443)
@@ -38,7 +38,9 @@
 use InFilesCompiler;
 
 my %defaultParameters = (
-    'namespace' => 0
+    'namespace' => 0,
+    'factoryFunction' => 0,
+    'useNamespaceAsSuffix' => 0,
 );
 
 sub defaultItemFactory
@@ -62,7 +64,7 @@
 
     generateImplementation($parsedParametersRef, $parsedItemsRef);
     $InCompiler->generateInterfacesHeader();
-    $InCompiler->generateHeadersHeader()
+    $InCompiler->generateHeadersHeader();
 }
 
 sub generateImplementation()
@@ -74,43 +76,72 @@
     my %parsedParameters = %{ $parsedParametersRef };
 
     my $namespace = $parsedParameters{"namespace"};
+    my $factoryFunction = $parsedParameters{"factoryFunction"};
+    ($factoryFunction eq "toJS" or $factoryFunction eq "toNewlyCreated") or die "factoryFunction should be either toJS or toNewlyCreated";
+    my $useNamespaceAsSuffix = $parsedParameters{"useNamespaceAsSuffix"};
 
-    # Currently, only Events have factory files.
-    return if $namespace ne "Event";
-
     my $F;
     open F, ">", "$outputDir/${namespace}Factory.cpp" or die "Failed to open file: $!";
 
     print F $InCompiler->license();
 
+    my $interfaceMethodName = lcfirst $namespace . "Interface";
+
     print F "#include \"config.h\"\n";
-    print F "#include \"${namespace}Factory.h\"\n";
+    print F "#include \"${namespace}Headers.h\"\n";
     print F "\n";
-    print F "#include \"${namespace}Headers.h\"\n";
+    print F "#include \"JSDOMGlobalObject.h\"\n";
     print F "#include <_javascript_Core/StructureInlines.h>\n";
     print F "\n";
     print F "namespace WebCore {\n";
     print F "\n";
-    print F "RefPtr<$namespace> ${namespace}Factory::create(const String& type)\n";
-    print F "{\n";
+    # FIXME: Why does Event need toNewlyCreated but EventTarget need toJS?
+    if ($factoryFunction eq "toNewlyCreated") {
+        print F "JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<${namespace}>&& impl)\n";
+        print F "{\n";
+        print F "    switch (impl->${interfaceMethodName}()) {\n";
+    } else {
+        print F "JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ${namespace}& impl)\n";
+        print F "{\n";
+        print F "    switch (impl.${interfaceMethodName}()) {\n";
+    }
 
+    my %generatedInterfaceNames = ();
+
     for my $eventName (sort keys %parsedEvents) {
         my $conditional = $parsedEvents{$eventName}{"conditional"};
         my $runtimeEnabled = $parsedEvents{$eventName}{"runtimeEnabled"};
         my $interfaceName = $InCompiler->interfaceForItem($eventName);
 
+        next if $generatedInterfaceNames{$interfaceName};
+        $generatedInterfaceNames{$interfaceName} = 1;
+
+        my $suffix = "";
+        if ($useNamespaceAsSuffix eq "true") {
+            $suffix = $namespace . $suffix;
+        }
+
         # FIXME: This should pay attention to $runtimeConditional so it can support RuntimeEnabledFeatures.
-
         if ($conditional) {
             my $conditionals = "#if ENABLE(" . join(") || ENABLE(", split("\\|", $conditional)) . ")";
             print F "$conditionals\n";
         }
-        print F "    if (equalIgnoringASCIICase(type, \"$eventName\"))\n";
-        print F "        return ${interfaceName}::create();\n";
+        print F "    case ${interfaceName}${suffix}InterfaceType:\n";
+        if ($factoryFunction eq "toNewlyCreated") {
+            print F "        return createWrapper<$interfaceName$suffix>(globalObject, WTFMove(impl));\n";
+        } else {
+            print F "        return toJS(state, globalObject, static_cast<$interfaceName&>(impl));\n";
+        }
         print F "#endif\n" if $conditional;
     }
 
-    print F "    return nullptr;\n";
+    print F "    }\n";
+    if ($factoryFunction eq "toNewlyCreated") {
+        print F "    return createWrapper<$namespace>(globalObject, WTFMove(impl));\n";
+    } else {
+        print F "    ASSERT_NOT_REACHED();\n";
+        print F "    return JSC::jsNull();\n";
+    }
     print F "}\n";
     print F "\n";
     print F "} // namespace WebCore\n";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to