Implement FrozenArray in webidl
Categories
(Core :: DOM: Bindings (WebIDL), enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox46 | --- | affected |
People
(Reporter: jib, Unassigned)
References
(Depends on 1 open bug, Blocks 2 open bugs, )
Details
(Keywords: dev-doc-needed)
Comment 1•9 years ago
|
||
Comment 2•9 years ago
|
||
Comment 3•9 years ago
|
||
Comment 4•9 years ago
|
||
Comment 5•9 years ago
|
||
Comment 6•9 years ago
|
||
Updated•9 years ago
|
Comment 7•9 years ago
|
||
Comment 8•8 years ago
|
||
Comment 9•8 years ago
|
||
Comment 10•8 years ago
|
||
Updated•7 years ago
|
| Assignee | ||
Updated•6 years ago
|
Comment 11•6 years ago
|
||
Just wanted to throw my hat in the ring on this one. Unfortunately we need support for FrozenArrays because it's the only way to implement a static attribute that returns a sequence.
E.g., https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute
The other workarounds are useful, but cannot be applied in the static case:
TypeError: Attribute PerformanceObserver.supportedEntryTypes is static, so we don't have a useful slot to cache it in, because we don't have support for that on interface objects.
Comment 12•6 years ago
|
||
Will, I just looked at the linked spec and it has two problems:
- If it's returning a new object each time, why is that object a FrozenArray? Why not just return a sequence?
- If it's returning a new object each time, why is it an attribute? That's a serious anti-pattern for attributes.
My guess is that "it's not a sequence, because IDL does not allow sequences, because it's an antipattern, so the spec authors worked around that by using a frozen array, but cheated by not actually returning it by reference like you're supposed to do with a frozen array". Incidentally, the spec is nonsense, because it's returning an infra list, not an actual FrozenArray value, for something of type FrozenArray, which is being forced on them by their broken workaround.
tl;dr: even if we implemented FrozenArray as defined in the IDL spec you would not be able to implement this spec as written with it. The right course of action is to file a spec issue: this spec should have a static operation that returns sequence, if it wants to return new values each time. Do you want to file that spec issue, or do you want me to?
Comment 13•6 years ago
|
||
Thanks for your reply, :bzbarsky. (For what it's worth, I hear that you are coming to the TO office for a workweek and I'm looking forward to meeting you!)
I would be happy to file the bug report, but I think that your arguments are really cogent and would carry more weight coming from you. There are several other aspects of the spec that are not fully baked and, after working through an implementation for FF, I will be filing some additional bugs.
Thanks again for your help with this!! And, of course, I didn't mean to imply that the spec was perfect and that we were wrong. I was simply trying to implement what they said.
Thanks again for your response!
Will
Comment 14•6 years ago
|
||
Will, looking forward to meeting you!
I filed https://github.com/w3c/performance-timeline/issues/117
In the meantime, if we really do want to implement what this spec says right now that is in fact possible: define the return type as object and then use ToJSValue on an nsTArray with the relevant strings to create the array, followed by freezing the array to create the value to return. It's not very pretty, but it's what you would have to do anyway even if we had FrozenArray support, if we implemented it per IDL spec.
Comment 15•6 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #14)
Will, looking forward to meeting you!
I filed https://github.com/w3c/performance-timeline/issues/117
In the meantime, if we really do want to implement what this spec says right now that is in fact possible: define the return type as
objectand then useToJSValueon annsTArraywith the relevant strings to create the array, followed by freezing the array to create the value to return. It's not very pretty, but it's what you would have to do anyway even if we hadFrozenArraysupport, if we implemented it per IDL spec.
Thanks again for the response! I don't know whether to be pleased or dismayed, but I generally understand the method you suggest. I will work through it tomorrow.
Look forward to meeting you in a few weeks!
Updated•6 years ago
|
Updated•5 years ago
|
Updated•3 years ago
|
Updated•5 months ago
|
Description
•