Commit 7627b400 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add PlainTime.prototype.(add|subtract)

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.add
https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.subtract

Bug: v8:11544
Change-Id: I0d684eec9eebfd26eceb6bb4c360025a33bd4c3c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3617390Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80957}
parent 9b4b64c2
...@@ -44,10 +44,6 @@ TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeUntil) ...@@ -44,10 +44,6 @@ TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeUntil)
TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeSince) TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeSince)
/* Temporal.PlaneTime */ /* Temporal.PlaneTime */
/* Temporal #sec-temporal.plaintime.prototype.add */
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeAdd)
/* Temporal #sec-temporal.plaintime.prototype.subtract */
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeSubtract)
/* Temporal #sec-temporal.plaintime.prototype.until */ /* Temporal #sec-temporal.plaintime.prototype.until */
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeUntil) TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeUntil)
/* Temporal #sec-temporal.plaintime.prototype.since */ /* Temporal #sec-temporal.plaintime.prototype.since */
...@@ -389,13 +385,15 @@ TEMPORAL_METHOD2(PlainTime, From) ...@@ -389,13 +385,15 @@ TEMPORAL_METHOD2(PlainTime, From)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToZonedDateTime, toZonedDateTime) TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToZonedDateTime, toZonedDateTime)
TEMPORAL_METHOD2(PlainTime, Compare) TEMPORAL_METHOD2(PlainTime, Compare)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, Equals, equals) TEMPORAL_PROTOTYPE_METHOD1(PlainTime, Equals, equals)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, Add, add)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, Subtract, subtract)
TEMPORAL_PROTOTYPE_METHOD0(PlainTime, GetISOFields, getISOFields) TEMPORAL_PROTOTYPE_METHOD0(PlainTime, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToPlainDateTime, toPlainDateTime) TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToPlainDateTime, toPlainDateTime)
TEMPORAL_PROTOTYPE_METHOD2(PlainTime, With, with)
TEMPORAL_VALUE_OF(PlainTime)
TEMPORAL_PROTOTYPE_METHOD0(PlainTime, ToJSON, toJSON) TEMPORAL_PROTOTYPE_METHOD0(PlainTime, ToJSON, toJSON)
TEMPORAL_PROTOTYPE_METHOD2(PlainTime, ToLocaleString, toLocaleString) TEMPORAL_PROTOTYPE_METHOD2(PlainTime, ToLocaleString, toLocaleString)
TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToString, toString) TEMPORAL_PROTOTYPE_METHOD1(PlainTime, ToString, toString)
TEMPORAL_PROTOTYPE_METHOD2(PlainTime, With, with)
TEMPORAL_VALUE_OF(PlainTime)
// PlainDateTime // PlainDateTime
BUILTIN(TemporalPlainDateTimeConstructor) { BUILTIN(TemporalPlainDateTimeConstructor) {
......
...@@ -10612,6 +10612,71 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainTime::ToPlainDateTime( ...@@ -10612,6 +10612,71 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainTime::ToPlainDateTime(
handle(temporal_date->calendar(), isolate)); handle(temporal_date->calendar(), isolate));
} }
namespace {
enum class Arithmetic { kAdd, kSubtract };
// #sec-temporal-adddurationtoorsubtractdurationfromplaintime
MaybeHandle<JSTemporalPlainTime> AddDurationToOrSubtractDurationFromPlainTime(
Isolate* isolate, Arithmetic operation,
Handle<JSTemporalPlainTime> temporal_time,
Handle<Object> temporal_duration_like, const char* method_name) {
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
double sign = operation == Arithmetic::kSubtract ? -1.0 : 1.0;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
DurationRecord duration;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, duration,
temporal::ToTemporalDurationRecord(isolate, temporal_duration_like,
method_name),
Handle<JSTemporalPlainTime>());
TimeDurationRecord& time_duration = duration.time_duration;
// 3. Let result be ! AddTime(temporalTime.[[ISOHour]],
// temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]],
// temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]],
// temporalTime.[[ISONanosecond]], sign x duration.[[Hours]], sign x
// duration.[[Minutes]], sign x duration.[[Seconds]], sign x
// duration.[[Milliseconds]], sign x duration.[[Microseconds]], sign x
// duration.[[Nanoseconds]]).
DateTimeRecordCommon result = AddTime(
isolate,
{temporal_time->iso_hour(), temporal_time->iso_minute(),
temporal_time->iso_second(), temporal_time->iso_millisecond(),
temporal_time->iso_microsecond(), temporal_time->iso_nanosecond()},
{0, sign * time_duration.hours, sign * time_duration.minutes,
sign * time_duration.seconds, sign * time_duration.milliseconds,
sign * time_duration.microseconds, sign * time_duration.nanoseconds});
// 4. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]],
// result.[[Second]], result.[[Millisecond]], result.[[Microsecond]],
// result.[[Nanosecond]]) is true.
DCHECK(IsValidTime(isolate, result.time));
// 5. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]],
// result.[[Second]], result.[[Millisecond]], result.[[Microsecond]],
// result.[[Nanosecond]]).
return CreateTemporalTime(isolate, result.time);
}
} // namespace
// #sec-temporal.plaintime.prototype.add
MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::Add(
Isolate* isolate, Handle<JSTemporalPlainTime> temporal_time,
Handle<Object> temporal_duration_like) {
return AddDurationToOrSubtractDurationFromPlainTime(
isolate, Arithmetic::kAdd, temporal_time, temporal_duration_like,
"Temporal.PlainTime.prototype.add");
}
// #sec-temporal.plaintime.prototype.subtract
MaybeHandle<JSTemporalPlainTime> JSTemporalPlainTime::Subtract(
Isolate* isolate, Handle<JSTemporalPlainTime> temporal_time,
Handle<Object> temporal_duration_like) {
return AddDurationToOrSubtractDurationFromPlainTime(
isolate, Arithmetic::kSubtract, temporal_time, temporal_duration_like,
"Temporal.PlainTime.prototype.subtract");
}
// #sec-temporal.plaintime.prototype.getisofields // #sec-temporal.plaintime.prototype.getisofields
MaybeHandle<JSReceiver> JSTemporalPlainTime::GetISOFields( MaybeHandle<JSReceiver> JSTemporalPlainTime::GetISOFields(
Isolate* isolate, Handle<JSTemporalPlainTime> temporal_time) { Isolate* isolate, Handle<JSTemporalPlainTime> temporal_time) {
......
...@@ -543,6 +543,16 @@ class JSTemporalPlainTime ...@@ -543,6 +543,16 @@ class JSTemporalPlainTime
ToZonedDateTime(Isolate* isolate, Handle<JSTemporalPlainTime> plain_time, ToZonedDateTime(Isolate* isolate, Handle<JSTemporalPlainTime> plain_time,
Handle<Object> item); Handle<Object> item);
// #sec-temporal.plaintime.prototype.add
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainTime> Add(
Isolate* isolate, Handle<JSTemporalPlainTime> plain_time,
Handle<Object> temporal_duration_like);
// #sec-temporal.plaintime.prototype.subtract
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainTime> Subtract(
Isolate* isolate, Handle<JSTemporalPlainTime> plain_time,
Handle<Object> temporal_duration_like);
// #sec-temporal.plaintime.prototype.getisofields // #sec-temporal.plaintime.prototype.getisofields
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields( V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields(
Isolate* isolate, Handle<JSTemporalPlainTime> plain_time); Isolate* isolate, Handle<JSTemporalPlainTime> plain_time);
......
...@@ -897,16 +897,8 @@ ...@@ -897,16 +897,8 @@
'built-ins/Temporal/PlainMonthDay/prototype/with/overflow-wrong-type': [FAIL], 'built-ins/Temporal/PlainMonthDay/prototype/with/overflow-wrong-type': [FAIL],
'built-ins/Temporal/PlainMonthDay/prototype/with/subclassing-ignored': [FAIL], 'built-ins/Temporal/PlainMonthDay/prototype/with/subclassing-ignored': [FAIL],
'built-ins/Temporal/PlainTime/from/argument-zoneddatetime-balance-negative-time-units': [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],
'built-ins/Temporal/PlainTime/prototype/add/argument-string-negative-fractional-units': [FAIL], 'built-ins/Temporal/PlainTime/prototype/add/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/balance-negative-time-units': [FAIL], 'built-ins/Temporal/PlainTime/prototype/add/balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/branding': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/negative-infinity-throws-rangeerror': [FAIL],
'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-zoneddatetime-balance-negative-time-units': [FAIL], 'built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/round/branding': [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-nan': [FAIL],
...@@ -950,16 +942,7 @@ ...@@ -950,16 +942,7 @@
'built-ins/Temporal/PlainTime/prototype/since/smallestunit-plurals-accepted': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/smallestunit-plurals-accepted': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/smallestunit-undefined': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/smallestunit-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/smallestunit-wrong-type': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/balance-negative-time-units': [FAIL], 'built-ins/Temporal/PlainTime/prototype/subtract/balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/branding': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/negative-infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/non-integer-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/order-of-operations': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/subclassing-ignored': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-non-integer': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-non-integer': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-wrong-type': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-wrong-type': [FAIL],
...@@ -1547,12 +1530,8 @@ ...@@ -1547,12 +1530,8 @@
'built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight': [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], 'built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation': [FAIL],
'built-ins/Temporal/PlainTime/from/argument-string-with-time-designator': [FAIL], 'built-ins/Temporal/PlainTime/from/argument-string-with-time-designator': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/argument-duration': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/argument-higher-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/argument-object': [FAIL], 'built-ins/Temporal/PlainTime/prototype/add/argument-object': [FAIL],
'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/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/options-ignored': [FAIL],
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight': [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-time-designator-required-for-disambiguation': [FAIL],
'built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator': [FAIL], 'built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator': [FAIL],
...@@ -1589,12 +1568,8 @@ ...@@ -1589,12 +1568,8 @@
'built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfExpand': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfExpand': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/roundingmode-trunc': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/roundingmode-trunc': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/year-zero': [FAIL], 'built-ins/Temporal/PlainTime/prototype/since/year-zero': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-duration': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-higher-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-object': [FAIL], 'built-ins/Temporal/PlainTime/prototype/subtract/argument-object': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-object-invalid': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-fractional-units-rounding-mode': [FAIL], 'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/options-ignored': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/basic': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/basic': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number': [FAIL], 'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-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