dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.07k stars 1.56k forks source link

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

Open jakemac53 opened 9 years ago

jakemac53 commented 9 years ago

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 commented 9 years ago

/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 commented 9 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

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 commented 7 years ago

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