Closed dckc closed 5 years ago
Not sure if this is relevant, but Jessie only has ===
, not ==
, so it is expected only to have value equality for strings and numbers.
JavaScript has no value equality. ===
on objects is identity equality. ==
is neither identity nor value equality, nor anything sensible. It is a pile of insane coercions followed by a ===
.
Since WeakMap
and WeakSet
accept only objects as keys, the equality they use is equivalent to ===
on these object keys.
Ignoring insane ==
which we omit from Jessie, JavaScript has three abstract equality operations that differ on their handling of NaN
and -0
but are otherwise equivalent. All three of these are unfortunately present in Jessie as well, since NaN
and -0
are present, as are the constructs that apply each of these three. The fourth case below is more of an abstraction leak and is fortunately absent from Jessie.
For ===
, indexOf
, switch
case matching, NaN !== NaN
. 0 === -0
.
Object.is
(which is in Jessie) and Object.defineProperty
(which is not in Jessie), Object.is(NaN, NaN)
. !(Object.is(0, -0))
.For the collections that accept non-object keys, i.e., Set
and Map
, and I think for something else, NaN
is considered the same as NaN
and 0
is considered the same as -0
.
Finally, code that serializes JavaScript values into ArrayBuffers can observe the encoding differences between different NaNs. EcmaScript has careful spec language around this to enable us to reason about the non-overt (covert and side) channels it opens up. Fortunately, these primitive serialization operations are absent from Jessie.
I wrote all this from memory. Someone should check it against the spec. In particular, I'm not sure I'm remembering indexOf
and switch
case matching accurately.
I didn't mean anything by ==
vs ===
.
It's pretty clear that the bottom line is: Too bad. JavaScript is what it is. Yes, if you're implementing Jessie in something where all maps from 1 to 2 and 3 to 4 are indistinguishable, you'll have to add some creation-marker thingy on the side to distinguish them in Jessie.
If I were to implement Jessie using something that has a notion of value-equality for maps, lists, and sets, like python, Monte, or scala, this would be particularly inconvenient:
Is there a feasible answer besides too bad :-P ?