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

[Temporal] Add ZonedDateTime to(Instant|Plain(Date)?(Time)?)

Also change some AO's return type from MaybeHandle to Handle
and call ToHandleChecked() on the right spot.

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toinstant
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaindate
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaintime
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaindatetime

Bug: v8:11544
Change-Id: I140b6a7053d00837bc48fb70980d69778715c0c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3385603
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80788}
parent e85a0243
...@@ -108,14 +108,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeEquals) ...@@ -108,14 +108,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeEquals)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToString) TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToString)
/* Temporal #sec-temporal.zonedddatetimeprototype.tojson */ /* Temporal #sec-temporal.zonedddatetimeprototype.tojson */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToJSON) TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToJSON)
/* Temporal #sec-temporal.zoneddatetime.prototype.toinstant */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToInstant)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplaindate */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainDate)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplaintime */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainTime)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplaindatetime */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainDateTime)
/* Temporal.Duration */ /* Temporal.Duration */
/* Temporal #sec-temporal.duration.compare */ /* Temporal #sec-temporal.duration.compare */
...@@ -614,8 +606,12 @@ TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainMonthDay, toPlainMonthDay) ...@@ -614,8 +606,12 @@ TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainMonthDay, toPlainMonthDay)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields) TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds) TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset) TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset)
TEMPORAL_VALUE_OF(ZonedDateTime)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, StartOfDay, startOfDay) TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, StartOfDay, startOfDay)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToInstant, toInstant)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainDate, toPlainDate)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainTime, toPlainTime)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainDateTime, toPlainDateTime)
TEMPORAL_VALUE_OF(ZonedDateTime)
// Duration // Duration
BUILTIN(TemporalDurationConstructor) { BUILTIN(TemporalDurationConstructor) {
......
...@@ -385,7 +385,7 @@ inline double modulo(double a, int32_t b) { return a - std::floor(a / b) * b; } ...@@ -385,7 +385,7 @@ inline double modulo(double a, int32_t b) { return a - std::floor(a / b) * b; }
isolate->factory()->NewStringFromStaticChars(TEMPORAL_DEBUG_INFO)) isolate->factory()->NewStringFromStaticChars(TEMPORAL_DEBUG_INFO))
// #sec-defaulttimezone // #sec-defaulttimezone
MaybeHandle<String> DefaultTimeZone(Isolate* isolate) { Handle<String> DefaultTimeZone(Isolate* isolate) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
// For now, always return "UTC" // For now, always return "UTC"
// TODO(ftang) implement behavior specified in #sup-defaulttimezone // TODO(ftang) implement behavior specified in #sup-defaulttimezone
...@@ -473,7 +473,7 @@ bool ISOYearMonthWithinLimits(int32_t year, int32_t month) { ...@@ -473,7 +473,7 @@ bool ISOYearMonthWithinLimits(int32_t year, int32_t month) {
isolate) isolate)
// #sec-temporal-systemutcepochnanoseconds // #sec-temporal-systemutcepochnanoseconds
MaybeHandle<BigInt> SystemUTCEpochNanoseconds(Isolate* isolate) { Handle<BigInt> SystemUTCEpochNanoseconds(Isolate* isolate) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
// 1. Let ns be the approximate current UTC date and time, in nanoseconds // 1. Let ns be the approximate current UTC date and time, in nanoseconds
// since the epoch. // since the epoch.
...@@ -484,7 +484,8 @@ MaybeHandle<BigInt> SystemUTCEpochNanoseconds(Isolate* isolate) { ...@@ -484,7 +484,8 @@ MaybeHandle<BigInt> SystemUTCEpochNanoseconds(Isolate* isolate) {
// 3. Return ℤ(ns). // 3. Return ℤ(ns).
double ns = ms * 1000000.0; double ns = ms * 1000000.0;
ns = std::floor(std::max(-8.64e21, std::min(ns, 8.64e21))); ns = std::floor(std::max(-8.64e21, std::min(ns, 8.64e21)));
return BigInt::FromNumber(isolate, isolate->factory()->NewNumber(ns)); return BigInt::FromNumber(isolate, isolate->factory()->NewNumber(ns))
.ToHandleChecked();
} }
// #sec-temporal-createtemporalcalendar // #sec-temporal-createtemporalcalendar
...@@ -662,10 +663,7 @@ MaybeHandle<JSTemporalPlainTime> CreateTemporalTime( ...@@ -662,10 +663,7 @@ MaybeHandle<JSTemporalPlainTime> CreateTemporalTime(
// [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »). // [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
ORDINARY_CREATE_FROM_CONSTRUCTOR(object, target, new_target, ORDINARY_CREATE_FROM_CONSTRUCTOR(object, target, new_target,
JSTemporalPlainTime) JSTemporalPlainTime)
Handle<JSTemporalCalendar> calendar; Handle<JSTemporalCalendar> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalPlainTime);
object->set_hour_minute_second(0); object->set_hour_minute_second(0);
object->set_second_parts(0); object->set_second_parts(0);
// 5. Set object.[[ISOHour]] to hour. // 5. Set object.[[ISOHour]] to hour.
...@@ -1080,23 +1078,20 @@ MaybeHandle<JSTemporalTimeZone> CreateTemporalTimeZone( ...@@ -1080,23 +1078,20 @@ MaybeHandle<JSTemporalTimeZone> CreateTemporalTimeZone(
namespace { namespace {
// #sec-temporal-systeminstant // #sec-temporal-systeminstant
MaybeHandle<JSTemporalInstant> SystemInstant(Isolate* isolate) { Handle<JSTemporalInstant> SystemInstant(Isolate* isolate) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
// 1. Let ns be ! SystemUTCEpochNanoseconds(). // 1. Let ns be ! SystemUTCEpochNanoseconds().
Handle<BigInt> ns; Handle<BigInt> ns = SystemUTCEpochNanoseconds(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, ns, SystemUTCEpochNanoseconds(isolate),
JSTemporalInstant);
// 2. Return ? CreateTemporalInstant(ns). // 2. Return ? CreateTemporalInstant(ns).
return temporal::CreateTemporalInstant(isolate, ns); return temporal::CreateTemporalInstant(isolate, ns).ToHandleChecked();
} }
// #sec-temporal-systemtimezone // #sec-temporal-systemtimezone
MaybeHandle<JSTemporalTimeZone> SystemTimeZone(Isolate* isolate) { Handle<JSTemporalTimeZone> SystemTimeZone(Isolate* isolate) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
Handle<String> default_time_zone; Handle<String> default_time_zone = DefaultTimeZone(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, default_time_zone, return temporal::CreateTemporalTimeZone(isolate, default_time_zone)
DefaultTimeZone(isolate), JSTemporalTimeZone); .ToHandleChecked();
return temporal::CreateTemporalTimeZone(isolate, default_time_zone);
} }
DateTimeRecordCommon GetISOPartsFromEpoch(Isolate* isolate, DateTimeRecordCommon GetISOPartsFromEpoch(Isolate* isolate,
...@@ -1590,28 +1585,17 @@ MaybeHandle<JSTemporalInstant> DisambiguatePossibleInstants( ...@@ -1590,28 +1585,17 @@ MaybeHandle<JSTemporalInstant> DisambiguatePossibleInstants(
// 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds − 8.64 × // 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds − 8.64 ×
// 10^13). // 10^13).
Handle<BigInt> one_day_in_ns = BigInt::FromUint64(isolate, 86400000000000ULL); Handle<BigInt> one_day_in_ns = BigInt::FromUint64(isolate, 86400000000000ULL);
Handle<BigInt> day_before_ns; Handle<BigInt> day_before_ns =
ASSIGN_RETURN_ON_EXCEPTION( BigInt::Subtract(isolate, epoch_nanoseconds, one_day_in_ns)
isolate, day_before_ns, .ToHandleChecked();
BigInt::Subtract(isolate, epoch_nanoseconds, one_day_in_ns), Handle<JSTemporalInstant> day_before =
JSTemporalInstant); temporal::CreateTemporalInstant(isolate, day_before_ns).ToHandleChecked();
Handle<JSTemporalInstant> day_before;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, day_before,
temporal::CreateTemporalInstant(isolate, day_before_ns),
JSTemporalInstant);
// 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 × // 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 ×
// 10^13). // 10^13).
Handle<BigInt> day_after_ns; Handle<BigInt> day_after_ns =
ASSIGN_RETURN_ON_EXCEPTION( BigInt::Add(isolate, epoch_nanoseconds, one_day_in_ns).ToHandleChecked();
isolate, day_after_ns, Handle<JSTemporalInstant> day_after =
BigInt::Add(isolate, epoch_nanoseconds, one_day_in_ns), temporal::CreateTemporalInstant(isolate, day_after_ns).ToHandleChecked();
JSTemporalInstant);
Handle<JSTemporalInstant> day_after;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, day_after,
temporal::CreateTemporalInstant(isolate, day_after_ns),
JSTemporalInstant);
// 10. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore). // 10. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
int64_t offset_before; int64_t offset_before;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
...@@ -2036,7 +2020,8 @@ MaybeHandle<JSTemporalInstant> ToTemporalInstant(Isolate* isolate, ...@@ -2036,7 +2020,8 @@ MaybeHandle<JSTemporalInstant> ToTemporalInstant(Isolate* isolate,
// i. Return ! CreateTemporalInstant(item.[[Nanoseconds]]). // i. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<BigInt> nanoseconds = Handle<BigInt> nanoseconds =
handle(JSTemporalZonedDateTime::cast(*item).nanoseconds(), isolate); handle(JSTemporalZonedDateTime::cast(*item).nanoseconds(), isolate);
return temporal::CreateTemporalInstant(isolate, nanoseconds); return temporal::CreateTemporalInstant(isolate, nanoseconds)
.ToHandleChecked();
} }
// 2. Let string be ? ToString(item). // 2. Let string be ? ToString(item).
Handle<String> string; Handle<String> string;
...@@ -2209,12 +2194,10 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate, ...@@ -2209,12 +2194,10 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate,
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<JSTemporalZonedDateTime> zoned_date_time = Handle<JSTemporalZonedDateTime> zoned_date_time =
Handle<JSTemporalZonedDateTime>::cast(item); Handle<JSTemporalZonedDateTime>::cast(item);
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)), isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate))
JSTemporalPlainDate); .ToHandleChecked();
// ii. Let plainDateTime be ? // ii. Let plainDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], // BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]],
// instant, item.[[Calendar]]). // instant, item.[[Calendar]]).
...@@ -2231,22 +2214,24 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate, ...@@ -2231,22 +2214,24 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate,
// plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], // plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]],
// plainDateTime.[[Calendar]]). // plainDateTime.[[Calendar]]).
return CreateTemporalDate( return CreateTemporalDate(
isolate, isolate,
{plain_date_time->iso_year(), plain_date_time->iso_month(), {plain_date_time->iso_year(), plain_date_time->iso_month(),
plain_date_time->iso_day()}, plain_date_time->iso_day()},
Handle<JSReceiver>(plain_date_time->calendar(), isolate)); handle(plain_date_time->calendar(), isolate))
.ToHandleChecked();
} }
// c. If item has an [[InitializedTemporalDateTime]] internal slot, then // c. If item has an [[InitializedTemporalDateTime]] internal slot, then
// i. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]],
// item.[[ISODay]], item.[[Calendar]]). // item.[[ISODay]], item.[[Calendar]]).
if (item->IsJSTemporalPlainDateTime()) { if (item->IsJSTemporalPlainDateTime()) {
// i. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]],
Handle<JSTemporalPlainDateTime> date_time = Handle<JSTemporalPlainDateTime> date_time =
Handle<JSTemporalPlainDateTime>::cast(item); Handle<JSTemporalPlainDateTime>::cast(item);
return CreateTemporalDate( return CreateTemporalDate(isolate,
isolate, {date_time->iso_year(), date_time->iso_month(),
{date_time->iso_year(), date_time->iso_month(), date_time->iso_day()}, date_time->iso_day()},
handle(date_time->calendar(), isolate)); handle(date_time->calendar(), isolate))
.ToHandleChecked();
} }
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item). // d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
...@@ -2412,12 +2397,10 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate, ...@@ -2412,12 +2397,10 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate,
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<JSTemporalZonedDateTime> zoned_date_time = Handle<JSTemporalZonedDateTime> zoned_date_time =
Handle<JSTemporalZonedDateTime>::cast(item); Handle<JSTemporalZonedDateTime>::cast(item);
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION( CreateTemporalInstant(isolate,
isolate, instant, handle(zoned_date_time->nanoseconds(), isolate))
CreateTemporalInstant( .ToHandleChecked();
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)),
JSTemporalPlainTime);
// ii. Set plainDateTime to ? // ii. Set plainDateTime to ?
// BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], // BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]],
// instant, item.[[Calendar]]). // instant, item.[[Calendar]]).
...@@ -2435,12 +2418,13 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate, ...@@ -2435,12 +2418,13 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate,
// plainDateTime.[[ISOMinute]], plainDateTime.[[ISOSecond]], // plainDateTime.[[ISOMinute]], plainDateTime.[[ISOSecond]],
// plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]], // plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]],
// plainDateTime.[[ISONanosecond]]). // plainDateTime.[[ISONanosecond]]).
return CreateTemporalTime( return CreateTemporalTime(isolate, {plain_date_time->iso_hour(),
isolate, plain_date_time->iso_minute(),
{plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(),
plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_millisecond(),
plain_date_time->iso_microsecond(), plain_date_time->iso_microsecond(),
plain_date_time->iso_nanosecond()}); plain_date_time->iso_nanosecond()})
.ToHandleChecked();
} }
// c. If item has an [[InitializedTemporalDateTime]] internal slot, then // c. If item has an [[InitializedTemporalDateTime]] internal slot, then
if (item->IsJSTemporalPlainDateTime()) { if (item->IsJSTemporalPlainDateTime()) {
...@@ -2450,9 +2434,11 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate, ...@@ -2450,9 +2434,11 @@ MaybeHandle<JSTemporalPlainTime> ToTemporalTime(Isolate* isolate,
Handle<JSTemporalPlainDateTime> date_time = Handle<JSTemporalPlainDateTime> date_time =
Handle<JSTemporalPlainDateTime>::cast(item); Handle<JSTemporalPlainDateTime>::cast(item);
return CreateTemporalTime( return CreateTemporalTime(
isolate, {date_time->iso_hour(), date_time->iso_minute(), isolate,
date_time->iso_second(), date_time->iso_millisecond(), {date_time->iso_hour(), date_time->iso_minute(),
date_time->iso_microsecond(), date_time->iso_nanosecond()}); date_time->iso_second(), date_time->iso_millisecond(),
date_time->iso_microsecond(), date_time->iso_nanosecond()})
.ToHandleChecked();
} }
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item). // d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
Handle<JSReceiver> calendar; Handle<JSReceiver> calendar;
...@@ -2750,8 +2736,7 @@ MaybeHandle<JSTemporalPlainDateTime> SystemDateTime( ...@@ -2750,8 +2736,7 @@ MaybeHandle<JSTemporalPlainDateTime> SystemDateTime(
// 1. 1. If temporalTimeZoneLike is undefined, then // 1. 1. If temporalTimeZoneLike is undefined, then
if (temporal_time_zone_like->IsUndefined()) { if (temporal_time_zone_like->IsUndefined()) {
// a. Let timeZone be ! SystemTimeZone(). // a. Let timeZone be ! SystemTimeZone().
ASSIGN_RETURN_ON_EXCEPTION(isolate, time_zone, SystemTimeZone(isolate), time_zone = SystemTimeZone(isolate);
JSTemporalPlainDateTime);
} else { } else {
// 2. Else, // 2. Else,
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike). // a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
...@@ -2768,9 +2753,7 @@ MaybeHandle<JSTemporalPlainDateTime> SystemDateTime( ...@@ -2768,9 +2753,7 @@ MaybeHandle<JSTemporalPlainDateTime> SystemDateTime(
temporal::ToTemporalCalendar(isolate, calendar_like, method_name), temporal::ToTemporalCalendar(isolate, calendar_like, method_name),
JSTemporalPlainDateTime); JSTemporalPlainDateTime);
// 4. Let instant be ! SystemInstant(). // 4. Let instant be ! SystemInstant().
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant = SystemInstant(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, instant, SystemInstant(isolate),
JSTemporalPlainDateTime);
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, // 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant,
// calendar). // calendar).
return temporal::BuiltinTimeZoneGetPlainDateTimeFor( return temporal::BuiltinTimeZoneGetPlainDateTimeFor(
...@@ -2786,8 +2769,7 @@ MaybeHandle<JSTemporalZonedDateTime> SystemZonedDateTime( ...@@ -2786,8 +2769,7 @@ MaybeHandle<JSTemporalZonedDateTime> SystemZonedDateTime(
// 1. 1. If temporalTimeZoneLike is undefined, then // 1. 1. If temporalTimeZoneLike is undefined, then
if (temporal_time_zone_like->IsUndefined()) { if (temporal_time_zone_like->IsUndefined()) {
// a. Let timeZone be ! SystemTimeZone(). // a. Let timeZone be ! SystemTimeZone().
ASSIGN_RETURN_ON_EXCEPTION(isolate, time_zone, SystemTimeZone(isolate), time_zone = SystemTimeZone(isolate);
JSTemporalZonedDateTime);
} else { } else {
// 2. Else, // 2. Else,
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike). // a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
...@@ -2804,9 +2786,7 @@ MaybeHandle<JSTemporalZonedDateTime> SystemZonedDateTime( ...@@ -2804,9 +2786,7 @@ MaybeHandle<JSTemporalZonedDateTime> SystemZonedDateTime(
temporal::ToTemporalCalendar(isolate, calendar_like, method_name), temporal::ToTemporalCalendar(isolate, calendar_like, method_name),
JSTemporalZonedDateTime); JSTemporalZonedDateTime);
// 4. Let ns be ! SystemUTCEpochNanoseconds(). // 4. Let ns be ! SystemUTCEpochNanoseconds().
Handle<BigInt> ns; Handle<BigInt> ns = SystemUTCEpochNanoseconds(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, ns, SystemUTCEpochNanoseconds(isolate),
JSTemporalZonedDateTime);
// Return ? CreateTemporalZonedDateTime(ns, timeZone, calendar). // Return ? CreateTemporalZonedDateTime(ns, timeZone, calendar).
return CreateTemporalZonedDateTime(isolate, ns, time_zone, calendar); return CreateTemporalZonedDateTime(isolate, ns, time_zone, calendar);
} }
...@@ -4179,8 +4159,9 @@ CALENDAR_ABSTRACT_OPERATION(MonthsInYear, monthsInYear) ...@@ -4179,8 +4159,9 @@ CALENDAR_ABSTRACT_OPERATION(MonthsInYear, monthsInYear)
CALENDAR_ABSTRACT_OPERATION(InLeapYear, inLeapYear) CALENDAR_ABSTRACT_OPERATION(InLeapYear, inLeapYear)
// #sec-temporal-getiso8601calendar // #sec-temporal-getiso8601calendar
MaybeHandle<JSTemporalCalendar> GetISO8601Calendar(Isolate* isolate) { Handle<JSTemporalCalendar> GetISO8601Calendar(Isolate* isolate) {
return CreateTemporalCalendar(isolate, isolate->factory()->iso8601_string()); return CreateTemporalCalendar(isolate, isolate->factory()->iso8601_string())
.ToHandleChecked();
} }
} // namespace temporal } // namespace temporal
...@@ -4873,13 +4854,13 @@ MaybeHandle<BigInt> AddZonedDateTime(Isolate* isolate, ...@@ -4873,13 +4854,13 @@ MaybeHandle<BigInt> AddZonedDateTime(Isolate* isolate,
time_duration.days == 0) { time_duration.days == 0) {
// a. Return ! AddInstant(epochNanoseconds, hours, minutes, seconds, // a. Return ! AddInstant(epochNanoseconds, hours, minutes, seconds,
// milliseconds, microseconds, nanoseconds). // milliseconds, microseconds, nanoseconds).
return AddInstant(isolate, epoch_nanoseconds, time_duration); return AddInstant(isolate, epoch_nanoseconds, time_duration)
.ToHandleChecked();
} }
// 3. Let instant be ! CreateTemporalInstant(epochNanoseconds). // 3. Let instant be ! CreateTemporalInstant(epochNanoseconds).
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION( temporal::CreateTemporalInstant(isolate, epoch_nanoseconds)
isolate, instant, .ToHandleChecked();
temporal::CreateTemporalInstant(isolate, epoch_nanoseconds), BigInt);
// 4. Let temporalDateTime be ? // 4. Let temporalDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar). // BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
...@@ -4948,9 +4929,10 @@ MaybeHandle<BigInt> AddZonedDateTime(Isolate* isolate, ...@@ -4948,9 +4929,10 @@ MaybeHandle<BigInt> AddZonedDateTime(Isolate* isolate,
// 10. Return ! AddInstant(intermediateInstant.[[Nanoseconds]], hours, // 10. Return ! AddInstant(intermediateInstant.[[Nanoseconds]], hours,
// minutes, seconds, milliseconds, microseconds, nanoseconds). // minutes, seconds, milliseconds, microseconds, nanoseconds).
time_duration.days = 0; time_duration.days = 0;
return AddInstant( return AddInstant(isolate,
isolate, Handle<BigInt>(intermediate_instant->nanoseconds(), isolate), handle(intermediate_instant->nanoseconds(), isolate),
time_duration); time_duration)
.ToHandleChecked();
} }
// #sec-temporal-nanosecondstodays // #sec-temporal-nanosecondstodays
...@@ -5015,12 +4997,10 @@ Maybe<NanosecondsToDaysResult> NanosecondsToDays(Isolate* isolate, ...@@ -5015,12 +4997,10 @@ Maybe<NanosecondsToDaysResult> NanosecondsToDays(Isolate* isolate,
// 7. Let startNs be ℝ(relativeTo.[[Nanoseconds]]). // 7. Let startNs be ℝ(relativeTo.[[Nanoseconds]]).
Handle<BigInt> start_ns = Handle<BigInt>(relative_to->nanoseconds(), isolate); Handle<BigInt> start_ns = Handle<BigInt>(relative_to->nanoseconds(), isolate);
// 8. Let startInstant be ! CreateTemporalInstant(ℤ(sartNs)). // 8. Let startInstant be ! CreateTemporalInstant(ℤ(sartNs)).
Handle<JSTemporalInstant> start_instant; Handle<JSTemporalInstant> start_instant =
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, start_instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(relative_to->nanoseconds(), isolate)), isolate, handle(relative_to->nanoseconds(), isolate))
Nothing<NanosecondsToDaysResult>()); .ToHandleChecked();
// 9. Let startDateTime be ? // 9. Let startDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], // BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]],
...@@ -5043,10 +5023,8 @@ Maybe<NanosecondsToDaysResult> NanosecondsToDays(Isolate* isolate, ...@@ -5043,10 +5023,8 @@ Maybe<NanosecondsToDaysResult> NanosecondsToDays(Isolate* isolate,
Nothing<NanosecondsToDaysResult>()); Nothing<NanosecondsToDaysResult>());
// 11. Let endInstant be ! CreateTemporalInstant(ℤ(endNs)). // 11. Let endInstant be ! CreateTemporalInstant(ℤ(endNs)).
Handle<JSTemporalInstant> end_instant; Handle<JSTemporalInstant> end_instant =
ASSIGN_RETURN_ON_EXCEPTION_VALUE( temporal::CreateTemporalInstant(isolate, end_ns).ToHandleChecked();
isolate, end_instant, temporal::CreateTemporalInstant(isolate, end_ns),
Nothing<NanosecondsToDaysResult>());
// 12. Let endDateTime be ? // 12. Let endDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], // BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]],
// endInstant, relativeTo.[[Calendar]]). // endInstant, relativeTo.[[Calendar]]).
...@@ -6059,7 +6037,7 @@ MaybeHandle<Smi> JSTemporalDuration::Sign(Isolate* isolate, ...@@ -6059,7 +6037,7 @@ MaybeHandle<Smi> JSTemporalDuration::Sign(Isolate* isolate,
// duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], // duration.[[Weeks]], duration.[[Days]], duration.[[Hours]],
// duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], // duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]],
// duration.[[Microseconds]], duration.[[Nanoseconds]]). // duration.[[Microseconds]], duration.[[Nanoseconds]]).
return Handle<Smi>( return handle(
Smi::FromInt(DurationSign( Smi::FromInt(DurationSign(
isolate, {duration->years().Number(), isolate, {duration->years().Number(),
duration->months().Number(), duration->months().Number(),
...@@ -6111,14 +6089,16 @@ MaybeHandle<JSTemporalDuration> CreateNegatedTemporalDuration( ...@@ -6111,14 +6089,16 @@ MaybeHandle<JSTemporalDuration> CreateNegatedTemporalDuration(
// −duration.[[Milliseconds]], −duration.[[Microseconds]], // −duration.[[Milliseconds]], −duration.[[Microseconds]],
// −duration.[[Nanoseconds]]). // −duration.[[Nanoseconds]]).
return CreateTemporalDuration( return CreateTemporalDuration(
isolate, isolate,
{-duration->years().Number(), {-duration->years().Number(),
-duration->months().Number(), -duration->months().Number(),
-duration->weeks().Number(), -duration->weeks().Number(),
{-duration->days().Number(), -duration->hours().Number(), {-duration->days().Number(), -duration->hours().Number(),
-duration->minutes().Number(), -duration->seconds().Number(), -duration->minutes().Number(), -duration->seconds().Number(),
-duration->milliseconds().Number(), -duration->microseconds().Number(), -duration->milliseconds().Number(),
-duration->nanoseconds().Number()}}); -duration->microseconds().Number(),
-duration->nanoseconds().Number()}})
.ToHandleChecked();
} }
} // namespace } // namespace
...@@ -6131,7 +6111,7 @@ MaybeHandle<JSTemporalDuration> JSTemporalDuration::Negated( ...@@ -6131,7 +6111,7 @@ MaybeHandle<JSTemporalDuration> JSTemporalDuration::Negated(
// [[InitializedTemporalDuration]]). // [[InitializedTemporalDuration]]).
// 3. Return ! CreateNegatedTemporalDuration(duration). // 3. Return ! CreateNegatedTemporalDuration(duration).
return CreateNegatedTemporalDuration(isolate, duration); return CreateNegatedTemporalDuration(isolate, duration).ToHandleChecked();
} }
// #sec-temporal.duration.prototype.abs // #sec-temporal.duration.prototype.abs
...@@ -7168,7 +7148,8 @@ MaybeHandle<JSTemporalDuration> JSTemporalCalendar::DateUntil( ...@@ -7168,7 +7148,8 @@ MaybeHandle<JSTemporalDuration> JSTemporalCalendar::DateUntil(
return CreateTemporalDuration(isolate, {result.years, return CreateTemporalDuration(isolate, {result.years,
result.months, result.months,
result.weeks, result.weeks,
{result.days, 0, 0, 0, 0, 0, 0}}); {result.days, 0, 0, 0, 0, 0, 0}})
.ToHandleChecked();
} }
// #sec-temporal.calendar.prototype.day // #sec-temporal.calendar.prototype.day
...@@ -7652,7 +7633,7 @@ MaybeHandle<Object> GetTransition(Isolate* isolate, ...@@ -7652,7 +7633,7 @@ MaybeHandle<Object> GetTransition(Isolate* isolate,
DCHECK(transition_obj->IsBigInt()); DCHECK(transition_obj->IsBigInt());
Handle<BigInt> transition = Handle<BigInt>::cast(transition_obj); Handle<BigInt> transition = Handle<BigInt>::cast(transition_obj);
// 7. Return ! CreateTemporalInstant(transition). // 7. Return ! CreateTemporalInstant(transition).
return temporal::CreateTemporalInstant(isolate, transition); return temporal::CreateTemporalInstant(isolate, transition).ToHandleChecked();
} }
// #sec-temporal.timezone.prototype.getnexttransition // #sec-temporal.timezone.prototype.getnexttransition
...@@ -8330,10 +8311,11 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::Now( ...@@ -8330,10 +8311,11 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::Now(
JSTemporalPlainDate); JSTemporalPlainDate);
// 2. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], // 2. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]],
// dateTime.[[ISODay]], dateTime.[[Calendar]]). // dateTime.[[ISODay]], dateTime.[[Calendar]]).
return CreateTemporalDate( return CreateTemporalDate(isolate,
isolate, {date_time->iso_year(), date_time->iso_month(),
{date_time->iso_year(), date_time->iso_month(), date_time->iso_day()}, date_time->iso_day()},
Handle<JSReceiver>(date_time->calendar(), isolate)); Handle<JSReceiver>(date_time->calendar(), isolate))
.ToHandleChecked();
} }
// #sec-temporal.now.plaindateiso // #sec-temporal.now.plaindateiso
...@@ -8341,10 +8323,7 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::NowISO( ...@@ -8341,10 +8323,7 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::NowISO(
Isolate* isolate, Handle<Object> temporal_time_zone_like) { Isolate* isolate, Handle<Object> temporal_time_zone_like) {
const char* method_name = "Temporal.Now.plainDateISO"; const char* method_name = "Temporal.Now.plainDateISO";
// 1. Let calendar be ! GetISO8601Calendar(). // 1. Let calendar be ! GetISO8601Calendar().
Handle<JSReceiver> calendar; Handle<JSReceiver> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalPlainDate);
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar). // 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
Handle<JSTemporalPlainDateTime> date_time; Handle<JSTemporalPlainDateTime> date_time;
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
...@@ -8353,10 +8332,11 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::NowISO( ...@@ -8353,10 +8332,11 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::NowISO(
JSTemporalPlainDate); JSTemporalPlainDate);
// 3. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], // 3. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]],
// dateTime.[[ISODay]], dateTime.[[Calendar]]). // dateTime.[[ISODay]], dateTime.[[Calendar]]).
return CreateTemporalDate( return CreateTemporalDate(isolate,
isolate, {date_time->iso_year(), date_time->iso_month(),
{date_time->iso_year(), date_time->iso_month(), date_time->iso_day()}, date_time->iso_day()},
Handle<JSReceiver>(date_time->calendar(), isolate)); Handle<JSReceiver>(date_time->calendar(), isolate))
.ToHandleChecked();
} }
// #sec-temporal.plaindate.from // #sec-temporal.plaindate.from
...@@ -8633,12 +8613,10 @@ MaybeHandle<JSTemporalPlainDateTime> ToTemporalDateTime( ...@@ -8633,12 +8613,10 @@ MaybeHandle<JSTemporalPlainDateTime> ToTemporalDateTime(
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<JSTemporalZonedDateTime> zoned_date_time = Handle<JSTemporalZonedDateTime> zoned_date_time =
Handle<JSTemporalZonedDateTime>::cast(item); Handle<JSTemporalZonedDateTime>::cast(item);
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate))
JSTemporalPlainDateTime); .ToHandleChecked();
// ii. Return ? // ii. Return ?
// temporal::BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], // temporal::BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]],
// instant, item.[[Calendar]]). // instant, item.[[Calendar]]).
...@@ -9154,10 +9132,7 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::NowISO( ...@@ -9154,10 +9132,7 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::NowISO(
Isolate* isolate, Handle<Object> temporal_time_zone_like) { Isolate* isolate, Handle<Object> temporal_time_zone_like) {
const char* method_name = "Temporal.Now.plainDateTimeISO"; const char* method_name = "Temporal.Now.plainDateTimeISO";
// 1. Let calendar be ! GetISO8601Calendar(). // 1. Let calendar be ! GetISO8601Calendar().
Handle<JSReceiver> calendar; Handle<JSReceiver> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalPlainDateTime);
// 2. Return ? SystemDateTime(temporalTimeZoneLike, calendar). // 2. Return ? SystemDateTime(temporalTimeZoneLike, calendar).
return SystemDateTime(isolate, temporal_time_zone_like, calendar, return SystemDateTime(isolate, temporal_time_zone_like, calendar,
method_name); method_name);
...@@ -10257,10 +10232,7 @@ MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::NowISO( ...@@ -10257,10 +10232,7 @@ MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::NowISO(
Isolate* isolate, Handle<Object> temporal_time_zone_like) { Isolate* isolate, Handle<Object> temporal_time_zone_like) {
const char* method_name = "Temporal.Now.plainTimeISO"; const char* method_name = "Temporal.Now.plainTimeISO";
// 1. Let calendar be ! GetISO8601Calendar(). // 1. Let calendar be ! GetISO8601Calendar().
Handle<JSReceiver> calendar; Handle<JSReceiver> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalPlainTime);
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar). // 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
Handle<JSTemporalPlainDateTime> date_time; Handle<JSTemporalPlainDateTime> date_time;
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
...@@ -10272,9 +10244,11 @@ MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::NowISO( ...@@ -10272,9 +10244,11 @@ MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::NowISO(
// dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], // dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]],
// dateTime.[[ISONanosecond]]). // dateTime.[[ISONanosecond]]).
return CreateTemporalTime( return CreateTemporalTime(
isolate, {date_time->iso_hour(), date_time->iso_minute(), isolate,
date_time->iso_second(), date_time->iso_millisecond(), {date_time->iso_hour(), date_time->iso_minute(),
date_time->iso_microsecond(), date_time->iso_nanosecond()}); date_time->iso_second(), date_time->iso_millisecond(),
date_time->iso_microsecond(), date_time->iso_nanosecond()})
.ToHandleChecked();
} }
// #sec-temporal.plaintime.from // #sec-temporal.plaintime.from
...@@ -10350,10 +10324,8 @@ MaybeHandle<JSReceiver> JSTemporalPlainTime::GetISOFields( ...@@ -10350,10 +10324,8 @@ MaybeHandle<JSReceiver> JSTemporalPlainTime::GetISOFields(
isolate->factory()->NewJSObject(isolate->object_function()); isolate->factory()->NewJSObject(isolate->object_function());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar",
// temporalTime.[[Calendar]]). // temporalTime.[[Calendar]]).
Handle<JSTemporalCalendar> iso8601_calendar; Handle<JSTemporalCalendar> iso8601_calendar =
ASSIGN_RETURN_ON_EXCEPTION(isolate, iso8601_calendar, temporal::GetISO8601Calendar(isolate);
temporal::GetISO8601Calendar(isolate),
JSTemporalPlainTime);
CHECK(JSReceiver::CreateDataProperty(isolate, fields, CHECK(JSReceiver::CreateDataProperty(isolate, fields,
factory->calendar_string(), factory->calendar_string(),
iso8601_calendar, Just(kThrowOnError)) iso8601_calendar, Just(kThrowOnError))
...@@ -10485,12 +10457,10 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::WithPlainTime( ...@@ -10485,12 +10457,10 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::WithPlainTime(
// 5. Let timeZone be zonedDateTime.[[TimeZone]]. // 5. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate); Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 6. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). // 6. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate))
JSTemporalZonedDateTime); .ToHandleChecked();
// 7. Let calendar be zonedDateTime.[[Calendar]]. // 7. Let calendar be zonedDateTime.[[Calendar]].
Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate); Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate);
// 8. Let plainDateTime be ? // 8. Let plainDateTime be ?
...@@ -10573,12 +10543,10 @@ MaybeHandle<T> ZonedDateTimeToPlainYearMonthOrMonthDay( ...@@ -10573,12 +10543,10 @@ MaybeHandle<T> ZonedDateTimeToPlainYearMonthOrMonthDay(
// 3. Let timeZone be zonedDateTime.[[TimeZone]]. // 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate); Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). // 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate))
T); .ToHandleChecked();
// 5. Let calendar be zonedDateTime.[[Calendar]]. // 5. Let calendar be zonedDateTime.[[Calendar]].
Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate); Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate);
// 6. Let temporalDateTime be ? // 6. Let temporalDateTime be ?
...@@ -10644,10 +10612,7 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::NowISO( ...@@ -10644,10 +10612,7 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::NowISO(
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
const char* method_name = "Temporal.Now.zonedDateTimeISO"; const char* method_name = "Temporal.Now.zonedDateTimeISO";
// 1. Let calendar be ! GetISO8601Calendar(). // 1. Let calendar be ! GetISO8601Calendar().
Handle<JSReceiver> calendar; Handle<JSReceiver> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalZonedDateTime);
// 2. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar). // 2. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar).
return SystemZonedDateTime(isolate, temporal_time_zone_like, calendar, return SystemZonedDateTime(isolate, temporal_time_zone_like, calendar,
method_name); method_name);
...@@ -10673,7 +10638,7 @@ MaybeHandle<JSReceiver> JSTemporalZonedDateTime::GetISOFields( ...@@ -10673,7 +10638,7 @@ MaybeHandle<JSReceiver> JSTemporalZonedDateTime::GetISOFields(
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant, isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, Handle<BigInt>(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate)),
JSReceiver); JSReceiver);
// 6. Let calendar be zonedDateTime.[[Calendar]]. // 6. Let calendar be zonedDateTime.[[Calendar]].
...@@ -10752,12 +10717,10 @@ MaybeHandle<Object> JSTemporalZonedDateTime::OffsetNanoseconds( ...@@ -10752,12 +10717,10 @@ MaybeHandle<Object> JSTemporalZonedDateTime::OffsetNanoseconds(
// 3. Let timeZone be zonedDateTime.[[TimeZone]]. // 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate); Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). // 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate))
Object); .ToHandleChecked();
// 5. Return 𝔽(? GetOffsetNanosecondsFor(timeZone, instant)). // 5. Return 𝔽(? GetOffsetNanosecondsFor(timeZone, instant)).
int64_t result; int64_t result;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
...@@ -10777,12 +10740,10 @@ MaybeHandle<String> JSTemporalZonedDateTime::Offset( ...@@ -10777,12 +10740,10 @@ MaybeHandle<String> JSTemporalZonedDateTime::Offset(
// 2. Perform ? RequireInternalSlot(zonedDateTime, // 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]). // [[InitializedTemporalZonedDateTime]]).
// 3. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]). // 3. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant; Handle<JSTemporalInstant> instant =
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant( temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate)), isolate, handle(zoned_date_time->nanoseconds(), isolate))
String); .ToHandleChecked();
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(zonedDateTime.[[TimeZone]], // 4. Return ? BuiltinTimeZoneGetOffsetStringFor(zonedDateTime.[[TimeZone]],
// instant). // instant).
return BuiltinTimeZoneGetOffsetStringFor( return BuiltinTimeZoneGetOffsetStringFor(
...@@ -10844,6 +10805,96 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::StartOfDay( ...@@ -10844,6 +10805,96 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::StartOfDay(
calendar); calendar);
} }
// #sec-temporal.zoneddatetime.prototype.toinstant
MaybeHandle<JSTemporalInstant> JSTemporalZonedDateTime::ToInstant(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
TEMPORAL_ENTER_FUNC();
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Return ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
return temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate))
.ToHandleChecked();
}
namespace {
// Function implment shared steps of toplaindate, toplaintime, toplaindatetime
MaybeHandle<JSTemporalPlainDateTime> ZonedDateTimeToPlainDateTime(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
const char* method_name) {
TEMPORAL_ENTER_FUNC();
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant =
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate))
.ToHandleChecked();
// 5. 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant,
// zonedDateTime.[[Calendar]]).
return temporal::BuiltinTimeZoneGetPlainDateTimeFor(
isolate, time_zone, instant, handle(zoned_date_time->calendar(), isolate),
method_name);
}
} // namespace
// #sec-temporal.zoneddatetime.prototype.toplaindate
MaybeHandle<JSTemporalPlainDate> JSTemporalZonedDateTime::ToPlainDate(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
// Step 1-6 are the same as toplaindatetime
Handle<JSTemporalPlainDateTime> temporal_date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
ZonedDateTimeToPlainDateTime(
isolate, zoned_date_time,
"Temporal.ZonedDateTime.prototype.toPlainDate"),
JSTemporalPlainDate);
// 7. Return ? CreateTemporalDate(temporalDateTime.[[ISOYear]],
// temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], calendar).
return CreateTemporalDate(
isolate,
{temporal_date_time->iso_year(), temporal_date_time->iso_month(),
temporal_date_time->iso_day()},
handle(zoned_date_time->calendar(), isolate));
}
// #sec-temporal.zoneddatetime.prototype.toplaintime
MaybeHandle<JSTemporalPlainTime> JSTemporalZonedDateTime::ToPlainTime(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
// Step 1-6 are the same as toplaindatetime
Handle<JSTemporalPlainDateTime> temporal_date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
ZonedDateTimeToPlainDateTime(
isolate, zoned_date_time,
"Temporal.ZonedDateTime.prototype.toPlainTime"),
JSTemporalPlainTime);
// 7. Return ? CreateTemporalTime(temporalDateTime.[[ISOHour]],
// temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]],
// temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]],
// temporalDateTime.[[ISONanosecond]]).
return CreateTemporalTime(
isolate,
{temporal_date_time->iso_hour(), temporal_date_time->iso_minute(),
temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(),
temporal_date_time->iso_microsecond(),
temporal_date_time->iso_nanosecond()});
}
// #sec-temporal.zoneddatetime.prototype.toplaindatetime
MaybeHandle<JSTemporalPlainDateTime> JSTemporalZonedDateTime::ToPlainDateTime(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
return ZonedDateTimeToPlainDateTime(
isolate, zoned_date_time,
"Temporal.ZonedDateTime.prototype.toPlainDateTime");
}
// #sec-temporal.instant // #sec-temporal.instant
MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor( MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target, Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
...@@ -11068,10 +11119,7 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalInstant::ToZonedDateTimeISO( ...@@ -11068,10 +11119,7 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalInstant::ToZonedDateTimeISO(
isolate, item_obj, "Temporal.Instant.prototype.toZonedDateTimeISO"), isolate, item_obj, "Temporal.Instant.prototype.toZonedDateTimeISO"),
JSTemporalZonedDateTime); JSTemporalZonedDateTime);
// 5. Let calendar be ! GetISO8601Calendar(). // 5. Let calendar be ! GetISO8601Calendar().
Handle<JSTemporalCalendar> calendar; Handle<JSTemporalCalendar> calendar = temporal::GetISO8601Calendar(isolate);
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar,
temporal::GetISO8601Calendar(isolate),
JSTemporalZonedDateTime);
// 6. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, // 6. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone,
// calendar). // calendar).
return CreateTemporalZonedDateTime( return CreateTemporalZonedDateTime(
......
...@@ -737,6 +737,23 @@ class JSTemporalZonedDateTime ...@@ -737,6 +737,23 @@ class JSTemporalZonedDateTime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> StartOfDay( V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> StartOfDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time); Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toinstant
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> ToInstant(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toplaindate
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDate> ToPlainDate(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toplaintime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainTime> ToPlainTime(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.toplaindatetime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDateTime>
ToPlainDateTime(Isolate* isolate,
Handle<JSTemporalZonedDateTime> zoned_date_time);
DECL_PRINTER(JSTemporalZonedDateTime) DECL_PRINTER(JSTemporalZonedDateTime)
TQ_OBJECT_CONSTRUCTORS(JSTemporalZonedDateTime) TQ_OBJECT_CONSTRUCTORS(JSTemporalZonedDateTime)
...@@ -777,8 +794,7 @@ DECLARE_CALENDAR_ABSTRACT_OPERATION(EraYear) ...@@ -777,8 +794,7 @@ DECLARE_CALENDAR_ABSTRACT_OPERATION(EraYear)
#undef DECLARE_CALENDAR_ABSTRACT_OPERATION #undef DECLARE_CALENDAR_ABSTRACT_OPERATION
// #sec-temporal-getiso8601calendar // #sec-temporal-getiso8601calendar
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalCalendar> GetISO8601Calendar( Handle<JSTemporalCalendar> GetISO8601Calendar(Isolate* isolate);
Isolate* isolate);
// #sec-temporal-builtintimezonegetplaindatetimefor // #sec-temporal-builtintimezonegetplaindatetimefor
V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalPlainDateTime> V8_WARN_UNUSED_RESULT MaybeHandle<JSTemporalPlainDateTime>
......
...@@ -1345,7 +1345,6 @@ ...@@ -1345,7 +1345,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-not-callable': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toInstant/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/balance-negative-time-units': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toJSON/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/branding': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toJSON/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/negative-epochnanoseconds': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toJSON/negative-epochnanoseconds': [FAIL],
...@@ -1357,26 +1356,9 @@ ...@@ -1357,26 +1356,9 @@
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/year-format': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toJSON/year-format': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/branding': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/return-string': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/return-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/balance-negative-time-units': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/plain-custom-timezone': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/plain-custom-timezone': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDate/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/balance-negative-time-units': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/balance-negative-time-units': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toString/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/branding': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toString/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string': [FAIL], 'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string': [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