[Temporal] Implement getters which forward to timeZone

get Temporal.ZonedDateTime.prototype.(hour|minute|*second)

Bug: v8:11544
Change-Id: I5f3d20f371db4898365876483c49df73d96f3728
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3373927
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78674}
This commit is contained in:
Frank Tang 2022-01-18 19:26:59 -08:00 committed by V8 LUCI CQ
parent a684fc4c92
commit 261ad0d5c2
4 changed files with 97 additions and 63 deletions

View File

@ -223,18 +223,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMonth)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMonthCode)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.day */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeDay)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.hour */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeHour)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.minute */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMinute)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.second */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeSecond)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.millisecond */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMillisecond)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.microsecond */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMicrosecond)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.nanosecond */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeNanosecond)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.dayofweek */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeDayOfWeek)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.dayofyear */
@ -704,6 +692,41 @@ TEMPORAL_VALUE_OF(PlainMonthDay)
// ZonedDateTime
#define TEMPORAL_ZONED_DATE_TIME_GET_PREPARE(M) \
HandleScope scope(isolate); \
const char* method = "get Temporal.ZonedDateTime.prototype." #M; \
/* 1. Let zonedDateTime be the this value. */ \
/* 2. Perform ? RequireInternalSlot(zonedDateTime, */ \
/* [[InitializedTemporalZonedDateTime]]). */ \
CHECK_RECEIVER(JSTemporalZonedDateTime, zoned_date_time, method); \
/* 3. Let timeZone be zonedDateTime.[[TimeZone]]. */ \
Handle<JSReceiver> time_zone = \
handle(zoned_date_time->time_zone(), isolate); \
/* 4. Let instant be ? */ \
/* CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). */ \
Handle<JSTemporalInstant> instant; \
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \
isolate, instant, \
temporal::CreateTemporalInstant( \
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate))); \
/* 5. Let calendar be zonedDateTime.[[Calendar]]. */ \
Handle<JSReceiver> calendar = handle(zoned_date_time->calendar(), isolate); \
/* 6. Let temporalDateTime be ? */ \
/* BuiltinTimeZoneGetPlainDateTimeFor(timeZone, */ \
/* instant, calendar). */ \
Handle<JSTemporalPlainDateTime> temporal_date_time; \
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \
isolate, temporal_date_time, \
temporal::BuiltinTimeZoneGetPlainDateTimeFor( \
isolate, time_zone, instant, calendar, method));
#define TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(M, field) \
BUILTIN(TemporalZonedDateTimePrototype##M) { \
TEMPORAL_ZONED_DATE_TIME_GET_PREPARE(M) \
/* 7. Return 𝔽(temporalDateTime.[[ #field ]]). */ \
return Smi::FromInt(temporal_date_time->field()); \
}
BUILTIN(TemporalZonedDateTimeConstructor) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
@ -722,6 +745,15 @@ TEMPORAL_GET_NUMBER_AFTER_DIVID(ZonedDateTime, EpochMilliseconds, nanoseconds,
1000000, epochMilliseconds)
TEMPORAL_GET_BIGINT_AFTER_DIVID(ZonedDateTime, EpochMicroseconds, nanoseconds,
1000, epochMicroseconds)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Hour, iso_hour)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Minute, iso_minute)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Second, iso_second)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Millisecond,
iso_millisecond)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Microsecond,
iso_microsecond)
TEMPORAL_ZONED_DATE_TIME_GET_INT_BY_FORWARD_TIME_ZONE(Nanosecond,
iso_nanosecond)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_VALUE_OF(ZonedDateTime)

View File

