You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
wasm null should be mapped to JS undefined, not JS null #9
As in any interlanguage mapping, no mapping is perfect but some are more useful than others.
NOTE: It may already be too late to make this change, even if we agree it would have been a good idea.
Wasm null is used for the uninitialized value on of values of nullable types. For nullable types, null will be the unique platform supported value to indicate that the expected value is absent. This corresponds most closely to the JS undefined rather than the JS null. For the ES specification itself, undefined is consistently treated as the indicator of absence:
varx;// x === undefinedlety;// y === undefinedfunctionfoo(x){console.log(x);}foo();// unbound parameters bound to undefinedfoo();// non-return returns undefined({}).z;// absent properties read as undefinedfunctionbar(x=3){returnx;}bar();// 3. unbound parameters use default valuebar(undefined);// 3. parameters bound to undefined act as if unboundbar(null);// null. null does not emulate unbound(newMap()).get("x");// undefined indicates absence
I disagree. My experience as author/designer of Scala.js is that Scala's null maps perfectly well to JavaScript's null. And that, despite the fact that uninitialized fields of reference types are initialized with null (as per the JVM behavior).
The perfect mapping we found for undefined is actually unit (written () in Scala). This may seem weird, but is easily explained when you consider "void" functions: in JavaScript, a function without explicit return (or with return; without expression) returns undefined; in Scala, a function that does not return any value returns () of type Unit.
For nullable types, null will be the unique platform supported value to indicate that the expected value is absent.
The key words here are for nullable types. But wasm also has non-nullable types, for example ints, and those are initialized with 0/false/etc.. Obviously wasm's 0 cannot map to undefined in JS. Now, an "undefined int variable" in JS would also be initialized to undefined (because, hey, no types). So the mapping of uninitialized would be inconsistent between nullable types (map to undefined) and non-nullable types (map to 0, false, etc.). For that reason, I do not think the "this corresponds closely to the JS undefined" is actually accurate. Or at least, if it did correspond so closely, then so should 0, and we know that's nonsense.
It might also be a source of confusion, because undefined then would be the symptom of two different causes: either a variable was indeed never defined, or it was a null reference that flew out of wasm. This would probably make debugging harder.
Reacted by Sébastien Doeraene, Sergey Rubanov and ExE Boss
Activity
sjrd commentedon Apr 10, 2018
I disagree. My experience as author/designer of Scala.js is that Scala's
nullmaps perfectly well to JavaScript'snull. And that, despite the fact that uninitialized fields of reference types are initialized withnull(as per the JVM behavior).The perfect mapping we found for
undefinedis actuallyunit(written()in Scala). This may seem weird, but is easily explained when you consider "void" functions: in JavaScript, a function without explicitreturn(or withreturn;without expression) returnsundefined; in Scala, a function that does not return any value returns()of typeUnit.The key words here are for nullable types. But wasm also has non-nullable types, for example ints, and those are initialized with
0/false/etc.. Obviously wasm's0cannot map toundefinedin JS. Now, an "undefined int variable" in JS would also be initialized toundefined(because, hey, no types). So the mapping of uninitialized would be inconsistent between nullable types (map toundefined) and non-nullable types (map to0,false, etc.). For that reason, I do not think the "this corresponds closely to the JSundefined" is actually accurate. Or at least, if it did correspond so closely, then so should0, and we know that's nonsense.bnjbvr commentedon Apr 11, 2018
It might also be a source of confusion, because
undefinedthen would be the symptom of two different causes: either a variable was indeed never defined, or it was a null reference that flew out of wasm. This would probably make debugging harder.lars-t-hansen commentedon Nov 15, 2019
@rossberg, can you tag this as [js-api] so that it's plain that it doesn't block the core proposal? Thanks.
rossberg commentedon Nov 15, 2019
Done. I also take the liberty to close this, since it is incompatible with the existing table API.