[Temporal] Add PlainTime.(compare|prototype.equals)
Also add AO: CompareTemporalTime Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.compare https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.equals https://tc39.es/proposal-temporal/#sec-temporal-comparetemporaltime Bug: v8:11544 Change-Id: I8e2a320c2e296558e1fb15ef6e855e6b6a14ece2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3538669 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#80732}
This commit is contained in:
parent
702f874a3b
commit
3ba8390cb9
@ -52,8 +52,6 @@ TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeSince)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeEquals)
|
||||
|
||||
/* Temporal.PlaneTime */
|
||||
/* Temporal #sec-temporal.plaintime.compare */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimeCompare)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.add */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeAdd)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.subtract */
|
||||
@ -66,8 +64,6 @@ TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeUntil)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeSince)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.round */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeRound)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.equals */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeEquals)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.toplaindatetime */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeToPlainDateTime)
|
||||
/* Temporal #sec-temporal.plaintime.prototype.tolocalestring */
|
||||
@ -435,6 +431,8 @@ TEMPORAL_GET_SMI(PlainTime, Microsecond, iso_microsecond)
|
||||
TEMPORAL_GET_SMI(PlainTime, Nanosecond, iso_nanosecond)
|
||||
TEMPORAL_METHOD2(PlainTime, From)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToZonedDateTime, toZonedDateTime)
|
||||
TEMPORAL_METHOD2(PlainTime, Compare)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, Equals, equals)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainTime, GetISOFields, getISOFields)
|
||||
TEMPORAL_VALUE_OF(PlainTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainTime, ToJSON, toJSON)
|
||||
|
@ -9462,6 +9462,116 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalPlainTime::ToZonedDateTime(
|
||||
calendar);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// #sec-temporal-comparetemporaltime
|
||||
int32_t CompareTemporalTime(const TimeRecordCommon& time1,
|
||||
const TimeRecordCommon& time2) {
|
||||
TEMPORAL_ENTER_FUNC();
|
||||
|
||||
// 1. Assert: h1, min1, s1, ms1, mus1, ns1, h2, min2, s2, ms2, mus2, and ns2
|
||||
// are integers.
|
||||
// 2. If h1 > h2, return 1.
|
||||
if (time1.hour > time2.hour) return 1;
|
||||
// 3. If h1 < h2, return -1.
|
||||
if (time1.hour < time2.hour) return -1;
|
||||
// 4. If min1 > min2, return 1.
|
||||
if (time1.minute > time2.minute) return 1;
|
||||
// 5. If min1 < min2, return -1.
|
||||
if (time1.minute < time2.minute) return -1;
|
||||
// 6. If s1 > s2, return 1.
|
||||
if (time1.second > time2.second) return 1;
|
||||
// 7. If s1 < s2, return -1.
|
||||
if (time1.second < time2.second) return -1;
|
||||
// 8. If ms1 > ms2, return 1.
|
||||
if (time1.millisecond > time2.millisecond) return 1;
|
||||
// 9. If ms1 < ms2, return -1.
|
||||
if (time1.millisecond < time2.millisecond) return -1;
|
||||
// 10. If mus1 > mus2, return 1.
|
||||
if (time1.microsecond > time2.microsecond) return 1;
|
||||
// 11. If mus1 < mus2, return -1.
|
||||
if (time1.microsecond < time2.microsecond) return -1;
|
||||
// 12. If ns1 > ns2, return 1.
|
||||
if (time1.nanosecond > time2.nanosecond) return 1;
|
||||
// 13. If ns1 < ns2, return -1.
|
||||
if (time1.nanosecond < time2.nanosecond) return -1;
|
||||
// 14. Return 0.
|
||||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.plaintime.compare
|
||||
MaybeHandle<Smi> JSTemporalPlainTime::Compare(Isolate* isolate,
|
||||
Handle<Object> one_obj,
|
||||
Handle<Object> two_obj) {
|
||||
const char* method_name = "Temporal.PainTime.compare";
|
||||
// 1. Set one to ? ToTemporalTime(one).
|
||||
Handle<JSTemporalPlainTime> one;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, one,
|
||||
temporal::ToTemporalTime(isolate, one_obj, ShowOverflow::kConstrain,
|
||||
method_name),
|
||||
Smi);
|
||||
// 2. Set two to ? ToTemporalTime(two).
|
||||
Handle<JSTemporalPlainTime> two;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, two,
|
||||
temporal::ToTemporalTime(isolate, two_obj, ShowOverflow::kConstrain,
|
||||
method_name),
|
||||
Smi);
|
||||
// 3. Return 𝔽(! CompareTemporalTime(one.[[ISOHour]], one.[[ISOMinute]],
|
||||
// one.[[ISOSecond]], one.[[ISOMillisecond]], one.[[ISOMicrosecond]],
|
||||
// one.[[ISONanosecond]], two.[[ISOHour]], two.[[ISOMinute]],
|
||||
// two.[[ISOSecond]], two.[[ISOMillisecond]], two.[[ISOMicrosecond]],
|
||||
// two.[[ISONanosecond]])).
|
||||
return handle(Smi::FromInt(CompareTemporalTime(
|
||||
{one->iso_hour(), one->iso_minute(), one->iso_second(),
|
||||
one->iso_millisecond(), one->iso_microsecond(),
|
||||
one->iso_nanosecond()},
|
||||
{two->iso_hour(), two->iso_minute(), two->iso_second(),
|
||||
two->iso_millisecond(), two->iso_microsecond(),
|
||||
two->iso_nanosecond()})),
|
||||
isolate);
|
||||
}
|
||||
|
||||
// #sec-temporal.plaintime.prototype.equals
|
||||
MaybeHandle<Oddball> JSTemporalPlainTime::Equals(
|
||||
Isolate* isolate, Handle<JSTemporalPlainTime> temporal_time,
|
||||
Handle<Object> other_obj) {
|
||||
// 1. Let temporalTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(temporalTime,
|
||||
// [[InitializedTemporalTime]]).
|
||||
// 3. Set other to ? ToTemporalTime(other).
|
||||
Handle<JSTemporalPlainTime> other;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, other,
|
||||
temporal::ToTemporalTime(isolate, other_obj, ShowOverflow::kConstrain,
|
||||
"Temporal.PlainTime.prototype.equals"),
|
||||
Oddball);
|
||||
// 4. If temporalTime.[[ISOHour]] ≠ other.[[ISOHour]], return false.
|
||||
if (temporal_time->iso_hour() != other->iso_hour())
|
||||
return isolate->factory()->false_value();
|
||||
// 5. If temporalTime.[[ISOMinute]] ≠ other.[[ISOMinute]], return false.
|
||||
if (temporal_time->iso_minute() != other->iso_minute())
|
||||
return isolate->factory()->false_value();
|
||||
// 6. If temporalTime.[[ISOSecond]] ≠ other.[[ISOSecond]], return false.
|
||||
if (temporal_time->iso_second() != other->iso_second())
|
||||
return isolate->factory()->false_value();
|
||||
// 7. If temporalTime.[[ISOMillisecond]] ≠ other.[[ISOMillisecond]], return
|
||||
// false.
|
||||
if (temporal_time->iso_millisecond() != other->iso_millisecond())
|
||||
return isolate->factory()->false_value();
|
||||
// 8. If temporalTime.[[ISOMicrosecond]] ≠ other.[[ISOMicrosecond]], return
|
||||
// false.
|
||||
if (temporal_time->iso_microsecond() != other->iso_microsecond())
|
||||
return isolate->factory()->false_value();
|
||||
// 9. If temporalTime.[[ISONanosecond]] ≠ other.[[ISONanosecond]], return
|
||||
// false.
|
||||
if (temporal_time->iso_nanosecond() != other->iso_nanosecond())
|
||||
return isolate->factory()->false_value();
|
||||
// 10. Return true.
|
||||
return isolate->factory()->true_value();
|
||||
}
|
||||
|
||||
// #sec-temporal.now.plaintimeiso
|
||||
MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::NowISO(
|
||||
Isolate* isolate, Handle<Object> temporal_time_zone_like) {
|
||||
|
@ -455,6 +455,16 @@ class JSTemporalPlainTime
|
||||
Handle<Object> second, Handle<Object> millisecond,
|
||||
Handle<Object> microsecond, Handle<Object> nanosecond);
|
||||
|
||||
// #sec-temporal.plaintime.compare
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Compare(Isolate* isolate,
|
||||
Handle<Object> one,
|
||||
Handle<Object> two);
|
||||
|
||||
// #sec-temporal.plaintime.prototype.equals
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Oddball> Equals(
|
||||
Isolate* isolate, Handle<JSTemporalPlainTime> plain_date,
|
||||
Handle<Object> other);
|
||||
|
||||
// #sec-temporal.plaintime.from
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainTime> From(
|
||||
Isolate* isolate, Handle<Object> item, Handle<Object> options);
|
||||
|
@ -1055,15 +1055,6 @@
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/with/overflow-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/with/overflow-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/with/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-string-with-utc-designator': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-negative-epochnanoseconds': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/plaintime-propertybag-no-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/use-internal-slots': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/from/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/argument-not-object': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/argument-string': [FAIL],
|
||||
@ -1075,17 +1066,7 @@
|
||||
'built-ins/Temporal/PlainTime/prototype/add/non-integer-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/order-of-operations': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-utc-designator': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-negative-epochnanoseconds': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/plaintime-propertybag-no-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/roundingincrement-nan': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/roundingincrement-non-integer': [FAIL],
|
||||
@ -1808,12 +1789,9 @@
|
||||
'built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-with-time-designator': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/year-zero': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/with/copy-properties-not-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-cast': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-string-with-time-designator': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/year-zero': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/from/argument-string': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation': [FAIL],
|
||||
@ -1824,12 +1802,9 @@
|
||||
'built-ins/Temporal/PlainTime/prototype/add/argument-object-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/argument-string-fractional-units-rounding-mode': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/add/options-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-cast': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/year-zero': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/rounding-cross-midnight': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/roundingincrement-hours': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/round/roundingincrement-invalid': [FAIL],
|
||||
@ -2296,9 +2271,6 @@
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-number': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/compare/argument-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/equals/argument-number': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/since/argument-number': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/since/argument-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainTime/prototype/since/plaintime-propertybag-no-time-units': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user