[Temporal] Add compare and equals to ZonedDateTime
Also add AOs: TimeZoneEquals Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.compare https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.equals https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals Bug: v8:11544 Change-Id: Ibcd1e42d72f86f16e0f5ddb1fd589bbe7ab2225c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3709217 Commit-Queue: Frank Tang <ftang@chromium.org> Reviewed-by: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/main@{#81227}
This commit is contained in:
parent
dcf34383f6
commit
08c18bfc2e
@ -60,16 +60,12 @@ TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeSince)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeRound)
|
||||
|
||||
/* Temporal.ZonedDateTime */
|
||||
/* Temporal #sec-temporal.zoneddatetime.compare */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimeCompare)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.until */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeUntil)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.since */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeSince)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.round */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeRound)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.equals */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeEquals)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.tostring */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToString)
|
||||
/* Temporal #sec-temporal.zonedddatetimeprototype.tojson */
|
||||
@ -536,6 +532,7 @@ BUILTIN(TemporalZonedDateTimeConstructor) {
|
||||
args.atOrUndefined(isolate, 3))); // calendar_like
|
||||
}
|
||||
TEMPORAL_METHOD2(ZonedDateTime, From)
|
||||
TEMPORAL_METHOD2(ZonedDateTime, Compare)
|
||||
TEMPORAL_GET(ZonedDateTime, Calendar, calendar)
|
||||
TEMPORAL_GET(ZonedDateTime, TimeZone, time_zone)
|
||||
TEMPORAL_ZONED_DATE_TIME_GET_BY_FORWARD_TIME_ZONE_AND_CALENDAR(Year)
|
||||
@ -566,6 +563,7 @@ TEMPORAL_ZONED_DATE_TIME_GET_BY_FORWARD_TIME_ZONE_AND_CALENDAR(DaysInMonth)
|
||||
TEMPORAL_ZONED_DATE_TIME_GET_BY_FORWARD_TIME_ZONE_AND_CALENDAR(DaysInYear)
|
||||
TEMPORAL_ZONED_DATE_TIME_GET_BY_FORWARD_TIME_ZONE_AND_CALENDAR(MonthsInYear)
|
||||
TEMPORAL_ZONED_DATE_TIME_GET_BY_FORWARD_TIME_ZONE_AND_CALENDAR(InLeapYear)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, Equals, equals)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, HoursInDay, hoursInDay)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(ZonedDateTime, With, with)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithCalendar, withCalendar)
|
||||
|
@ -11791,6 +11791,13 @@ MaybeHandle<JSTemporalZonedDateTime> ToTemporalZonedDateTime(
|
||||
calendar);
|
||||
}
|
||||
|
||||
MaybeHandle<JSTemporalZonedDateTime> ToTemporalZonedDateTime(
|
||||
Isolate* isolate, Handle<Object> item_obj, const char* method_name) {
|
||||
// 1. If options is not present, set options to undefined.
|
||||
return ToTemporalZonedDateTime(
|
||||
isolate, item_obj, isolate->factory()->undefined_value(), method_name);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.zoneddatetime.from
|
||||
@ -11844,6 +11851,92 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::From(
|
||||
return ToTemporalZonedDateTime(isolate, item, options, method_name);
|
||||
}
|
||||
|
||||
// #sec-temporal.zoneddatetime.compare
|
||||
MaybeHandle<Smi> JSTemporalZonedDateTime::Compare(Isolate* isolate,
|
||||
Handle<Object> one_obj,
|
||||
Handle<Object> two_obj) {
|
||||
TEMPORAL_ENTER_FUNC();
|
||||
const char* method_name = "Temporal.ZonedDateTime.compare";
|
||||
// 1. Set one to ? ToTemporalZonedDateTime(one).
|
||||
Handle<JSTemporalZonedDateTime> one;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, one, ToTemporalZonedDateTime(isolate, one_obj, method_name),
|
||||
Smi);
|
||||
// 2. Set two to ? ToTemporalZonedDateTime(two).
|
||||
Handle<JSTemporalZonedDateTime> two;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, two, ToTemporalZonedDateTime(isolate, two_obj, method_name),
|
||||
Smi);
|
||||
// 3. Return 𝔽(! CompareEpochNanoseconds(one.[[Nanoseconds]],
|
||||
// two.[[Nanoseconds]])).
|
||||
return CompareEpochNanoseconds(isolate, handle(one->nanoseconds(), isolate),
|
||||
handle(two->nanoseconds(), isolate));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// #sec-temporal-timezoneequals
|
||||
Maybe<bool> TimeZoneEquals(Isolate* isolate, Handle<JSReceiver> one,
|
||||
Handle<JSReceiver> two) {
|
||||
// 1. If one and two are the same Object value, return true.
|
||||
if (one.is_identical_to(two)) {
|
||||
return Just(true);
|
||||
}
|
||||
|
||||
// 2. Let timeZoneOne be ? ToString(one).
|
||||
Handle<String> time_zone_one;
|
||||
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, time_zone_one, Object::ToString(isolate, one), Nothing<bool>());
|
||||
// 3. Let timeZoneTwo be ? ToString(two).
|
||||
Handle<String> time_zone_two;
|
||||
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, time_zone_two, Object::ToString(isolate, two), Nothing<bool>());
|
||||
// 4. If timeZoneOne is timeZoneTwo, return true.
|
||||
if (String::Equals(isolate, time_zone_one, time_zone_two)) {
|
||||
return Just(true);
|
||||
}
|
||||
// 5. Return false.
|
||||
return Just(false);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.equals
|
||||
MaybeHandle<Oddball> JSTemporalZonedDateTime::Equals(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> other_obj) {
|
||||
TEMPORAL_ENTER_FUNC();
|
||||
const char* method_name = "Temporal.ZonedDateTime.prototype.equals";
|
||||
Factory* factory = isolate->factory();
|
||||
// 1. Let zonedDateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(zonedDateTime,
|
||||
// [[InitializedTemporalZonedDateTime]]).
|
||||
// 3. Set other to ? ToTemporalZonedDateTime(other).
|
||||
Handle<JSTemporalZonedDateTime> other;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, other, ToTemporalZonedDateTime(isolate, other_obj, method_name),
|
||||
Oddball);
|
||||
// 4. If zonedDateTime.[[Nanoseconds]] ≠ other.[[Nanoseconds]], return false.
|
||||
if (!BigInt::EqualToBigInt(zoned_date_time->nanoseconds(),
|
||||
other->nanoseconds())) {
|
||||
return factory->false_value();
|
||||
}
|
||||
// 5. If ? TimeZoneEquals(zonedDateTime.[[TimeZone]], other.[[TimeZone]]) is
|
||||
// false, return false.
|
||||
bool equals;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, equals,
|
||||
TimeZoneEquals(isolate, handle(zoned_date_time->time_zone(), isolate),
|
||||
handle(other->time_zone(), isolate)),
|
||||
Handle<Oddball>());
|
||||
if (!equals) {
|
||||
return factory->false_value();
|
||||
}
|
||||
// 6. Return ? CalendarEquals(zonedDateTime.[[Calendar]], other.[[Calendar]]).
|
||||
return CalendarEquals(isolate, handle(zoned_date_time->calendar(), isolate),
|
||||
handle(other->calendar(), isolate));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// #sec-temporal-interpretisodatetimeoffset
|
||||
|
@ -790,6 +790,16 @@ class JSTemporalZonedDateTime
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> From(
|
||||
Isolate* isolate, Handle<Object> item, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.zoneddatetime.compare
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Compare(Isolate* isolate,
|
||||
Handle<Object> one,
|
||||
Handle<Object> two);
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.equals
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Oddball> Equals(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> other);
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.with
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> With(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
|
@ -1027,16 +1027,6 @@
|
||||
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/instant-string': [FAIL],
|
||||
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/pre-epoch': [FAIL],
|
||||
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/calendar-fields-iterable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/read-time-fields-before-datefromfields': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/timezone-getpossibleinstantsfor-iterable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/timezone-string-datetime': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string-multiple-offsets': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/from/balance-negative-time-units': [FAIL],
|
||||
@ -1050,17 +1040,7 @@
|
||||
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-string-multiple-offsets': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-sub-minute-offset': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/day/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/branding': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/calendar-fields-iterable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/read-time-fields-before-datefromfields': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/sub-minute-offset': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-getpossibleinstantsfor-iterable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-datetime': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-multiple-offsets': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/zoneddatetime-string': [FAIL],
|
||||
@ -1272,8 +1252,6 @@
|
||||
'intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/instant-string': [FAIL],
|
||||
'intl402/Temporal/TimeZone/prototype/getOffsetStringFor/instant-string': [FAIL],
|
||||
'intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/instant-string': [FAIL],
|
||||
'intl402/Temporal/ZonedDateTime/compare/infinity-throws-rangeerror': [FAIL],
|
||||
'intl402/Temporal/ZonedDateTime/prototype/equals/infinity-throws-rangeerror': [FAIL],
|
||||
'intl402/Temporal/ZonedDateTime/prototype/since/infinity-throws-rangeerror': [FAIL],
|
||||
'intl402/Temporal/ZonedDateTime/prototype/toLocaleString/locales-undefined': [FAIL],
|
||||
'intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-conflict': [FAIL],
|
||||
@ -1468,10 +1446,6 @@
|
||||
'built-ins/Temporal/PlainYearMonth/prototype/until/year-zero': [FAIL],
|
||||
'built-ins/Temporal/PlainYearMonth/prototype/with/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainYearMonth/prototype/with/copy-properties-not-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/largestunit-smallestunit-mismatch': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/year-zero': [FAIL],
|
||||
@ -1729,14 +1703,8 @@
|
||||
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/timezone-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-wrong-type': [FAIL],
|
||||
@ -1859,22 +1827,14 @@
|
||||
'built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-time-separators': [FAIL],
|
||||
'built-ins/Temporal/PlainYearMonth/prototype/until/leap-second': [FAIL],
|
||||
'built-ins/Temporal/TimeZone/prototype/constructor': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/argument-string-time-separators': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/timezone-string-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/compare/timezone-string-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/from/argument-string-time-separators': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/from/leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/add/argument-string-negative-fractional-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/constructor': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-time-separators': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-time-separators': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user