Skip to content

dart2js passes type parameters to @JS constructors #43373

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

Open
harryterkelsen opened this issue Sep 9, 2020 · 2 comments
Open

dart2js passes type parameters to @JS constructors #43373

harryterkelsen opened this issue Sep 9, 2020 · 2 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P2 A bug or feature request we're likely to work on web-dart2js web-js-interop Issues that impact all js interop

Comments

@harryterkelsen
Copy link
Contributor

We have a @js annotated class with a type parameter:

typedef SkObjectFinalizer<T> = void Function(T key);

 @JS('window.FinalizationRegistry')
class SkObjectFinalizationRegistry<T> {
  external SkObjectFinalizationRegistry(SkObjectFinalizer<T> finalizer);
  external void register(Object ckObject, Object skObject);
}

And an instantiation:

final SkObjectFinalizationRegistry<SkDeletable> skObjectFinalizationRegistry = SkObjectFinalizationRegistry<SkDeletable>(js.allowInterop((SkDeletable deletable) {
  _skObjectDeleteQueue.add(deletable);
  _skObjectCollector ??= _scheduleSkObjectCollection();
}));

This causes an exception at runtime due to passing the SkDeletable type to the FinalizationRegistry constructor. The generated code is something like this:

new FinalizationRegistry(new H.closure(), lookupType('SkDeletable'));

I expect for dart2js not to pass type parameters to native constructors.

@harryterkelsen harryterkelsen added web-js-interop Issues that impact all js interop dart2js-crash labels Sep 9, 2020
@sigmundch sigmundch added area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dart2js and removed dart2js-crash labels Sep 9, 2020
@sigmundch sigmundch added the P2 A bug or feature request we're likely to work on label Sep 9, 2020
@sigmundch
Copy link
Member

My first thought here would be to change the original code to remove the type parameter, seems like @hterkelsen you already have a PR to do so, correct? If so, I'm keeping this as a P2 to eventually fix dart2js.

Because generics are not reified on JS-interop types, I'm wondering whether this should be a static compile-time error instead. If we decide to go down that path, we could add it as part of the js-interop validation checks that @srujzs has been working on recently, my only fear is that this would be more breaking than other checks we've been adding so far.

@srujzs
Copy link
Contributor

srujzs commented Sep 10, 2020

FYI: there are related tasks to be done in #32929 regarding specifying and adding errors for generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P2 A bug or feature request we're likely to work on web-dart2js web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants