-
Notifications
You must be signed in to change notification settings - Fork 137
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
Invalid Web IDL for VideoFrame: attributes cannot accept dictionary types #278
Comments
Assuming that we use a getter, should we be freezing the result so that we can return the same dictionary multiple times? |
I find whatwg/webidl#938 surprising. I follow that it may not be obvious that a dictionary attribute is always copied, but I'm confused why returning it via getter method helps clarify? @domenic +1 to Dan's question above. |
It is very surprising to JavaScript developers when It is not surprising to JavaScript developers when This is codified in https://w3ctag.github.io/design-principles/#attributes-like-data . So using a method instead of a getter avoids this problem. |
@domenic It's still not clear whether a freezing these dictionary attributes would be sufficient to meet the requirements? |
Freezing dictionaries isn't really a pattern we've seen on the web platform, apart from a couple of legacy cases. You'd have to work outside of the system of IDL bindings, i.e. just use A getter method is probably better. Or, just inline the attributes into the parent interface, e.g. instead of |
Looking into the cause here, I think the problem is that you're duplicating a lot of work people have already done by creating the DOMRectReadOnly and DOMRectInit types... I'd suggest using those instead. Note that DOMRectReadOnly is an interface so it can be the type of an attribute. You'd have to do your own normalization on the input DOMRectInit to round any values and outlaw infinites/NaNs, but that's fine. |
We considered We also previously did have inlined attributes (eg. I think we prefer methods over switching to |
Note that the integer vs. double types are not visible to JavaScript developers or other API users. (JavaScript only has doubles.) They are only manifested in how many "automatic" normalization steps you get done by Web IDL automatically. So DOMRectInit + a manual normalization step to integers on inputs has the exact same semantics as an integer-only dictionary. And DOMRectReadOnly on the output side has the exact same semantics as an integer-only dictionary, as long as you only put integers into it in your spec. (Well, aside from DOMRectReadOnly being an interface, and thus being valid Web IDL to use for this.) So I'd really suggest DOMRectReadOnly + DOMRectInit. |
This is surprising to me, I was expecting future direct WASM bindings to be more IDL-like?
I'm assuming you are proposing that our parameters should be (DOMRect or DOMRectReadOnly or DOMRectInit)? |
They should be DOMRectInit, since a DOMRect or DOMRectReadOnly automatically satisfies the contract of DOMRectInit. |
To give a bit more detail (sorry, I was typing the above while in a meeting):
|
Is it preferable to convert vs require? We could instead check that integers were provided and throw exceptions. |
I can't think of any other API on the web platform which throws an exception on non-integer values (including your own specification of VideoFrameRect), so I think convert would be better. |
#208 introduced attributes
codedRect
andvisibleRect
toVideoFrame
with aVideoFrameRect
dictionary type.Web IDL forbids the use of a dictionary type for attributes, see the Dictionaries section: "Dictionaries must not be used as the type of an attribute or constant". For the rationale, see for example whatwg/webidl#938.
I believe the alternative is to define an explicit
getter
operation.The text was updated successfully, but these errors were encountered: