-
Notifications
You must be signed in to change notification settings - Fork 131
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
No constructors #10
Comments
I guess I don't really understand why it's better to have objects created explicitly in JS rather than "magically" by the UA. We could have device enumeration just return a dictionary for each device, including a unique identifier for each one, and then let the user construct a USBDevice object over one of those identifiers? And we could do the same for each interface, alternate, endpoint, etc. But what is the advantage to doing this? It seems like the API would be more annoying to use in that case. |
Any further thoughts on this? Note that devices don't have any inherent, reliable unique identifier, and even if they did we wouldn't want to expose it through the API. Adding a constructor for USBDevice would mean the UA would have to provide some artificial notion of a device identifier. I am wary of doing anything like that because it's hard to make guarantees about the stability of that identifier under certain conditions (i.e. device detach and reattach), and in turn it's easy for developers to make bad assumptions about the stability of that identifier. Though even without device IDs, the other types could trivially get constructors that take a device object and some numbers; so pending further feedback, I'll make that addition now. |
Well, in general reducing the magic in the platform to a small core is ideal.
No need to return a dictionary; you can return the constructed object. But from what you describe, it'd be perfectly possible to have a working JavaScript-exposed USBDevice constructor that takes a dictionary. If that's possible, then you have a (non-magical) explanation for where USBDevice instances come from, which is great!
Definitely no need to make it more annoying. Return actual class instances. But if those classes don't require any UA-provided data to be initialized, and can instead be initialized from simple dictionaries, then JS should be allowed to do so too!
OK, that's a perfectly good example of the "core magic" that we'd just need to keep.
Makes sense! I'll go review that PR. |
Thanks. So actually I just had a discussion with Reilly and we've concluded that there are real benefits to having some notion of a device "instance ID" which remains stable for the lifetime of a device's connection to the host, so we are going to try to work with that approach and be explicit about its meaning in the spec. Zero magic! |
We initially had a In the current API a site can request all devices with Thoughts @domenic? |
The other issue with adding a constructor for I think given that |
This sounds reasonable. In this case the decision is that it's explicitly impossible for author code to create USBDevice instances; that can only be done by the UA, on behalf of the author, in part because the UA needs to do it asynchronously. |
These interfaces can have trivial constructors. This resolves issue WICG#10.
These interfaces can have trivial constructors. This resolves issue WICG#10.
These interfaces can have trivial constructors. This resolves issue #10.
In some cases it is OK for an interface to not have a WebIDL-defined constructor. Those are the cases when an object is meant to only be created by the UA. (In which case, it has a constructor, but one that is not callable by normal JS code.)
Are all of the objects in the spec such cases? Is there a way to design the architecture better so that there are fewer magically-created objects, and more normal-constructible-from-JS objects?
The text was updated successfully, but these errors were encountered: