Skip to content
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

Static interop should use compiler-dependent global context #52955

Closed
srujzs opened this issue Jul 17, 2023 · 2 comments
Closed

Static interop should use compiler-dependent global context #52955

srujzs opened this issue Jul 17, 2023 · 2 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@srujzs
Copy link
Contributor

srujzs commented Jul 17, 2023

Currently, we use globalThis everywhere, but this is not necessarily available. Instead, we should have the compilers decide what to use for interop. For dart2js, this is likely self and for DDC, this is likely dart.global. Long-term, we should avoid making interop based on the global context unless requested and instead define a scope where we expect users to export their JS code to. We do need to be careful about the compilers shadowing names, however.

@srujzs srujzs changed the title Add preamble to dart2js and DDC to set globalThis if it doesn't exist for static interop Static interop should use compiler-dependent global context Jul 17, 2023
@srujzs srujzs added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop labels Jul 17, 2023
@rakudrama
Copy link
Member

Is the global context something that is fixed, and can be captured for re-use?

Is dart2js allowed to reuse an access of the global context as an optimization?

@srujzs
Copy link
Contributor Author

srujzs commented Jul 18, 2023

Talked offline about this but yes, we'd want dart2js to be able to cache this by marking this getter as "pure" through the JS foreign function's metadata. DDC naturally won't be able to do this, but that's okay, since that's the current behavior of interop and dart:html.

@srujzs srujzs self-assigned this Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
Status: Done
Development

No branches or pull requests

2 participants