Skip to content
Permalink
Browse files
[JSC] Fix Temporal regulateTime's constraints for milliseconds, micro…
…seconds, and nanoseconds

https://bugs.webkit.org/show_bug.cgi?id=241818
rdar://95534859

Reviewed by Ross Kirsling.

This patch fixes constraints for milliseconds, microseconds, and nanoseconds in constrainTime.
It should be from 0 to 999, not to 1000[1].

[1]: https://tc39.es/proposal-temporal/#sec-temporal-constraintime

* JSTests/stress/temporal-plaintime-tostring-1000-millisecond.js: Added.
(shouldBe):
(throw.new.Error):
* Source/JavaScriptCore/runtime/TemporalPlainTime.cpp:
(JSC::constrainTime):

Canonical link: https://commits.webkit.org/251698@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295693 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Constellation committed Jun 21, 2022
1 parent c337b98 commit 9b4ed7838982af6ad2539c1a58012e9fe832be36
Showing 2 changed files with 46 additions and 3 deletions.
@@ -0,0 +1,43 @@
//@ requireOptions("--useTemporal=1")

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}

{
let data = Temporal.PlainTime.from({
hour: 0,
minute: 0,
second: 0,
millisecond: 1000,
microsecond: 0,
nanosecond: 0,
}).toString();

shouldBe(data, `00:00:00.999`);
}
{
let data = Temporal.PlainTime.from({
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
microsecond: 1000,
nanosecond: 0,
}).toString();

shouldBe(data, `00:00:00.000999`);
}
{
let data = Temporal.PlainTime.from({
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
microsecond: 0,
nanosecond: 1000,
}).toString();

shouldBe(data, `00:00:00.000000999`);
}
@@ -375,9 +375,9 @@ static ISO8601::PlainTime constrainTime(ISO8601::Duration&& duration)
constrainToRange(duration.hours(), 0, 23),
constrainToRange(duration.minutes(), 0, 59),
constrainToRange(duration.seconds(), 0, 59),
constrainToRange(duration.milliseconds(), 0, 1000),
constrainToRange(duration.microseconds(), 0, 1000),
constrainToRange(duration.nanoseconds(), 0, 1000));
constrainToRange(duration.milliseconds(), 0, 999),
constrainToRange(duration.microseconds(), 0, 999),
constrainToRange(duration.nanoseconds(), 0, 999));
}

static ISO8601::PlainTime regulateTime(JSGlobalObject* globalObject, ISO8601::Duration&& duration, TemporalOverflow overflow)

0 comments on commit 9b4ed78

Please sign in to comment.