@ -743,6 +743,10 @@ MaybeHandle<JSTemporalDuration> CreateTemporalDuration(
microseconds, nanoseconds);
}
} // namespace
namespace temporal {
// #sec-temporal-createtemporalinstant
MaybeHandle<JSTemporalInstant> CreateTemporalInstant(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
@ -769,6 +773,10 @@ MaybeHandle<JSTemporalInstant> CreateTemporalInstant(
CONSTRUCTOR(instant), epoch_nanoseconds);
}
} // namespace temporal
namespace {
MaybeHandle<JSTemporalTimeZone> CreateTemporalTimeZoneFromIndex(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
int32_t index) {
@ -968,6 +976,9 @@ DateTimeRecordCommon BalanceISODateTime(Isolate* isolate, int32_t year,
balanced_time.nanosecond};
}
} // namespace
namespace temporal {
MaybeHandle<JSTemporalPlainDateTime> BuiltinTimeZoneGetPlainDateTimeFor(
Isolate* isolate, Handle<JSReceiver> time_zone,
Handle<JSTemporalInstant> instant, Handle<JSReceiver> calendar,
@ -1002,6 +1013,9 @@ MaybeHandle<JSTemporalPlainDateTime> BuiltinTimeZoneGetPlainDateTimeFor(
result.nanosecond, calendar);
}
} // namespace temporal
namespace {
// #sec-temporal-getpossibleinstantsfor
MaybeHandle<FixedArray> GetPossibleInstantsFor(Isolate* isolate,
Handle<JSReceiver> time_zone,
@ -1123,9 +1137,10 @@ MaybeHandle<JSTemporalInstant> DisambiguatePossibleInstants(
BigInt::Subtract(isolate, epoch_nanoseconds, one_day_in_ns),
JSTemporalInstant);
Handle<JSTemporalInstant> day_before;
ASSIGN_RETURN_ON_EXCEPTION(isolate, day_before,
CreateTemporalInstant(isolate, day_before_ns),
JSTemporalInstant);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, day_before,
temporal::CreateTemporalInstant(isolate, day_before_ns),
JSTemporalInstant);
// 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 ×
// 10^13).
Handle<BigInt> day_after_ns;
@ -1134,9 +1149,10 @@ MaybeHandle<JSTemporalInstant> DisambiguatePossibleInstants(
BigInt::Add(isolate, epoch_nanoseconds, one_day_in_ns),
JSTemporalInstant);
Handle<JSTemporalInstant> day_after;
ASSIGN_RETURN_ON_EXCEPTION(isolate, day_after,
CreateTemporalInstant(isolate, day_after_ns),
JSTemporalInstant);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, day_after,
temporal::CreateTemporalInstant(isolate, day_after_ns),
JSTemporalInstant);
// 10. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
Maybe<int64_t> maybe_offset_before =
GetOffsetNanosecondsFor(isolate, time_zone, day_before, method);
@ -2425,15 +2441,15 @@ MaybeHandle<BigInt> AddZonedDateTime(Isolate* isolate,
}
// 3. Let instant be ! CreateTemporalInstant(epochNanoseconds).
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(isolate, instant,
CreateTemporalInstant(isolate, epoch_nanoseconds),
BigInt);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant(isolate, epoch_nanoseconds), BigInt);
// 4. Let temporalDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
Handle<JSTemporalPlainDateTime> temporal_date_time;
ASSIGN_RETURN_ON_EXCEPTION(isolate, temporal_date_time,
BuiltinTimeZoneGetPlainDateTimeFor(
temporal::BuiltinTimeZoneGetPlainDateTimeFor(
isolate, time_zone, instant, calendar, method),
BigInt);
// 5. Let datePart be ? CreateTemporalDate(temporalDateTime.[[ISOYear]],
@ -2559,7 +2575,7 @@ Maybe<bool> NanosecondsToDays(Isolate* isolate, Handle<BigInt> nanoseconds,
Handle<JSTemporalInstant> start_instant;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, start_instant,
CreateTemporalInstant(
temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(relative_to->nanoseconds(), isolate)),
Nothing<bool>());
@ -2573,8 +2589,8 @@ Maybe<bool> NanosecondsToDays(Isolate* isolate, Handle<BigInt> nanoseconds,
Handle<JSTemporalPlainDateTime> start_date_time;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, start_date_time,
BuiltinTimeZoneGetPlainDateTimeFor(isolate, time_zone, start_instant,
calendar, method),
temporal::BuiltinTimeZoneGetPlainDateTimeFor(
isolate, time_zone, start_instant, calendar, method),
Nothing<bool>());
// 10. Let endNs be startNs + nanoseconds.
@ -2585,17 +2601,17 @@ Maybe<bool> NanosecondsToDays(Isolate* isolate, Handle<BigInt> nanoseconds,
// 11. Let endInstant be ! CreateTemporalInstant((endNs)).
Handle<JSTemporalInstant> end_instant;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, end_instant,
CreateTemporalInstant(isolate, end_ns),
Nothing<bool>());
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, end_instant, temporal::CreateTemporalInstant(isolate, end_ns),
Nothing<bool>());
// 12. Let endDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]],
// endInstant, relativeTo.[[Calendar]]).
Handle<JSTemporalPlainDateTime> end_date_time;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, end_date_time,
BuiltinTimeZoneGetPlainDateTimeFor(isolate, time_zone, end_instant,
calendar, method),
temporal::BuiltinTimeZoneGetPlainDateTimeFor(
isolate, time_zone, end_instant, calendar, method),
Nothing<bool>());
// 13. Let dateDifference be ?
@ -4019,7 +4035,7 @@ MaybeHandle<JSReceiver> JSTemporalZonedDateTime::GetISOFields(
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
CreateTemporalInstant(
temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)),
JSReceiver);
@ -4030,7 +4046,7 @@ MaybeHandle<JSReceiver> JSTemporalZonedDateTime::GetISOFields(
// instant, calendar).
Handle<JSTemporalPlainDateTime> date_time;
ASSIGN_RETURN_ON_EXCEPTION(isolate, date_time,
BuiltinTimeZoneGetPlainDateTimeFor(
temporal::BuiltinTimeZoneGetPlainDateTimeFor(
isolate, time_zone, instant, calendar, method),
JSReceiver);
// 8. Let offset be ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
@ -4109,7 +4125,8 @@ MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor(
JSTemporalInstant);
}
// 4. Return ? CreateTemporalInstant(epochNanoseconds, NewTarget).
return CreateTemporalInstant(isolate, target, new_target, epoch_nanoseconds);
return temporal::CreateTemporalInstant(isolate, target, new_target,
epoch_nanoseconds);
}
} // namespace internal

