Autogenerate Exception-downcast code in bindings
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Oct 2011 20:20:50 +0000 (20:20 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Oct 2011 20:20:50 +0000 (20:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71108

Reviewed by Eric Seidel.

This patch uses the same generated code style as we're using for Events
to generate the downcasts for the Exception types in the bindings.
This cause me to refactor more code from make_event_factory.pl into
InFilesCompiler.pm.

After this patch, some of these files and scripts are misnamed.  I'll
rename them in a followup patch.

* DerivedSources.make:
* GNUmakefile.am:
* GNUmakefile.list.am:
* WebCore.gyp/WebCore.gyp:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMBinding.cpp:
(WebCore::setDOMException):
* bindings/objc/ExceptionHandlers.mm:
(WebCore::raiseDOMException):
* bindings/scripts/InFilesCompiler.pm:
(initializeFromCommandLine):
(compile):
(interfaceForItem):
(toMacroStyle):
(generateInterfacesHeader):
(generateHeadersHeader):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::setDOMException):
* dom/ExceptionCodeDescription.in:
* dom/make_event_factory.pl:
(generateCode):
(generateImplementation):
* dom/make_exception_code_description.pl:
(defaultItemFactory):
(generateCode):

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/GNUmakefile.am
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gyp/WebCore.gyp
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/objc/ExceptionHandlers.mm
Source/WebCore/bindings/scripts/InFilesCompiler.pm
Source/WebCore/bindings/v8/V8Proxy.cpp
Source/WebCore/dom/ExceptionCodeDescription.in
Source/WebCore/dom/make_event_factory.pl
Source/WebCore/dom/make_exception_code_description.pl

index c373134..e8f98e6 100755 (executable)
@@ -1,3 +1,46 @@
+2011-10-28  Adam Barth  <abarth@webkit.org>
+
+        Autogenerate Exception-downcast code in bindings
+        https://bugs.webkit.org/show_bug.cgi?id=71108
+
+        Reviewed by Eric Seidel.
+
+        This patch uses the same generated code style as we're using for Events
+        to generate the downcasts for the Exception types in the bindings.
+        This cause me to refactor more code from make_event_factory.pl into
+        InFilesCompiler.pm.
+
+        After this patch, some of these files and scripts are misnamed.  I'll
+        rename them in a followup patch.
+
+        * DerivedSources.make:
+        * GNUmakefile.am:
+        * GNUmakefile.list.am:
+        * WebCore.gyp/WebCore.gyp:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::setDOMException):
+        * bindings/objc/ExceptionHandlers.mm:
+        (WebCore::raiseDOMException):
+        * bindings/scripts/InFilesCompiler.pm:
+        (initializeFromCommandLine):
+        (compile):
+        (interfaceForItem):
+        (toMacroStyle):
+        (generateInterfacesHeader):
+        (generateHeadersHeader):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::setDOMException):
+        * dom/ExceptionCodeDescription.in:
+        * dom/make_event_factory.pl:
+        (generateCode):
+        (generateImplementation):
+        * dom/make_exception_code_description.pl:
+        (defaultItemFactory):
+        (generateCode):
+
 2011-10-28  Simon Fraser  <simon.fraser@apple.com>
 
         Fix builds which have ACCELERATED_COMPOSITING disabled.
index 5defad1..e5d4f16 100644 (file)
@@ -857,7 +857,7 @@ EventFactory.cpp EventHeaders.h EventInterfaces.h : dom/make_event_factory.pl do
 EventTargetHeaders.h EventTargetInterfaces.h : dom/make_event_factory.pl dom/EventTargetFactory.in
        perl -I $(WebCore)/bindings/scripts $< --input $(WebCore)/dom/EventTargetFactory.in
 
