Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GamepadEvent constructor is missing the type argument #35

Closed
foolip opened this issue Sep 15, 2016 · 12 comments
Closed

GamepadEvent constructor is missing the type argument #35

foolip opened this issue Sep 15, 2016 · 12 comments

Comments

@foolip
Copy link
Member

foolip commented Sep 15, 2016

https://w3c.github.io/gamepad/#gamepadevent-interface

[Constructor(GamepadEventInit eventInitDict)]
interface GamepadEvent : Event {
    readonly        attribute Gamepad gamepad;
};

A type argument needs to precede the dictionary. [SameObject] would be nice too, so:

[Constructor(DOMString type, GamepadEventInit eventInitDict)]
interface GamepadEvent : Event {
    [SameObject] readonly attribute Gamepad gamepad;
};
@cdumez
Copy link

cdumez commented Oct 10, 2016

Yes, I noticed it as well when updating WebKit. Gecko / Blink and WebKit all take a type as first constructor parameter.

@cdumez
Copy link

cdumez commented Sep 21, 2017

eventInitDict should also be marked as optional. This matches both Firefox and Chrome's behavior. I will align WebKit accordingly.

@cdumez
Copy link

cdumez commented Sep 21, 2017

Per Web IDL:
"""
If the type of an argument is a dictionary type (or a union type that has a dictionary as one of its flattened member types), and that dictionary type and its ancestors have no required members, and the argument is either the final argument or is followed only by optional arguments, then the argument must be specified as optional. Such arguments are always considered to have a default value of an empty dictionary, unless otherwise specified.
"""

@foolip
Copy link
Member Author

foolip commented Sep 22, 2017

@toji, can you take a look at this?

@nondebug
Copy link
Collaborator

The PR looks good to me, but I think the GamepadEventInit param need not be optional unless we also change the gamepad member to optional.

@cdumez
Copy link

cdumez commented Sep 22, 2017

Good point about making the gamepad dictionary member optional.

That said, Firefox and Chrome have the GamepadEventInit parameter as optional. The following WPT relies on it being optional too:
http://w3c-test.org/dom/events/Event-timestamp-high-resolution.html

I made it optional yesterday in WebKit to align with Firefox and Chrome.

As such, I would suggest updating the spec to match browsers?

@foolip
Copy link
Member Author

foolip commented Sep 22, 2017

Ah, another of these cases where the dictionary member being optional makes the corresponding interface attribute nullable be necessity. There's a TODO around this in Blink pointing to https://crbug.com/647693 and this very issue.

Making it nullable+optional would make sense given that it already effectively is all implementations it seems.

@cdumez
Copy link

cdumez commented Sep 22, 2017

Yes, I confirmed it is nullable in WebKit as well:

[
    Constructor(DOMString type, optional GamepadEventInit eventInitDict),
] interface GamepadEvent : Event {
    readonly attribute Gamepad? gamepad;
};

dictionary GamepadEventInit : EventInit {
    // The specification says this member should be required and non-nullable.
    // However, this does not match the behavior of Chrome or Firefox.
    Gamepad? gamepad = null;
};

@ddorwin
Copy link
Contributor

ddorwin commented Dec 4, 2018

@foolip Should GamepadEventInit be made optional too? This is still unresolved (web-platform-tests/wpt#14357). @ylafon, please reopen to address this issue.

@foolip
Copy link
Member Author

foolip commented Dec 4, 2018

@ddorwin, it should be optional if there are no required members, and otherwise non-optional.

@foolip
Copy link
Member Author

foolip commented Dec 4, 2018

(This is just generally how dictionary arguments are handled made optional or not depending on dictionary members, not something special about this case.)

@marcoscaceres
Copy link
Member

And default values in the dictionary, if possible 😊 general advice too. Feel free to tag me for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants