Skip to content

Commit

Permalink
[MERGE #4754 @jackhorton] OS#16115338 Update _.floor to normalize -0 …
Browse files Browse the repository at this point in the history
…to 0 [OSS-Fuzz]

Merge pull request #4754 from jackhorton:os16115338

The intl spec refers to the `floor` function in [DefaultNumberOption](https://tc39.github.io/ecma402/#sec-defaultnumberoption), which we had previously implemented as exactly Math.floor Math.floor is defined to return -0 when given -0 as input. However, DefaultNumberOption actually refers to [the floor mathematical operation](https://tc39.github.io/ecma262/#sec-mathematical-operations), which states that -0 should be normalized to 0, which is the more intuitive behavior.

This fixes a FailFast that triggered when we couldn't retrieve the minimumFractionDigits as a TaggedInt.
  • Loading branch information
jackhorton committed Mar 1, 2018
2 parents 12f84bd + 02df7fe commit a61618b
Show file tree
Hide file tree
Showing 6 changed files with 27,437 additions and 27,384 deletions.
3 changes: 2 additions & 1 deletion lib/Runtime/Library/InJavascript/Intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
setPrototypeOf(target, proto = null) { return platform.builtInSetPrototype(target, proto); },

abs: platform.builtInMathAbs,
floor: platform.builtInMathFloor,
// Make _.floor more like ECMA262 #sec-mathematical-operations' floor by normalizing -0
floor(x) { return x === 0 ? 0 : platform.builtInMathFloor(x) },
max: platform.builtInMathMax,
pow: platform.builtInMathPow,

Expand Down
14,200 changes: 7,105 additions & 7,095 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Large diffs are not rendered by default.

14,198 changes: 7,104 additions & 7,094 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Large diffs are not rendered by default.

13,206 changes: 6,608 additions & 6,598 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Large diffs are not rendered by default.

13,202 changes: 6,606 additions & 6,596 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions test/Intl/NumberFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ const tests = [
assert.matches(/1[\x20\u00a0]?%/, format({ style: "percent" }, 0.01));
assert.matches(/10,000[\x20\u00a0]?%/,format({ style: "percent" }, 100));
}
},
{
name: "Negative 0",
body() {
assert.areEqual(
0,
new Intl.NumberFormat(undefined, { minimumFractionDigits: -0 }).resolvedOptions().minimumFractionDigits,
"Passing -0 for minimumFractionDigits should get normalized to 0 by DefaultNumberOption"
);
// This assert may need to change in the future, pending any decision made on https://github.com/tc39/ecma402/issues/219
assert.areEqual("0", (-0).toLocaleString(), "-0 should be formatted as 0");
}
}
];

Expand Down

0 comments on commit a61618b

Please sign in to comment.