diff --git a/src/builtins/builtins-temporal.cc b/src/builtins/builtins-temporal.cc index 02a8c329e8..d84bde908b 100644 --- a/src/builtins/builtins-temporal.cc +++ b/src/builtins/builtins-temporal.cc @@ -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) diff --git a/src/objects/js-temporal-objects.cc b/src/objects/js-temporal-objects.cc index d79cdc42f5..1c113ccf53 100644 --- a/src/objects/js-temporal-objects.cc +++ b/src/objects/js-temporal-objects.cc @@ -11791,6 +11791,13 @@ MaybeHandle ToTemporalZonedDateTime( calendar); } +MaybeHandle ToTemporalZonedDateTime( + Isolate* isolate, Handle 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::From( return ToTemporalZonedDateTime(isolate, item, options, method_name); } +// #sec-temporal.zoneddatetime.compare +MaybeHandle JSTemporalZonedDateTime::Compare(Isolate* isolate, + Handle one_obj, + Handle two_obj) { + TEMPORAL_ENTER_FUNC(); + const char* method_name = "Temporal.ZonedDateTime.compare"; + // 1. Set one to ? ToTemporalZonedDateTime(one). + Handle one; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, one, ToTemporalZonedDateTime(isolate, one_obj, method_name), + Smi); + // 2. Set two to ? ToTemporalZonedDateTime(two). + Handle 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 TimeZoneEquals(Isolate* isolate, Handle one, + Handle 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 time_zone_one; + ASSIGN_RETURN_ON_EXCEPTION_VALUE( + isolate, time_zone_one, Object::ToString(isolate, one), Nothing()); + // 3. Let timeZoneTwo be ? ToString(two). + Handle time_zone_two; + ASSIGN_RETURN_ON_EXCEPTION_VALUE( + isolate, time_zone_two, Object::ToString(isolate, two), Nothing()); + // 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 JSTemporalZonedDateTime::Equals( + Isolate* isolate, Handle zoned_date_time, + Handle 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 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()); + 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 diff --git a/src/objects/js-temporal-objects.h b/src/objects/js-temporal-objects.h index cc2a05749d..055bf4faf4 100644 --- a/src/objects/js-temporal-objects.h +++ b/src/objects/js-temporal-objects.h @@ -790,6 +790,16 @@ class JSTemporalZonedDateTime V8_WARN_UNUSED_RESULT static MaybeHandle From( Isolate* isolate, Handle item, Handle options); + // #sec-temporal.zoneddatetime.compare + V8_WARN_UNUSED_RESULT static MaybeHandle Compare(Isolate* isolate, + Handle one, + Handle two); + + // #sec-temporal.zoneddatetime.prototype.equals + V8_WARN_UNUSED_RESULT static MaybeHandle Equals( + Isolate* isolate, Handle zoned_date_time, + Handle other); + // #sec-temporal.zoneddatetime.prototype.with V8_WARN_UNUSED_RESULT static MaybeHandle With( Isolate* isolate, Handle zoned_date_time, diff --git a/test/test262/test262.status b/test/test262/test262.status index 14b795f9d6..294ff41667 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -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],