Changeset 206964 in webkit


Ignore:
Timestamp:
Oct 8, 2016 8:46:39 PM (8 years ago)
Author:
Chris Dumez
Message:

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

Reviewed by Darin Adler.

Source/WebCore:

Update CustomEvent to stop using legacy [ConstructorTemplate=Event] and
use an actual constructor instead, like in the specification:

There is a very minor behavior change when explictly passing undefined
as detail value in CustomEventInit. We used to initialize detail to
undefined but we now initialize it to null instead, which is its default
value. The new behavior matches the one of Chrome and Firefox.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateDefaultValue):
(GenerateDictionaryImplementationContent):

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

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

  • bindings/scripts/test/TestObj.idl:
  • dom/CustomEvent.cpp:

(WebCore::CustomEvent::CustomEvent):

  • dom/CustomEvent.h:
  • dom/CustomEvent.idl:
  • dom/Document.cpp:

(WebCore::Document::createEvent):

  • dom/Event.cpp:

(WebCore::Event::Event):

  • dom/Event.h:

LayoutTests:

Update existing layout test to reflect minor behavior change.

  • fast/events/constructors/custom-event-constructor-expected.txt:
  • fast/events/constructors/custom-event-constructor.html:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206963 r206964  
     12016-10-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Update CustomEvent to stop using legacy [ConstructorTemplate=Event]
     4        https://bugs.webkit.org/show_bug.cgi?id=163174
     5
     6        Reviewed by Darin Adler.
     7
     8        Update existing layout test to reflect minor behavior change.
     9
     10        * fast/events/constructors/custom-event-constructor-expected.txt:
     11        * fast/events/constructors/custom-event-constructor.html:
     12
    1132016-10-08  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/fast/events/constructors/custom-event-constructor-expected.txt

    r186955 r206964  
    1414PASS new CustomEvent('eventType', { detail: detailObject }).detail is detailObject
    1515PASS new CustomEvent('eventType', { detail: document }).detail is document
    16 PASS new CustomEvent('eventType', { detail: undefined }).detail is undefined
     16PASS new CustomEvent('eventType', { detail: undefined }).detail is null
    1717PASS new CustomEvent('eventType', { detail: null }).detail is null
    1818PASS new CustomEvent('eventType', { get detail() { return true; } }).detail is true
  • trunk/LayoutTests/fast/events/constructors/custom-event-constructor.html

    r186955 r206964  
    3333
    3434// Detail is undefined.
    35 shouldBe("new CustomEvent('eventType', { detail: undefined }).detail", "undefined");
     35shouldBeNull("new CustomEvent('eventType', { detail: undefined }).detail");
    3636
    3737// Detail is null.
    38 shouldBe("new CustomEvent('eventType', { detail: null }).detail", "null");
     38shouldBeNull("new CustomEvent('eventType', { detail: null }).detail");
    3939
    4040// Detail is a getter.
  • trunk/Source/WebCore/ChangeLog

    r206963 r206964  
     12016-10-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Update CustomEvent to stop using legacy [ConstructorTemplate=Event]
     4        https://bugs.webkit.org/show_bug.cgi?id=163174
     5
     6        Reviewed by Darin Adler.
     7
     8        Update CustomEvent to stop using legacy [ConstructorTemplate=Event] and
     9        use an actual constructor instead, like in the specification:
     10        - https://dom.spec.whatwg.org/#interface-customevent
     11
     12        There is a very minor behavior change when explictly passing undefined
     13        as detail value in CustomEventInit. We used to initialize detail to
     14        undefined but we now initialize it to null instead, which is its default
     15        value. The new behavior matches the one of Chrome and Firefox.
     16
     17        * bindings/scripts/CodeGeneratorJS.pm:
     18        (GenerateDefaultValue):
     19        (GenerateDictionaryImplementationContent):
     20        * bindings/scripts/test/JS/JSTestObj.cpp:
     21        (WebCore::convertDictionary<TestObj::Dictionary>):
     22        * bindings/scripts/test/TestObj.idl:
     23        * dom/CustomEvent.cpp:
     24        (WebCore::CustomEvent::CustomEvent):
     25        * dom/CustomEvent.h:
     26        * dom/CustomEvent.idl:
     27        * dom/Document.cpp:
     28        (WebCore::Document::createEvent):
     29        * dom/Event.cpp:
     30        (WebCore::Event::Event):
     31        * dom/Event.h:
     32
    1332016-10-08  Chris Dumez  <cdumez@apple.com>
    234
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r206963 r206964  
    983983        $value = $className . "::" . $enumerationValueName;
    984984    }
    985     $value = "nullptr" if $value eq "null";
     985    if ($value eq "null") {
     986        $value = $member->type eq "any" ? "jsNull()" : "nullptr";
     987    }
    986988    $value = "jsUndefined()" if $value eq "undefined";
    987989
     
    10901092        my @sortedMembers = sort { $a->name cmp $b->name } @{$dictionary->members};
    10911093        foreach my $member (@sortedMembers) {
    1092             $member->default("undefined") if $member->type eq "any"; # Use undefined as default value for member of type 'any'.
     1094            $member->default("undefined") if $member->type eq "any" and !defined($member->default); # Use undefined as default value for member of type 'any' unless specified otherwise.
    10931095
    10941096            my $type = $member->type;
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r206960 r206964  
    489489    } else
    490490        anyValue = jsUndefined();
     491    JSValue anyValueWithNullDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "anyValueWithNullDefault"));
     492    JSC::JSValue anyValueWithNullDefault;
     493    if (!anyValueWithNullDefaultValue.isUndefined()) {
     494        anyValueWithNullDefault = convert<JSC::JSValue>(state, anyValueWithNullDefaultValue);
     495        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     496    } else
     497        anyValueWithNullDefault = jsNull();
    491498    JSValue booleanWithDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "booleanWithDefault"));
    492499    bool booleanWithDefault;
     
    683690    } else
    684691        unsignedLargeIntegerWithDefault = 0;
    685     return TestObj::Dictionary { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings), WTFMove(restrictedDouble), WTFMove(unrestrictedDouble), WTFMove(restrictedDoubleWithDefault), WTFMove(unrestrictedDoubleWithDefault), WTFMove(restrictedFloat), WTFMove(unrestrictedFloat), WTFMove(restrictedFloatWithDefault), WTFMove(unrestrictedFloatWithDefault), WTFMove(smallIntegerClamped), WTFMove(smallIntegerWithDefault), WTFMove(smallUnsignedIntegerEnforcedRange), WTFMove(smallUnsignedIntegerWithDefault), WTFMove(integer), WTFMove(integerWithDefault), WTFMove(unsignedInteger), WTFMove(unsignedIntegerWithDefault), WTFMove(largeInteger), WTFMove(largeIntegerWithDefault), WTFMove(unsignedLargeInteger), WTFMove(unsignedLargeIntegerWithDefault), WTFMove(nullableNode), WTFMove(anyValue), WTFMove(anyTypedefValue), dictionaryMember.value() };
     692    return TestObj::Dictionary { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings), WTFMove(restrictedDouble), WTFMove(unrestrictedDouble), WTFMove(restrictedDoubleWithDefault), WTFMove(unrestrictedDoubleWithDefault), WTFMove(restrictedFloat), WTFMove(unrestrictedFloat), WTFMove(restrictedFloatWithDefault), WTFMove(unrestrictedFloatWithDefault), WTFMove(smallIntegerClamped), WTFMove(smallIntegerWithDefault), WTFMove(smallUnsignedIntegerEnforcedRange), WTFMove(smallUnsignedIntegerWithDefault), WTFMove(integer), WTFMove(integerWithDefault), WTFMove(unsignedInteger), WTFMove(unsignedIntegerWithDefault), WTFMove(largeInteger), WTFMove(largeIntegerWithDefault), WTFMove(unsignedLargeInteger), WTFMove(unsignedLargeIntegerWithDefault), WTFMove(nullableNode), WTFMove(anyValue), WTFMove(anyValueWithNullDefault), WTFMove(anyTypedefValue), dictionaryMember.value() };
    686693}
    687694
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r206960 r206964  
    460460    Node? nullableNode = null;
    461461    any anyValue;
     462    any anyValueWithNullDefault = null;
    462463    AnyTypedef anyTypedefValue;
    463464    TestDictionaryThatShouldTolerateNull dictionaryMember;
  • trunk/Source/WebCore/dom/CustomEvent.cpp

    r204288 r206964  
    3232namespace WebCore {
    3333
    34 CustomEvent::CustomEvent()
     34CustomEvent::CustomEvent(IsTrusted isTrusted)
     35    : Event(isTrusted)
    3536{
    3637}
    3738
    38 CustomEvent::CustomEvent(const AtomicString& type, const CustomEventInit& initializer)
    39     : Event(type, initializer)
    40     , m_detail(initializer.detail)
     39CustomEvent::CustomEvent(JSC::ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted)
     40    : Event(type, initializer, isTrusted)
     41    , m_detail(state.vm(), initializer.detail)
    4142{
    4243}
  • trunk/Source/WebCore/dom/CustomEvent.h

    r202023 r206964  
    3333namespace WebCore {
    3434
    35 struct CustomEventInit : public EventInit {
    36     Deprecated::ScriptValue detail;
    37 };
    38 
    3935class CustomEvent final : public Event {
    4036public:
    4137    virtual ~CustomEvent();
    4238
    43     static Ref<CustomEvent> createForBindings()
     39    static Ref<CustomEvent> create(IsTrusted isTrusted = IsTrusted::No)
    4440    {
    45         return adoptRef(*new CustomEvent);
     41        return adoptRef(*new CustomEvent(isTrusted));
    4642    }
    4743
    48     static Ref<CustomEvent> createForBindings(const AtomicString& type, const CustomEventInit& initializer)
     44    struct Init : public EventInit {
     45        Init(bool bubbles, bool cancelable, bool composed, JSC::JSValue detail)
     46            : EventInit(bubbles, cancelable, composed)
     47            , detail(detail)
     48        { }
     49
     50        JSC::JSValue detail;
     51    };
     52
     53    static Ref<CustomEvent> create(JSC::ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
    4954    {
    50         return adoptRef(*new CustomEvent(type, initializer));
     55        return adoptRef(*new CustomEvent(state, type, initializer, isTrusted));
    5156    }
    5257
     
    6065
    6166private:
    62     CustomEvent();
    63     CustomEvent(const AtomicString& type, const CustomEventInit& initializer);
     67    CustomEvent(IsTrusted);
     68    CustomEvent(JSC::ExecState&, const AtomicString& type, const Init& initializer, IsTrusted);
    6469
    6570    Deprecated::ScriptValue m_detail; // FIXME: Why is it OK to use a strong reference here? What prevents a reference cycle?
  • trunk/Source/WebCore/dom/CustomEvent.idl

    r203734 r206964  
    2525
    2626// Introduced in DOM Level 3:
     27// FIXME: This should be exposed to workers as well.
    2728[
    28     ConstructorTemplate=Event,
     29    Constructor(DOMString type, optional CustomEventInit eventInitDict),
     30    ConstructorCallWith=ScriptState,
    2931] interface CustomEvent : Event {
    30     [InitializedByEventConstructor, CustomGetter] readonly attribute any detail;
     32    [CustomGetter] readonly attribute any detail;
    3133
    3234    [CallWith=ScriptState] void initCustomEvent(DOMString type, boolean bubbles, boolean cancelable, any detail);
    3335};
     36
     37dictionary CustomEventInit : EventInit {
     38    any detail = null;
     39};
  • trunk/Source/WebCore/dom/Document.cpp

    r206960 r206964  
    41304130
    41314131    if (equalLettersIgnoringASCIICase(type, "customevent"))
    4132         return CustomEvent::createForBindings();
     4132        return CustomEvent::create();
    41334133    if (equalLettersIgnoringASCIICase(type, "event") || equalLettersIgnoringASCIICase(type, "events") || equalLettersIgnoringASCIICase(type, "htmlevents"))
    41344134        return Event::createForBindings();
  • trunk/Source/WebCore/dom/Event.cpp

    r206963 r206964  
    3232namespace WebCore {
    3333
    34 Event::Event()
    35     : m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
     34Event::Event(IsTrusted isTrusted)
     35    : m_isTrusted(isTrusted == IsTrusted::Yes)
     36    , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
    3637{
    3738}
  • trunk/Source/WebCore/dom/Event.h

    r206963 r206964  
    191191
    192192protected:
    193     Event();
     193    Event(IsTrusted = IsTrusted::No);
    194194    WEBCORE_EXPORT Event(const AtomicString& type, bool canBubble, bool cancelable);
    195195    Event(const AtomicString& type, bool canBubble, bool cancelable, double timestamp);
Note: See TracChangeset for help on using the changeset viewer.