Bug 1617586 - Part 1: Don't return -0 from ToInteger. r=jwalden

Changes ToInteger to return +0 instead of -0 and updates two callers which were
already performing the -0 to +0 conversion. Also changes NumberIsInt32 to
NumberEqualsInt32 in `atomics_isLockFree`, because we no longer need to care
about handling -0 in this function.

Differential Revision: https://phabricator.services.mozilla.com/D64027

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2020-02-27 13:10:48 +00:00
parent 67c18495c0
commit 77d747f17b
6 changed files with 12 additions and 9 deletions

View File

@ -139,10 +139,13 @@ MOZ_ALWAYS_INLINE bool ToNumber(JSContext* cx, HandleValue v, double* out) {
return js::ToNumberSlow(cx, v, out);
}
/* ES6 draft 20141224, ToInteger (specialized for doubles). */
// ES2020 draft rev 6b05bc56ba4e3c7a2b9922c4282d9eb844426d9b
// 7.1.5 ToInteger ( argument )
//
// Specialized for double values.
inline double ToInteger(double d) {
if (d == 0) {
return d;
return 0;
}
if (!mozilla::IsFinite(d)) {
@ -152,7 +155,7 @@ inline double ToInteger(double d) {
return d;
}
return d < 0 ? ceil(d) : floor(d);
return (d < 0 ? ceil(d) : floor(d)) + (+0.0); // Add zero to convert -0 to +0.
}
/* ES6 draft 20141224, 7.1.5. */

View File

@ -108,7 +108,7 @@ inline ClippedTime TimeClip(double time) {
}
// Step 3.
return ClippedTime(ToInteger(time) + (+0.0));
return ClippedTime(ToInteger(time));
}
// Produce a double Value from the given time. Because times may be NaN,

View File

@ -462,7 +462,7 @@ bool js::atomics_isLockFree(JSContext* cx, unsigned argc, Value* vp) {
if (!ToInteger(cx, v, &dsize)) {
return false;
}
if (!mozilla::NumberIsInt32(dsize, &size)) {
if (!mozilla::NumberEqualsInt32(dsize, &size)) {
args.rval().setBoolean(false);
return true;
}

View File

@ -10,7 +10,7 @@ function f() {
assertEq(Atomics.store(ia, 0, 3.5), 3);
assertEq(ia[0], 3);
assertEq(Atomics.store(ia, 0, -0), -0);
assertEq(Atomics.store(ia, 0, -0), +0);
assertEq(ia[0], 0);
assertEq(Atomics.store(ia, 0, '4.6'), 4);

View File

@ -292,7 +292,8 @@ static MOZ_ALWAYS_INLINE bool IsDefinitelyIndex(const Value& v,
return false;
}
/* ES5 9.4 ToInteger. */
// ES2020 draft rev 6b05bc56ba4e3c7a2b9922c4282d9eb844426d9b
// 7.1.5 ToInteger ( argument )
static MOZ_MUST_USE inline bool ToInteger(JSContext* cx, HandleValue v,
double* dp) {
if (v.isInt32()) {

View File

@ -162,8 +162,7 @@ static bool intrinsic_ToIntegerPositiveZero(JSContext* cx, unsigned argc,
if (!ToInteger(cx, args[0], &result)) {
return false;
}
// Add zero to convert -0 to +0.
args.rval().setNumber(result + 0.0);
args.rval().setNumber(result);
return true;
}