⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 98755 in webkit


Ignore:
Timestamp:
Oct 28, 2011, 1:20:50 PM (15 years ago)
Author:
abarth@webkit.org
Message:

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):

Location:
trunk/Source/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r98752 r98755  
     12011-10-28  Adam Barth  <abarth@webkit.org>
     2
     3        Autogenerate Exception-downcast code in bindings
     4        https://bugs.webkit.org/show_bug.cgi?id=71108
     5
     6        Reviewed by Eric Seidel.
     7
     8        This patch uses the same generated code style as we're using for Events
     9        to generate the downcasts for the Exception types in the bindings.
     10        This cause me to refactor more code from make_event_factory.pl into
     11        InFilesCompiler.pm.
     12
     13        After this patch, some of these files and scripts are misnamed.  I'll
     14        rename them in a followup patch.
     15
     16        * DerivedSources.make:
     17        * GNUmakefile.am:
     18        * GNUmakefile.list.am:
     19        * WebCore.gyp/WebCore.gyp:
     20        * WebCore.gypi:
     21        * WebCore.vcproj/WebCore.vcproj:
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * bindings/js/JSDOMBinding.cpp:
     24        (WebCore::setDOMException):
     25        * bindings/objc/ExceptionHandlers.mm:
     26        (WebCore::raiseDOMException):
     27        * bindings/scripts/InFilesCompiler.pm:
     28        (initializeFromCommandLine):
     29        (compile):
     30        (interfaceForItem):
     31        (toMacroStyle):
     32        (generateInterfacesHeader):
     33        (generateHeadersHeader):
     34        * bindings/v8/V8Proxy.cpp:
     35        (WebCore::V8Proxy::setDOMException):
     36        * dom/ExceptionCodeDescription.in:
     37        * dom/make_event_factory.pl:
     38        (generateCode):
     39        (generateImplementation):
     40        * dom/make_exception_code_description.pl:
     41        (defaultItemFactory):
     42        (generateCode):
     43
    1442011-10-28  Simon Fraser  <simon.fraser@apple.com>
    245
  • trunk/Source/WebCore/DerivedSources.make

    r98711 r98755  
    858858        perl -I $(WebCore)/bindings/scripts $< --input $(WebCore)/dom/EventTargetFactory.in
    859859
    860 ExceptionCodeDescription.cpp ExceptionCodeDescription.h : dom/make_exception_code_description.pl dom/ExceptionCodeDescription.in
     860ExceptionCodeDescription.cpp ExceptionCodeDescription.h ExceptionHeaders.h ExceptionInterfaces.h : dom/make_exception_code_description.pl dom/ExceptionCodeDescription.in
    861861        perl -I $(WebCore)/bindings/scripts $< --input $(WebCore)/dom/ExceptionCodeDescription.in
    862862
  • trunk/Source/WebCore/GNUmakefile.am

    r98711 r98755  
    697697        $(AM_V_GEN)$(PERL) -I$(WebCore)/bindings/scripts $< --input $(WebCore)/dom/EventTargetFactory.in --outputDir "$(GENSOURCES_WEBCORE)"
    698698
    699 DerivedSources/WebCore/ExceptionCodeDescription.cpp DerivedSources/WebCore/ExceptionCodeDescription.h: $(WebCore)/dom/make_exception_code_description.pl $(WebCore)/dom/ExceptionCodeDescription.in
     699DerivedSources/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
    700700        $(AM_V_GEN)$(PERL) -I$(WebCore)/bindings/scripts $< --input $(WebCore)/dom/ExceptionCodeDescription.in --outputDir "$(GENSOURCES_WEBCORE)"
    701701
  • trunk/Source/WebCore/GNUmakefile.list.am

    r98711 r98755  
    1616        DerivedSources/WebCore/EventTargetInterfaces.h \
    1717        DerivedSources/WebCore/ExceptionCodeDescription.cpp \
     18        DerivedSources/WebCore/ExceptionHeaders.h \
     19        DerivedSources/WebCore/ExceptionInterfaces.h \
    1820        DerivedSources/WebCore/HTMLElementFactory.cpp \
    1921        DerivedSources/WebCore/HTMLElementFactory.h \
  • trunk/Source/WebCore/WebCore.gyp/WebCore.gyp

    r98711 r98755  
    705705            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionCodeDescription.cpp',
    706706            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionCodeDescription.h',
     707            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionHeaders.h',
     708            '<(SHARED_INTERMEDIATE_DIR)/webkit/ExceptionInterfaces.h',
    707709          ],
    708710          'action': [
  • trunk/Source/WebCore/WebCore.gypi

    r98711 r98755  
    70827082            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionCodeDescription.cpp',
    70837083            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionCodeDescription.h',
     7084            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionHeaders.h',
     7085            '<(PRODUCT_DIR)/DerivedSources/WebCore/ExceptionInterfaces.h',
    70847086            '<(PRODUCT_DIR)/DerivedSources/WebCore/HTMLElementFactory.cpp',
    70857087            '<(PRODUCT_DIR)/DerivedSources/WebCore/HTMLElementFactory.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r98711 r98755  
    571571                        </File>
    572572                        <File
     573                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\ExceptionHeaders.h"
     574                                >
     575                        </File>
     576                        <File
     577                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\ExceptionInterfaces.h"
     578                                >
     579                        </File>
     580                        <File
    573581                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\HTMLElementFactory.h"
    574582                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r98720 r98755  
    32123212                97665013144FAA4200F6BB51 /* EventFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 97665011144FAA4200F6BB51 /* EventFactory.h */; };
    32133213                9766504F144FBFFE00F6BB51 /* EventFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9766504E144FBFFE00F6BB51 /* EventFactory.cpp */; };
     3214                9767CE0B145ABC13005E64DB /* ExceptionHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 9767CE09145ABC12005E64DB /* ExceptionHeaders.h */; };
     3215                9767CE0C145ABC13005E64DB /* ExceptionInterfaces.h in Headers */ = {isa = PBXBuildFile; fileRef = 9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */; };
    32143216                976D6C77122B8A3D001FD1F7 /* AsyncFileWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */; };
    32153217                976D6C78122B8A3D001FD1F7 /* Blob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C59122B8A3D001FD1F7 /* Blob.cpp */; };
     
    1035710359                97665011144FAA4200F6BB51 /* EventFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventFactory.h; sourceTree = "<group>"; };
    1035810360                9766504E144FBFFE00F6BB51 /* EventFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventFactory.cpp; sourceTree = "<group>"; };
     10361                9767CE09145ABC12005E64DB /* ExceptionHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionHeaders.h; sourceTree = "<group>"; };
     10362                9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionInterfaces.h; sourceTree = "<group>"; };
    1035910363                976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncFileWriter.h; path = fileapi/AsyncFileWriter.h; sourceTree = "<group>"; };
    1036010364                976D6C59122B8A3D001FD1F7 /* Blob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Blob.cpp; path = fileapi/Blob.cpp; sourceTree = "<group>"; };
     
    1518615190                                973DC63D145A9409002842C2 /* ExceptionCodeDescription.cpp */,
    1518715191                                973DC63E145A9409002842C2 /* ExceptionCodeDescription.h */,
     15192                                9767CE09145ABC12005E64DB /* ExceptionHeaders.h */,
     15193                                9767CE0A145ABC13005E64DB /* ExceptionInterfaces.h */,
    1518815194                                A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */,
    1518915195                                A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */,
     
    2453024536                                A0EE0DF6144F825500F80B0D /* WebGLDebugRendererInfo.h in Headers */,
    2453124537                                A0EE0DF8144F825500F80B0D /* WebGLDebugShaders.h in Headers */,
     24538                                9767CE0B145ABC13005E64DB /* ExceptionHeaders.h in Headers */,
     24539                                9767CE0C145ABC13005E64DB /* ExceptionInterfaces.h in Headers */,
    2453224540                                973DC640145A9409002842C2 /* ExceptionCodeDescription.h in Headers */,
    2453324541                                97AA3CA5145237CC003E1DA6 /* EventTargetHeaders.h in Headers */,
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp

    r98715 r98755  
    2222#include "JSDOMBinding.h"
    2323
    24 #include "DOMCoreException.h"
    2524#include "DOMObjectHashTableMap.h"
    26 #include "EventException.h"
    27 #include "ExceptionBase.h"
    2825#include "ExceptionCode.h"
    29 #include "FileException.h"
     26#include "ExceptionHeaders.h"
     27#include "ExceptionInterfaces.h"
    3028#include "Frame.h"
    31 #include "IDBDatabaseException.h"
    32 #include "JSDOMCoreException.h"
    3329#include "JSDOMWindowCustom.h"
    34 #include "JSEventException.h"
    3530#include "JSExceptionBase.h"
    36 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
    37 #include "JSFileException.h"
    38 #include "JSOperationNotAllowedException.h"
    39 #endif
    40 #include "JSRangeException.h"
    41 #if ENABLE(SQL_DATABASE)
    42 #include "JSSQLException.h"
    43 #endif
    44 #if ENABLE(SVG)
    45 #include "JSSVGException.h"
    46 #endif
    47 #include "JSXMLHttpRequestException.h"
    48 #include "JSXPathException.h"
    49 #include "OperationNotAllowedException.h"
    50 #include "RangeException.h"
    51 #include "SQLException.h"
    52 #include "SVGException.h"
    5331#include "ScriptCallStack.h"
    54 #include "XMLHttpRequestException.h"
    55 #include "XPathException.h"
    5632#include <runtime/DateInstance.h>
    5733#include <runtime/Error.h>
     
    200176}
    201177
     178#define TRY_TO_CREATE_EXCEPTION(interfaceName) \
     179    case interfaceName##Type: \
     180        errorObject = toJS(exec, globalObject, interfaceName::create(description)); \
     181        break;
     182
    202183void setDOMException(ExecState* exec, ExceptionCode ec)
    203184{
     
    214195    JSValue errorObject;
    215196    switch (description.type) {
    216         case DOMCoreExceptionType:
    217             errorObject = toJS(exec, globalObject, DOMCoreException::create(description));
    218             break;
    219         case RangeExceptionType:
    220             errorObject = toJS(exec, globalObject, RangeException::create(description));
    221             break;
    222         case EventExceptionType:
    223             errorObject = toJS(exec, globalObject, EventException::create(description));
    224             break;
    225         case XMLHttpRequestExceptionType:
    226             errorObject = toJS(exec, globalObject, XMLHttpRequestException::create(description));
    227             break;
    228 #if ENABLE(SVG)
    229         case SVGExceptionType:
    230             errorObject = toJS(exec, globalObject, SVGException::create(description).get());
    231             break;
    232 #endif
    233         case XPathExceptionType:
    234             errorObject = toJS(exec, globalObject, XPathException::create(description));
    235             break;
    236 #if ENABLE(SQL_DATABASE)
    237         case SQLExceptionType:
    238             errorObject = toJS(exec, globalObject, SQLException::create(description));
    239             break;
    240 #endif
    241 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
    242         case FileExceptionType:
    243             errorObject = toJS(exec, globalObject, FileException::create(description));
    244             break;
    245         case OperationNotAllowedExceptionType:
    246             errorObject = toJS(exec, globalObject, OperationNotAllowedException::create(description));
    247             break;
    248 #endif
    249 #if ENABLE(INDEXED_DATABASE)
    250         case IDBDatabaseExceptionType:
    251             errorObject = toJS(exec, globalObject, IDBDatabaseException::create(description));
    252             break;
    253 #endif
     197        DOM_EXCEPTION_INTERFACES_FOR_EACH(TRY_TO_CREATE_EXCEPTION)
    254198    }
    255199
     
    257201    throwError(exec, errorObject);
    258202}
     203
     204#undef TRY_TO_CREATE_EXCEPTION
    259205
    260206DOMWindow* activeDOMWindow(ExecState* exec)
  • trunk/Source/WebCore/bindings/objc/ExceptionHandlers.mm

    r98715 r98755  
    4747
    4848    NSString *exceptionName;
     49    // FIXME: We can use the enum to do these comparisons faster.
    4950    if (strcmp(description.typeName, "DOM Range") == 0)
    5051        exceptionName = DOMRangeException;
  • trunk/Source/WebCore/bindings/scripts/InFilesCompiler.pm

    r98704 r98755  
    2727use strict;
    2828
     29use Config;
     30use Getopt::Long;
     31use File::Path;
     32use File::Spec;
    2933use IO::File;
    3034use InFilesParser;
    3135
     36require Config;
     37
    3238package InFilesCompiler;
    3339
     40my $inputFile = "";
     41my $outputDir = ".";
    3442my $defaultItemFactory;
    3543
     
    7280}
    7381
     82sub initializeFromCommandLine()
     83{
     84    ::GetOptions(
     85        'input=s' => \$inputFile,
     86        'outputDir=s' => \$outputDir,
     87    );
     88
     89    die "You must specify --input <file>" unless length($inputFile);
     90
     91    ::mkpath($outputDir);
     92
     93    # FIXME: Should we provide outputDir via an accessor?
     94    return $outputDir;
     95}
     96
    7497sub compile()
    7598{
    7699    my $object = shift;
    77 
    78     my $inputFile = shift;
    79100    my $generateCode = shift;
    80101
     
    123144}
    124145
     146sub interfaceForItem($)
     147{
     148    my $object = shift;
     149    my $itemName = shift;
     150
     151    my $interfaceName = $parsedItems{$itemName}{"interfaceName"};
     152    $interfaceName = $itemName unless $interfaceName;
     153
     154    return $interfaceName;
     155}
     156
     157sub toMacroStyle($$)
     158{
     159    my $object = shift;
     160    my $camelCase = shift;
     161
     162    return "EVENT" if $camelCase eq "Event";
     163    return "EVENT_TARGET" if $camelCase eq "EventTarget";
     164    return "EXCEPTION" if $camelCase eq "Exception";
     165
     166    die "Ok, you got me. This script is really just a giant hack. (\$camelCase=${camelCase})";
     167}
     168
     169sub generateInterfacesHeader()
     170{
     171    my $object = shift;
     172
     173    my $F;
     174    my $namespace = $parsedParameters{"namespace"};
     175    my $outputFile = "$outputDir/${namespace}Interfaces.h";
     176
     177    open F, ">$outputFile" or die "Failed to open file: $!";
     178
     179    print F license();
     180
     181    print F "#ifndef ${namespace}Interfaces_h\n";
     182    print F "#define ${namespace}Interfaces_h\n";
     183    print F "\n";
     184
     185    my %unconditionalInterfaces = ();
     186    my %interfacesByConditional = ();
     187
     188    for my $itemName (sort keys %parsedItems) {
     189        my $conditional = $parsedItems{$itemName}{"conditional"};
     190        my $interfaceName = $object->interfaceForItem($itemName);
     191
     192        if ($conditional) {
     193            if (!defined($interfacesByConditional{$conditional})) {
     194                $interfacesByConditional{$conditional} = ();
     195            }
     196            $interfacesByConditional{$conditional}{$interfaceName} = 1;
     197        } else {
     198            $unconditionalInterfaces{$interfaceName} = 1
     199        }
     200    }
     201
     202    my $macroStyledNamespace = $object->toMacroStyle($namespace);
     203
     204    for my $conditional (sort keys %interfacesByConditional) {
     205        print F "#if ENABLE($conditional)\n";
     206        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
     207
     208        for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) {
     209            next if defined($unconditionalInterfaces{$interface});
     210            print F "    macro($interface) \\\n";
     211        }
     212
     213        print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional\n";
     214        print F "#else\n";
     215        print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro)\n";
     216        print F "#endif\n";
     217        print F "\n";
     218    }
     219
     220    print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH(macro) \\\n";
     221    print F "    \\\n";
     222    for my $interface (sort keys %unconditionalInterfaces) {
     223            print F "    macro($interface) \\\n";
     224    }
     225    print F "    \\\n";
     226    for my $conditional (sort keys %interfacesByConditional) {
     227        print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
     228    }
     229
     230    print F "\n";
     231    print F "#endif // ${namespace}Interfaces_h\n";
     232
     233    close F;
     234}
     235
     236sub generateHeadersHeader()
     237{
     238    my $object = shift;
     239
     240    my $F;
     241    my $namespace = $parsedParameters{"namespace"};
     242    my $outputFile = "$outputDir/${namespace}Headers.h";
     243
     244    open F, ">$outputFile" or die "Failed to open file: $!";
     245
     246    print F license();
     247
     248    print F "#ifndef ${namespace}Headers_h\n";
     249    print F "#define ${namespace}Headers_h\n";
     250    print F "\n";
     251
     252    my %includedInterfaces = ();
     253
     254    for my $itemName (sort keys %parsedItems) {
     255        my $conditional = $parsedItems{$itemName}{"conditional"};
     256        my $interfaceName = $object->interfaceForItem($itemName);
     257
     258        next if defined($includedInterfaces{$interfaceName});
     259        $includedInterfaces{$interfaceName} = 1;
     260
     261        print F "#if ENABLE($conditional)\n" if $conditional;
     262        print F "#include \"$interfaceName.h\"\n";
     263        print F "#if USE(JSC)\n";
     264        print F "#include \"JS$interfaceName.h\"\n";
     265        print F "#elif USE(V8)\n";
     266        print F "#include \"V8$interfaceName.h\"\n";
     267        print F "#endif\n";
     268        print F "#endif\n" if $conditional;
     269    }
     270
     271    print F "\n";
     272    print F "#endif // ${namespace}Headers_h\n";
     273
     274    close F;
     275}
     276
    1252771;
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r98730 r98755  
    3838#include "Document.h"
    3939#include "DocumentLoader.h"
     40#include "ExceptionHeaders.h"
     41#include "ExceptionInterfaces.h"
    4042#include "Frame.h"
    4143#include "FrameLoaderClient.h"
    42 #include "IDBDatabaseException.h"
    4344#include "IDBFactoryBackendInterface.h"
    4445#include "IDBPendingTransactionMonitor.h"
     
    5758#include "V8DOMMap.h"
    5859#include "V8DOMWindow.h"
    59 #include "V8EventException.h"
    60 #include "V8FileException.h"
    6160#include "V8HiddenPropertyName.h"
    6261#include "V8IsolatedContext.h"
    63 #include "V8OperationNotAllowedException.h"
    64 #include "V8RangeException.h"
    65 #include "V8SQLException.h"
    66 #include "V8XMLHttpRequestException.h"
    67 #include "V8XPathException.h"
    6862#include "WebKitMutationObserver.h"
    6963#include "WorkerContext.h"
    7064#include "WorkerContextExecutionProxy.h"
    71 
    72 #if ENABLE(INDEXED_DATABASE)
    73 #include "V8IDBDatabaseException.h"
    74 #endif
    75 
    76 #if ENABLE(SVG)
    77 #include "V8SVGException.h"
    78 #endif
    7965
    8066#include <algorithm>
     
    650636}
    651637
     638#define TRY_TO_CREATE_EXCEPTION(interfaceName) \
     639    case interfaceName##Type: \
     640        exception = toV8(interfaceName::create(description)); \
     641        break;
     642
    652643void V8Proxy::setDOMException(int ec)
    653644{
     
    659650    v8::Handle<v8::Value> exception;
    660651    switch (description.type) {
    661     case DOMCoreExceptionType:
    662         exception = toV8(DOMCoreException::create(description));
    663         break;
    664     case RangeExceptionType:
    665         exception = toV8(RangeException::create(description));
    666         break;
    667     case EventExceptionType:
    668         exception = toV8(EventException::create(description));
    669         break;
    670     case XMLHttpRequestExceptionType:
    671         exception = toV8(XMLHttpRequestException::create(description));
    672         break;
    673 #if ENABLE(SVG)
    674     case SVGExceptionType:
    675         exception = toV8(SVGException::create(description));
    676         break;
    677 #endif
    678     case XPathExceptionType:
    679         exception = toV8(XPathException::create(description));
    680         break;
    681 #if ENABLE(SQL_DATABASE)
    682     case SQLExceptionType:
    683         exception = toV8(SQLException::create(description));
    684         break;
    685 #endif
    686 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
    687     case FileExceptionType:
    688         exception = toV8(FileException::create(description));
    689         break;
    690     case OperationNotAllowedExceptionType:
    691         exception = toV8(OperationNotAllowedException::create(description));
    692         break;
    693 #endif
    694 #if ENABLE(INDEXED_DATABASE)
    695     case IDBDatabaseExceptionType:
    696         exception = toV8(IDBDatabaseException::create(description));
    697         break;
    698 #endif
    699     default:
    700         ASSERT_NOT_REACHED();
     652        DOM_EXCEPTION_INTERFACES_FOR_EACH(TRY_TO_CREATE_EXCEPTION)
    701653    }
    702654
     
    704656        v8::ThrowException(exception);
    705657}
     658
     659#undef TRY_TO_CREATE_EXCEPTION
    706660
    707661v8::Handle<v8::Value> V8Proxy::throwError(ErrorType type, const char* message)
  • trunk/Source/WebCore/dom/ExceptionCodeDescription.in

    r98711 r98755  
    1 namespace=ExceptionCodeDescription
     1namespace=Exception
    22
    33DOMCoreException
  • trunk/Source/WebCore/dom/make_event_factory.pl

    r98713 r98755  
    3333use strict;
    3434
    35 use Config;
    36 use Getopt::Long;
    37 use File::Path;
    38 use File::Spec;
    39 use IO::File;
    4035use InFilesCompiler;
    41 
    42 require Config;
    43 
    44 my $inputFile = "";
    45 my $outputDir = ".";
    46 
    47 GetOptions(
    48     'input=s' => \$inputFile,
    49     'outputDir=s' => \$outputDir,
    50 );
    51 
    52 mkpath($outputDir);
    53 
    54 die "You must specify --input <file>" unless length($inputFile);
    5536
    5637my %defaultParameters = (
    5738    'namespace' => 0
    5839);
    59 
    60 my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
    61 
    62 $InCompiler->compile($inputFile, \&generateCode);
    6340
    6441sub defaultItemFactory
     
    7047}
    7148
    72 sub interfaceForEvent($$)
    73 {
    74     my ($eventName, $parsedItemsRef) = @_;
     49my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
    7550
    76     my %parsedItems = %{ $parsedItemsRef };
    77 
    78     my $interfaceName = $parsedItems{$eventName}{"interfaceName"};
    79     $interfaceName = $eventName unless $interfaceName;
    80 
    81     return $interfaceName;
    82 }
    83 
    84 sub toMacroStyle($)
    85 {
    86     my ($camelCase) = @_;
    87 
    88     return "EVENT" if $camelCase eq "Event";
    89     return "EVENT_TARGET" if $camelCase eq "EventTarget";
    90 
    91     die "Ok, you got me. This script is really just a giant hack. (\$camelCase=${camelCase})";
    92 }
     51my $outputDir = $InCompiler->initializeFromCommandLine();
     52$InCompiler->compile(\&generateCode);
    9353
    9454sub generateCode()
     
    9757    my $parsedItemsRef = shift;
    9858
    99     printFactoryFile($parsedParametersRef, $parsedItemsRef);
    100     printMacroFile($parsedParametersRef, $parsedItemsRef);
    101     printHeadersFile($parsedParametersRef, $parsedItemsRef);
     59    generateImplementation($parsedParametersRef, $parsedItemsRef);
     60    $InCompiler->generateInterfacesHeader();
     61    $InCompiler->generateHeadersHeader()
    10262}
    10363
    104 sub printFactoryFile()
     64sub generateImplementation()
    10565{
    10666    my $parsedParametersRef = shift;
     
    13494    for my $eventName (sort keys %parsedEvents) {
    13595        my $conditional = $parsedEvents{$eventName}{"conditional"};
    136         my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
     96        my $interfaceName = $InCompiler->interfaceForItem($eventName);
    13797
    13898        print F "#if ENABLE($conditional)\n" if $conditional;
     
    149109    close F;
    150110}
    151 
    152 sub printMacroFile()
    153 {
    154     my $parsedParametersRef = shift;
    155     my $parsedItemsRef = shift;
    156 
    157     my $F;
    158     my %parsedEvents = %{ $parsedItemsRef };
    159     my %parsedParameters = %{ $parsedParametersRef };
    160 
    161     my $namespace = $parsedParameters{"namespace"};
    162 
    163     my $outputFile = "$outputDir/${namespace}Interfaces.h";
    164 
    165     open F, ">$outputFile" or die "Failed to open file: $!";
    166 
    167     print F $InCompiler->license();
    168 
    169     print F "#ifndef ${namespace}Interfaces_h\n";
    170     print F "#define ${namespace}Interfaces_h\n";
    171     print F "\n";
    172 
    173     my %unconditionalInterfaces = ();
    174     my %interfacesByConditional = ();
    175 
    176     for my $eventName (sort keys %parsedEvents) {
    177         my $conditional = $parsedEvents{$eventName}{"conditional"};
    178         my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
    179 
    180         if ($conditional) {
    181             if (!defined($interfacesByConditional{$conditional})) {
    182                 $interfacesByConditional{$conditional} = ();
    183             }
    184             $interfacesByConditional{$conditional}{$interfaceName} = 1;
    185         } else {
    186             $unconditionalInterfaces{$interfaceName} = 1
    187         }
    188     }
    189 
    190     my $macroStyledNamespace = toMacroStyle($namespace);
    191 
    192     for my $conditional (sort keys %interfacesByConditional) {
    193         print F "#if ENABLE($conditional)\n";
    194         print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
    195 
    196         for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) {
    197             next if defined($unconditionalInterfaces{$interface});
    198             print F "    macro($interface) \\\n";
    199         }
    200 
    201         print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional\n";
    202         print F "#else\n";
    203         print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro)\n";
    204         print F "#endif\n";
    205         print F "\n";
    206     }
    207 
    208     print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH(macro) \\\n";
    209     print F "    \\\n";
    210     for my $interface (sort keys %unconditionalInterfaces) {
    211             print F "    macro($interface) \\\n";
    212     }
    213     print F "    \\\n";
    214     for my $conditional (sort keys %interfacesByConditional) {
    215         print F "    DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$conditional(macro) \\\n";
    216     }
    217 
    218     print F "\n";
    219     print F "#endif // ${namespace}Interfaces_h\n";
    220 
    221     close F;
    222 }
    223 
    224 sub printHeadersFile()
    225 {
    226     my $parsedParametersRef = shift;
    227     my $parsedItemsRef = shift;
    228 
    229     my $F;
    230     my %parsedEvents = %{ $parsedItemsRef };
    231     my %parsedParameters = %{ $parsedParametersRef };
    232 
    233     my $namespace = $parsedParameters{"namespace"};
    234 
    235     my $outputFile = "$outputDir/${namespace}Headers.h";
    236 
    237     open F, ">$outputFile" or die "Failed to open file: $!";
    238 
    239     print F $InCompiler->license();
    240 
    241     print F "#ifndef ${namespace}Headers_h\n";
    242     print F "#define ${namespace}Headers_h\n";
    243     print F "\n";
    244 
    245     my %includedInterfaces = ();
    246 
    247     for my $eventName (sort keys %parsedEvents) {
    248         my $conditional = $parsedEvents{$eventName}{"conditional"};
    249         my $interfaceName = interfaceForEvent($eventName, $parsedItemsRef);
    250 
    251         next if defined($includedInterfaces{$interfaceName});
    252         $includedInterfaces{$interfaceName} = 1;
    253 
    254         print F "#if ENABLE($conditional)\n" if $conditional;
    255         print F "#include \"$interfaceName.h\"\n";
    256         print F "#if USE(JSC)\n";
    257         print F "#include \"JS$interfaceName.h\"\n";
    258         print F "#elif USE(V8)\n";
    259         print F "#include \"V8$interfaceName.h\"\n";
    260         print F "#endif\n";
    261         print F "#endif\n" if $conditional;
    262     }
    263 
    264     print F "\n";
    265     print F "#endif // ${namespace}Headers_h\n";
    266 
    267     close F;
    268 }
  • trunk/Source/WebCore/dom/make_exception_code_description.pl

    r98715 r98755  
    3333use strict;
    3434
    35 use Config;
    36 use Getopt::Long;
    37 use File::Path;
    38 use File::Spec;
    39 use IO::File;
    4035use InFilesCompiler;
    41 
    42 require Config;
    43 
    44 my $inputFile;
    45 my $outputDir = ".";
    46 
    47 GetOptions(
    48     'input=s' => \$inputFile,
    49     'outputDir=s' => \$outputDir,
    50 );
    51 
    52 mkpath($outputDir);
    53 
    54 die "You must specify --input <file>" unless length($inputFile);
    5536
    5637my %defaultParameters = (
     
    5839);
    5940
    60 my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
    61 
    62 $InCompiler->compile($inputFile, \&generateCode);
    63 
    6441sub defaultItemFactory
    6542{
    6643    return (
     44        'interfaceName' => 0,
    6745        'conditional' => 0
    6846    );
    6947}
    7048
     49my $InCompiler = InFilesCompiler->new(\%defaultParameters, \&defaultItemFactory);
     50
     51my $outputDir = $InCompiler->initializeFromCommandLine();
     52$InCompiler->compile(\&generateCode);
     53
    7154sub generateCode()
    7255{
    73     my $parsedParameters = shift;
    74     my $parsedItems = shift;
     56    my $parsedParametersRef = shift;
     57    my $parsedItemsRef = shift;
    7558
    76     generateHeader($parsedParameters, $parsedItems);
    77     generateImplementation($parsedParameters, $parsedItems);
     59    generateHeader($parsedParametersRef, $parsedItemsRef);
     60    generateImplementation($parsedParametersRef, $parsedItemsRef);
     61    $InCompiler->generateInterfacesHeader();
     62    $InCompiler->generateHeadersHeader()
    7863}
    7964
Note: See TracChangeset for help on using the changeset viewer.