Commit 97c0084b authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Fix TemporalCalendarString ambiguity #2394

Sync with https://github.com/tc39/proposal-temporal/pull/2394
to fix  TemporalCalendarString ambiguity issues


Spec text:
https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar

Bug: v8:11544
Change-Id: I31d0255e55d1a432681fd060cf4f841cb1479480
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3901196Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83409}
parent ac3c846f
...@@ -2394,21 +2394,18 @@ MaybeHandle<JSReceiver> ToTemporalCalendar( ...@@ -2394,21 +2394,18 @@ MaybeHandle<JSReceiver> ToTemporalCalendar(
ASSIGN_RETURN_ON_EXCEPTION(isolate, identifier, ASSIGN_RETURN_ON_EXCEPTION(isolate, identifier,
Object::ToString(isolate, temporal_calendar_like), Object::ToString(isolate, temporal_calendar_like),
JSReceiver); JSReceiver);
// 3. If ! IsBuiltinCalendar(identifier) is false, then // 3. Let identifier be ? ParseTemporalCalendarString(identifier).
ASSIGN_RETURN_ON_EXCEPTION(isolate, identifier,
ParseTemporalCalendarString(isolate, identifier),
JSReceiver);
// 4. If IsBuiltinCalendar(identifier) is false, throw a RangeError
// exception.
if (!IsBuiltinCalendar(isolate, identifier)) { if (!IsBuiltinCalendar(isolate, identifier)) {
// a. Let identifier be ? ParseTemporalCalendarString(identifier). THROW_NEW_ERROR(
ASSIGN_RETURN_ON_EXCEPTION(isolate, identifier, isolate, NewRangeError(MessageTemplate::kInvalidCalendar, identifier),
ParseTemporalCalendarString(isolate, identifier), JSReceiver);
JSReceiver);
// b. If IsBuiltinCalendar(identifier) is false, throw a RangeError
// exception.
if (!IsBuiltinCalendar(isolate, identifier)) {
THROW_NEW_ERROR(
isolate, NewRangeError(MessageTemplate::kInvalidCalendar, identifier),
JSReceiver);
}
} }
// 4. Return ? CreateTemporalCalendar(identifier). // 5. Return ? CreateTemporalCalendar(identifier).
return CreateTemporalCalendar(isolate, identifier); return CreateTemporalCalendar(isolate, identifier);
} }
...@@ -4058,25 +4055,38 @@ MaybeHandle<String> ParseTemporalCalendarString(Isolate* isolate, ...@@ -4058,25 +4055,38 @@ MaybeHandle<String> ParseTemporalCalendarString(Isolate* isolate,
Handle<String> iso_string) { Handle<String> iso_string) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
// 1. Assert: Type(isoString) is String. // 1. Let parseResult be Completion(ParseISODateTime(isoString)).
// 2. If isoString does not satisfy the syntax of a TemporalCalendarString Maybe<DateTimeRecordWithCalendar> parse_result =
// (see 13.33), then a. Throw a RangeError exception. ParseISODateTime(isolate, iso_string);
base::Optional<ParsedISO8601Result> parsed = // 2. If parseResult is a normal completion, then
TemporalParser::ParseTemporalCalendarString(isolate, iso_string); if (parse_result.IsJust()) {
if (!parsed.has_value()) { // a. Let calendar be parseResult.[[Value]].[[Calendar]].
THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALID_ARG_RANGE_ERROR(), String); Handle<Object> calendar = parse_result.FromJust().calendar;
// b. If calendar is undefined, return "iso8601".
if (calendar->IsUndefined()) {
return isolate->factory()->iso8601_string();
// c. Else, return calendar.
} else {
CHECK(calendar->IsString());
return Handle<String>::cast(calendar);
}
// 3. Else,
} else {
DCHECK(isolate->has_pending_exception());
isolate->clear_pending_exception();
// a. Set parseResult to ParseText(StringToCodePoints(isoString),
// CalendarName).
base::Optional<ParsedISO8601Result> parsed =
TemporalParser::ParseCalendarName(isolate, iso_string);
// b. If parseResult is a List of errors, throw a RangeError exception.
if (!parsed.has_value()) {
THROW_NEW_ERROR(
isolate, NewRangeError(MessageTemplate::kInvalidCalendar, iso_string),
String);
}
// c. Else, return isoString.
return iso_string;
} }
// 3. Let id be the part of isoString produced by the CalendarName production,
// or undefined if not present.
// 4. If id is empty, then
if (parsed->calendar_name_length == 0) {
// a. Return "iso8601".
return isolate->factory()->iso8601_string();
}
// 5. Return CodePointsToString(id).
return isolate->factory()->NewSubString(
iso_string, parsed->calendar_name_start,
parsed->calendar_name_start + parsed->calendar_name_length);
} }
// #sec-temporal-calendarequals // #sec-temporal-calendarequals
......
...@@ -458,70 +458,6 @@ ...@@ -458,70 +458,6 @@
'built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor-basic': [FAIL], 'built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor-basic': [FAIL],
'intl402/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar': [FAIL], 'intl402/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar': [FAIL],
# https://github.com/tc39/test262/issues/3553
'built-ins/Temporal/Calendar/from/calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number': [FAIL],
'built-ins/Temporal/Now/plainDate/calendar-number': [FAIL],
'built-ins/Temporal/Now/plainDateTime/calendar-number': [FAIL],
'built-ins/Temporal/Now/zonedDateTime/calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/calendar-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number': [FAIL],
'built-ins/Temporal/PlainMonthDay/calendar-number': [FAIL],
'built-ins/Temporal/PlainYearMonth/calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/calendar-number': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number': [FAIL],
'built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Duration/prototype/round/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],
'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],
......
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