Changeset 207766 in webkit


Ignore:
Timestamp:
Oct 24, 2016 11:12:01 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[CodeGeneratorJS] Standalone dictionaries have misplaced build guards
https://bugs.webkit.org/show_bug.cgi?id=163881

Patch by Zan Dobersek <zdobersek@igalia.com> on 2016-10-24
Reviewed by Chris Dumez.

Build guards that are generated from the Conditional attribute
on WebIDL dictionary declarations properly guard the relevant
convertDictionary() functions for WebIDL files that also specify
interfaces. But for standalone dictionaries these build guards
should guard the complete header and implementation files, much
like this is done for files that originate from interfaces or
callbacks.

Before this patch, guarding a standalone dictionary resulted in
malformed output because GenerateHeaderContentHeader() and
GenerateImplementationContentHeader() functions both generated
the #if macro that would guard the whole file, but
GenerateDictionary{Header,Implementation}() didn't generate the
closing #endif.

CodeGeneratorJS.pm now passes the conditional string, if any,
to GenerateDictionary{Header,Implementation}Content() functions
in case of a non-standalone dictionary. Otherwise, the
conditional string, if any, is used to guard the complete
header and implementation files.

Generator tests are updated to cover various build guard
combinations on dictionaries in TestObj.idl, and the standalone
dictionary WebIDL file now has a Conditional attribute to check
that the build guards cover complete generated header and
implementation files.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateDictionaryHeaderContent):
(GenerateDictionariesHeaderContent):
(GenerateDictionaryImplementationContent):
(GenerateDictionariesImplementationContent):
(GenerateDictionaryHeader):
(GenerateDictionaryImplementation):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::convertDictionary<TestObj::ConditionalDictionaryA>):
(WebCore::convertDictionary<TestObj::ConditionalDictionaryB>):
(WebCore::convertDictionary<TestObj::ConditionalDictionaryC>):

  • bindings/scripts/test/JS/JSTestObj.h:
  • bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp:
  • bindings/scripts/test/JS/JSTestStandaloneDictionary.h:
  • bindings/scripts/test/TestObj.idl:
  • bindings/scripts/test/TestStandaloneDictionary.idl:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207764 r207766  
     12016-10-24  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CodeGeneratorJS] Standalone dictionaries have misplaced build guards
     4        https://bugs.webkit.org/show_bug.cgi?id=163881
     5
     6        Reviewed by Chris Dumez.
     7
     8        Build guards that are generated from the Conditional attribute
     9        on WebIDL dictionary declarations properly guard the relevant
     10        convertDictionary() functions for WebIDL files that also specify
     11        interfaces. But for standalone dictionaries these build guards
     12        should guard the complete header and implementation files, much
     13        like this is done for files that originate from interfaces or
     14        callbacks.
     15
     16        Before this patch, guarding a standalone dictionary resulted in
     17        malformed output because GenerateHeaderContentHeader() and
     18        GenerateImplementationContentHeader() functions both generated
     19        the #if macro that would guard the whole file, but
     20        GenerateDictionary{Header,Implementation}() didn't generate the
     21        closing #endif.
     22
     23        CodeGeneratorJS.pm now passes the conditional string, if any,
     24        to GenerateDictionary{Header,Implementation}Content() functions
     25        in case of a non-standalone dictionary. Otherwise, the
     26        conditional string, if any, is used to guard the complete
     27        header and implementation files.
     28
     29        Generator tests are updated to cover various build guard
     30        combinations on dictionaries in TestObj.idl, and the standalone
     31        dictionary WebIDL file now has a Conditional attribute to check
     32        that the build guards cover complete generated header and
     33        implementation files.
     34
     35        * bindings/scripts/CodeGeneratorJS.pm:
     36        (GenerateDictionaryHeaderContent):
     37        (GenerateDictionariesHeaderContent):
     38        (GenerateDictionaryImplementationContent):
     39        (GenerateDictionariesImplementationContent):
     40        (GenerateDictionaryHeader):
     41        (GenerateDictionaryImplementation):
     42        * bindings/scripts/test/JS/JSTestObj.cpp:
     43        (WebCore::convertDictionary<TestObj::ConditionalDictionaryA>):
     44        (WebCore::convertDictionary<TestObj::ConditionalDictionaryB>):
     45        (WebCore::convertDictionary<TestObj::ConditionalDictionaryC>):
     46        * bindings/scripts/test/JS/JSTestObj.h:
     47        * bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp:
     48        * bindings/scripts/test/JS/JSTestStandaloneDictionary.h:
     49        * bindings/scripts/test/TestObj.idl:
     50        * bindings/scripts/test/TestStandaloneDictionary.idl:
     51
    1522016-10-24  Eric Carlson  <eric.carlson@apple.com>
    253
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r207737 r207766  
    10541054sub GenerateDictionaryHeaderContent
    10551055{
    1056     my ($dictionary, $className) = @_;
     1056    my ($dictionary, $className, $conditionalString) = @_;
    10571057
    10581058    my $result = "";
    1059     my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
    10601059    $result .= "#if ${conditionalString}\n\n" if $conditionalString;
    10611060    $result .= "template<> $className convertDictionary<$className>(JSC::ExecState&, JSC::JSValue);\n\n";
     
    10761075        $headerIncludes{$interface->name . ".h"} = 1;
    10771076        my $className = GetDictionaryClassName($dictionary->name, $interface);
    1078         $result .= GenerateDictionaryHeaderContent($dictionary, $className);
     1077        my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
     1078        $result .= GenerateDictionaryHeaderContent($dictionary, $className, $conditionalString);
    10791079    }
    10801080    return $result;
     
    10831083sub GenerateDictionaryImplementationContent
    10841084{
    1085     my ($dictionary, $className, $interface) = @_;
     1085    my ($dictionary, $className, $interface, $conditionalString) = @_;
    10861086
    10871087    my $result = "";
     
    10891089    my $name = $dictionary->name;
    10901090
    1091     my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
    10921091    $result .= "#if ${conditionalString}\n\n" if $conditionalString;
    10931092
     
    11871186    foreach my $dictionary (@$allDictionaries) {
    11881187        my $className = GetDictionaryClassName($dictionary->name, $interface);
    1189         $result .= GenerateDictionaryImplementationContent($dictionary, $className, $interface);
     1188        my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
     1189        $result .= GenerateDictionaryImplementationContent($dictionary, $className, $interface, $conditionalString);
    11901190    }
    11911191    return $result;
     
    44684468    push(@headerContent, GenerateDictionaryHeaderContent($dictionary, $className));
    44694469    push(@headerContent, "} // namespace WebCore\n");
     4470
     4471    my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
     4472    push(@headerContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
    44704473   
    44714474    # - Generate dependencies.
     
    44954498    push(@implContent, GenerateDictionaryImplementationContent($dictionary, $className));
    44964499    push(@implContent, "} // namespace WebCore\n");
     4500
     4501    my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
     4502    push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
    44974503}
    44984504
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r207737 r207766  
    857857    return result;
    858858}
     859
     860#if ENABLE(Condition1)
     861
     862template<> TestObj::ConditionalDictionaryA convertDictionary<TestObj::ConditionalDictionaryA>(ExecState& state, JSValue value)
     863{
     864    VM& vm = state.vm();
     865    auto throwScope = DECLARE_THROW_SCOPE(vm);
     866    bool isNullOrUndefined = value.isUndefinedOrNull();
     867    auto* object = isNullOrUndefined ? nullptr : value.getObject();
     868    if (UNLIKELY(!isNullOrUndefined && !object)) {
     869        throwTypeError(&state, throwScope);
     870        return { };
     871    }
     872    if (UNLIKELY(object && object->type() == RegExpObjectType)) {
     873        throwTypeError(&state, throwScope);
     874        return { };
     875    }
     876    TestObj::ConditionalDictionaryA result;
     877    JSValue stringWithoutDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "stringWithoutDefault"));
     878    if (!stringWithoutDefaultValue.isUndefined()) {
     879        result.stringWithoutDefault = convert<IDLDOMString>(state, stringWithoutDefaultValue);
     880        RETURN_IF_EXCEPTION(throwScope, { });
     881    }
     882    return result;
     883}
     884
     885#endif
     886
     887#if ENABLE(Condition1) && ENABLE(Condition2)
     888
     889template<> TestObj::ConditionalDictionaryB convertDictionary<TestObj::ConditionalDictionaryB>(ExecState& state, JSValue value)
     890{
     891    VM& vm = state.vm();
     892    auto throwScope = DECLARE_THROW_SCOPE(vm);
     893    bool isNullOrUndefined = value.isUndefinedOrNull();
     894    auto* object = isNullOrUndefined ? nullptr : value.getObject();
     895    if (UNLIKELY(!isNullOrUndefined && !object)) {
     896        throwTypeError(&state, throwScope);
     897        return { };
     898    }
     899    if (UNLIKELY(object && object->type() == RegExpObjectType)) {
     900        throwTypeError(&state, throwScope);
     901        return { };
     902    }
     903    TestObj::ConditionalDictionaryB result;
     904    JSValue stringWithoutDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "stringWithoutDefault"));
     905    if (!stringWithoutDefaultValue.isUndefined()) {
     906        result.stringWithoutDefault = convert<IDLDOMString>(state, stringWithoutDefaultValue);
     907        RETURN_IF_EXCEPTION(throwScope, { });
     908    }
     909    return result;
     910}
     911
     912#endif
     913
     914#if ENABLE(Condition1) || ENABLE(Condition2)
     915
     916template<> TestObj::ConditionalDictionaryC convertDictionary<TestObj::ConditionalDictionaryC>(ExecState& state, JSValue value)
     917{
     918    VM& vm = state.vm();
     919    auto throwScope = DECLARE_THROW_SCOPE(vm);
     920    bool isNullOrUndefined = value.isUndefinedOrNull();
     921    auto* object = isNullOrUndefined ? nullptr : value.getObject();
     922    if (UNLIKELY(!isNullOrUndefined && !object)) {
     923        throwTypeError(&state, throwScope);
     924        return { };
     925    }
     926    if (UNLIKELY(object && object->type() == RegExpObjectType)) {
     927        throwTypeError(&state, throwScope);
     928        return { };
     929    }
     930    TestObj::ConditionalDictionaryC result;
     931    JSValue stringWithoutDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "stringWithoutDefault"));
     932    if (!stringWithoutDefaultValue.isUndefined()) {
     933        result.stringWithoutDefault = convert<IDLDOMString>(state, stringWithoutDefaultValue);
     934        RETURN_IF_EXCEPTION(throwScope, { });
     935    }
     936    return result;
     937}
     938
     939#endif
    859940
    860941// Functions
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h

    r207737 r207766  
    185185template<> TestObj::ChildDictionary convertDictionary<TestObj::ChildDictionary>(JSC::ExecState&, JSC::JSValue);
    186186
     187#if ENABLE(Condition1)
     188
     189template<> TestObj::ConditionalDictionaryA convertDictionary<TestObj::ConditionalDictionaryA>(JSC::ExecState&, JSC::JSValue);
     190
     191#endif
     192
     193#if ENABLE(Condition1) && ENABLE(Condition2)
     194
     195template<> TestObj::ConditionalDictionaryB convertDictionary<TestObj::ConditionalDictionaryB>(JSC::ExecState&, JSC::JSValue);
     196
     197#endif
     198
     199#if ENABLE(Condition1) || ENABLE(Condition2)
     200
     201template<> TestObj::ConditionalDictionaryC convertDictionary<TestObj::ConditionalDictionaryC>(JSC::ExecState&, JSC::JSValue);
     202
     203#endif
     204
    187205
    188206} // namespace WebCore
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp

    r207498 r207766  
    2020
    2121#include "config.h"
     22
     23#if ENABLE(Condition1)
     24
    2225#include "JSTestStandaloneDictionary.h"
    2326
     
    5659
    5760} // namespace WebCore
     61
     62#endif // ENABLE(Condition1)
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.h

    r207498 r207766  
    2121#pragma once
    2222
     23#if ENABLE(Condition1)
     24
    2325#include "DictionaryImplName.h"
    2426#include "JSDOMConvert.h"
     
    2931
    3032} // namespace WebCore
     33
     34#endif // ENABLE(Condition1)
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r207725 r207766  
    513513};
    514514
     515[
     516    Conditional=Condition1
     517] dictionary TestConditionalDictionaryA {
     518    DOMString stringWithoutDefault;
     519};
     520
     521[
     522    Conditional=Condition1&Condition2
     523] dictionary TestConditionalDictionaryB {
     524    DOMString stringWithoutDefault;
     525};
     526
     527[
     528    Conditional=Condition1|Condition2
     529] dictionary TestConditionalDictionaryC {
     530    DOMString stringWithoutDefault;
     531};
  • trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl

    r207243 r207766  
    2929[
    3030    ImplementedAs=DictionaryImplName,
     31    Conditional=Condition1,
    3132] dictionary TestStandaloneDictionary {
    3233    boolean boolMember;
Note: See TracChangeset for help on using the changeset viewer.