Commit 6fd50360 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Fix test to sync with latest spec after spec change.

1. fix year value between 100 and 9999 should use 4 digit padding without '+' prefix to sync with the latest spec in
mjsunit/temporal/plain-date-time-to-json

2. Change the the toPlainDateTime to accept object with partial time fields to sync with current spect in
test/mjsunit/temporal/plain-date-to-plain-date-time.js

3. Change the test to accept input parameter type to Number instead of BigInt for Instant fromEpochSeconds and from EpochMilliseconds in
test/mjsunit/temporal/instant-from-epoch-milliseconds.js and
test/mjsunit/temporal/instant-from-epoch-seconds.js
Throw TypeError if the type is BigInt.

4. Change the return type of Instant epochSeconds and epochMilliseconds from BigInt to Number to sync with the spec in
test/mjsunit/temporal/instant-constructor.js

Spec text
https://tc39.es/proposal-temporal/#sec-temporal-padisoyear
https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimerecord
https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmilliseconds
https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochseconds
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmilliseconds
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochseconds

Bug: v8:11544
Change-Id: Icd290905b65fdabbedece27e59c785635c212ec2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3807122Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82185}
parent f4a938e4
......@@ -47,11 +47,6 @@
# https://crbug.com/v8/11544
'temporal/calendar-week-of-year': [FAIL],
'temporal/duration-add': [FAIL],
'temporal/instant-constructor': [FAIL],
'temporal/instant-from-epoch-milliseconds': [FAIL],
'temporal/instant-from-epoch-seconds': [FAIL],
'temporal/plain-date-time-to-json': [FAIL],
'temporal/plain-date-to-plain-date-time': [FAIL],
##############################################################################
# Open bugs.
......
......@@ -6,14 +6,14 @@
let inst1 = new Temporal.Instant(1234567890123456789n);
assertEquals(1234567890123456789n , inst1.epochNanoseconds);
assertEquals(1234567890123456n , inst1.epochMicroseconds);
assertEquals(1234567890123n , inst1.epochMilliseconds);
assertEquals(1234567890n , inst1.epochSeconds);
assertEquals(1234567890123 , inst1.epochMilliseconds);
assertEquals(1234567890 , inst1.epochSeconds);
let inst2 = new Temporal.Instant(-1234567890123456789n);
assertEquals(-1234567890123456789n , inst2.epochNanoseconds);
assertEquals(-1234567890123456n , inst2.epochMicroseconds);
assertEquals(-1234567890123n , inst2.epochMilliseconds);
assertEquals(-1234567890n , inst2.epochSeconds);
assertEquals(-1234567890123 , inst2.epochMilliseconds);
assertEquals(-1234567890 , inst2.epochSeconds);
// 1. If NewTarget is undefined, then
// a. Throw a TypeError exception.
......
......@@ -4,25 +4,29 @@
// Flags: --harmony-temporal
let bigint_nano = 567890123456789000000n;
let bigint_milli = 567890123456789n;
let milli = 567890123456789;
let bigint_milli = BigInt(milli);
let inst1 = new Temporal.Instant(bigint_nano);
let inst2 = Temporal.Instant.fromEpochMilliseconds(bigint_milli);
assertThrows(() =>
Temporal.Instant.fromEpochMilliseconds(bigint_milli),
TypeError);
let inst2 = Temporal.Instant.fromEpochMilliseconds(milli);
assertEquals(inst1, inst2);
let just_fit_neg_bigint = -8640000000000000n;
let just_fit_pos_bigint = 8640000000000000n;
let too_big_bigint = 8640000000000001n;
let too_small_bigint = -8640000000000001n;
let just_fit_neg = -8640000000000000;
let just_fit_pos = 8640000000000000;
let too_big = 8640000000000001;
let too_small = -8640000000000001;
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochMilliseconds(too_small_bigint)},
Temporal.Instant.fromEpochMilliseconds(too_small),
RangeError);
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochMilliseconds(too_big_bigint)},
Temporal.Instant.fromEpochMilliseconds(too_big),
RangeError);
assertEquals(just_fit_neg_bigint,
assertEquals(just_fit_neg,
(Temporal.Instant.fromEpochMilliseconds(
just_fit_neg_bigint)).epochMilliseconds);
assertEquals(just_fit_pos_bigint,
just_fit_neg)).epochMilliseconds);
assertEquals(just_fit_pos,
(Temporal.Instant.fromEpochMilliseconds(
just_fit_pos_bigint)).epochMilliseconds);
just_fit_pos)).epochMilliseconds);
......@@ -4,23 +4,27 @@
// Flags: --harmony-temporal
let bigint_nano = 7890123456789000000000n;
let bigint_sec = 7890123456789n;
let sec = 7890123456789;
let bigint_sec = BigInt(sec);
let inst1 = new Temporal.Instant(bigint_nano);
let inst2 = Temporal.Instant.fromEpochSeconds(bigint_sec);
assertThrows(() =>
Temporal.Instant.fromEpochSeconds(bigint_sec),
TypeError)
let inst2 = Temporal.Instant.fromEpochSeconds(sec);
assertEquals(inst1, inst2);
let just_fit_neg_bigint = -8640000000000n;
let just_fit_pos_bigint = 8640000000000n;
let too_big_bigint = 8640000000001n;
let too_small_bigint = -8640000000001n;
let just_fit_neg = -8640000000000;
let just_fit_pos = 8640000000000;
let too_big = 8640000000001;
let too_small = -8640000000001;
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochSeconds(too_small_bigint)},
Temporal.Instant.fromEpochSeconds(too_small),
RangeError)
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochSeconds(too_big_bigint)},
Temporal.Instant.fromEpochSeconds(too_big),
RangeError)
assertEquals(just_fit_neg_bigint,
(Temporal.Instant.fromEpochSeconds(just_fit_neg_bigint)).epochSeconds);
assertEquals(just_fit_pos_bigint,
(Temporal.Instant.fromEpochSeconds(just_fit_pos_bigint)).epochSeconds);
assertEquals(just_fit_neg,
(Temporal.Instant.fromEpochSeconds(just_fit_neg)).epochSeconds);
assertEquals(just_fit_pos,
(Temporal.Instant.fromEpochSeconds(just_fit_pos)).epochSeconds);
......@@ -16,9 +16,9 @@ assertEquals("+010000-01-01T00:00:00",
(new Temporal.PlainDateTime(10000, 1, 1)).toJSON());
assertEquals("+025021-07-01T00:00:00",
(new Temporal.PlainDateTime(25021, 7, 1)).toJSON());
assertEquals("+000999-12-31T00:00:00",
assertEquals("0999-12-31T00:00:00",
(new Temporal.PlainDateTime(999, 12, 31)).toJSON());
assertEquals("+000099-08-01T00:00:00",
assertEquals("0099-08-01T00:00:00",
(new Temporal.PlainDateTime(99, 8, 1)).toJSON());
assertEquals("-000020-09-30T00:00:00",
(new Temporal.PlainDateTime(-20, 9, 30)).toJSON());
......
......@@ -15,17 +15,28 @@ assertThrows(() => d1.toPlainDateTime(true), RangeError);
assertThrows(() => d1.toPlainDateTime(false), RangeError);
assertThrows(() => d1.toPlainDateTime(NaN), RangeError);
assertThrows(() => d1.toPlainDateTime(Infinity), RangeError);
// assertThrows(() => d1.toPlainDateTime(123), RangeError);
//assertThrows(() => d1.toPlainDateTime(456n), RangeError);
assertThrows(() => d1.toPlainDateTime(123), RangeError);
assertThrows(() => d1.toPlainDateTime(456n), RangeError);
assertThrows(() => d1.toPlainDateTime(Symbol()), TypeError);
assertThrows(() => d1.toPlainDateTime({}), TypeError);
assertThrows(() => d1.toPlainDateTime({hour: 23}), TypeError);
assertThrows(() => d1.toPlainDateTime({minute: 23}), TypeError);
assertThrows(() => d1.toPlainDateTime({second: 23}), TypeError);
assertThrows(() => d1.toPlainDateTime({millisecond: 23}), TypeError);
assertThrows(() => d1.toPlainDateTime({microecond: 23}), TypeError);
assertThrows(() => d1.toPlainDateTime({nanosecond: 23}), TypeError);
assertPlainDateTime(d1.toPlainDateTime(
{hour: 23}),
2021, 12, 11, 23, 0, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{minute: 23}),
2021, 12, 11, 0, 23, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{second: 23}),
2021, 12, 11, 0, 0, 23, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{millisecond: 23}),
2021, 12, 11, 0, 0, 0, 23, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{microsecond: 23}),
2021, 12, 11, 0, 0, 0, 0, 23, 0);
assertPlainDateTime(d1.toPlainDateTime(
{nanosecond: 23}),
2021, 12, 11, 0, 0, 0, 0, 0, 23);
assertPlainDateTime(d1.toPlainDateTime(),
2021, 12, 11, 0, 0, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment