Skip to content

Commit

Permalink
Temporal.Instant#round should treat the Big Bang (not the Unix epoch)…
Browse files Browse the repository at this point in the history
… as zero

https://bugs.webkit.org/show_bug.cgi?id=241622

Reviewed by Yusuke Suzuki.

Implement the spec fix of tc39/proposal-temporal#2210.
This change is quite simple, as we can just update the Int128 version of roundNumberToIncrement.

* JSTests/test262/expectations.yaml:
Mark four test cases as passing.

* Source/JavaScriptCore/runtime/TemporalObject.cpp:
(JSC::roundNumberToIncrement):
(JSC::abs): Deleted.

Canonical link: https://commits.webkit.org/251556@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295551 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rkirsling committed Jun 15, 2022
1 parent 671daff commit 94a9bc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 0 additions & 6 deletions JSTests/test262/expectations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1038,18 +1038,12 @@ test/built-ins/Temporal/Duration/prototype/total/timezone-wrong-type.js:
test/built-ins/Temporal/Duration/prototype/total/unit-plurals-accepted-string.js:
default: 'TypeError: Right hand side of instanceof is not an object'
strict mode: 'TypeError: Right hand side of instanceof is not an object'
test/built-ins/Temporal/Instant/prototype/round/rounding-direction.js:
default: 'Test262Error: Rounding down is towards the Big Bang, not the epoch or 1 BCE (roundingMode trunc) Expected SameValue(«-65261246399000000000», «-65261246400000000000») to be true'
strict mode: 'Test262Error: Rounding down is towards the Big Bang, not the epoch or 1 BCE (roundingMode trunc) Expected SameValue(«-65261246399000000000», «-65261246400000000000») to be true'
test/built-ins/Temporal/Instant/prototype/since/largestunit.js:
default: 'Test262Error: does not include higher units than necessary (largest unit unspecified) nanoseconds result Expected SameValue(«40», «101») to be true'
strict mode: 'Test262Error: does not include higher units than necessary (largest unit unspecified) nanoseconds result Expected SameValue(«40», «101») to be true'
test/built-ins/Temporal/Instant/prototype/toJSON/timezone-getoffsetnanosecondsfor-not-callable.js:
default: 'Test262Error: Uncallable undefined getOffsetNanosecondsFor should throw TypeError Expected a TypeError to be thrown but no exception was thrown at all'
strict mode: 'Test262Error: Uncallable undefined getOffsetNanosecondsFor should throw TypeError Expected a TypeError to be thrown but no exception was thrown at all'
test/built-ins/Temporal/Instant/prototype/toString/rounding-direction.js:
default: 'Test262Error: Rounding down is towards the Big Bang, not the epoch or 1 BCE (roundingMode trunc) Expected SameValue(«-000099-12-15T12:00:01Z», «-000099-12-15T12:00:00Z») to be true'
strict mode: 'Test262Error: Rounding down is towards the Big Bang, not the epoch or 1 BCE (roundingMode trunc) Expected SameValue(«-000099-12-15T12:00:01Z», «-000099-12-15T12:00:00Z») to be true'
test/built-ins/Temporal/Instant/prototype/toString/timezone-getoffsetnanosecondsfor-not-callable.js:
default: 'Test262Error: Uncallable undefined getOffsetNanosecondsFor should throw TypeError Expected a TypeError to be thrown but no exception was thrown at all'
strict mode: 'Test262Error: Uncallable undefined getOffsetNanosecondsFor should throw TypeError Expected a TypeError to be thrown but no exception was thrown at all'
Expand Down
19 changes: 8 additions & 11 deletions Source/JavaScriptCore/runtime/TemporalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,8 @@ double roundNumberToIncrement(double x, double increment, RoundingMode mode)
RELEASE_ASSERT_NOT_REACHED();
}

static Int128 abs(Int128 x)
{
return x < 0 ? -x : x;
}

// Same as above, but with Int128
// RoundNumberToIncrementAsIfPositive ( x, increment, roundingMode )
// https://tc39.es/proposal-temporal/#sec-temporal-roundnumbertoincrementasifpositive
Int128 roundNumberToIncrement(Int128 x, Int128 increment, RoundingMode mode)
{
ASSERT(increment);
Expand All @@ -497,15 +493,16 @@ Int128 roundNumberToIncrement(Int128 x, Int128 increment, RoundingMode mode)
quotient++;
break;
case RoundingMode::Floor:
case RoundingMode::Trunc:
if (sign)
quotient--;
break;
case RoundingMode::Trunc:
break;
case RoundingMode::HalfExpand:
// "half up away from zero"
if (abs(remainder * 2) >= increment)
quotient += sign ? -1 : 1;
// "half up toward infinity"
if (!sign && remainder * 2 >= increment)
quotient++;
else if (sign && -remainder * 2 > increment)
quotient--;
break;
// They are not supported in Temporal right now.
case RoundingMode::Expand:
Expand Down

0 comments on commit 94a9bc2

Please sign in to comment.