-ExceptionCodeDescription.cpp ExceptionCodeDescription.h : dom/make_exception_code_description.pl dom/ExceptionCodeDescription.in
+ExceptionCodeDescription.cpp ExceptionCodeDescription.h ExceptionHeaders.h ExceptionInterfaces.h : dom/make_exception_code_description.pl dom/ExceptionCodeDescription.in
        perl -I $(WebCore)/bindings/scripts $< --input $(WebCore)/dom/ExceptionCodeDescription.in
 
 # --------
index 1c07b18..18298d1 100644 (file)
@@ -696,7 +696,7 @@ DerivedSources/WebCore/EventFactory.cpp DerivedSources/WebCore/EventHeaders.h De
 DerivedSources/WebCore/EventTargetHeaders.h DerivedSources/WebCore/EventTargetInterfaces.h: $(WebCore)/dom/make_event_factory.pl $(WebCore)/dom/EventTargetFactory.in
        $(AM_V_GEN)$(PERL) -I$(WebCore)/bindings/scripts $< --input $(WebCore)/dom/EventTargetFactory.in --outputDir "$(GENSOURCES_WEBCORE)"
 
-DerivedSources/WebCore/ExceptionCodeDescription.cpp DerivedSources/WebCore/ExceptionCodeDescription.h: $(WebCore)/dom/make_exception_code_description.pl $(WebCore)/dom/ExceptionCodeDescription.in
+DerivedSources/WebCore/ExceptionCodeDescription.cpp DerivedSources/WebCore/ExceptionCodeDescription.h DerivedSources/WebCore/ExceptionHeaders.h DerivedSources/WebCore/ExceptionInterfaces.h: $(WebCore)/dom/make_exception_code_description.pl $(WebCore)/dom/ExceptionCodeDescription.in
        $(AM_V_GEN)$(PERL) -I$(WebCore)/bindings/scripts $< --input $(WebCore)/dom/ExceptionCodeDescription.in --outputDir "$(GENSOURCES_WEBCORE)"
 
 # All Web Inspector generated files are created with this one call to CodeGeneratorInspector.py
index a890089..cfe6362 100644 (file)
@@ -15,6 +15,8 @@ webcore_built_sources += \
        DerivedSources/WebCore/EventTargetHeaders.h \
        DerivedSources/WebCore/EventTargetInterfaces.h \
        DerivedSources/WebCore/ExceptionCodeDescription.cpp \
+       DerivedSources/WebCore/ExceptionHeaders.h \
+       DerivedSources/WebCore/ExceptionInterfaces.h \
        DerivedSources/WebCore/HTMLElementFactory.cpp \
        DerivedSources/WebCore/HTMLElementFactory.h \
        DerivedSources/WebCore/HTMLEntityTable.cpp \
index 228117e..c049e2f 100644 (file)
           'outputs': [
             '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionCodeDescription.cpp',
             '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionCodeDescription.h',
+            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionHeaders.h',
+            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionInterfaces.h',
           ],
           'action': [
             'python',
index 0c5df69..5996046 100644 (file)
             '<(PRODUCT_DIR)/DerivedSources/WebCore/EventTargetInterfaces.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionCodeDescription.cpp',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionCodeDescription.h',
+            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionHeaders.h',
+            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionInterfaces.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/HTMLElementFactory.cpp',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/HTMLElementFactory.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/HTMLEntityTable.cpp',
index a99150c..497ccce 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\ExceptionHeaders.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\ExceptionInterfaces.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\HTMLElementFactory.h"
                                >
                        </File>
index 0aabd5b..dd9eff1 100644 (file)
                975CA2A21303679D00E99AD9 /* JSCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 975CA2A01303679D00E99AD9 /* JSCrypto.h */; };
                97665013144FAA4200F6BB51 /* EventFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 97665011144FAA4200F6BB51 /* EventFactory.h */; };
                9766504F144FBFFE00F6BB51 /* EventFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9766504E144FBFFE00F6BB51 /* EventFactory.cpp */; };
+               9767CE0B145ABC13005E64DB /* ExceptionHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 9767CE09145ABC12005E64DB /* ExceptionHeaders.h */; };
+               9767CE0C145ABC13005E64DB /* ExceptionInterfaces.h in Headers */ = {isa = PBXBuildFile; fileRef = 9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */; };
                976D6C77122B8A3D001FD1F7 /* AsyncFileWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */; };
                976D6C78122B8A3D001FD1F7 /* Blob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C59122B8A3D001FD1F7 /* Blob.cpp */; };
                976D6C79122B8A3D001FD1F7 /* Blob.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C5A122B8A3D001FD1F7 /* Blob.h */; };
                975CA2A01303679D00E99AD9 /* JSCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCrypto.h; sourceTree = "<group>"; };
                97665011144FAA4200F6BB51 /* EventFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventFactory.h; sourceTree = "<group>"; };
                9766504E144FBFFE00F6BB51 /* EventFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventFactory.cpp; sourceTree = "<group>"; };
+               9767CE09145ABC12005E64DB /* ExceptionHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionHeaders.h; sourceTree = "<group>"; };
+               9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionInterfaces.h; sourceTree = "<group>"; };
                976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncFileWriter.h; path = fileapi/AsyncFileWriter.h; sourceTree = "<group>"; };
                976D6C59122B8A3D001FD1F7 /* Blob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Blob.cpp; path = fileapi/Blob.cpp; sourceTree = "<group>"; };
                976D6C5A122B8A3D001FD1F7 /* Blob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Blob.h; path = fileapi/Blob.h; sourceTree = "<group>"; };
                                97AA3CA4145237CC003E1DA6 /* EventTargetInterfaces.h */,
                                973DC63D145A9409002842C2 /* ExceptionCodeDescription.cpp */,
                                973DC63E145A9409002842C2 /* ExceptionCodeDescription.h */,
+                               9767CE09145ABC12005E64DB /* ExceptionHeaders.h */,
+                               9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */,
                                A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */,
                                A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */,
                                A8BC04911214F69600B5F122 /* HTMLEntityTable.cpp */,
                                97665013144FAA4200F6BB51 /* EventFactory.h in Headers */,
                                A0EE0DF6144F825500F80B0D /* WebGLDebugRendererInfo.h in Headers */,
                                A0EE0DF8144F825500F80B0D /* WebGLDebugShaders.h in Headers */,
+                               9767CE0B145ABC13005E64DB /* ExceptionHeaders.h in Headers */,
+                               9767CE0C145ABC13005E64DB /* ExceptionInterfaces.h in Headers */,
                                973DC640145A9409002842C2 /* ExceptionCodeDescription.h in Headers */,
                                97AA3CA5145237CC003E1DA6 /* EventTargetHeaders.h in Headers */,
                                97AA3CA6145237CC003E1DA6 /* EventTargetInterfaces.h in Headers */,
index c79f017..59bd9f2 100644 (file)
 #include "config.h"
 #include "JSDOMBinding.h"
 
-#include "DOMCoreException.h"
 #include "DOMObjectHashTableMap.h"
-#include "EventException.h"
-#include "ExceptionBase.h"
 #include "ExceptionCode.h"
-#include "FileException.h"
+#include "ExceptionHeaders.h"
+#include "ExceptionInterfaces.h"
 #include "Frame.h"
-#include "IDBDatabaseException.h"
-#include "JSDOMCoreException.h"
 #include "JSDOMWindowCustom.h"
-#include "JSEventException.h"
 #include "JSExceptionBase.h"
-#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
-#include "JSFileException.h"
-#include "JSOperationNotAllowedException.h"
-#endif
-#include "JSRangeException.h"
-#if ENABLE(SQL_DATABASE)
-#include "JSSQLException.h"
-#endif
-#if ENABLE(SVG)
-#include "JSSVGException.h"
-#endif
-#include "JSXMLHttpRequestException.h"
-#include "JSXPathException.h"
-#include "OperationNotAllowedException.h"
-#include "RangeException.h"
-#include "SQLException.h"
-#include "SVGException.h"
 #include "ScriptCallStack.h"
