[Temporal] Add PlainDateTime.prototype.(add|subtract)
Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.add https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.subtract Bug: v8:11544 Change-Id: Ib76b090a62a932931ab48cb5814ce1f1050fae10 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3617391 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#80956}
This commit is contained in:
parent
88b644717f
commit
9b4b64c282
@ -56,10 +56,6 @@ TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeSince)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainTimePrototypeRound)
|
||||
|
||||
/* Temporal.PlaneDateTime */
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.add */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeAdd)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.subtract */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeSubtract)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.until */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeUntil)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.since */
|
||||
@ -449,11 +445,13 @@ TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, ToZonedDateTime, toZonedDateTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, GetISOFields, getISOFields)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(PlainDateTime, WithPlainDate, withPlainDate)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, With, with)
|
||||
TEMPORAL_VALUE_OF(PlainDateTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, Add, add)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, Subtract, subtract)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToPlainDate, toPlainDate)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToPlainTime, toPlainTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToJSON, toJSON)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, ToLocaleString, toLocaleString)
|
||||
TEMPORAL_VALUE_OF(PlainDateTime)
|
||||
|
||||
// PlainYearMonth
|
||||
BUILTIN(TemporalPlainYearMonthConstructor) {
|
||||
|
@ -9347,6 +9347,97 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::NowISO(
|
||||
method_name);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
enum class Arithmetic { kAdd, kSubtract };
|
||||
|
||||
MaybeHandle<JSTemporalPlainDateTime>
|
||||
AddDurationToOrSubtractDurationFromPlainDateTime(
|
||||
Isolate* isolate, Arithmetic operation,
|
||||
Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_duration_like, Handle<Object> options_obj,
|
||||
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<JSTemporalPlainDateTime>());
|
||||
|
||||
TimeDurationRecord& time_duration = duration.time_duration;
|
||||
|
||||
// 3. Set options to ? GetOptionsObject(options).
|
||||
Handle<JSReceiver> options;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, options, GetOptionsObject(isolate, options_obj, method_name),
|
||||
JSTemporalPlainDateTime);
|
||||
// 4. Let result be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]],
|
||||
// dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]],
|
||||
// dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]],
|
||||
// dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]],
|
||||
// dateTime.[[Calendar]], duration.[[Years]], duration.[[Months]],
|
||||
// duration.[[Weeks]], duration.[[Days]], duration.[[Hours]],
|
||||
// duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]],
|
||||
// duration.[[Microseconds]], duration.[[Nanoseconds]], options).
|
||||
DateTimeRecordCommon result;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, result,
|
||||
AddDateTime(isolate,
|
||||
{{date_time->iso_year(), date_time->iso_month(),
|
||||
date_time->iso_day()},
|
||||
{date_time->iso_hour(), date_time->iso_minute(),
|
||||
date_time->iso_second(), date_time->iso_millisecond(),
|
||||
date_time->iso_microsecond(), date_time->iso_nanosecond()}},
|
||||
handle(date_time->calendar(), isolate),
|
||||
{sign * duration.years,
|
||||
sign * duration.months,
|
||||
sign * duration.weeks,
|
||||
{sign * time_duration.days, sign * time_duration.hours,
|
||||
sign * time_duration.minutes, sign * time_duration.seconds,
|
||||
sign * time_duration.milliseconds,
|
||||
sign * time_duration.microseconds,
|
||||
sign * time_duration.nanoseconds}},
|
||||
options),
|
||||
Handle<JSTemporalPlainDateTime>());
|
||||
|
||||
// 5. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]],
|
||||
// result.[[Day]]) is true.
|
||||
DCHECK(IsValidISODate(isolate, result.date));
|
||||
// 6. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]],
|
||||
// result.[[Second]], result.[[Millisecond]], result.[[Microsecond]],
|
||||
// result.[[Nanosecond]]) is true.
|
||||
DCHECK(IsValidTime(isolate, result.time));
|
||||
// 7. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]],
|
||||
// result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]],
|
||||
// result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]],
|
||||
// dateTime.[[Calendar]]).
|
||||
return temporal::CreateTemporalDateTime(
|
||||
isolate, result, handle(date_time->calendar(), isolate));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.add
|
||||
MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::Add(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_duration_like, Handle<Object> options) {
|
||||
return AddDurationToOrSubtractDurationFromPlainDateTime(
|
||||
isolate, Arithmetic::kAdd, date_time, temporal_duration_like, options,
|
||||
"Temporal.PlainDateTime.prototype.add");
|
||||
}
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.subtract
|
||||
MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::Subtract(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_duration_like, Handle<Object> options) {
|
||||
return AddDurationToOrSubtractDurationFromPlainDateTime(
|
||||
isolate, Arithmetic::kSubtract, date_time, temporal_duration_like,
|
||||
options, "Temporal.PlainDateTime.prototype.subtract");
|
||||
}
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.getisofields
|
||||
MaybeHandle<JSReceiver> JSTemporalPlainDateTime::GetISOFields(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time) {
|
||||
|
@ -423,6 +423,16 @@ class JSTemporalPlainDateTime
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> locales, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.add
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDateTime> Add(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_duration_like, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.subtract
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDateTime> Subtract(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_duration_like, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.now.plaindatetime
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDateTime> Now(
|
||||
Isolate* isolate, Handle<Object> calendar_like,
|
||||
|
@ -757,20 +757,8 @@
|
||||
'built-ins/Temporal/PlainDate/prototype/with/plaindatelike-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/with/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/from/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-string': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-string-negative-fractional-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/negative-infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/non-integer-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/options-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/order-of-operations': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/overflow-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/overflow-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/overflow-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/round/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-nan': [FAIL],
|
||||
@ -824,20 +812,7 @@
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/smallestunit-plurals-accepted': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/smallestunit-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/smallestunit-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-string': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-string-negative-fractional-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/negative-infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/non-integer-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/options-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/order-of-operations': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toPlainDate/limits': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string': [FAIL],
|
||||
@ -1735,22 +1710,10 @@
|
||||
'built-ins/Temporal/PlainDate/prototype/since/argument-string-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/until/argument-string-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/datetime-math': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/ambiguous-date': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-duration': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/argument-plain-object-mixed-signs': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/hour-overflow': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/negative-duration': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/options-empty': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/options-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/ambiguous-date': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-duration': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-object-insufficient-data': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/argument-plain-object-mixed-signs': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/hour-overflow': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/negative-duration': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/options-empty': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/options-invalid': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/until/casts-argument': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/until/different-calendars-throws': [FAIL],
|
||||
@ -1792,7 +1755,6 @@
|
||||
'built-ins/Temporal/Instant/prototype/until/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/since/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/until/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/add/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/round/balance': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/round/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/round/rounding-direction': [FAIL],
|
||||
@ -1830,7 +1792,6 @@
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/round-relative-to-receiver': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/subseconds': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/since/weeks-months-mutually-exclusive': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-auto': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-number': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/options-wrong-type': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user