Generate event and event target interface types directly instead of via macros
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jul 2018 22:54:32 +0000 (22:54 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jul 2018 22:54:32 +0000 (22:54 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233443 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/WebCoreMacros.cmake
Source/WebCore/bindings/js/JSEventCustom.cpp
Source/WebCore/bindings/js/JSEventTargetCustom.cpp
Source/WebCore/bindings/scripts/InFilesCompiler.pm
Source/WebCore/dom/Event.h
Source/WebCore/dom/EventNames.in
Source/WebCore/dom/EventTarget.h
Source/WebCore/dom/EventTargetFactory.in
Source/WebCore/dom/make_event_factory.pl
jstests/stress/instanceof-non-object-prototype.js [deleted file]

index a3a19ce..7150680 100644 (file)
@@ -1896,12 +1896,14 @@ GENERATE_DOM_NAMES(HTML ${WEBCORE_DIR}/html/HTMLAttributeNames.in ${WEBCORE_DIR}
 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)
index d9cc7f5..956e62e 100644 (file)
@@ -1,3 +1,41 @@
+2018-06-29  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <zalan@apple.com>
 
         HTML widget displays blank when playing on page
index 239f1ae..3d3e93c 100644 (file)
@@ -1396,8 +1396,8 @@ EventFactory%cpp EventHeaders%h EventInterfaces%h : dom/make_event_factory.pl $(
 
 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, $^))
 
 # --------
index 4a89af8..b423c7b 100644 (file)
@@ -2361,6 +2361,8 @@ xml/parser/XMLDocumentParserScope.cpp
 
 CSSValueKeywords.cpp
 ColorData.cpp
+EventFactory.cpp
+EventTargetFactory.cpp
 HTMLElementFactory.cpp
 HTMLEntityTable.cpp
 MathMLElementFactory.cpp
index c45a450..ae619b4 100644 (file)
                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>"; };
                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>"; };
                                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 */,
index 78d5845..2b49e84 100644 (file)
@@ -159,11 +159,12 @@ macro(GENERATE_FONT_NAMES _infile)
 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}
index e2e5d15..87199eb 100644 (file)
 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);
index f5f737e..6295f58 100644 (file)
 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))
index f42bdd3..909e8be 100644 (file)
@@ -193,14 +193,14 @@ sub generateInterfacesHeader()
 
     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: $!";
 
     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 @@ sub generateInterfacesHeader()
 
     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 "    \\\n";
-    for my $conditional (sort keys %interfacesByConditional) {
-        my $preferredConditional = $object->preferredConditional($conditional);
-        print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro) \\\n";
+        print F "    ${interface}${suffix} = $count,\n";
+        $count++;
     }
 
+    print F "};\n";
     print F "\n";
-    print F "#endif // ${namespace}Interfaces_h\n";
+    print F "} // namespace WebCore\n";
 
     close F;
 }
index 5e56ac5..0409d30 100644 (file)
@@ -38,14 +38,6 @@ class EventPath;
 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 };
index bc92e05..39a1b0e 100644 (file)
@@ -1,4 +1,6 @@
 namespace="Event"
+factoryFunction=toNewlyCreated
+useNamespaceAsSuffix=false
 
 Event
 Events interfaceName=Event
index 90b122a..a3e9a47 100644 (file)
@@ -50,14 +50,6 @@ public:
     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(); }
index a8144d8..3ad9c32 100644 (file)
@@ -1,4 +1,6 @@
 namespace="EventTarget"
+factoryFunction=toJS
+useNamespaceAsSuffix=true
 
 AbortSignal
 ApplePaySession conditional=APPLE_PAY
index 273ab87..96c2d0f 100644 (file)
@@ -38,7 +38,9 @@ use lib "$FindBin::Bin/../bindings/scripts";
 use InFilesCompiler;
 
 my %defaultParameters = (
-    'namespace' => 0
+    'namespace' => 0,
+    'factoryFunction' => 0,
+    'useNamespaceAsSuffix' => 0,
 );
 
 sub defaultItemFactory
@@ -62,7 +64,7 @@ sub generateCode()
 
     generateImplementation($parsedParametersRef, $parsedItemsRef);
     $InCompiler->generateInterfacesHeader();
-    $InCompiler->generateHeadersHeader()
+    $InCompiler->generateHeadersHeader();
 }
 
 sub generateImplementation()
@@ -74,43 +76,72 @@ sub generateImplementation()
     my %parsedParameters = %{ $parsedParametersRef };
 
     my $namespace = $parsedParameters{"namespace"};
-
-    # Currently, only Events have factory files.
-    return if $namespace ne "Event";
+    my $factoryFunction = $parsedParameters{"factoryFunction"};
+    ($factoryFunction eq "toJS" or $factoryFunction eq "toNewlyCreated") or die "factoryFunction should be either toJS or toNewlyCreated";
+    my $useNamespaceAsSuffix = $parsedParameters{"useNamespaceAsSuffix"};
 
     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 "\n";
     print F "#include \"${namespace}Headers.h\"\n";
+    print F "\n";
+    print F "#include \"JSDOMGlobalObject.h\"\n";
     print F "#include <JavaScriptCore/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);
 
-        # FIXME: This should pay attention to $runtimeConditional so it can support RuntimeEnabledFeatures.
+        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";
diff --git a/jstests/stress/instanceof-non-object-prototype.js b/jstests/stress/instanceof-non-object-prototype.js
deleted file mode 100644 (file)
index a43bd57..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-let base = "sting";
-let constructor = function() { };
-constructor.prototype = 42;
-
-function test(a, b) {
-    return a instanceof b;
-}
-noInline(test);
-
-for (let i = 0; i < 10000; i++) {
-    let exception;
-    try {
-        var result = test(base, constructor);
-    } catch (e) {
-        exception = e;
-    }
-    if (exception)
-        throw new Error("Threw an exception: " + exception);
-    if (result !== false)
-        throw new Error("instanceof returned: " + result);
-}