Bug 161321 - document.createEvent("popstateevent") should create a PopStateEvent
Summary: document.createEvent("popstateevent") should create a PopStateEvent
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: WebExposed
Depends on:
Blocks:
 
Reported: 2016-08-29 11:58 PDT by Chris Dumez
Modified: 2016-08-29 12:57 PDT (History)
9 users (show)

See Also:


Attachments
Patch (8.86 KB, patch)
2016-08-29 12:15 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2016-08-29 11:58:57 PDT
document.createEvent("popstateevent") should create a PopStateEvent as per:
- https://dom.spec.whatwg.org/#dom-document-createevent

Firefox and Chrome match the specification but WebKit throws an exception, which is risky compatibility-wise.
Comment 1 Chris Dumez 2016-08-29 12:15:42 PDT
Created attachment 287305 [details]
Patch
Comment 2 Darin Adler 2016-08-29 12:20:00 PDT
Comment on attachment 287305 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=287305&action=review

> Source/WebCore/dom/PopStateEvent.h:58
> +    PopStateEvent() = default;

I don’t think this is right. I think we want to pass some arguments to the Event constructor: Event(eventNames().popstateEvent, false, true).
Comment 3 Chris Dumez 2016-08-29 12:24:01 PDT
Comment on attachment 287305 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=287305&action=review

>> Source/WebCore/dom/PopStateEvent.h:58
>> +    PopStateEvent() = default;
> 
> I don’t think this is right. I think we want to pass some arguments to the Event constructor: Event(eventNames().popstateEvent, false, true).

Hmm, this is what we do elsewhere. e.g.
    static Ref<Event> createForBindings()
    {
        return adoptRef(*new Event);
    }

    static Ref<CustomEvent> createForBindings()
    {
        return adoptRef(*new CustomEvent);
    }

People are supposed to call init*Event() to initialize the members after using document.createEvent() to construct the event.

Also note step 5 in the spec (link in the changeling):
Let event be the result of invoking the initial value of constructor with the empty string as argument.
Comment 4 Chris Dumez 2016-08-29 12:25:18 PDT
(In reply to comment #3)
> Comment on attachment 287305 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=287305&action=review
> 
> >> Source/WebCore/dom/PopStateEvent.h:58
> >> +    PopStateEvent() = default;
> > 
> > I don’t think this is right. I think we want to pass some arguments to the Event constructor: Event(eventNames().popstateEvent, false, true).
> 
> Hmm, this is what we do elsewhere. e.g.
>     static Ref<Event> createForBindings()
>     {
>         return adoptRef(*new Event);
>     }
> 
>     static Ref<CustomEvent> createForBindings()
>     {
>         return adoptRef(*new CustomEvent);
>     }
> 
> People are supposed to call init*Event() to initialize the members after
> using document.createEvent() to construct the event.
> 
> Also note step 5 in the spec (link in the changeling):
> Let event be the result of invoking the initial value of constructor with
> the empty string as argument.

So as per the spec, this should be equivalent to calling:
new PopStateEvent("");
Comment 5 Chris Dumez 2016-08-29 12:28:19 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > Comment on attachment 287305 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=287305&action=review
> > 
> > >> Source/WebCore/dom/PopStateEvent.h:58
> > >> +    PopStateEvent() = default;
> > > 
> > > I don’t think this is right. I think we want to pass some arguments to the Event constructor: Event(eventNames().popstateEvent, false, true).
> > 
> > Hmm, this is what we do elsewhere. e.g.
> >     static Ref<Event> createForBindings()
> >     {
> >         return adoptRef(*new Event);
> >     }
> > 
> >     static Ref<CustomEvent> createForBindings()
> >     {
> >         return adoptRef(*new CustomEvent);
> >     }
> > 
> > People are supposed to call init*Event() to initialize the members after
> > using document.createEvent() to construct the event.
> > 
> > Also note step 5 in the spec (link in the changeling):
> > Let event be the result of invoking the initial value of constructor with
> > the empty string as argument.
> 
> So as per the spec, this should be equivalent to calling:
> new PopStateEvent("");

So I do believe this patch is correct as per the specification. The values of event.type as well as the Event flags are also converted by dom/nodes/Document-createEvent.html which we PASS for PopStateEvent after my patch.

From Test:
function testAlias(arg, iface) {
  var ev;
  test(function() {
    ev = document.createEvent(arg);
    assert_true(ev instanceof window[iface]);
    assert_true(ev instanceof Event);
  }, arg + " should be an alias for " + iface + ".");
  test(function() {
    assert_equals(ev.type, "",
                  "type should be initialized to the empty string");
    assert_equals(ev.target, null,
                  "target should be initialized to null");
    assert_equals(ev.currentTarget, null,
                  "currentTarget should be initialized to null");
    assert_equals(ev.eventPhase, 0,
                  "eventPhase should be initialized to NONE (0)");
    assert_equals(ev.bubbles, false,
                  "bubbles should be initialized to false");
    assert_equals(ev.cancelable, false,
                  "cancelable should be initialized to false");
    assert_equals(ev.defaultPrevented, false,
                  "defaultPrevented should be initialized to false");
    assert_equals(ev.isTrusted, false,
                  "isTrusted should be initialized to false");
  }, "createEvent('" + arg + "') should be initialized correctly.");
}
Comment 6 WebKit Commit Bot 2016-08-29 12:57:02 PDT
Comment on attachment 287305 [details]
Patch

Clearing flags on attachment: 287305

Committed r205138: <http://trac.webkit.org/changeset/205138>
Comment 7 WebKit Commit Bot 2016-08-29 12:57:09 PDT
All reviewed patches have been landed.  Closing bug.