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

[Temporal] Add Calendar.prototype.daysInYear

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

Note- this is only the non-intl version. intl version in
https://tc39.es/proposal-temporal/#sup-temporal.calendar.prototype.daysinyear
will be implemented in later cl.

Bug: v8:11544
Change-Id: I627fcf82641659c4697395057ee664a37f237228
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531557Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79634}
parent c232d789
......@@ -334,8 +334,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInWeek)
/* Temporal #sec-temporal.calendar.prototype.daysinmonth */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInMonth)
/* Temporal #sec-temporal.calendar.prototype.daysinyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDaysInYear)
/* Temporal #sec-temporal.calendar.prototype.monthsinyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthsInYear)
/* Temporal #sec-temporal.calendar.prototype.inleapyear */
......@@ -804,6 +802,7 @@ TEMPORAL_GET_BIGINT_AFTER_DIVID(Instant, EpochMicroseconds, nanoseconds, 1000,
// Calendar
TEMPORAL_CONSTRUCTOR1(Calendar)
TEMPORAL_ID_BY_TO_STRING(Calendar)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DaysInYear, daysInYear)
TEMPORAL_TO_STRING(Calendar)
// #sec-temporal.calendar.from
BUILTIN(TemporalCalendarFrom) {
......
......@@ -4789,6 +4789,46 @@ MaybeHandle<JSTemporalCalendar> JSTemporalCalendar::Constructor(
return CreateTemporalCalendar(isolate, target, new_target, identifier);
}
// #sec-temporal.calendar.prototype.daysinyear
MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not
// have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]] or
// [[InitializedTemporalYearMonth]] internal slot, then
if (!(temporal_date_like->IsJSTemporalPlainDate() ||
temporal_date_like->IsJSTemporalPlainDateTime() ||
temporal_date_like->IsJSTemporalPlainYearMonth())) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_like,
ToTemporalDate(isolate, temporal_date_like,
isolate->factory()->NewJSObjectWithNullProto(),
"Temporal.Calendar.prototype.daysInYear"),
Smi);
}
// a. Let daysInYear be ! ISODaysInYear(temporalDateLike.[[ISOYear]]).
int32_t year;
if (temporal_date_like->IsJSTemporalPlainDate()) {
year = Handle<JSTemporalPlainDate>::cast(temporal_date_like)->iso_year();
} else if (temporal_date_like->IsJSTemporalPlainDateTime()) {
year =
Handle<JSTemporalPlainDateTime>::cast(temporal_date_like)->iso_year();
} else {
DCHECK(temporal_date_like->IsJSTemporalPlainYearMonth());
year =
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_year();
}
int32_t days_in_year = ISODaysInYear(isolate, year);
// 6. Return 𝔽(daysInYear).
return handle(Smi::FromInt(days_in_year), isolate);
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
......
......@@ -52,6 +52,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSFunction> target,
Handle<HeapObject> new_target, Handle<Object> identifier);
// #sec-temporal.calendar.prototype.daysinyear
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.tostring
static MaybeHandle<String> ToString(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,
......
......@@ -52,7 +52,6 @@
'temporal/calendar-day-of-year': [FAIL],
'temporal/calendar-days-in-month': [FAIL],
'temporal/calendar-days-in-week': [FAIL],
'temporal/calendar-days-in-year': [FAIL],
'temporal/calendar-fields': [FAIL],
'temporal/calendar-in-leap-year': [FAIL],
'temporal/calendar-merge-fields': [FAIL],
......
......@@ -544,20 +544,10 @@
'built-ins/Temporal/Calendar/prototype/daysInWeek/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInWeek/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/plain-date': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInYear/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/day/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/day/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/fields/argument-iterable-not-array': [FAIL],
......@@ -2640,7 +2630,6 @@
'built-ins/Temporal/PlainYearMonth/prototype/add/month-length': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/add/options-invalid': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/daysInYear/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/basic': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar': [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