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

Need a way of passing undefined to JS via dart:js #24088

Open
jakemac53 opened this issue Aug 14, 2015 · 6 comments
Open

Need a way of passing undefined to JS via dart:js #24088

jakemac53 opened this issue Aug 14, 2015 · 6 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-js type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop

Comments

@jakemac53
Copy link
Contributor

Many apis on the JS side of things treat null and undefined very differently. We need a way of explicitly passing undefined via js interop.

The easiest way is probably to define a top level const variable?

@sigmundch
Copy link
Member

/cc @jacob314 @jmesserly - I recall we were having some discussions about this about a month ago

this should be solvable by changing the dart:js library. We don't want to wrap "undefined" in the Dart side of things though, so while we can pass undefined down, I would prefer that we continue to translate undefined to null when reading it back in Dart.

@jakemac53
Copy link
Contributor Author

@sigmundch I agree. I think the cases where a JS api returns a value of null and undefined as different things are pretty rare. In that case you could always make a little wrapper js function which returns some other value for undefined.

@alextekartik
Copy link

Is there any workaround for that? indexeddb Index.count() and ObjectStore.count() on IE10/11/Edge12 seems to expect an undefined key, not a null key for counting all items

@jakemac53
Copy link
Contributor Author

You can today create a js object which you use to represent undefined, and then wrap the functions on the js side, checking for that value and replacing it with undefined as necessary. Until we get real support I think that is the only option?

@jacob314
Copy link
Member

We could add a getter to js_util called "undefined".
It will work great it in ddc and dart2js but in dartium it will be a bit wonky.
Specifically in dart2js and dartium, it will work any time you would have used null but in dartium it will be strangely different from null. It will convert to undefined when passed to JS but otherwise it will look like an instance of some strange class (e.g. _JSUndefined).

@filiph
Copy link
Contributor

filiph commented Mar 9, 2017

FWIW, I'm fine with this. Since this is blocking people from using some major JS APIs (like Firebase, googlearchive/firebase-dart#90) right now, I think it's worth it. _JSUndefined seems like a good name to me.

nshahan pushed a commit to angulardart/angular_components that referenced this issue Nov 12, 2018
Add a default value and try/catch block around WheelEvent.delta(X/Y/Mode).

html_dart2js does not throw error when deltaX/deltaY is null. So null handling is also added.

Add test for null deltaX/deltaY/deltaMode because 'undefined' cannot be passed as value.
dart-lang/sdk#24088
dart-lang/sdk#31515

PiperOrigin-RevId: 218253658
nshahan pushed a commit to angulardart/angular_components that referenced this issue Nov 15, 2018
Add a default value and try/catch block around WheelEvent.delta(X/Y/Mode).

html_dart2js does not throw error when deltaX/deltaY is null. So null handling is also added.

Add test for null deltaX/deltaY/deltaMode because 'undefined' cannot be passed as value.
dart-lang/sdk#24088
dart-lang/sdk#31515

PiperOrigin-RevId: 218253658
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@joshualitt joshualitt added the web-js-interop Issues that impact all js interop label Nov 2, 2021
@lrhn lrhn added the type-enhancement A request for a change that isn't a bug label Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-js type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

9 participants