View File

@ -284,10 +284,25 @@ class JSTemporalZonedDateTime
namespace temporal {
// #sec-temporal-createtemporalinstant
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalInstant> CreateTemporalInstant(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
Handle<BigInt> epoch_nanoseconds);
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalInstant> CreateTemporalInstant(
Isolate* isolate, Handle<BigInt> epoch_nanoseconds);
// #sec-temporal-getiso8601calendar
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalCalendar> GetISO8601Calendar(
Isolate* isolate);
// #sec-temporal-builtintimezonegetplaindatetimefor
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalPlainDateTime>
BuiltinTimeZoneGetPlainDateTimeFor(Isolate* isolate,
Handle<JSReceiver> time_zone,
Handle<JSTemporalInstant> instant,
Handle<JSReceiver> calendar,
const char* method);
} // namespace temporal
} // namespace internal
} // namespace v8

View File

@ -2177,42 +2177,22 @@
'built-ins/Temporal/ZonedDateTime/prototype/getISOFields/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/getISOFields/offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hour/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hour/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/timezone-getpossibleinstantsfor-iterable': [SKIP],
'built-ins/Temporal/ZonedDateTime/prototype/hour/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hour/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hour/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/hour/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/microsecond/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/millisecond/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/minute/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/month/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/month/calendar-returns-infinity': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/monthCode/branding': [FAIL],
@ -2229,12 +2209,7 @@
'built-ins/Temporal/ZonedDateTime/prototype/month/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/month/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/month/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/basic': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/branding': [FAIL],
@ -2270,11 +2245,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/round/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/timezone-getpossibleinstantsfor-iterable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/second/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/branding': [FAIL],