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
So for example, [ ...new Set([ -0 ]) ][0] is 0, not -0. More importantly this means new Set([ -0, 0 ]) and new Set([ 0, -0 ]) behave equivalently — you can’t observe which zero happened to be added first.
The proposal’s updated SameValueZero will have SameValueZero(#[ -0 ], #[ 0 ]) === true (which makes sense), but I would expect corresponding updates in %Map.prototype.set% and %Set.prototype.add% that canonicalize* the key to include, at depth, only positive zeros. Presumably this would be realized with a new shared abstract op (e.g. ToCanonicalSVZValue) that could also encapsulate the existing -0 → 0 behavior.
* This is spiritually related to #291, but observable non-canonical NaNs showing up in weird places is a meta-issue that isn’t specific to this proposal. The Map/Set negative zero canonicalization on the other hand is an existing concrete/262-specified behavior.
The text was updated successfully, but these errors were encountered:
Thanks @acutmore, sorry for the dupe. At length indeed! I remember reading that a while ago now, but missed the conclusion that it was intentional to break from the existing Map/Set canonicalization behavior.
Though I personally believe that behavior should never have existed in the first place, it does and can’t go away now, so I think the decision to depart from it here is unfortunate — it (unintuitively) adds more quirky complexity to Map/Set’s keying semantics, it doesn’t reduce it — but I appreciate that this has already been discussed in depth.
%Map% and %Set% use SameValueZero semantics for key comparison, but they additionally normalize
-0
to0
:Map.prototype.set(key, value)
Set.prototype.add(value)
So for example,
[ ...new Set([ -0 ]) ][0]
is0
, not-0
. More importantly this meansnew Set([ -0, 0 ])
andnew Set([ 0, -0 ])
behave equivalently — you can’t observe which zero happened to be added first.The proposal’s updated SameValueZero will have
SameValueZero(#[ -0 ], #[ 0 ]) === true
(which makes sense), but I would expect corresponding updates in %Map.prototype.set% and %Set.prototype.add% that canonicalize* the key to include, at depth, only positive zeros. Presumably this would be realized with a new shared abstract op (e.g. ToCanonicalSVZValue) that could also encapsulate the existing-0
→0
behavior.* This is spiritually related to #291, but observable non-canonical NaNs showing up in weird places is a meta-issue that isn’t specific to this proposal. The Map/Set negative zero canonicalization on the other hand is an existing concrete/262-specified behavior.
The text was updated successfully, but these errors were encountered: