Commit 093e68b4 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Sync the Parser to the latest spec.

Add TimeHourMinuteBasicFormatNotAmbiguousWithMonthDay
TimeZoneNumericUTCOffsetNotAmbiguousWithDayOfMonth
TimeZoneNumericUTCOffsetNotAmbiguousWithMonth
TimeZoneIdentifier, UnpaddedHour, TimeZoneIANALegacyName productions.

Sync the spec of TemporalInstantString, TemporalTimeString
TimeZone, TimeZoneBracketedAnnotation, TemporalTimeZoneString,
ToTemporalTimeZone, TimeZoneIANAName productions.

Fix bug in ScanCalendarDateTimeTimeRequired, ToTemporalTimeZone

Change name from Handle<String> to Handle<Object> to hold undefined

Update parser tests accordingly.

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal-iso8601grammar
https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone


Related PR changes:
https://github.com/tc39/proposal-temporal/pull/2284
https://github.com/tc39/proposal-temporal/pull/2287
https://github.com/tc39/proposal-temporal/pull/2345


Bug: v8:11544
Change-Id: I6f1a5e5dedba461db9f36abe76fa97119c1f8c2c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3822342Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83123}
parent b1a14770
...@@ -152,7 +152,7 @@ struct DateDurationRecord { ...@@ -152,7 +152,7 @@ struct DateDurationRecord {
struct TimeZoneRecord { struct TimeZoneRecord {
bool z; bool z;
Handle<Object> offset_string; // String or Undefined Handle<Object> offset_string; // String or Undefined
Handle<String> name; Handle<Object> name; // String or Undefined
}; };
struct ZonedDateTimeRecord { struct ZonedDateTimeRecord {
...@@ -3007,27 +3007,15 @@ MaybeHandle<JSReceiver> ToTemporalTimeZone( ...@@ -3007,27 +3007,15 @@ MaybeHandle<JSReceiver> ToTemporalTimeZone(
Handle<JSReceiver>()); Handle<JSReceiver>());
// 4. If parseResult.[[Name]] is not undefined, then // 4. If parseResult.[[Name]] is not undefined, then
if (parse_result.name->length() > 0) { if (!parse_result.name->IsUndefined()) {
DCHECK(parse_result.name->IsString());
// a. Let name be parseResult.[[Name]]. // a. Let name be parseResult.[[Name]].
Handle<String> name = parse_result.name; Handle<String> name = Handle<String>::cast(parse_result.name);
// b. If ParseText(StringToCodePoints(name, TimeZoneNumericUTCOffset)) is // b. If ParseText(StringToCodePoints(name, TimeZoneNumericUTCOffset)) is
// not a List of errors, then // a List of errors, then
base::Optional<ParsedISO8601Result> parsed_offset = base::Optional<ParsedISO8601Result> parsed_offset =
TemporalParser::ParseTimeZoneNumericUTCOffset(isolate, name); TemporalParser::ParseTimeZoneNumericUTCOffset(isolate, name);
if (parsed_offset.has_value()) { if (!parsed_offset.has_value()) {
// i. If parseResult.[[OffsetString]] is not undefined, and !
// ParseTimeZoneOffsetString(parseResult.[[OffsetString]]) ≠ !
// ParseTimeZoneOffsetString(name), throw a RangeError exception.
if (!parse_result.offset_string->IsUndefined() &&
ParseTimeZoneOffsetString(
isolate, Handle<String>::cast(parse_result.offset_string))
.ToChecked() !=
ParseTimeZoneOffsetString(isolate, name).ToChecked()) {
THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALID_ARG_RANGE_ERROR(),
JSReceiver);
}
// c. Else,
} else {
// i. If ! IsValidTimeZoneName(name) is false, throw a RangeError // i. If ! IsValidTimeZoneName(name) is false, throw a RangeError
// exception. // exception.
if (!IsValidTimeZoneName(isolate, name)) { if (!IsValidTimeZoneName(isolate, name)) {
...@@ -3036,10 +3024,9 @@ MaybeHandle<JSReceiver> ToTemporalTimeZone( ...@@ -3036,10 +3024,9 @@ MaybeHandle<JSReceiver> ToTemporalTimeZone(
} }
// ii. Set name to ! CanonicalizeTimeZoneName(name). // ii. Set name to ! CanonicalizeTimeZoneName(name).
name = CanonicalizeTimeZoneName(isolate, name); name = CanonicalizeTimeZoneName(isolate, name);
// d. Return ! CreateTemporalTimeZone(name).
return temporal::CreateTemporalTimeZone(isolate, name);
} }
// c. Return ! CreateTemporalTimeZone(name).
return temporal::CreateTemporalTimeZone(isolate, name);
} }
// 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC"). // 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC").
if (parse_result.z) { if (parse_result.z) {
...@@ -3654,6 +3641,7 @@ Maybe<ZonedDateTimeRecord> ParseTemporalRelativeToString( ...@@ -3654,6 +3641,7 @@ Maybe<ZonedDateTimeRecord> ParseTemporalRelativeToString(
// b. Let offsetString be undefined. // b. Let offsetString be undefined.
result.time_zone.offset_string = isolate->factory()->undefined_value(); result.time_zone.offset_string = isolate->factory()->undefined_value();
// c. Let timeZone be undefined. // c. Let timeZone be undefined.
result.time_zone.name = isolate->factory()->undefined_value();
} }
// 5. Return the Record { [[Year]]: result.[[Year]], [[Month]]: // 5. Return the Record { [[Year]]: result.[[Year]], [[Month]]:
// result.[[Month]], [[Day]]: result.[[Day]], [[Hour]]: result.[[Hour]], // result.[[Month]], [[Day]]: result.[[Day]], [[Hour]]: result.[[Hour]],
...@@ -3932,7 +3920,7 @@ Maybe<TimeZoneRecord> ParseTemporalTimeZoneString(Isolate* isolate, ...@@ -3932,7 +3920,7 @@ Maybe<TimeZoneRecord> ParseTemporalTimeZoneString(Isolate* isolate,
// productions, or undefined if not present. // productions, or undefined if not present.
// 4. If name is empty, then // 4. If name is empty, then
// a. Set name to undefined. // a. Set name to undefined.
Handle<String> name = isolate->factory()->empty_string(); Handle<Object> name = isolate->factory()->undefined_value();
// 5. Else, // 5. Else,
// a. Set name to CodePointsToString(name). // a. Set name to CodePointsToString(name).
if (parsed->tzi_name_length > 0) { if (parsed->tzi_name_length > 0) {
...@@ -8195,12 +8183,14 @@ MaybeHandle<Object> ToRelativeTemporalObject(Isolate* isolate, ...@@ -8195,12 +8183,14 @@ MaybeHandle<Object> ToRelativeTemporalObject(Isolate* isolate,
offset_string_obj = result.time_zone.offset_string; offset_string_obj = result.time_zone.offset_string;
// e. Let timeZoneName be result.[[TimeZoneIANAName]]. // e. Let timeZoneName be result.[[TimeZoneIANAName]].
Handle<String> time_zone_name = result.time_zone.name; Handle<Object> time_zone_name_obj = result.time_zone.name;
// f. If timeZoneName is not undefined, then // f. If timeZoneName is not undefined, then
if (!time_zone_name.is_null()) { if (!time_zone_name_obj->IsUndefined()) {
// i. If ParseText(StringToCodePoints(timeZoneName), // i. If ParseText(StringToCodePoints(timeZoneName),
// TimeZoneNumericUTCOffset) is a List of errors, then // TimeZoneNumericUTCOffset) is a List of errors, then
DCHECK(time_zone_name_obj->IsString());
Handle<String> time_zone_name = Handle<String>::cast(time_zone_name_obj);
base::Optional<ParsedISO8601Result> parsed = base::Optional<ParsedISO8601Result> parsed =
TemporalParser::ParseTimeZoneNumericUTCOffset(isolate, TemporalParser::ParseTimeZoneNumericUTCOffset(isolate,
time_zone_name); time_zone_name);
...@@ -16066,8 +16056,8 @@ MaybeHandle<JSTemporalZonedDateTime> ToTemporalZonedDateTime( ...@@ -16066,8 +16056,8 @@ MaybeHandle<JSTemporalZonedDateTime> ToTemporalZonedDateTime(
Handle<JSTemporalZonedDateTime>()); Handle<JSTemporalZonedDateTime>());
// e. Assert: timeZoneName is not undefined. // e. Assert: timeZoneName is not undefined.
Handle<String> time_zone_name = result.time_zone.name; DCHECK(!result.time_zone.name->IsUndefined());
DCHECK(!time_zone_name.is_null()); Handle<String> time_zone_name = Handle<String>::cast(result.time_zone.name);
// f. If ParseText(StringToCodePoints(timeZoneName), // f. If ParseText(StringToCodePoints(timeZoneName),
// TimeZoneNumericUTCOffset) is a List of errors, then // TimeZoneNumericUTCOffset) is a List of errors, then
......
This diff is collapsed.
...@@ -444,63 +444,15 @@ ...@@ -444,63 +444,15 @@
# https://github.com/tc39/proposal-temporal/pull/1862 # https://github.com/tc39/proposal-temporal/pull/1862
'built-ins/Temporal/Duration/prototype/total/timezone-getpossibleinstantsfor-iterable': [FAIL], 'built-ins/Temporal/Duration/prototype/total/timezone-getpossibleinstantsfor-iterable': [FAIL],
# TimeZone name test should move to intl402
# https://github.com/tc39/test262/issues/3253
'built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime': [FAIL],
'built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime': [FAIL],
# precision
'built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=11544 # https://bugs.chromium.org/p/v8/issues/detail?id=11544
'built-ins/Temporal/Calendar/prototype/weekOfYear/calendar-datefromfields-called-with-options-undefined': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/calendar-datefromfields-called-with-options-undefined': [FAIL],
'built-ins/Temporal/Duration/compare/relativeto-sub-minute-offset': [FAIL],
'built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset': [FAIL],
'built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime': [FAIL],
'built-ins/Temporal/Duration/prototype/round/relativeto-sub-minute-offset': [FAIL],
'built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset': [FAIL],
'built-ins/Temporal/Duration/prototype/total/balance-negative-result': [FAIL], 'built-ins/Temporal/Duration/prototype/total/balance-negative-result': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-sub-minute-offset': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Now/zonedDateTimeISO/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Now/zonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/TimeZone/from/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-sub-minute-offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/sub-minute-offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-datetime': [SKIP],
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/sub-minute-offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/sub-minute-offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string-multiple-offsets': [FAIL],
'intl402/Temporal/Calendar/prototype/dateFromFields/infinity-throws-rangeerror': [FAIL], 'intl402/Temporal/Calendar/prototype/dateFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/monthDayFromFields/infinity-throws-rangeerror': [FAIL], 'intl402/Temporal/Calendar/prototype/monthDayFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/yearMonthFromFields/infinity-throws-rangeerror': [FAIL], 'intl402/Temporal/Calendar/prototype/yearMonthFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Duration/prototype/round/relativeto-string-datetime': [FAIL], 'intl402/Temporal/Duration/prototype/round/relativeto-string-datetime': [FAIL],
'intl402/Temporal/Duration/prototype/total/relativeto-string-datetime': [FAIL], 'intl402/Temporal/Duration/prototype/total/relativeto-string-datetime': [FAIL],
'intl402/Temporal/PlainYearMonth/from/argument-object': [FAIL], 'intl402/Temporal/PlainYearMonth/from/argument-object': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL], 'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/rounding-direction': [FAIL], 'built-ins/Temporal/Instant/prototype/toString/rounding-direction': [FAIL],
...@@ -575,21 +527,16 @@ ...@@ -575,21 +527,16 @@
'built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number': [FAIL], 'built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number': [FAIL], 'built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Duration/prototype/add/relativeto-year': [FAIL], 'built-ins/Temporal/Duration/prototype/add/relativeto-year': [FAIL],
'built-ins/Temporal/Instant/from/argument-string': [FAIL],
'intl402/Temporal/Calendar/prototype/dateFromFields/order-of-operations': [FAIL], 'intl402/Temporal/Calendar/prototype/dateFromFields/order-of-operations': [FAIL],
'intl402/Temporal/Calendar/prototype/monthDayFromFields/order-of-operations': [FAIL], 'intl402/Temporal/Calendar/prototype/monthDayFromFields/order-of-operations': [FAIL],
'intl402/Temporal/Calendar/prototype/yearMonthFromFields/order-of-operations': [FAIL], 'intl402/Temporal/Calendar/prototype/yearMonthFromFields/order-of-operations': [FAIL],
'intl402/Temporal/Duration/compare/relativeto-hour': [FAIL], 'intl402/Temporal/Duration/compare/relativeto-hour': [FAIL],
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days-different-sign': [FAIL], 'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days-different-sign': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days': [FAIL], 'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days': [FAIL],
'intl402/Temporal/TimeZone/prototype/getNextTransition/subtract-second-and-nanosecond-from-last-transition': [FAIL], 'intl402/Temporal/TimeZone/prototype/getNextTransition/subtract-second-and-nanosecond-from-last-transition': [FAIL],
'intl402/Temporal/TimeZone/prototype/getPreviousTransition/nanoseconds-subtracted-or-added-at-dst-transition': [FAIL], 'intl402/Temporal/TimeZone/prototype/getPreviousTransition/nanoseconds-subtracted-or-added-at-dst-transition': [FAIL],
'intl402/Temporal/TimeZone/from/etc-timezone': [FAIL],
'intl402/Temporal/TimeZone/from/iana-legacy-names': [FAIL],
'intl402/Temporal/TimeZone/prototype/getNextTransition/transition-at-instant-boundaries': [FAIL], 'intl402/Temporal/TimeZone/prototype/getNextTransition/transition-at-instant-boundaries': [FAIL],
'intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/nanoseconds-subtracted-or-added-at-dst-transition': [FAIL], 'intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/nanoseconds-subtracted-or-added-at-dst-transition': [FAIL],
'intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst': [FAIL], 'intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst': [FAIL],
...@@ -624,16 +571,6 @@ ...@@ -624,16 +571,6 @@
'harness/temporalHelpers-one-shift-time-zone': [SKIP], 'harness/temporalHelpers-one-shift-time-zone': [SKIP],
'built-ins/Temporal/Instant/compare/instant-string': [FAIL],
'built-ins/Temporal/Instant/from/instant-string': [FAIL],
'built-ins/Temporal/Instant/prototype/equals/instant-string': [FAIL],
'built-ins/Temporal/Instant/prototype/since/instant-string': [FAIL],
'built-ins/Temporal/Instant/prototype/until/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getNextTransition/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPreviousTransition/instant-string': [FAIL],
'staging/Intl402/Temporal/old/addition-across-lunisolar-leap-months': [FAIL], 'staging/Intl402/Temporal/old/addition-across-lunisolar-leap-months': [FAIL],
'staging/Intl402/Temporal/old/date-time-format': [FAIL], 'staging/Intl402/Temporal/old/date-time-format': [FAIL],
'staging/Intl402/Temporal/old/datetime-toLocaleString': [FAIL], 'staging/Intl402/Temporal/old/datetime-toLocaleString': [FAIL],
......
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