Skip to content

DDC: JS-Interop tearoffs cause type errors #32370

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

Closed
matanlurey opened this issue Mar 1, 2018 · 3 comments
Closed

DDC: JS-Interop tearoffs cause type errors #32370

matanlurey opened this issue Mar 1, 2018 · 3 comments
Labels
closed-duplicate Closed in favor of an existing report web-js-interop Issues that impact all js interop

Comments

@matanlurey
Copy link
Contributor

I had code like the following:

sink.stream.listen(worker.postMessage);

... and had to change it to the following to get it to work/not error out:

sink.stream.listen((m) => worker.postMessage(m));
@kevmoo kevmoo added web-js-interop Issues that impact all js interop web-dev-compiler labels Mar 1, 2018
@jmesserly
Copy link

If you have more info (like a full repro) I'd be curious to see it. JS functions are supposed to be able to subtype all Dart functions.

Note that JS "tearoffs" obey JS rules: they don't bind this. That is intentional, as far as I know (CC @jacob314 ). I'm not sure the best way to trigger bind on the JS function from Dart.

@jacob314
Copy link
Member

jacob314 commented May 3, 2018

yes JS tearoffs intentionally follow JS function tearoff semantics not Dart function tearoff semantics and in Dart 1.0 there was definitely no way we could make them follow Dart semantics as Dart 1.0 is too dynamic so this is ambiguous at compilation time.

For example, there might be another JS interop class where
postMessage is a getter that returns a Function in which case binding "this" is definitely not what you want.
For Dart 2.0 it could be reasonable to bind this in a tearoff of a JS method. In the static dispatch case there would be no cost in Dart 2 and in Dart2 it is ok if the dynamic dispatch case is more expensive. There would be some edge cases in the dynamic case that would be a bit off for anonymous js classes but the amount of odd behavior would be a lot more limited.

Back in a Dart 1.0 world this was also reasonable you could implement a Dart class with noSuchMethod that chose to use JS semantics for tearoffs so it isn't quite as far outside of the regular Dart behavior.

@jmesserly
Copy link

merging this into #35084. Agree with y'all that we should perform the tearoff, based on the static type info.

@jmesserly jmesserly added the closed-duplicate Closed in favor of an existing report label Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants