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

[Temporal] Add Temporal.Duration.from

Also add AOs:
IsIntegralNumber, ToIntegerWithoutRounding, ToTemporalDurationRecord,
ToTemporalDuration, ParseTemporalDurationString, CreateDurationRecord

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.duration.from
https://tc39.es/ecma262/#sec-isintegralnumber
https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldurationstring
https://tc39.es/proposal-temporal/#sec-temporal-createdurationrecord

Bug: v8:11544
Change-Id: I0f4176921e088bd2f2fd48ddd28f22f3b454bd3b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3379233Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80195}
parent c575e8ae
......@@ -194,8 +194,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainTime)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToPlainDateTime)
/* Temporal.Duration */
/* Temporal #sec-temporal.duration.from */
TO_BE_IMPLEMENTED(TemporalDurationFrom)
/* Temporal #sec-temporal.duration.compare */
TO_BE_IMPLEMENTED(TemporalDurationCompare)
/* Temporal #sec-temporal.duration.prototype.with */
......@@ -413,6 +411,14 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToLocaleString)
args.atOrUndefined(isolate, 3))); \
}
#define TEMPORAL_METHOD1(T, METHOD) \
BUILTIN(Temporal##T##METHOD) { \
HandleScope scope(isolate); \
RETURN_RESULT_OR_FAILURE( \
isolate, \
JSTemporal##T ::METHOD(isolate, args.atOrUndefined(isolate, 1))); \
}
#define TEMPORAL_METHOD2(T, METHOD) \
BUILTIN(Temporal##T##METHOD) { \
HandleScope scope(isolate); \
......@@ -750,6 +756,7 @@ BUILTIN(TemporalDurationConstructor) {
args.atOrUndefined(isolate, 9), // microseconds
args.atOrUndefined(isolate, 10))); // nanoseconds
}
TEMPORAL_METHOD1(Duration, From)
TEMPORAL_GET(Duration, Years, years)
TEMPORAL_GET(Duration, Months, months)
TEMPORAL_GET(Duration, Weeks, weeks)
......
This diff is collapsed.
......@@ -133,6 +133,10 @@ class JSTemporalDuration
Handle<Object> milliseconds, Handle<Object> microseconds,
Handle<Object> nanoseconds);
// #sec-temporal.duration.from
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalDuration> From(
Isolate* isolate, Handle<Object> item);
// #sec-get-temporal.duration.prototype.sign
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> Sign(
Isolate* isolate, Handle<JSTemporalDuration> duration);
......
......@@ -1020,10 +1020,10 @@ SCAN_FORWARD(DurationSecondsFraction, TimeFraction, int64_t)
int32_t ScanDurationWhole##Name##FractionDesignator( \
base::Vector<Char> str, int32_t s, ParsedISO8601Duration* r) { \
int32_t cur = s; \
int64_t whole = 0; \
int64_t whole = ParsedISO8601Duration::kEmpty; \
cur += ScanDurationWhole##Name(str, cur, &whole); \
if (cur == s) return 0; \
int64_t fraction = 0; \
int64_t fraction = ParsedISO8601Duration::kEmpty; \
int32_t len = ScanDuration##Name##Fraction(str, cur, &fraction); \
cur += len; \
if (str.length() < (cur + 1) || AsciiAlphaToLower(str[cur++]) != (d)) \
......
......@@ -84,6 +84,8 @@ struct ParsedISO8601Result {
* ParsedISO8601Duration contains the parsed result of ISO 8601 grammar
* documented in #prod-TemporalDurationString
* for TemporalDurationString.
* A special value kEmpty is used to represent the
* field is "undefined" after parsing for all fields except sign.
*/
struct ParsedISO8601Duration {
int64_t sign; // Sign production
......@@ -99,18 +101,19 @@ struct ParsedISO8601Duration {
int64_t seconds_fraction; // DurationSecondFraction, in unit of nanosecond (
// 1e-9 seconds).
static constexpr int64_t kEmpty = -1;
ParsedISO8601Duration()
: sign(1),
years(0),
months(0),
weeks(0),
days(0),
whole_hours(0),
hours_fraction(0),
whole_minutes(0),
minutes_fraction(0),
whole_seconds(0),
seconds_fraction(0) {}
years(kEmpty),
months(kEmpty),
weeks(kEmpty),
days(kEmpty),
whole_hours(kEmpty),
hours_fraction(kEmpty),
whole_minutes(kEmpty),
minutes_fraction(kEmpty),
whole_seconds(kEmpty),
seconds_fraction(kEmpty) {}
};
/**
......
This diff is collapsed.
......@@ -55,7 +55,6 @@
'temporal/calendar-week-of-year': [FAIL],
'temporal/calendar-year-month-from-fields': [FAIL],
'temporal/duration-add': [FAIL],
'temporal/duration-from': [FAIL],
'temporal/duration-to-json': [FAIL],
'temporal/duration-with': [FAIL],
'temporal/instant-add': [FAIL],
......
......@@ -567,16 +567,6 @@
'built-ins/Temporal/Duration/compare/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Duration/compare/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Duration/compare/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Duration/fractional-throws-rangeerror': [FAIL],
'built-ins/Temporal/Duration/from/argument-existing-object': [FAIL],
'built-ins/Temporal/Duration/from/argument-non-string': [FAIL],
'built-ins/Temporal/Duration/from/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/Duration/from/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Duration/from/negative-inifinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Duration/from/non-integer-throws-rangeerror': [FAIL],
'built-ins/Temporal/Duration/from/order-of-operations': [FAIL],
'built-ins/Temporal/Duration/from/string-with-skipped-units': [FAIL],
'built-ins/Temporal/Duration/from/subclassing-ignored': [FAIL],
'built-ins/Temporal/Duration/prototype/add/branding': [FAIL],
'built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-plaindate-instance': [FAIL],
'built-ins/Temporal/Duration/prototype/add/infinity-throws-rangeerror': [FAIL],
......@@ -2311,7 +2301,6 @@
'built-ins/Temporal/Duration/compare/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/Duration/compare/calendar-possibly-required': [FAIL],
'built-ins/Temporal/Duration/compare/year-zero': [FAIL],
'built-ins/Temporal/Duration/from/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/Duration/prototype/add/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/Duration/prototype/add/year-zero': [FAIL],
'built-ins/Temporal/Duration/prototype/round/calendar-possibly-required': [FAIL],
......@@ -2622,9 +2611,6 @@
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain': [FAIL],
'built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-reject': [FAIL],
'built-ins/Temporal/Duration/compare/twenty-five-hour-day': [FAIL],
'built-ins/Temporal/Duration/from/argument-object-invalid': [FAIL],
'built-ins/Temporal/Duration/from/argument-string': [FAIL],
'built-ins/Temporal/Duration/from/argument-string-invalid': [FAIL],
'built-ins/Temporal/Duration/prototype/toJSON/basic': [FAIL],
'built-ins/Temporal/Duration/prototype/toString/balance': [FAIL],
'built-ins/Temporal/Duration/prototype/with/all-negative': [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