Changeset 207058 in webkit


Ignore:
Timestamp:
Oct 11, 2016 12:11:40 AM (7 years ago)
Author:
Chris Dumez
Message:

Update IDBVersionChangeEvent to stop using legacy [ConstructorTemplate=Event]
https://bugs.webkit.org/show_bug.cgi?id=163266

Reviewed by Darin Adler.

Source/WebCore:

Update IDBVersionChangeEvent to stop using legacy [ConstructorTemplate=Event]
and use a regular constructor instead, as in the specification:

This patch also fixes a bug where the IDBVersionChangeEvent was ignoring the
EventInit dictionary members passed by the JavaScript (e.g. bubbles).

No new tests, updated existing test.

  • Modules/indexeddb/IDBVersionChangeEvent.cpp:

(WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):

  • Modules/indexeddb/IDBVersionChangeEvent.h:
  • Modules/indexeddb/IDBVersionChangeEvent.idl:
  • bindings/js/JSDOMConvert.h:

(WebCore::convertNullable):
(WebCore::convert): Deleted.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateDefaultValue):
(GenerateDictionaryImplementationContent):

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

(WebCore::convertDictionary<TestObj::Dictionary>):

  • bindings/scripts/test/TestObj.idl:

LayoutTests:

Update existing layout test covering the IDBVersionChangeEvent constructor
to test to EventInit dictionary members as well.

  • storage/indexeddb/modern/idbversionchangeevent-constructor-expected.txt:
  • storage/indexeddb/modern/idbversionchangeevent-constructor.html:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207052 r207058  
     12016-10-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Update IDBVersionChangeEvent to stop using legacy [ConstructorTemplate=Event]
     4        https://bugs.webkit.org/show_bug.cgi?id=163266
     5
     6        Reviewed by Darin Adler.
     7
     8        Update existing layout test covering the IDBVersionChangeEvent constructor
     9        to test to EventInit dictionary members as well.
     10
     11        * storage/indexeddb/modern/idbversionchangeevent-constructor-expected.txt:
     12        * storage/indexeddb/modern/idbversionchangeevent-constructor.html:
     13
    1142016-10-10  Adam Bergkvist  <adam.bergkvist@ericsson.com> and Alejandro G. Castro <alex@igalia.com>
    215
  • trunk/LayoutTests/storage/indexeddb/modern/idbversionchangeevent-constructor-expected.txt

    r199774 r207058  
    2020PASS event.oldVersion is 43876528735628
    2121PASS event.newVersion is 0
     22event = new IDBVersionChangeEvent('bar', { bubbles: true, cancelable: true, composed: true });
     23PASS event.type is "bar"
     24PASS event.bubbles is true
     25PASS event.cancelable is true
     26PASS event.composed is true
    2227PASS successfullyParsed is true
    2328
  • trunk/LayoutTests/storage/indexeddb/modern/idbversionchangeevent-constructor.html

    r199774 r207058  
    3636shouldBeEqualToNumber("event.newVersion", 0);
    3737
     38evalAndLog("event = new IDBVersionChangeEvent('bar', { bubbles: true, cancelable: true, composed: true });");
     39shouldBeEqualToString("event.type", "bar");
     40shouldBeTrue("event.bubbles");
     41shouldBeTrue("event.cancelable");
     42shouldBeTrue("event.composed");
     43
    3844finishJSTest();
    3945
  • trunk/Source/WebCore/ChangeLog

    r207057 r207058  
     12016-10-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Update IDBVersionChangeEvent to stop using legacy [ConstructorTemplate=Event]
     4        https://bugs.webkit.org/show_bug.cgi?id=163266
     5
     6        Reviewed by Darin Adler.
     7
     8        Update IDBVersionChangeEvent to stop using legacy [ConstructorTemplate=Event]
     9        and use a regular constructor instead, as in the specification:
     10        - http://w3c.github.io/IndexedDB/#request-idbversionchangeevent
     11
     12        This patch also fixes a bug where the IDBVersionChangeEvent was ignoring the
     13        EventInit dictionary members passed by the JavaScript (e.g. bubbles).
     14
     15        No new tests, updated existing test.
     16
     17        * Modules/indexeddb/IDBVersionChangeEvent.cpp:
     18        (WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):
     19        * Modules/indexeddb/IDBVersionChangeEvent.h:
     20        * Modules/indexeddb/IDBVersionChangeEvent.idl:
     21        * bindings/js/JSDOMConvert.h:
     22        (WebCore::convertNullable):
     23        (WebCore::convert): Deleted.
     24        * bindings/scripts/CodeGeneratorJS.pm:
     25        (GenerateDefaultValue):
     26        (GenerateDictionaryImplementationContent):
     27        * bindings/scripts/test/JS/JSTestObj.cpp:
     28        (WebCore::convertDictionary<TestObj::Dictionary>):
     29        * bindings/scripts/test/TestObj.idl:
     30
    1312016-10-11  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.cpp

    r199750 r207058  
    4242}
    4343
    44 IDBVersionChangeEvent::IDBVersionChangeEvent(const AtomicString& name, const IDBVersionChangeEventInit& init)
    45     : Event(name, false /*canBubble*/, false /*cancelable*/)
     44IDBVersionChangeEvent::IDBVersionChangeEvent(const AtomicString& name, const Init& init, IsTrusted isTrusted)
     45    : Event(name, init, isTrusted)
    4646    , m_oldVersion(init.oldVersion)
    4747    , m_newVersion(init.newVersion)
  • trunk/Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.h

    r199774 r207058  
    3434namespace WebCore {
    3535
    36 struct IDBVersionChangeEventInit : public EventInit {
    37     uint64_t oldVersion { 0 };
    38     Optional<uint64_t> newVersion;
    39 };
    40 
    4136class IDBVersionChangeEvent final : public Event {
    4237public:
     
    5146    }
    5247
    53     static Ref<IDBVersionChangeEvent> createForBindings(const AtomicString& type, const IDBVersionChangeEventInit& initializer)
     48    struct Init : EventInit {
     49        uint64_t oldVersion { 0 };
     50        Optional<uint64_t> newVersion;
     51    };
     52
     53    static Ref<IDBVersionChangeEvent> create(const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
    5454    {
    55         return adoptRef(*new IDBVersionChangeEvent(type, initializer));
     55        return adoptRef(*new IDBVersionChangeEvent(type, initializer, isTrusted));
    5656    }
    5757
     
    6565private:
    6666    IDBVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion, const AtomicString& eventType);
    67     IDBVersionChangeEvent(const AtomicString&, const IDBVersionChangeEventInit&);
     67    IDBVersionChangeEvent(const AtomicString&, const Init&, IsTrusted);
    6868
    6969    EventInterface eventInterface() const;
  • trunk/Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.idl

    r199889 r207058  
    2424 */
    2525
     26// FIXME: This should be exposed to workers as well.
    2627[
    2728    Conditional=INDEXED_DATABASE,
    2829    EnabledAtRuntime=IndexedDB,
    29     ConstructorTemplate=Event,
     30    Constructor(DOMString type, optional IDBVersionChangeEventInit eventInitDict),
    3031] interface IDBVersionChangeEvent : Event {
    3132    [InitializedByEventConstructor] readonly attribute unsigned long long oldVersion;
    3233    [InitializedByEventConstructor] readonly attribute unsigned long long? newVersion;
    3334};
     35
     36dictionary IDBVersionChangeEventInit : EventInit {
     37    unsigned long long oldVersion = 0;
     38    unsigned long long? newVersion = null;
     39};
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r207016 r207058  
    4040template<typename T> T convert(JSC::ExecState&, JSC::JSValue);
    4141template<typename T> EnableIfIntegralType<T> convert(JSC::ExecState&, JSC::JSValue, IntegerConversionConfiguration);
     42template<typename T> EnableIfIntegralType<Optional<T>> convertNullable(JSC::ExecState&, JSC::JSValue, IntegerConversionConfiguration);
    4243template<typename T> EnableIfFloatingPointType<T> convert(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite);
    4344
     
    6263{
    6364    return Converter<T>::convert(state, value, configuration);
     65}
     66
     67template<typename T> inline EnableIfIntegralType<T, Optional<T>> convertNullable(JSC::ExecState& state, JSC::JSValue value, IntegerConversionConfiguration configuration)
     68{
     69    return value.isUndefinedOrNull() ? Optional<T>() : Converter<T>::convert(state, value, configuration);
    6470}
    6571
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r207041 r207058  
    975975    my ($interface, $member) = @_;
    976976
    977     my $value = $member->default;
     977    my $defaultValue = $member->default;
    978978
    979979    if ($codeGenerator->IsEnumType($member->type)) {
     
    981981        # FIXME: Would be nice to report an error if the value is not one of the enumeration values.
    982982        my $className = GetEnumerationClassName($member->type, $interface);
    983         my $enumerationValueName = GetEnumerationValueName(substr($value, 1, -1));
    984         $value = $className . "::" . $enumerationValueName;
    985     }
    986     if ($value eq "null") {
    987         $value = $member->type eq "any" ? "jsNull()" : "nullptr";
    988     }
    989     $value = "{ }" if $value eq "[]";
    990     $value = "jsUndefined()" if $value eq "undefined";
    991 
    992     return $value;
     983        my $enumerationValueName = GetEnumerationValueName(substr($defaultValue, 1, -1));
     984        return $className . "::" . $enumerationValueName;
     985    }
     986    if ($defaultValue eq "null") {
     987        return "jsNull()" if $member->type eq "any";
     988        return "nullptr" if $codeGenerator->IsWrapperType($member->type);
     989        return "String()" if $codeGenerator->IsStringType($member->type);
     990        return "Nullopt";
     991    }
     992    return "{ }" if $defaultValue eq "[]";
     993    return "jsUndefined()" if $defaultValue eq "undefined";
     994
     995    return $defaultValue;
    993996}
    994997
     
    11321135            } else {
    11331136                my $conversionRuleWithLeadingComma = GenerateConversionRuleWithLeadingComma($interface, $member);
    1134                 $result .= "        result.$key = convert<${nativeType}>(state, ${key}Value${conversionRuleWithLeadingComma});\n";
     1137                my $convertFunction = $member->isNullable ? "convertNullable" : "convert";
     1138                $result .= "        result.$key = $convertFunction<${nativeType}>(state, ${key}Value${conversionRuleWithLeadingComma});\n";
    11351139                $result .= "        RETURN_IF_EXCEPTION(throwScope, Nullopt);\n";
    11361140            }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r206992 r207058  
    551551    } else
    552552        result.largeIntegerWithDefault = 0;
     553    JSValue nullableIntegerWithDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "nullableIntegerWithDefault"));
     554    if (!nullableIntegerWithDefaultValue.isUndefined()) {
     555        result.nullableIntegerWithDefault = convertNullable<int32_t>(state, nullableIntegerWithDefaultValue, NormalConversion);
     556        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     557    } else
     558        result.nullableIntegerWithDefault = Nullopt;
    553559    JSValue nullableNodeValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "nullableNode"));
    554560    if (!nullableNodeValue.isUndefined()) {
     
    557563    } else
    558564        result.nullableNode = nullptr;
     565    JSValue nullableStringWithDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "nullableStringWithDefault"));
     566    if (!nullableStringWithDefaultValue.isUndefined()) {
     567        result.nullableStringWithDefault = convertNullable<String>(state, nullableStringWithDefaultValue);
     568        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     569    } else
     570        result.nullableStringWithDefault = String();
    559571    JSValue restrictedDoubleValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "restrictedDouble"));
    560572    if (!restrictedDoubleValue.isUndefined()) {
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r206976 r207058  
    434434    DOMString stringWithDefault = "defaultString";
    435435    DOMString stringWithoutDefault;
     436    DOMString? nullableStringWithDefault = null;
    436437    boolean booleanWithDefault = false;
    437438    boolean booleanWithoutDefault;
     
    457458    unsigned long long unsignedLargeInteger;
    458459    unsigned long long unsignedLargeIntegerWithDefault = 0;
     460    long? nullableIntegerWithDefault = null;
    459461    Node? nullableNode = null;
    460462    any anyValue;
Note: See TracChangeset for help on using the changeset viewer.