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

[Temporal] Add Instant.prototype.round

Also add AOs: ToTemporalRoundingMode, ToSmallestTemporalUnit,
ToTemporalRoundingIncrement, RoundHalfAwayFromZero,
RoundNumberToIncrement, RoundTemporalInstant

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round
https://tc39.es/proposal-temporal/#sec-temporal-totemporalroundingmode
https://tc39.es/proposal-temporal/#sec-temporal-tosmallesttemporalunit
https://tc39.es/proposal-temporal/#sec-temporal-totemporalroundingincrement
https://tc39.es/proposal-temporal/#sec-temporal-roundhalfawayfromzero
https://tc39.es/proposal-temporal/#sec-temporal-roundnumbertoincrement
https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant

Bug: v8:11544
Change-Id: I37750f166e6b5597db16574d2ce4d5f92065a7b0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3566671
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81212}
parent 8c5610eb
...@@ -94,8 +94,6 @@ TO_BE_IMPLEMENTED(TemporalDurationPrototypeToString) ...@@ -94,8 +94,6 @@ TO_BE_IMPLEMENTED(TemporalDurationPrototypeToString)
TO_BE_IMPLEMENTED(TemporalInstantPrototypeUntil) TO_BE_IMPLEMENTED(TemporalInstantPrototypeUntil)
/* Temporal #sec-temporal.instant.prototype.since */ /* Temporal #sec-temporal.instant.prototype.since */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeSince) TO_BE_IMPLEMENTED(TemporalInstantPrototypeSince)
/* Temporal #sec-temporal.instant.prototype.round */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeRound)
/* Temporal #sec-temporal.instant.prototype.tolocalestring */ /* Temporal #sec-temporal.instant.prototype.tolocalestring */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeToLocaleString) TO_BE_IMPLEMENTED(TemporalInstantPrototypeToLocaleString)
/* Temporal #sec-temporal.instant.prototype.tostring */ /* Temporal #sec-temporal.instant.prototype.tostring */
...@@ -642,10 +640,11 @@ TEMPORAL_GET_NUMBER_AFTER_DIVID(Instant, EpochMilliseconds, nanoseconds, ...@@ -642,10 +640,11 @@ TEMPORAL_GET_NUMBER_AFTER_DIVID(Instant, EpochMilliseconds, nanoseconds,
1000000, epochMilliseconds) 1000000, epochMilliseconds)
TEMPORAL_GET_BIGINT_AFTER_DIVID(Instant, EpochMicroseconds, nanoseconds, 1000, TEMPORAL_GET_BIGINT_AFTER_DIVID(Instant, EpochMicroseconds, nanoseconds, 1000,
epochMicroseconds) epochMicroseconds)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTime, toZonedDateTime)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTimeISO, toZonedDateTimeISO)
TEMPORAL_PROTOTYPE_METHOD1(Instant, Add, add) TEMPORAL_PROTOTYPE_METHOD1(Instant, Add, add)
TEMPORAL_PROTOTYPE_METHOD1(Instant, Round, round)
TEMPORAL_PROTOTYPE_METHOD1(Instant, Subtract, subtract) TEMPORAL_PROTOTYPE_METHOD1(Instant, Subtract, subtract)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTime, toZonedDateTime)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTimeISO, toZonedDateTimeISO)
// Calendar // Calendar
TEMPORAL_CONSTRUCTOR1(Calendar) TEMPORAL_CONSTRUCTOR1(Calendar)
......
...@@ -1726,11 +1726,13 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New( ...@@ -1726,11 +1726,13 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
if (item.property == "timeZoneName") { if (item.property == "timeZoneName") {
// Let _value_ be ? GetNumberOption(options, "fractionalSecondDigits", 1, // Let _value_ be ? GetNumberOption(options, "fractionalSecondDigits", 1,
// 3, *undefined*). The *undefined* is represented by value 0 here. // 3, *undefined*). The *undefined* is represented by value 0 here.
Maybe<int> maybe_fsd = GetNumberOption( int fsd;
isolate, options, factory->fractionalSecondDigits_string(), 1, 3, 0); MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
MAYBE_RETURN(maybe_fsd, MaybeHandle<JSDateTimeFormat>()); isolate, fsd,
GetNumberOption(isolate, options,
factory->fractionalSecondDigits_string(), 1, 3, 0),
Handle<JSDateTimeFormat>());
// Convert fractionalSecondDigits to skeleton. // Convert fractionalSecondDigits to skeleton.
int fsd = maybe_fsd.FromJust();
for (int i = 0; i < fsd; i++) { for (int i = 0; i < fsd; i++) {
skeleton += "S"; skeleton += "S";
} }
......
...@@ -1442,15 +1442,16 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate, ...@@ -1442,15 +1442,16 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
Notation notation = Notation::STANDARD; Notation notation = Notation::STANDARD;
// 18. Let notation be ? GetOption(options, "notation", "string", « // 18. Let notation be ? GetOption(options, "notation", "string", «
// "standard", "scientific", "engineering", "compact" », "standard"). // "standard", "scientific", "engineering", "compact" », "standard").
Maybe<Notation> maybe_notation = GetStringOption<Notation>( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, options, "notation", service, isolate, notation,
{"standard", "scientific", "engineering", "compact"}, GetStringOption<Notation>(
{Notation::STANDARD, Notation::SCIENTIFIC, Notation::ENGINEERING, isolate, options, "notation", service,
Notation::COMPACT}, {"standard", "scientific", "engineering", "compact"},
Notation::STANDARD); {Notation::STANDARD, Notation::SCIENTIFIC, Notation::ENGINEERING,
MAYBE_RETURN(maybe_notation, MaybeHandle<JSNumberFormat>()); Notation::COMPACT},
Notation::STANDARD),
Handle<JSNumberFormat>());
// 19. Set numberFormat.[[Notation]] to notation. // 19. Set numberFormat.[[Notation]] to notation.
notation = maybe_notation.FromJust();
// 20. Perform ? SetNumberFormatDigitOptions(numberFormat, options, // 20. Perform ? SetNumberFormatDigitOptions(numberFormat, options,
// mnfdDefault, mxfdDefault). // mnfdDefault, mxfdDefault).
......
This diff is collapsed.
...@@ -227,16 +227,24 @@ class JSTemporalInstant ...@@ -227,16 +227,24 @@ class JSTemporalInstant
// #sec-temporal.instant.fromepochseconds // #sec-temporal.instant.fromepochseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> FromEpochSeconds( V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> FromEpochSeconds(
Isolate* isolate, Handle<Object> epoch_seconds); Isolate* isolate, Handle<Object> epoch_seconds);
// #sec-temporal.instant.fromepochmilliseconds // #sec-temporal.instant.fromepochmilliseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochMilliseconds(Isolate* isolate, Handle<Object> epoch_milliseconds); FromEpochMilliseconds(Isolate* isolate, Handle<Object> epoch_milliseconds);
// #sec-temporal.instant.fromepochmicroseconds // #sec-temporal.instant.fromepochmicroseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochMicroseconds(Isolate* isolate, Handle<Object> epoch_microseconds); FromEpochMicroseconds(Isolate* isolate, Handle<Object> epoch_microseconds);
// #sec-temporal.instant.fromepochnanoeconds // #sec-temporal.instant.fromepochnanoeconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochNanoseconds(Isolate* isolate, Handle<Object> epoch_nanoseconds); FromEpochNanoseconds(Isolate* isolate, Handle<Object> epoch_nanoseconds);
// #sec-temporal.instant.prototype.round
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> Round(
Isolate* isolate, Handle<JSTemporalInstant> instant,
Handle<Object> options);
// #sec-temporal.instant.from // #sec-temporal.instant.from
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> From( V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> From(
Isolate* isolate, Handle<Object> item); Isolate* isolate, Handle<Object> item);
......
...@@ -168,5 +168,36 @@ Maybe<int> GetNumberOption(Isolate* isolate, Handle<JSReceiver> options, ...@@ -168,5 +168,36 @@ Maybe<int> GetNumberOption(Isolate* isolate, Handle<JSReceiver> options,
return DefaultNumberOption(isolate, value, min, max, fallback, property); return DefaultNumberOption(isolate, value, min, max, fallback, property);
} }
// #sec-getoption while type is "number"
Maybe<double> GetNumberOptionAsDouble(Isolate* isolate,
Handle<JSReceiver> options,
Handle<String> property,
double default_value) {
// 1. Let value be ? Get(options, property).
Handle<Object> value;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, value, JSReceiver::GetProperty(isolate, options, property),
Nothing<double>());
// 2. If value is undefined, then
if (value->IsUndefined()) {
// b. Return default.
return Just(default_value);
}
// 4. Else if type is "number", then
// a. Set value to ? ToNumber(value).
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, value, Object::ToNumber(isolate, value), Nothing<double>());
// b. If value is NaN, throw a RangeError exception.
if (value->IsNaN()) {
THROW_NEW_ERROR_RETURN_VALUE(
isolate,
NewRangeError(MessageTemplate::kPropertyValueOutOfRange, property),
Nothing<double>());
}
// 7. Return value.
return Just(value->Number());
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -156,6 +156,11 @@ V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Maybe<int> GetNumberOption( ...@@ -156,6 +156,11 @@ V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Maybe<int> GetNumberOption(
Isolate* isolate, Handle<JSReceiver> options, Handle<String> property, Isolate* isolate, Handle<JSReceiver> options, Handle<String> property,
int min, int max, int fallback); int min, int max, int fallback);
// #sec-getoption while type is "number"
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Maybe<double> GetNumberOptionAsDouble(
Isolate* isolate, Handle<JSReceiver> options, Handle<String> property,
double default_value);
// ecma402/#sec-defaultnumberoption // ecma402/#sec-defaultnumberoption
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Maybe<int> DefaultNumberOption( V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Maybe<int> DefaultNumberOption(
Isolate* isolate, Handle<Object> value, int min, int max, int fallback, Isolate* isolate, Handle<Object> value, int min, int max, int fallback,
......
...@@ -543,20 +543,6 @@ ...@@ -543,20 +543,6 @@
'built-ins/Temporal/Instant/from/timezone-custom': [FAIL], 'built-ins/Temporal/Instant/from/timezone-custom': [FAIL],
'built-ins/Temporal/Instant/prototype/equals/argument-wrong-type': [FAIL], 'built-ins/Temporal/Instant/prototype/equals/argument-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/equals/instant-string': [FAIL], 'built-ins/Temporal/Instant/prototype/equals/instant-string': [FAIL],
'built-ins/Temporal/Instant/prototype/round/branding': [FAIL],
'built-ins/Temporal/Instant/prototype/round/options-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingincrement-nan': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingincrement-non-integer': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingincrement-out-of-range': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingincrement-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingincrement-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingmode-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingmode-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundingmode-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/round/smallestunit-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/round/smallestunit-plurals-accepted': [FAIL],
'built-ins/Temporal/Instant/prototype/round/smallestunit-string-shorthand': [FAIL],
'built-ins/Temporal/Instant/prototype/round/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/round/subclassing-ignored': [FAIL], 'built-ins/Temporal/Instant/prototype/round/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/prototype/since/argument-zoneddatetime': [FAIL], 'built-ins/Temporal/Instant/prototype/since/argument-zoneddatetime': [FAIL],
'built-ins/Temporal/Instant/prototype/since/branding': [FAIL], 'built-ins/Temporal/Instant/prototype/since/branding': [FAIL],
...@@ -1531,7 +1517,6 @@ ...@@ -1531,7 +1517,6 @@
'built-ins/Temporal/Duration/prototype/toString/roundingmode-trunc': [FAIL], 'built-ins/Temporal/Duration/prototype/toString/roundingmode-trunc': [FAIL],
'built-ins/Temporal/Duration/prototype/toString/smallestunit-fractionalseconddigits': [FAIL], 'built-ins/Temporal/Duration/prototype/toString/smallestunit-fractionalseconddigits': [FAIL],
'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL], 'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL],
'built-ins/Temporal/Instant/prototype/round/roundto-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/since/options-wrong-type': [FAIL], 'built-ins/Temporal/Instant/prototype/since/options-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-auto': [FAIL], 'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-auto': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-number': [FAIL], 'built-ins/Temporal/Instant/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