-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Today, compiled code in each of the compilers (testing with test_runner) behaves the following way:
dart2wasm: strict mode (@osa1 mentions not intentionally with "use strict"
, it looks like the imported generated JS code when instantiating the module uses strict mode implicitly)
dart2js: non-strict mode
ddc: strict mode with "use strict"
(both AMD and DDC library bundle formats)
This is an issue when it comes to JS interop. For example, if we have a Dart function that's passed to JS and called, the semantics of the function will depend on the compiler. One example is if we use toJSCaptureThis
and call it with .call('abc')
in JS. With strict mode, the this
value in the function will stay a string, but with non-strict mode, it will be converted to an object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call#thisarg.
Another issue is that functions and files can opt into strict mode using "use strict"
headers, but cannot necessarily opt out, so that may influence which direction we go with this. That being said, one can't just put "use strict"
in the toJS
'd Dart function as it may get tree-shaken/the compiled code may look different, so opting into strict mode may not be easy either.
We could make strict mode configurable, but that might be more effort/testing than it's worth. I'd prioritize consistency first.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status