-#include "XMLHttpRequestException.h"
-#include "XPathException.h"
 #include <runtime/DateInstance.h>
 #include <runtime/Error.h>
 #include <runtime/ExceptionHelpers.h>
@@ -199,6 +175,11 @@ void reportCurrentException(ExecState* exec)
     reportException(exec, exception);
 }
 
+#define TRY_TO_CREATE_EXCEPTION(interfaceName) \
+    case interfaceName##Type: \
+        errorObject = toJS(exec, globalObject, interfaceName::create(description)); \
+        break;
+
 void setDOMException(ExecState* exec, ExceptionCode ec)
 {
     if (!ec || exec->hadException())
@@ -213,50 +194,15 @@ void setDOMException(ExecState* exec, ExceptionCode ec)
 
     JSValue errorObject;
     switch (description.type) {
-        case DOMCoreExceptionType:
-            errorObject = toJS(exec, globalObject, DOMCoreException::create(description));
-            break;
-        case RangeExceptionType:
-            errorObject = toJS(exec, globalObject, RangeException::create(description));
-            break;
-        case EventExceptionType:
-            errorObject = toJS(exec, globalObject, EventException::create(description));
-            break;
-        case XMLHttpRequestExceptionType:
-            errorObject = toJS(exec, globalObject, XMLHttpRequestException::create(description));
-            break;
-#if ENABLE(SVG)
-        case SVGExceptionType:
-            errorObject = toJS(exec, globalObject, SVGException::create(description).get());
-            break;
-#endif
-        case XPathExceptionType:
-            errorObject = toJS(exec, globalObject, XPathException::create(description));
-            break;
-#if ENABLE(SQL_DATABASE)
-        case SQLExceptionType:
-            errorObject = toJS(exec, globalObject, SQLException::create(description));
-            break;
-#endif
-#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
-        case FileExceptionType:
-            errorObject = toJS(exec, globalObject, FileException::create(description));
-            break;
-        case OperationNotAllowedExceptionType:
-            errorObject = toJS(exec, globalObject, OperationNotAllowedException::create(description));
-            break;
-#endif
-#if ENABLE(INDEXED_DATABASE)
-        case IDBDatabaseExceptionType:
-            errorObject = toJS(exec, globalObject, IDBDatabaseException::create(description));
-            break;
-#endif
+        DOM_EXCEPTION_INTERFACES_FOR_EACH(TRY_TO_CREATE_EXCEPTION)
     }
 
     ASSERT(errorObject);
     throwError(exec, errorObject);
 }
 
+#undef TRY_TO_CREATE_EXCEPTION
+
 DOMWindow* activeDOMWindow(ExecState* exec)
 {
     return asJSDOMWindow(exec->lexicalGlobalObject())->impl();
index 79465aa..403ad9b 100644 (file)
@@ -46,6 +46,7 @@ void raiseDOMException(ExceptionCode ec)
     ExceptionCodeDescription description(ec);
 
     NSString *exceptionName;
+    // FIXME: We can use the enum to do these comparisons faster.
     if (strcmp(description.typeName, "DOM Range") == 0)
         exceptionName = DOMRangeException;
     else if (strcmp(description.typeName, "DOM Events") == 0)
index ecbccc4..e126068 100644 (file)
 
 use strict;
 
+use Config;
+use Getopt::Long;
+use File::Path;
+use File::Spec;
 use IO::File;
 use InFilesParser;
 
+require Config;
+
 package InFilesCompiler;
 
+my $inputFile = "";
+my $outputDir = ".";
 my $defaultItemFactory;
 
 my %parsedItems;
@@ -71,11 +79,24 @@ sub new()
     return $reference;
 }
 
+sub initializeFromCommandLine()
+{
+    ::GetOptions(
+        'input=s' => \$inputFile,
+        'outputDir=s' => \$outputDir,
+    );
+
+    die "You must specify --input <file>" unless length($inputFile);
+
+    ::mkpath($outputDir);
+
+    # FIXME: Should we provide outputDir via an accessor?
+    return $outputDir;
+}
+
 sub compile()
 {
     my $object = shift;
-
-    my $inputFile = shift;
     my $generateCode = shift;
 
     my $file = new IO::File;
@@ -122,4 +143,135 @@ sub license()
 ";
 }
 
+sub interfaceForItem($)
+{
+    my $object = shift;
+    my $itemName = shift;
+
+    my $interfaceName = $parsedItems{$itemName}{"interfaceName"};
+    $interfaceName = $itemName unless $interfaceName;
+
+    return $interfaceName;
+}
+
+sub toMacroStyle($$)
+{
+    my $object = shift;
+    my $camelCase = shift;
+
+    return "EVENT" if $camelCase eq "Event";
+    return "EVENT_TARGET" if $camelCase eq "EventTarget";
+    return "EXCEPTION" if $camelCase eq "Exception";
+
+    die "Ok, you got me. This script is really just a giant hack. (\$camelCase=${camelCase})";
+}
+
+sub generateInterfacesHeader()
+{
+    my $object = shift;
+
+    my $F;
+    my $namespace = $parsedParameters{"namespace"};
+    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 "\n";
+
+    my %unconditionalInterfaces = ();
+    my %interfacesByConditional = ();
+
+    for my $itemName (sort keys %parsedItems) {
+        my $conditional = $parsedItems{$itemName}{"conditional"};
+        my $interfaceName = $object->interfaceForItem($itemName);
+
+        if ($conditional) {
+            if (!defined($interfacesByConditional{$conditional})) {
+                $interfacesByConditional{$conditional} = ();
+            }
+            $interfacesByConditional{$conditional}{$interfaceName} = 1;
+        } else {
+            $unconditionalInterfaces{$interfaceName} = 1
+        }
+    }
+
+    my $macroStyledNamespace = $object->toMacroStyle($namespace);
+
+    for my $conditional (sort keys %interfacesByConditional) {
+        print F "#if ENABLE($conditional)\n";
+        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
+
+        for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) {
+            next if defined($unconditionalInterfaces{$interface});
+            print F "    macro($interface) \\\n";
+        }
+
+        print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional\n";
+        print F "#else\n";
+        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(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) {
+        print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
+    }
+
+    print F "\n";
+    print F "#endif // ${namespace}Interfaces_h\n";
+
+    close F;
+}
+
+sub generateHeadersHeader()
+{
+    my $object = shift;
+
+    my $F;
+    my $namespace = $parsedParameters{"namespace"};
+    my $outputFile = "$outputDir/${namespace}Headers.h";
+
+    open F, ">$outputFile" or die "Failed to open file: $!";
+
+    print F license();
+
+    print F "#ifndef ${namespace}Headers_h\n";
+    print F "#define ${namespace}Headers_h\n";
+    print F "\n";
+
+    my %includedInterfaces = ();
+
+    for my $itemName (sort keys %parsedItems) {
+        my $conditional = $parsedItems{$itemName}{"conditional"};
+        my $interfaceName = $object->interfaceForItem($itemName);
+
+        next if defined($includedInterfaces{$interfaceName});
+        $includedInterfaces{$interfaceName} = 1;
+
+        print F "#if ENABLE($conditional)\n" if $conditional;
+        print F "#include \"$interfaceName.h\"\n";
+        print F "#if USE(JSC)\n";
+        print F "#include \"JS$interfaceName.h\"\n";
+        print F "#elif USE(V8)\n";
+        print F "#include \"V8$interfaceName.h\"\n";
+        print F "#endif\n";
+        print F "#endif\n" if $conditional;
+    }
+
+    print F "\n";
+    print F "#endif // ${namespace}Headers_h\n";
+
+    close F;
+}
+
 1;
index 9e645fb..f61bd9f 100644 (file)
 #include "DateExtension.h"
 #include "Document.h"
 #include "DocumentLoader.h"
+#include "ExceptionHeaders.h"
+#include "ExceptionInterfaces.h"
 #include "Frame.h"
 #include "FrameLoaderClient.h"
-#include "IDBDatabaseException.h"
 #include "IDBFactoryBackendInterface.h"
 #include "IDBPendingTransactionMonitor.h"
 #include "InspectorInstrumentation.h"
 #include "V8DOMCoreException.h"
 #include "V8DOMMap.h"
 #include "V8DOMWindow.h"
-#include "V8EventException.h"
-#include "V8FileException.h"
 #include "V8HiddenPropertyName.h"
 #include "V8IsolatedContext.h"
-#include "V8OperationNotAllowedException.h"
-#include "V8RangeException.h"
-#include "V8SQLException.h"
-#include "V8XMLHttpRequestException.h"
-#include "V8XPathException.h"
 #include "WebKitMutationObserver.h"
 #include "WorkerContext.h"
 #include "WorkerContextExecutionProxy.h"
 
-#if ENABLE(INDEXED_DATABASE)
-#include "V8IDBDatabaseException.h"
-#endif
-
-#if ENABLE(SVG)
-#include "V8SVGException.h"
-#endif
-
 #include <algorithm>
 #include <stdio.h>
 #include <utility>
@@ -649,6 +635,11 @@ void V8Proxy::clearForNavigation()
     windowShell()->clearForNavigation();
 }
 
+#define TRY_TO_CREATE_EXCEPTION(interfaceName) \
+    case interfaceName##Type: \
+        exception = toV8(interfaceName::create(description)); \
+        break;
+
 void V8Proxy::setDOMException(int ec)
 {
     if (ec <= 0)
@@ -658,52 +649,15 @@ void V8Proxy::setDOMException(int ec)
 
     v8::Handle<v8::Value> exception;
     switch (description.type) {
-    case DOMCoreExceptionType:
-        exception = toV8(DOMCoreException::create(description));
-        break;
-    case RangeExceptionType:
-        exception = toV8(RangeException::create(description));
-        break;
-    case EventExceptionType:
-        exception = toV8(EventException::create(description));
-        break;
-    case XMLHttpRequestExceptionType:
-        exception = toV8(XMLHttpRequestException::create(description));
-        break;
-#if ENABLE(SVG)
-    case SVGExceptionType:
-        exception = toV8(SVGException::create(description));
-        break;
-#endif
-    case XPathExceptionType:
-        exception = toV8(XPathException::create(description));
-        break;
-#if ENABLE(SQL_DATABASE)
-    case SQLExceptionType:
-        exception = toV8(SQLException::create(description));
-        break;
-#endif
-#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
-    case FileExceptionType:
-        exception = toV8(FileException::create(description));
-        break;
-    case OperationNotAllowedExceptionType:
-        exception = toV8(OperationNotAllowedException::create(description));
-        break;
-#endif
-#if ENABLE(INDEXED_DATABASE)
-    case IDBDatabaseExceptionType:
-        exception = toV8(IDBDatabaseException::create(description));
-        break;
-#endif
-    default:
-        ASSERT_NOT_REACHED();
+        DOM_EXCEPTION_INTERFACES_FOR_EACH(TRY_TO_CREATE_EXCEPTION)
     }
 
     if (!exception.IsEmpty())
         v8::ThrowException(exception);
 }
 
