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

Revert "[Temporal] Use double/int32_t instead of int64_t for duration parsing"

This reverts commit a165e82e.

Reason for revert: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../src/objects/js-temporal-objects.cc:3837:22  

Original change's description:
> [Temporal] Use double/int32_t instead of int64_t for duration parsing
>
> Use double instead of int64_t and int32_t in duration parsing result
> so we can parse very large duration fields as infinity and throw RangeError in later stages. The three fractional parts can hold up value from 0 to 999,999,999 so we use int32_t to hold it. Other part could be infinity so we use double to hold it. Also rearrange the order of the three int32_t in the struct ParsedISO8601Duration after all the double
>
> Bug: v8:11544
> Change-Id: I7e5b02f7c7bbb60997f1419f016aed61dd3e0d6c
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3840761
> Reviewed-by: Shu-yu Guo <syg@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#82754}

Bug: v8:11544
Change-Id: Ia9d0a014463b00640d43b051753a554f42171c2b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3858575Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82755}
parent a165e82e
......@@ -3726,7 +3726,7 @@ Maybe<DurationRecord> CreateDurationRecord(Isolate* isolate,
return Just(duration);
}
inline double IfEmptyReturnZero(double value) {
inline int64_t IfEmptyReturnZero(int64_t value) {
return value == ParsedISO8601Duration::kEmpty ? 0 : value;
}
......
......@@ -186,6 +186,14 @@ int32_t ScanFractionalPart(base::Vector<Char> str, int32_t s, int32_t* out) {
return cur - s;
}
template <typename Char>
int32_t ScanFractionalPart(base::Vector<Char> str, int32_t s, int64_t* out) {
int32_t out32;
int32_t len = ScanFractionalPart(str, s, &out32);
*out = out32;
return len;
}
// TimeFraction: FractionalPart
SCAN_FORWARD(TimeFractionalPart, FractionalPart, int32_t)
......@@ -1430,10 +1438,21 @@ bool SatisfyTemporalCalendarString(base::Vector<Char> str,
// Duration
SCAN_FORWARD(TimeFractionalPart, FractionalPart, int64_t)
template <typename Char>
int32_t ScanFraction(base::Vector<Char> str, int32_t s, int64_t* out) {
if (str.length() < (s + 2) || !IsDecimalSeparator(str[s])) return 0;
int32_t len = ScanTimeFractionalPart(str, s + 1, out);
return (len == 0) ? 0 : len + 1;
}
SCAN_FORWARD(TimeFraction, Fraction, int64_t)
// Digits : Digit [Digits]
template <typename Char>
int32_t ScanDigits(base::Vector<Char> str, int32_t s, double* out) {
int32_t ScanDigits(base::Vector<Char> str, int32_t s, int64_t* out) {
if (str.length() < (s + 1) || !IsDecimalDigit(str[s])) return 0;
*out = ToInt(str[s]);
int32_t len = 1;
......@@ -1444,38 +1463,38 @@ int32_t ScanDigits(base::Vector<Char> str, int32_t s, double* out) {
return len;
}
SCAN_FORWARD(DurationYears, Digits, double)
SCAN_FORWARD(DurationMonths, Digits, double)
SCAN_FORWARD(DurationWeeks, Digits, double)
SCAN_FORWARD(DurationDays, Digits, double)
SCAN_FORWARD(DurationYears, Digits, int64_t)
SCAN_FORWARD(DurationMonths, Digits, int64_t)
SCAN_FORWARD(DurationWeeks, Digits, int64_t)
SCAN_FORWARD(DurationDays, Digits, int64_t)
// DurationWholeHours : Digits
SCAN_FORWARD(DurationWholeHours, Digits, double)
SCAN_FORWARD(DurationWholeHours, Digits, int64_t)
// DurationWholeMinutes : Digits
SCAN_FORWARD(DurationWholeMinutes, Digits, double)
SCAN_FORWARD(DurationWholeMinutes, Digits, int64_t)
// DurationWholeSeconds : Digits
SCAN_FORWARD(DurationWholeSeconds, Digits, double)
SCAN_FORWARD(DurationWholeSeconds, Digits, int64_t)
// DurationHoursFraction : TimeFraction
SCAN_FORWARD(DurationHoursFraction, TimeFraction, int32_t)
SCAN_FORWARD(DurationHoursFraction, TimeFraction, int64_t)
// DurationMinutesFraction : TimeFraction
SCAN_FORWARD(DurationMinutesFraction, TimeFraction, int32_t)
SCAN_FORWARD(DurationMinutesFraction, TimeFraction, int64_t)
// DurationSecondsFraction : TimeFraction
SCAN_FORWARD(DurationSecondsFraction, TimeFraction, int32_t)
SCAN_FORWARD(DurationSecondsFraction, TimeFraction, int64_t)
#define DURATION_WHOLE_FRACTION_DESIGNATOR(Name, name, d) \
template <typename Char> \
int32_t ScanDurationWhole##Name##FractionDesignator( \
base::Vector<Char> str, int32_t s, ParsedISO8601Duration* r) { \
int32_t cur = s; \
double whole = ParsedISO8601Duration::kEmpty; \
int64_t whole = ParsedISO8601Duration::kEmpty; \
cur += ScanDurationWhole##Name(str, cur, &whole); \
if (cur == s) return 0; \
int32_t fraction = ParsedISO8601Duration::kEmpty; \
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)) \
......@@ -1551,7 +1570,7 @@ int32_t ScanDurationTime(base::Vector<Char> str, int32_t s,
int32_t ScanDuration##Name##Designator(base::Vector<Char> str, int32_t s, \
ParsedISO8601Duration* r) { \
int32_t cur = s; \
double name; \
int64_t name; \
if ((cur += ScanDuration##Name(str, cur, &name)) == s) return 0; \
if (str.length() < (cur + 1) || AsciiAlphaToLower(str[cur++]) != (d)) { \
return 0; \
......
......@@ -95,20 +95,20 @@ struct ParsedISO8601Result {
* field is "undefined" after parsing for all fields except sign.
*/
struct ParsedISO8601Duration {
double sign; // Sign production
double years; // DurationYears production
double months; // DurationMonths production
double weeks; // DurationWeeks production
double days; // DurationDays production
double whole_hours; // DurationWholeHours production
double whole_minutes; // DurationWholeMinutes production
double whole_seconds; // DurationWholeSeconds production
int32_t hours_fraction; // DurationHoursFraction, in unit of 1e-9 hours
int32_t minutes_fraction; // DurationMinuteFraction, in unit of 1e-9 minutes
int32_t seconds_fraction; // DurationSecondFraction, in unit of nanosecond (
int64_t sign; // Sign production
int64_t years; // DurationYears production
int64_t months; // DurationMonths production
int64_t weeks; // DurationWeeks production
int64_t days; // DurationDays production
int64_t whole_hours; // DurationWholeHours production
int64_t hours_fraction; // DurationHoursFraction, in unit of 1e-9 hours
int64_t whole_minutes; // DurationWholeMinutes production
int64_t minutes_fraction; // DurationMinuteFraction, in unit of 1e-9 minutes
int64_t whole_seconds; // DurationWholeSeconds production
int64_t seconds_fraction; // DurationSecondFraction, in unit of nanosecond (
// 1e-9 seconds).
static constexpr int32_t kEmpty = -1;
static constexpr int64_t kEmpty = -1;
ParsedISO8601Duration()
: sign(1),
years(kEmpty),
......@@ -116,10 +116,10 @@ struct ParsedISO8601Duration {
weeks(kEmpty),
days(kEmpty),
whole_hours(kEmpty),
whole_minutes(kEmpty),
whole_seconds(kEmpty),
hours_fraction(kEmpty),
whole_minutes(kEmpty),
minutes_fraction(kEmpty),
whole_seconds(kEmpty),
seconds_fraction(kEmpty) {}
};
......
......@@ -681,6 +681,8 @@
'built-ins/Temporal/Duration/prototype/subtract/nanoseconds-is-number-max-value-1': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days-different-sign': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-with-fractional-days': [FAIL],
'built-ins/Temporal/PlainTime/prototype/add/argument-string-duration-too-large': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-duration-too-large': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/fixed-offset-near-date-time-limits': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-daylength-too-large': [FAIL],
'intl402/Temporal/TimeZone/prototype/getNextTransition/subtract-second-and-nanosecond-from-last-transition': [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