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

[Temporal] Sync PR 2203 ISOMonthDayFromFields

Adjust order of operations in ISO{Date,MonthDay}FromFields

https://github.com/tc39/proposal-temporal/pull/2203

Spec text:
https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields

Bug: v8:11544
Change-Id: I4ae945656e3f35d0af422ee86e1f5108a350b6a6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3857452Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82845}
parent 881fc049
...@@ -2000,7 +2000,13 @@ MaybeHandle<JSReceiver> GetTemporalCalendarWithISODefault( ...@@ -2000,7 +2000,13 @@ MaybeHandle<JSReceiver> GetTemporalCalendarWithISODefault(
return ToTemporalCalendarWithISODefault(isolate, calendar, method_name); return ToTemporalCalendarWithISODefault(isolate, calendar, method_name);
} }
enum class RequiredFields { kNone, kTimeZone, kTimeZoneAndOffset, kDay }; enum class RequiredFields {
kNone,
kTimeZone,
kTimeZoneAndOffset,
kDay,
kYearAndDay
};
// The common part of PrepareTemporalFields and PreparePartialTemporalFields // The common part of PrepareTemporalFields and PreparePartialTemporalFields
// #sec-temporal-preparetemporalfields // #sec-temporal-preparetemporalfields
...@@ -2034,13 +2040,16 @@ V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> PrepareTemporalFieldsOrPartial( ...@@ -2034,13 +2040,16 @@ V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> PrepareTemporalFieldsOrPartial(
if (partial) continue; if (partial) continue;
// i. If requiredFields contains property, then // i. If requiredFields contains property, then
if ((required == RequiredFields::kDay && if (((required == RequiredFields::kDay ||
required == RequiredFields::kYearAndDay) &&
String::Equals(isolate, property, factory->day_string())) || String::Equals(isolate, property, factory->day_string())) ||
((required == RequiredFields::kTimeZone || ((required == RequiredFields::kTimeZone ||
required == RequiredFields::kTimeZoneAndOffset) && required == RequiredFields::kTimeZoneAndOffset) &&
String::Equals(isolate, property, factory->timeZone_string())) || String::Equals(isolate, property, factory->timeZone_string())) ||
(required == RequiredFields::kTimeZoneAndOffset && (required == RequiredFields::kTimeZoneAndOffset &&
String::Equals(isolate, property, factory->offset_string()))) { String::Equals(isolate, property, factory->offset_string())) ||
(required == RequiredFields::kYearAndDay &&
String::Equals(isolate, property, factory->year_string()))) {
// 1. Throw a TypeError exception. // 1. Throw a TypeError exception.
THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(), THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(),
JSObject); JSObject);
...@@ -6415,12 +6424,11 @@ Maybe<DateRecordCommon> ISOMonthDayFromFields(Isolate* isolate, ...@@ -6415,12 +6424,11 @@ Maybe<DateRecordCommon> ISOMonthDayFromFields(Isolate* isolate,
Nothing<DateRecordCommon>()); Nothing<DateRecordCommon>());
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", // 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month",
// "monthCode", "year" », «»). // "monthCode", "year" », «"day"»).
Handle<FixedArray> field_names = DayMonthMonthCodeYearInFixedArray(isolate); Handle<FixedArray> field_names = DayMonthMonthCodeYearInFixedArray(isolate);
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, fields, isolate, fields,
PrepareTemporalFields(isolate, fields, field_names, PrepareTemporalFields(isolate, fields, field_names, RequiredFields::kDay),
RequiredFields::kNone),
Nothing<DateRecordCommon>()); Nothing<DateRecordCommon>());
// 4. Let month be ! Get(fields, "month"). // 4. Let month be ! Get(fields, "month").
Handle<Object> month_obj = Handle<Object> month_obj =
...@@ -6452,11 +6460,11 @@ Maybe<DateRecordCommon> ISOMonthDayFromFields(Isolate* isolate, ...@@ -6452,11 +6460,11 @@ Maybe<DateRecordCommon> ISOMonthDayFromFields(Isolate* isolate,
Handle<Object> day_obj = Handle<Object> day_obj =
JSReceiver::GetProperty(isolate, fields, factory->day_string()) JSReceiver::GetProperty(isolate, fields, factory->day_string())
.ToHandleChecked(); .ToHandleChecked();
// 10. If day is undefined, throw a TypeError exception. // 10. Assert: Type(day) is Number.
if (day_obj->IsUndefined(isolate)) { // Note: "day" in fields is always converted by
THROW_NEW_ERROR_RETURN_VALUE(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(), // ToIntegerThrowOnInfinity inside the PrepareTemporalFields above.
Nothing<DateRecordCommon>()); // Therefore the day_obj is always an integer.
} DCHECK(day_obj->IsSmi() || day_obj->IsHeapNumber());
result.day = FastD2I(floor(day_obj->Number())); result.day = FastD2I(floor(day_obj->Number()));
// 11. Let referenceISOYear be 1972 (the first leap year after the Unix // 11. Let referenceISOYear be 1972 (the first leap year after the Unix
// epoch). // epoch).
...@@ -9746,23 +9754,19 @@ Maybe<DateRecordCommon> ISODateFromFields(Isolate* isolate, ...@@ -9746,23 +9754,19 @@ Maybe<DateRecordCommon> ISODateFromFields(Isolate* isolate,
isolate, overflow, ToTemporalOverflow(isolate, options, method_name), isolate, overflow, ToTemporalOverflow(isolate, options, method_name),
Nothing<DateRecordCommon>()); Nothing<DateRecordCommon>());
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", // 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month",
// "monthCode", "year" », «»). // "monthCode", "year" », «"year", "day"»).
Handle<FixedArray> field_names = DayMonthMonthCodeYearInFixedArray(isolate); Handle<FixedArray> field_names = DayMonthMonthCodeYearInFixedArray(isolate);
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, fields, isolate, fields,
PrepareTemporalFields(isolate, fields, field_names, PrepareTemporalFields(isolate, fields, field_names,
RequiredFields::kNone), RequiredFields::kYearAndDay),
Nothing<DateRecordCommon>()); Nothing<DateRecordCommon>());
// 4. Let year be ! Get(fields, "year"). // 4. Let year be ! Get(fields, "year").
Handle<Object> year_obj = Handle<Object> year_obj =
JSReceiver::GetProperty(isolate, fields, factory->year_string()) JSReceiver::GetProperty(isolate, fields, factory->year_string())
.ToHandleChecked(); .ToHandleChecked();
// 5. If year is undefined, throw a TypeError exception. // 5. Assert: Type(year) is Number.
if (year_obj->IsUndefined(isolate)) {
THROW_NEW_ERROR_RETURN_VALUE(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(),
Nothing<DateRecordCommon>());
}
// Note: "year" in fields is always converted by // Note: "year" in fields is always converted by
// ToIntegerThrowOnInfinity inside the PrepareTemporalFields above. // ToIntegerThrowOnInfinity inside the PrepareTemporalFields above.
// Therefore the year_obj is always an integer. // Therefore the year_obj is always an integer.
...@@ -9778,11 +9782,7 @@ Maybe<DateRecordCommon> ISODateFromFields(Isolate* isolate, ...@@ -9778,11 +9782,7 @@ Maybe<DateRecordCommon> ISODateFromFields(Isolate* isolate,
Handle<Object> day_obj = Handle<Object> day_obj =
JSReceiver::GetProperty(isolate, fields, factory->day_string()) JSReceiver::GetProperty(isolate, fields, factory->day_string())
.ToHandleChecked(); .ToHandleChecked();
// 8. If day is undefined, throw a TypeError exception. // 8. Assert: Type(day) is Number.
if (day_obj->IsUndefined(isolate)) {
THROW_NEW_ERROR_RETURN_VALUE(isolate, NEW_TEMPORAL_INVALID_ARG_TYPE_ERROR(),
Nothing<DateRecordCommon>());
}
// Note: "day" in fields is always converted by // Note: "day" in fields is always converted by
// ToIntegerThrowOnInfinity inside the PrepareTemporalFields above. // ToIntegerThrowOnInfinity inside the PrepareTemporalFields above.
// Therefore the day_obj is always an integer. // Therefore the day_obj is always an integer.
......
...@@ -582,8 +582,6 @@ ...@@ -582,8 +582,6 @@
'built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type': [SKIP], 'built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type': [SKIP],
'built-ins/Temporal/ZonedDateTime/timezone-string-multiple-offsets': [FAIL], 'built-ins/Temporal/ZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateFromFields/missing-properties': [FAIL],
'built-ins/Temporal/Calendar/prototype/monthDayFromFields/missing-properties': [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], '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],
......
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