-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow users to access hidden and incomplete HTML APIs #42200
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
Comments
With the second option, note that there are some native classes in Otherwise, I think the least disruptive migration path would be that if an app or plugin defines its own |
Thanks @ryanheise for sharing your insights here and in #44211! Your point on existing methods having incorrect signatures is very valid, and something we want to improve on. We would love for To address some of your comments:
I am not sure I followed your concern here. Is this referring to names in external members of JS-interop classes? Or names from extension methods? The former are likely to show a lot of false positives, so we can't really reject them. If someone has a JS object that happens to have a property named The latter I hope it can be resolved by the compiler without conflicts.
Unfortunately this is not possible yet today because it breaks composition of libraries. Imagine you have one library written against We are, however, aiming to get close to this desired scenario. It all comes down to static or virtual dispatch calls. The source of conflict comes form virtual calls, where we have to use the same semantics in the whole program. However, relying more on static dispatch mechanisms (like static extension methods), will let us generate code differently on a library that uses those static calls. |
Let's take an example from @Native("MediaSession")
class MediaSession extends Interceptor {
// ...
void setActionHandler(String action, MediaSessionActionHandler? handler)
native;
} Now let's say we want to use the extension method approach to fix the incorrect parameter type of
I was assuming that any sort of checking here would be scoped to the class of that member. Something like: raise a conflict if there is a native |
Got it, that makes perfect sense and we too share that concern and don't want an error that would prevent you from doing that. Thanks for clarifying! |
Several APIs in dart:html are incomplete and some have been hidden in our code generator as private classes. Users have run into scenarios where they want to use these classes but they find that they are incomplete, and the standard way of using Js-interop doesn't work in dart2js.
See two examples:
_USBDevice
: dart2js vs. DDC: How to cast List<dynamic> Promise callbacks (specific: navigator.usb.getDevices callback) #39147_SubtleCrypto
: NoMethodFoundError only during 'webdev serve --release' but not in 'webdev serve' for JS Interop #42194The users noticed that the API is hidden, so they tried using
@JS
to access it directly. This creates an issue because dart2js associates the dart:html interceptor with those types, so their JS-interop interfaces don't work. The only mechanism that works for them is to: store the objects in a dynamic variable and invoke it's methods viajs_util.callMethod
.Some ways to address the original issue would be to:
The former would work right away, but could potentially be a source of breaking changes in the future if we were to add back the definition in the future. The latter requires compiler work (support for external extension methods is not available), so the fix will not be available as quickly.
The text was updated successfully, but these errors were encountered: