-
Notifications
You must be signed in to change notification settings - Fork 165
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
Dictionary mixins #195
Comments
This specific case can't be handled with dictionary inheritance? The general case of multiple specs all wanting to add stuff to multiple dictionaries can't be handled that way, of course, but the specific cases of "multiple specs wanting to add stuff to a single dictionary" case is handled by partial dictionary and afaict "multiple specs wanting to share a single dictionary definition but extend it" is handled by dictionary inheritance. Unlike interface inheritance, dictionary inheritance has very little in the way of observable properties (nothing apart from [[Get]] ordering), so should be quite usable as a specification device as needed here. We can probably do full-on dictionary mixins, but I'd like to see a better justification for the resulting complexity, both in terms of spec and in terms of implementations. |
The problem with inheritance is that we have Event (EventInit dict) > MessageEvent (MessageEventInit dict) and on the other side we have Event (EventInit dict) > ExtendableEvent (ExtendableEventInit dict) > ExtendableMessageEvent (ExtendableMessageEventInit dict). I don't really see how to make that work. (If inheritance worked for dictionaries here it would also work for the interface side of things, no?) |
Oh, I see. I hadn't realized that the ExtendableEventInit thing was in there too. Then yeah, doing this does require mixins. :( |
@tobie Any follow-up on the plan to add dictionary mixins (#363 (comment))? This would help document only once properties used in multiple dictionary types. |
None at present, unfortunately. |
@tobie Ok. In the meantime, any recommendation for specifying complex dictionary structures intended to be passed to Web APIs? |
Is there still any interest in adding this? I have a possible use for it in WebKit. In my opinion, allowing |
@dcrousso the property [[Get]] order, as bzbarsky mentioned, does expose the inheritance chain to ES code. Within a single "tier", keys are sorted lexically, but the access order is one-tier-at-a-time. If they were always sorted across the chain, the exposure would go away, but that likely isn't web compatible (and might lead to problems for implementers). One ordering solution for mixins would be to handle them like partials: "these keys belong to the includes-target, so they get sorted lexically among the others". I'm pretty sure that would keep the access order well-defined without borking anything that already exists? |
For dictionaries in particular I think we should keep lexicographical ordering. If we have dictionary mixins, that would be across all of the members. I agree that's not possible for interfaces/classes. There per-thing is probably the best we can do. |
ExtendableMessageEvent defined at https://w3c.github.io/ServiceWorker/#extendablemessage-event-section and MessageEvent defined at https://html.spec.whatwg.org/multipage/comms.html#messageevent are extremely similar.
To duplicate less and consolidate fixes in a single place it would be better if they used a shared mixin. However, that would not work for initializing them as the dictionaries would still need to have the duplication.
Thus, the need is born for dictionary mixins.
Background: w3c/ServiceWorker#989.
The text was updated successfully, but these errors were encountered: