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

[Temporal] Fix relativeTo passing bug

Fix BalanceDuration to pass relativeTo to BalancePossiblyInfiniteDurationResult
and then pass to NanosecondsToDays.

The bug is introduced in
https://chromium-review.googlesource.com/c/v8/v8/+/3781117

The spec text in 4-a of BalancePossiblyInfiniteDuration is
"a. Let result be ? NanosecondsToDays(nanoseconds, relativeTo)."
but the code wrote
"a. Let result be ? NanosecondsToDays(nanoseconds, *undefined*)."

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal-balancepossiblyinfiniteduration

Bug: v8:11544
Change-Id: I3ea9a3b71521cdcc210e9db370d6e849fcde56ee
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3834431
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82570}
parent 3752ce19
...@@ -332,8 +332,17 @@ BalancePossiblyInfiniteDuration(Isolate* isolate, Unit largest_unit, ...@@ -332,8 +332,17 @@ BalancePossiblyInfiniteDuration(Isolate* isolate, Unit largest_unit,
// This version has no relative_to. // This version has no relative_to.
V8_WARN_UNUSED_RESULT Maybe<BalancePossiblyInfiniteDurationResult> V8_WARN_UNUSED_RESULT Maybe<BalancePossiblyInfiniteDurationResult>
BalancePossiblyInfiniteDuration(Isolate* isolate, Unit largest_unit, BalancePossiblyInfiniteDuration(Isolate* isolate, Unit largest_unit,
double days, Handle<BigInt> nanoseconds, Handle<Object> relative_to, double days,
Handle<BigInt> nanoseconds,
const char* method_name); const char* method_name);
V8_WARN_UNUSED_RESULT Maybe<BalancePossiblyInfiniteDurationResult>
BalancePossiblyInfiniteDuration(Isolate* isolate, Unit largest_unit,
double days, Handle<BigInt> nanoseconds,
const char* method_name) {
return BalancePossiblyInfiniteDuration(isolate, largest_unit,
isolate->factory()->undefined_value(),
days, nanoseconds, method_name);
}
V8_WARN_UNUSED_RESULT Maybe<DurationRecord> DifferenceISODateTime( V8_WARN_UNUSED_RESULT Maybe<DurationRecord> DifferenceISODateTime(
Isolate* isolate, const DateTimeRecordCommon& date_time1, Isolate* isolate, const DateTimeRecordCommon& date_time1,
...@@ -5157,16 +5166,17 @@ Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration( ...@@ -5157,16 +5166,17 @@ Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration(
// 1) step 4 and 5 use nanoseconds and days only, and // 1) step 4 and 5 use nanoseconds and days only, and
// 2) step 6 is "Set hours, minutes, seconds, milliseconds, and microseconds // 2) step 6 is "Set hours, minutes, seconds, milliseconds, and microseconds
// to 0." // to 0."
return BalancePossiblyInfiniteDuration(isolate, largest_unit, duration.days, return BalancePossiblyInfiniteDuration(isolate, largest_unit, relative_to_obj,
nanoseconds, method_name); duration.days, nanoseconds,
method_name);
} }
// The special case of BalancePossiblyInfiniteDuration while the nanosecond is a // The special case of BalancePossiblyInfiniteDuration while the nanosecond is a
// large value and days contains non-zero values but the rest are 0. // large value and days contains non-zero values but the rest are 0.
// This version has no relative_to. // This version has no relative_to.
Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration( Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration(
Isolate* isolate, Unit largest_unit, double days, Isolate* isolate, Unit largest_unit, Handle<Object> relative_to_obj,
Handle<BigInt> nanoseconds, const char* method_name) { double days, Handle<BigInt> nanoseconds, const char* method_name) {
TEMPORAL_ENTER_FUNC(); TEMPORAL_ENTER_FUNC();
// 4. If largestUnit is one of "year", "month", "week", or "day", then // 4. If largestUnit is one of "year", "month", "week", or "day", then
...@@ -5176,8 +5186,7 @@ Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration( ...@@ -5176,8 +5186,7 @@ Maybe<BalancePossiblyInfiniteDurationResult> BalancePossiblyInfiniteDuration(
NanosecondsToDaysResult result; NanosecondsToDaysResult result;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, result, isolate, result,
NanosecondsToDays(isolate, nanoseconds, NanosecondsToDays(isolate, nanoseconds, relative_to_obj, method_name),
isolate->factory()->undefined_value(), method_name),
Nothing<BalancePossiblyInfiniteDurationResult>()); Nothing<BalancePossiblyInfiniteDurationResult>());
// b. Set days to result.[[Days]]. // b. Set days to result.[[Days]].
days = result.days; days = result.days;
......
...@@ -442,9 +442,6 @@ ...@@ -442,9 +442,6 @@
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindatetime': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindatetime': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/calendar-datefromfields-called-with-options-undefined': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/calendar-datefromfields-called-with-options-undefined': [FAIL],
'built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined': [FAIL],
'built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined': [FAIL],
'built-ins/Temporal/Duration/prototype/total/calendar-dateuntil-called-with-singular-largestunit': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-string-zoneddatetime': [FAIL], 'built-ins/Temporal/Duration/prototype/total/relativeto-string-zoneddatetime': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-with-utc-designator': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL], 'built-ins/Temporal/Calendar/prototype/weekOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
...@@ -708,7 +705,6 @@ ...@@ -708,7 +705,6 @@
'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/Duration/prototype/add/days-is-number-max-value': [FAIL], 'built-ins/Temporal/Duration/prototype/add/days-is-number-max-value': [FAIL],
'built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-value-1': [FAIL], 'built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-value-1': [FAIL],
'built-ins/Temporal/Duration/prototype/round/nanoseconds-to-days-loop-indefinitely-1': [FAIL],
'built-ins/Temporal/Duration/prototype/round/throws-in-balance-duration-when-sign-mismatched-with-zoned-date-time': [FAIL], 'built-ins/Temporal/Duration/prototype/round/throws-in-balance-duration-when-sign-mismatched-with-zoned-date-time': [FAIL],
'built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime': [PASS, FAIL], 'built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime': [PASS, FAIL],
'built-ins/Temporal/Duration/prototype/subtract/days-is-number-max-value': [FAIL], 'built-ins/Temporal/Duration/prototype/subtract/days-is-number-max-value': [FAIL],
...@@ -767,9 +763,6 @@ ...@@ -767,9 +763,6 @@
'staging/Temporal/ZonedDateTime/old/until': [FAIL], 'staging/Temporal/ZonedDateTime/old/until': [FAIL],
'staging/Temporal/ZonedDateTime/old/with': [FAIL], 'staging/Temporal/ZonedDateTime/old/with': [FAIL],
'built-ins/Temporal/Duration/prototype/round/calendar-dateuntil-called-with-singular-largestunit': [FAIL],
'built-ins/Temporal/Duration/prototype/round/nanoseconds-to-days-loop-indefinitely-2': [FAIL],
# UBSan complain about static_cast<int32_t> from double in AddISODate() # UBSan complain about static_cast<int32_t> from double in AddISODate()
'built-ins/Temporal/Calendar/prototype/dateAdd/argument-duration-years-and-months-number-max-value': [SKIP], 'built-ins/Temporal/Calendar/prototype/dateAdd/argument-duration-years-and-months-number-max-value': [SKIP],
......
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