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

[Temporal] Add Calendar.prototype.dateAdd

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateadd

is not yet implemented.

Note: The intl version stated in
https: //tc39.es/proposal-temporal/#sup-temporal.calendar.prototype.dateadd
Bug: v8:11544
Change-Id: Id7fd043d234f559c0e03bdf3f0f31d8bc91da27f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3609208Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80364}
parent 904b372b
......@@ -292,8 +292,6 @@ TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetPreviousTransition)
/* Temporal.Calendar */
/* Temporal #sec-temporal.calendar.prototype.yearmonthfromfields */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeYearMonthFromFields)
/* Temporal #sec-temporal.calendar.prototype.dateadd */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDateAdd)
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
......@@ -788,6 +786,7 @@ BUILTIN(TemporalCalendarPrototypeToString) {
isolate, JSTemporalCalendar::ToString(isolate, calendar, method_name));
}
TEMPORAL_PROTOTYPE_METHOD3(Calendar, DateAdd, dateAdd)
TEMPORAL_PROTOTYPE_METHOD2(Calendar, DateFromFields, dateFromFields)
TEMPORAL_PROTOTYPE_METHOD3(Calendar, DateUntil, dateUntil)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Day, day)
......
......@@ -5908,6 +5908,86 @@ Maybe<DateDurationRecord> DifferenceISODate(Isolate* isolate,
} // namespace
// #sec-temporal.calendar.prototype.dateadd
MaybeHandle<JSTemporalPlainDate> JSTemporalCalendar::DateAdd(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> date_obj, Handle<Object> duration_obj,
Handle<Object> options_obj) {
const char* method_name = "Temporal.Calendar.prototype.dateAdd";
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
// 4. Set date to ? ToTemporalDate(date).
Handle<JSTemporalPlainDate> date;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, date,
ToTemporalDate(isolate, date_obj,
isolate->factory()->NewJSObjectWithNullProto(),
method_name),
JSTemporalPlainDate);
// 5. Set duration to ? ToTemporalDuration(duration).
Handle<JSTemporalDuration> duration;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, duration,
temporal::ToTemporalDuration(isolate, duration_obj, method_name),
JSTemporalPlainDate);
// 6. Set options to ? GetOptionsObject(options).
Handle<JSReceiver> options;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, options, GetOptionsObject(isolate, options_obj, method_name),
JSTemporalPlainDate);
// 7. Let overflow be ? ToTemporalOverflow(options).
ShowOverflow overflow;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, overflow, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainDate>());
// 8. Let balanceResult be ! BalanceDuration(duration.[[Days]],
// duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]],
// duration.[[Milliseconds]], duration.[[Microseconds]],
// duration.[[Nanoseconds]], "day").
TimeDurationRecord balance_result;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, balance_result,
BalanceDuration(
isolate, Unit::kDay,
{duration->days().Number(), duration->hours().Number(),
duration->minutes().Number(), duration->seconds().Number(),
duration->milliseconds().Number(), duration->microseconds().Number(),
duration->nanoseconds().Number()},
method_name),
Handle<JSTemporalPlainDate>());
DateRecordCommon result;
// If calendar.[[Identifier]] is "iso8601", then
if (calendar->calendar_index() == 0) {
// 9. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]],
// date.[[ISODay]], duration.[[Years]], duration.[[Months]],
// duration.[[Weeks]], balanceResult.[[Days]], overflow).
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, result,
AddISODate(isolate,
{date->iso_year(), date->iso_month(), date->iso_day()},
{duration->years().Number(), duration->months().Number(),
duration->weeks().Number(), balance_result.days},
overflow),
Handle<JSTemporalPlainDate>());
} else {
#ifdef V8_INTL_SUPPORT
// TODO(ftang) add code for other calendar.
UNIMPLEMENTED();
#else // V8_INTL_SUPPORT
UNREACHABLE();
#endif // V8_INTL_SUPPORT
}
// 10. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]],
// result.[[Day]], calendar).
return CreateTemporalDate(isolate, result, calendar);
}
// #sec-temporal.calendar.prototype.daysinyear
MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -57,6 +57,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.dateadd
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDate> DateAdd(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> date, Handle<Object> durations, Handle<Object> options);
// #sec-temporal.calendar.prototype.daysinyear
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -433,34 +433,6 @@
'built-ins/Temporal/Duration/prototype/with/non-integer-throws-rangeerror': [FAIL],
'built-ins/Temporal/Duration/prototype/with/order-of-operations': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-days': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-plaindatetime': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/balance-smaller-units': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/date-infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-invalid-string': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-undefined': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateUntil/argument-plaindatetime': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/month/basic': [FAIL],
......@@ -2059,7 +2031,6 @@
'intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-objects-resolved-time-zone': [FAIL],
'intl402/DateTimeFormat/prototype/format/temporal-objects-resolved-time-zone': [FAIL],
'intl402/DateTimeFormat/prototype/formatToParts/temporal-objects-resolved-time-zone': [FAIL],
'intl402/Temporal/Calendar/prototype/dateAdd/date-infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/dateFromFields/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-string-with-utc-designator': [FAIL],
'intl402/Temporal/Calendar/prototype/era/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
......@@ -2474,7 +2445,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-with-time-designator': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/year-zero': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-missing-properties': [FAIL],
......@@ -2559,7 +2529,6 @@
'intl402/Temporal/Calendar/prototype/era/argument-string-invalid': [FAIL],
'intl402/Temporal/Calendar/prototype/eraYear/argument-string-invalid': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/options-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/options-wrong-type': [FAIL],
'built-ins/Temporal/Duration/compare/options-wrong-type': [FAIL],
'built-ins/Temporal/Duration/prototype/add/options-wrong-type': [FAIL],
......@@ -2709,10 +2678,8 @@
'built-ins/Temporal/Calendar/from/calendar-number': [FAIL],
'built-ins/Temporal/Calendar/from/calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number': [FAIL],
......@@ -3077,6 +3044,23 @@
'built-ins/Temporal/PlainDateTime/second-undefined': [SKIP],
'built-ins/Temporal/PlainYearMonth/basic': [SKIP],
'built-ins/Temporal/PlainYearMonth/limits': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-number': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-plaindatetime': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/balance-smaller-units': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/basic': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-undefined': [SKIP],
'built-ins/Temporal/Calendar/prototype/dateAdd/overflow-wrong-type': [SKIP],
# Flaky Temporal tests
'built-ins/Temporal/Instant/from/instant-string-sub-minute-offset': [SKIP],
......
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