Skip to content

Commit

Permalink
[Temporal] Sync PR 2225 Consistently check overflow options
Browse files Browse the repository at this point in the history
tc39/proposal-temporal#2225

Call ToTemporalOverflow in ToTemporalDate and ToTemporalDateTime

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal-totemporaldate
https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime

Bug: v8:11544
Change-Id: I3d2846e2efc214ea5385be58cb49e319369b5900
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3855705
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82797}
  • Loading branch information
FrankYFTang authored and V8 LUCI CQ committed Aug 30, 2022
1 parent 41419aa commit f54b1eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 26 additions & 8 deletions src/objects/js-temporal-objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2456,14 +2456,19 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate,
// b. If item has an [[InitializedTemporalZonedDateTime]] internal slot,
// then
if (item->IsJSTemporalZonedDateTime()) {
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
// i. Perform ? ToTemporalOverflow(options).
MAYBE_RETURN_ON_EXCEPTION_VALUE(
isolate, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainDate>());

// ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<JSTemporalZonedDateTime> zoned_date_time =
Handle<JSTemporalZonedDateTime>::cast(item);
Handle<JSTemporalInstant> instant =
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate))
.ToHandleChecked();
// ii. Let plainDateTime be ?
// iii. Let plainDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]],
// instant, item.[[Calendar]]).
Handle<JSTemporalPlainDateTime> plain_date_time;
Expand All @@ -2475,7 +2480,7 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate,
instant, Handle<JSReceiver>(zoned_date_time->calendar(), isolate),
method_name),
JSTemporalPlainDate);
// iii. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]],
// iv. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]],
// plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]],
// plainDateTime.[[Calendar]]).
return CreateTemporalDate(
Expand All @@ -2489,7 +2494,11 @@ MaybeHandle<JSTemporalPlainDate> ToTemporalDate(Isolate* isolate,
// c. If item has an [[InitializedTemporalDateTime]] internal slot, then
// item.[[ISODay]], item.[[Calendar]]).
if (item->IsJSTemporalPlainDateTime()) {
// i. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]],
// i. Perform ? ToTemporalOverflow(options).
MAYBE_RETURN_ON_EXCEPTION_VALUE(
isolate, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainDate>());
// ii. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]],
Handle<JSTemporalPlainDateTime> date_time =
Handle<JSTemporalPlainDateTime>::cast(item);
return CreateTemporalDate(isolate,
Expand Down Expand Up @@ -12313,14 +12322,18 @@ MaybeHandle<JSTemporalPlainDateTime> ToTemporalDateTime(
// b. If item has an [[InitializedTemporalZonedDateTime]] internal slot,
// then
if (item->IsJSTemporalZonedDateTime()) {
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
// i. Perform ? ToTemporalOverflow(options).
MAYBE_RETURN_ON_EXCEPTION_VALUE(
isolate, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainDateTime>());
// ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
Handle<JSTemporalZonedDateTime> zoned_date_time =
Handle<JSTemporalZonedDateTime>::cast(item);
Handle<JSTemporalInstant> instant =
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate))
.ToHandleChecked();
// ii. Return ?
// iii. Return ?
// temporal::BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]],
// instant, item.[[Calendar]]).
return temporal::BuiltinTimeZoneGetPlainDateTimeFor(
Expand All @@ -12329,8 +12342,13 @@ MaybeHandle<JSTemporalPlainDateTime> ToTemporalDateTime(
}
// c. If item has an [[InitializedTemporalDate]] internal slot, then
if (item->IsJSTemporalPlainDate()) {
// i. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]],
// item.[[ISODay]], 0, 0, 0, 0, 0, 0, item.[[Calendar]]).
// i. Perform ? ToTemporalOverflow(options).
MAYBE_RETURN_ON_EXCEPTION_VALUE(
isolate, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainDateTime>());
// ii. Return ? CreateTemporalDateTime(item.[[ISOYear]],
// item.[[ISOMonth]], item.[[ISODay]], 0, 0, 0, 0, 0, 0,
// item.[[Calendar]]).
Handle<JSTemporalPlainDate> date =
Handle<JSTemporalPlainDate>::cast(item);
return temporal::CreateTemporalDateTime(
Expand Down
2 changes: 0 additions & 2 deletions test/test262/test262.status
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@
'built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDate/compare/argument-calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDate/from/overflow-invalid-string': [FAIL],
'built-ins/Temporal/PlainDate/prototype/equals/argument-calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/calendar-dateuntil-called-with-null-prototype-options': [FAIL],
Expand All @@ -622,7 +621,6 @@
'built-ins/Temporal/PlainDate/prototype/with/calendar-mergefields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDateTime/from/calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDateTime/from/overflow-invalid-string': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/equals/calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/since/calendar-datefromfields-called-with-null-prototype-fields': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/since/calendar-dateuntil-called-with-null-prototype-options': [FAIL],
Expand Down

0 comments on commit f54b1eb

Please sign in to comment.