Skip to content

Commit

Permalink
fix(pass-style,marshal): -0 should round trip distinct from 0
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Oct 13, 2023
1 parent 41e1215 commit da77610
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/marshal/src/encodePassable.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const CanonicalNaNBits = 'fff8000000000000';
*/
const encodeBinary64 = n => {
// Normalize -0 to 0 and NaN to a canonical encoding
// TODO https://github.com/endojs/endo/issues/1602
if (is(n, -0)) {
n = 0;
} else if (is(n, NaN)) {
Expand Down
1 change: 1 addition & 0 deletions packages/marshal/src/encodeToCapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const makeEncodeToCapData = (encodeOptions = {}) => {
return { [QCLASS]: '-Infinity' };
}
// Pass through everything else, replacing -0 with 0.
// TODO https://github.com/endojs/endo/issues/1602
return is(passable, -0) ? 0 : passable;
}
case 'bigint': {
Expand Down
1 change: 1 addition & 0 deletions packages/marshal/src/encodeToSmallcaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const makeEncodeToSmallcaps = (encodeOptions = {}) => {
return '#-Infinity';
}
// Pass through everything else, replacing -0 with 0.
// TODO https://github.com/endojs/endo/issues/1602
return is(passable, -0) ? 0 : passable;
}
case 'bigint': {
Expand Down
2 changes: 2 additions & 0 deletions packages/marshal/src/rankOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const { entries, fromEntries, setPrototypeOf, is } = Object;
* abstractions, where NaN is the same as NaN and -0 is the same as
* 0. Marshal serializes -0 as zero, so the semantics of our distributed
* object system does not distinguish 0 from -0.
* TODO https://github.com/endojs/endo/issues/1602
* and revise above comment.
*
* `sameValueZero` is the EcmaScript spec name for this equality comparison,
* but TODO we need a better name for the API.
Expand Down

0 comments on commit da77610

Please sign in to comment.