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

[Temporal] Add TimeZone.prototype.getInstantFor

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

Bug: v8:11544
Change-Id: Ibb38f807386c4e213bfd2bb568911a96a17cf1be
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3623196Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80350}
parent dd3289d7
......@@ -282,8 +282,6 @@ TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetOffsetNanosecondsFor)
TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetOffsetStringFor)
/* Temporal #sec-temporal.timezone.prototype.getplaindatetimefor */
TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetPlainDateTimeFor)
/* Temporal #sec-temporal.timezone.prototype.getinstantfor */
TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetInstantFor)
/* Temporal #sec-temporal.timezone.prototype.getpossibleinstantsfor */
TO_BE_IMPLEMENTED(TemporalTimeZonePrototypeGetPossibleInstantsFor)
/* Temporal #sec-temporal.timezone.prototype.getnexttransition */
......@@ -813,6 +811,7 @@ BUILTIN(TemporalCalendarFrom) {
TEMPORAL_CONSTRUCTOR1(TimeZone)
TEMPORAL_ID_BY_TO_STRING(TimeZone)
TEMPORAL_TO_STRING(TimeZone)
TEMPORAL_PROTOTYPE_METHOD2(TimeZone, GetInstantFor, getInstantFor)
// #sec-temporal.timezone.from
BUILTIN(TemporalTimeZoneFrom) {
HandleScope scope(isolate);
......
......@@ -1699,6 +1699,18 @@ Maybe<ShowOverflow> ToTemporalOverflow(Isolate* isolate,
ShowOverflow::kConstrain);
}
// #sec-temporal-totemporaldisambiguation
Maybe<Disambiguation> ToTemporalDisambiguation(Isolate* isolate,
Handle<JSReceiver> options,
const char* method_name) {
return GetStringOption<Disambiguation>(
isolate, options, "disambiguation", method_name,
{"compatible", "earlier", "later", "reject"},
{Disambiguation::kCompatible, Disambiguation::kEarlier,
Disambiguation::kLater, Disambiguation::kReject},
Disambiguation::kCompatible);
}
// #sec-temporal-builtintimezonegetinstantfor
MaybeHandle<JSTemporalInstant> BuiltinTimeZoneGetInstantFor(
Isolate* isolate, Handle<JSReceiver> time_zone,
......@@ -6336,6 +6348,49 @@ MaybeHandle<JSTemporalTimeZone> JSTemporalTimeZone::Constructor(
return CreateTemporalTimeZone(isolate, target, new_target, canonical);
}
namespace {
MaybeHandle<JSTemporalPlainDateTime> ToTemporalDateTime(
Isolate* isolate, Handle<Object> item_obj, Handle<JSReceiver> options,
const char* method_name);
} // namespace
// #sec-temporal.timezone.prototype.getinstantfor
MaybeHandle<JSTemporalInstant> JSTemporalTimeZone::GetInstantFor(
Isolate* isolate, Handle<JSTemporalTimeZone> time_zone,
Handle<Object> date_time_obj, Handle<Object> options_obj) {
const char* method_name = "Temporal.TimeZone.prototype.getInstantFor";
// 1. Let timeZone be the this value.
// 2. Perform ? RequireInternalSlot(timeZone,
// [[InitializedTemporalTimeZone]]).
// 3. Set dateTime to ? ToTemporalDateTime(dateTime).
Handle<JSTemporalPlainDateTime> date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, date_time,
ToTemporalDateTime(isolate, date_time_obj,
isolate->factory()->NewJSObjectWithNullProto(),
method_name),
JSTemporalInstant);
// 4. Set options to ? GetOptionsObject(options).
Handle<JSReceiver> options;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, options, GetOptionsObject(isolate, options_obj, method_name),
JSTemporalInstant);
// 5. Let disambiguation be ? ToTemporalDisambiguation(options).
Maybe<Disambiguation> maybe_disambiguation =
ToTemporalDisambiguation(isolate, options, method_name);
MAYBE_RETURN(maybe_disambiguation, Handle<JSTemporalInstant>());
Disambiguation disambiguation = maybe_disambiguation.FromJust();
// 6. Return ? BuiltinTimeZoneGetInstantFor(timeZone, dateTime,
// disambiguation).
return BuiltinTimeZoneGetInstantFor(isolate, time_zone, date_time,
disambiguation, method_name);
}
// #sec-temporal.timezone.prototype.tostring
MaybeHandle<Object> JSTemporalTimeZone::ToString(
Isolate* isolate, Handle<JSTemporalTimeZone> time_zone,
......
......@@ -383,6 +383,11 @@ class JSTemporalTimeZone
Isolate* isolate, Handle<JSFunction> target,
Handle<HeapObject> new_target, Handle<Object> identifier);
// #sec-temporal.timezone.prototype.getinstantfor
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> GetInstantFor(
Isolate* isolate, Handle<JSTemporalTimeZone> time_zone,
Handle<Object> dateTime, Handle<Object> options);
// #sec-temporal.timezone.prototype.tostring
static MaybeHandle<Object> ToString(Isolate* isolate,
Handle<JSTemporalTimeZone> time_zone,
......
......@@ -1641,23 +1641,14 @@
'built-ins/Temporal/TimeZone/from/argument-primitive': [FAIL],
'built-ins/Temporal/TimeZone/from/timezone-string-datetime': [FAIL],
'built-ins/Temporal/TimeZone/from/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-not-datetime': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-plaindate': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-balance-negative-time-units': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/balance-negative-time-units': [SKIP],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/branding': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-temporal-object': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/disambiguation-invalid-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/disambiguation-undefined': [SKIP],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/disambiguation-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/options-undefined': [SKIP],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/read-time-fields-before-datefromfields': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-zoneddatetime': [FAIL],
......@@ -2187,7 +2178,6 @@
'intl402/Temporal/PlainYearMonth/prototype/toLocaleString/resolved-time-zone': [FAIL],
'intl402/Temporal/PlainYearMonth/prototype/toLocaleString/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'intl402/Temporal/PlainYearMonth/prototype/until/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/TimeZone/prototype/getInstantFor/infinity-throws-rangeerror': [FAIL],
'intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/instant-string': [FAIL],
'intl402/Temporal/TimeZone/prototype/getOffsetStringFor/instant-string': [FAIL],
'intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/instant-string': [FAIL],
......@@ -2769,7 +2759,6 @@
'built-ins/Temporal/PlainYearMonth/prototype/subtract/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/toString/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/until/options-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/options-wrong-type': [FAIL],
......@@ -3014,7 +3003,6 @@
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-object-tostring': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number': [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