+#undef TRY_TO_CREATE_EXCEPTION
+
 v8::Handle<v8::Value> V8Proxy::throwError(ErrorType type, const char* message)
 {
     switch (type) {
index 8c7497e..f5c06aa 100644 (file)
@@ -1,4 +1,4 @@
-namespace=ExceptionCodeDescription
+namespace=Exception
 
 DOMCoreException
 EventException
index 18d02f4..db6a934 100644 (file)
 
 use strict;
 
-use Config;
-use Getopt::Long;
-use File::Path;
-use File::Spec;
-use IO::File;
 use InFilesCompiler;
 
-require Config;
-
-my $inputFile = "";
-my $outputDir = ".";
-
-GetOptions(
-    'input=s' => \$inputFile,
-    'outputDir=s' => \$outputDir,
-);
-
-mkpath($outputDir);
-
-die "You must specify --input <file>" unless length($inputFile);
-
 my %defaultParameters = (
     'namespace' => 0
 );
 
-my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
-
-$InCompiler->compile($inputFile, \&generateCode);
-
 sub defaultItemFactory
 {
     return (
@@ -69,39 +46,22 @@ sub defaultItemFactory
     );
 }
 
-sub interfaceForEvent($$)
-{
-    my ($eventName, $parsedItemsRef) = @_;
-
-    my %parsedItems = %{ $parsedItemsRef };
-
-    my $interfaceName = $parsedItems{$eventName}{"interfaceName"};
-    $interfaceName = $eventName unless $interfaceName;
-
-    return $interfaceName;
-}
-
-sub toMacroStyle($)
-{
-    my ($camelCase) = @_;
-
-    return "EVENT" if $camelCase eq "Event";
-    return "EVENT_TARGET" if $camelCase eq "EventTarget";
+my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
 
-    die "Ok, you got me. This script is really just a giant hack. (\$camelCase=${camelCase})";
-}
+my $outputDir = $InCompiler->initializeFromCommandLine();
+$InCompiler->compile(\&generateCode);
 
 sub generateCode()
 {
     my $parsedParametersRef = shift;
     my $parsedItemsRef = shift;
 
-    printFactoryFile($parsedParametersRef, $parsedItemsRef);
-    printMacroFile($parsedParametersRef, $parsedItemsRef);
-    printHeadersFile($parsedParametersRef, $parsedItemsRef);
+    generateImplementation($parsedParametersRef, $parsedItemsRef);
+    $InCompiler->generateInterfacesHeader();
+    $InCompiler->generateHeadersHeader()
 }
 
-sub printFactoryFile()
+sub generateImplementation()
 {
     my $parsedParametersRef = shift;
     my $parsedItemsRef = shift;
@@ -133,7 +93,7 @@ sub printFactoryFile()
 
     for my $eventName (sort keys %parsedEvents) {
         my $conditional = $parsedEvents{$eventName}{"conditional"};
-        my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
+        my $interfaceName = $InCompiler->interfaceForItem($eventName);
 
         print F "#if ENABLE($conditional)\n" if $conditional;
         print F "    if (type == \"$eventName\")\n";
@@ -148,121 +108,3 @@ sub printFactoryFile()
 
     close F;
 }
-
-sub printMacroFile()
-{
-    my $parsedParametersRef = shift;
-    my $parsedItemsRef = shift;
-
-    my $F;
-    my %parsedEvents = %{ $parsedItemsRef };
-    my %parsedParameters = %{ $parsedParametersRef };
-
-    my $namespace = $parsedParameters{"namespace"};
-
-    my $outputFile = "$outputDir/${namespace}Interfaces.h";
-
-    open F, ">$outputFile" or die "Failed to open file: $!";
-
-    print F $InCompiler->license();
-
-    print F "#ifndef ${namespace}Interfaces_h\n";
-    print F "#define ${namespace}Interfaces_h\n";
-    print F "\n";
-
-    my %unconditionalInterfaces = ();
-    my %interfacesByConditional = ();
-
-    for my $eventName (sort keys %parsedEvents) {
-        my $conditional = $parsedEvents{$eventName}{"conditional"};
-        my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
-
-        if ($conditional) {
-            if (!defined($interfacesByConditional{$conditional})) {
-                $interfacesByConditional{$conditional} = ();
-            }
-            $interfacesByConditional{$conditional}{$interfaceName} = 1;
-        } else {
-            $unconditionalInterfaces{$interfaceName} = 1
-        }
-    }
-
-    my $macroStyledNamespace = toMacroStyle($namespace);
-
-    for my $conditional (sort keys %interfacesByConditional) {
-        print F "#if ENABLE($conditional)\n";
-        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
-
-        for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) {
-            next if defined($unconditionalInterfaces{$interface});
-            print F "    macro($interface) \\\n";
-        }
-
-        print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional\n";
-        print F "#else\n";
-        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(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) {
-        print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
-    }
-
-    print F "\n";
-    print F "#endif // ${namespace}Interfaces_h\n";
-
-    close F;
-}
-
-sub printHeadersFile()
-{
-    my $parsedParametersRef = shift;
-    my $parsedItemsRef = shift;
-
-    my $F;
-    my %parsedEvents = %{ $parsedItemsRef };
-    my %parsedParameters = %{ $parsedParametersRef };
-
-    my $namespace = $parsedParameters{"namespace"};
-
-    my $outputFile = "$outputDir/${namespace}Headers.h";
-
-    open F, ">$outputFile" or die "Failed to open file: $!";
-
-    print F $InCompiler->license();
-
-    print F "#ifndef ${namespace}Headers_h\n";
-    print F "#define ${namespace}Headers_h\n";
-    print F "\n";
-
-    my %includedInterfaces = ();
-
-    for my $eventName (sort keys %parsedEvents) {
-        my $conditional = $parsedEvents{$eventName}{"conditional"};
-        my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
-
-        next if defined($includedInterfaces{$interfaceName});
-        $includedInterfaces{$interfaceName} = 1;
-
-        print F "#if ENABLE($conditional)\n" if $conditional;
-        print F "#include \"$interfaceName.h\"\n";
-        print F "#if USE(JSC)\n";
-        print F "#include \"JS$interfaceName.h\"\n";
-        print F "#elif USE(V8)\n";
-        print F "#include \"V8$interfaceName.h\"\n";
-        print F "#endif\n";
-        print F "#endif\n" if $conditional;
-    }
-
-    print F "\n";
-    print F "#endif // ${namespace}Headers_h\n";
-
-    close F;
-}
index cbda381..ed3c848 100644 (file)
 
 use strict;
 
-use Config;
-use Getopt::Long;
-use File::Path;
-use File::Spec;
-use IO::File;
 use InFilesCompiler;
 
-require Config;
-
-my $inputFile;
-my $outputDir = ".";
-
-GetOptions(
-    'input=s' => \$inputFile,
-    'outputDir=s' => \$outputDir,
-);
-
-mkpath($outputDir);
-
-die "You must specify --input <file>" unless length($inputFile);
-
 my %defaultParameters = (
     'namespace' => 0
 );
 
-my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
-
-$InCompiler->compile($inputFile, \&generateCode);
-
 sub defaultItemFactory
 {
     return (
+        'interfaceName' => 0,
         'conditional' => 0
     );
 }
 
+my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
+
+my $outputDir = $InCompiler->initializeFromCommandLine();
+$InCompiler->compile(\&generateCode);
+
 sub generateCode()
 {
-    my $parsedParameters = shift;
-    my $parsedItems = shift;
+    my $parsedParametersRef = shift;
+    my $parsedItemsRef = shift;
 
-    generateHeader($parsedParameters, $parsedItems);
-    generateImplementation($parsedParameters, $parsedItems);
+    generateHeader($parsedParametersRef, $parsedItemsRef);
+    generateImplementation($parsedParametersRef, $parsedItemsRef);
+    $InCompiler->generateInterfacesHeader();
+    $InCompiler->generateHeadersHeader()
 }
 
 sub generateHeader()