Title: [295551] trunk
- Revision
- 295551
- Author
- ross.kirsl...@sony.com
- Date
- 2022-06-14 19:49:15 -0700 (Tue, 14 Jun 2022)
Log Message
Temporal.Instant#round should treat the Big Bang (not the Unix epoch) 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/_javascript_Core/runtime/TemporalObject.cpp:
(JSC::roundNumberToIncrement):
(JSC::abs): Deleted.
Canonical link: https://commits.webkit.org/251556@main
Modified Paths
Diff
Modified: trunk/JSTests/test262/expectations.yaml (295550 => 295551)
--- trunk/JSTests/test262/expectations.yaml 2022-06-15 02:27:07 UTC (rev 295550)
+++ trunk/JSTests/test262/expectations.yaml 2022-06-15 02:49:15 UTC (rev 295551)
@@ -1038,9 +1038,6 @@
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'
@@ -1047,9 +1044,6 @@
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'
Modified: trunk/Source/_javascript_Core/runtime/TemporalObject.cpp (295550 => 295551)
--- trunk/Source/_javascript_Core/runtime/TemporalObject.cpp 2022-06-15 02:27:07 UTC (rev 295550)
+++ trunk/Source/_javascript_Core/runtime/TemporalObject.cpp 2022-06-15 02:49:15 UTC (rev 295551)
@@ -472,12 +472,8 @@
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);
@@ -497,15 +493,16 @@
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:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes