[Temporal] Sync PR 2344 change BalanceDurationRelative by using newRelativeTo to store info

Spec Change PR:
https://github.com/tc39/proposal-temporal/pull/2344

Relative tests in test262 are
built-ins/Temporal/Duration/prototype/round/february-leap-year.js

Bug: v8:11544
Change-Id: Id31648436f629a8adf395e3b4c835adf46a2c455
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3855701
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82757}
This commit is contained in:
Frank Tang 2022-08-24 22:17:39 -07:00 committed by V8 LUCI CQ
parent 31e17fe62d
commit 88a8b5358b

View File

@ -7038,8 +7038,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
isolate, move_result, isolate, move_result,
MoveRelativeDate(isolate, calendar, relative_to, one_year, method_name), MoveRelativeDate(isolate, calendar, relative_to, one_year, method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// b. Set relativeTo to moveResult.[[RelativeTo]]. // b. Let newRelativeTo be moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; Handle<JSTemporalPlainDate> new_relative_to = move_result.relative_to;
// c. Let oneYearDays be moveResult.[[Days]]. // c. Let oneYearDays be moveResult.[[Days]].
double one_year_days = move_result.days; double one_year_days = move_result.days;
// d. Repeat, while abs(days) ≥ abs(oneYearDays), // d. Repeat, while abs(days) ≥ abs(oneYearDays),
@ -7048,7 +7048,9 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
result.days -= one_year_days; result.days -= one_year_days;
// ii. Set years to years + sign. // ii. Set years to years + sign.
result.years += sign; result.years += sign;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, // iii. Set relativeTo to newRelativeTo.
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo,
// oneYear). // oneYear).
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, move_result, isolate, move_result,
@ -7056,8 +7058,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// iv. Set relativeTo to moveResult.[[RelativeTo]]. // iv. Set newRelativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; new_relative_to = move_result.relative_to;
// v. Set oneYearDays to moveResult.[[Days]]. // v. Set oneYearDays to moveResult.[[Days]].
one_year_days = move_result.days; one_year_days = move_result.days;
} }
@ -7067,8 +7069,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
MoveRelativeDate(isolate, calendar, relative_to, one_month, MoveRelativeDate(isolate, calendar, relative_to, one_month,
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// f. Set relativeTo to moveResult.[[RelativeTo]]. // f. Set newRelativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; new_relative_to = move_result.relative_to;
// g. Let oneMonthDays be moveResult.[[Days]]. // g. Let oneMonthDays be moveResult.[[Days]].
double one_month_days = move_result.days; double one_month_days = move_result.days;
// h. Repeat, while abs(days) ≥ abs(oneMonthDays), // h. Repeat, while abs(days) ≥ abs(oneMonthDays),
@ -7077,15 +7079,17 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
result.days -= one_month_days; result.days -= one_month_days;
// ii. Set months to months + sign. // ii. Set months to months + sign.
result.months += sign; result.months += sign;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, // iii. Set relativeTo to newRelativeTo.
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo,
// oneMonth). // oneMonth).
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, move_result, isolate, move_result,
MoveRelativeDate(isolate, calendar, relative_to, one_month, MoveRelativeDate(isolate, calendar, relative_to, one_month,
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// iv. Set relativeTo to moveResult.[[RelativeTo]]. // iv. Set newRrelativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; new_relative_to = move_result.relative_to;
// v. Set oneMonthDays to moveResult.[[Days]]. // v. Set oneMonthDays to moveResult.[[Days]].
one_month_days = move_result.days; one_month_days = move_result.days;
} }
@ -7095,9 +7099,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
isolate, date_add, isolate, date_add,
Object::GetMethod(calendar, factory->dateAdd_string()), Object::GetMethod(calendar, factory->dateAdd_string()),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// j. Let newRelativeTo be ? CalendarDateAdd(calendar, relativeTo, oneYear, // j. Set newRelativeTo be ? CalendarDateAdd(calendar, relativeTo, oneYear,
// undefined, dateAdd). // undefined, dateAdd).
Handle<JSTemporalPlainDate> new_relative_to;
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, new_relative_to, isolate, new_relative_to,
CalendarDateAdd(isolate, calendar, relative_to, one_year, CalendarDateAdd(isolate, calendar, relative_to, one_year,
@ -7169,8 +7172,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
MoveRelativeDate(isolate, calendar, relative_to, one_month, MoveRelativeDate(isolate, calendar, relative_to, one_month,
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// b. Set relativeTo to moveResult.[[RelativeTo]]. // b. Let newRelativeTo be moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; Handle<JSTemporalPlainDate> new_relative_to = move_result.relative_to;
// c. Let oneMonthDays be moveResult.[[Days]]. // c. Let oneMonthDays be moveResult.[[Days]].
double one_month_days = move_result.days; double one_month_days = move_result.days;
// d. Repeat, while abs(days) ≥ abs(oneMonthDays), // d. Repeat, while abs(days) ≥ abs(oneMonthDays),
@ -7179,16 +7182,18 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
result.days -= one_month_days; result.days -= one_month_days;
// ii. Set months to months + sign. // ii. Set months to months + sign.
result.months += sign; result.months += sign;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, // iii. Set relativeTo to newRelativeTo.
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo,
// oneMonth). // oneMonth).
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, move_result, isolate, move_result,
MoveRelativeDate(isolate, calendar, relative_to, one_month, MoveRelativeDate(isolate, calendar, relative_to, one_month,
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// iv. Set relativeTo to moveResult.[[RelativeTo]]. // v. Set newRelativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; new_relative_to = move_result.relative_to;
// v. Set oneMonthDays to moveResult.[[Days]]. // vi. Set oneMonthDays to moveResult.[[Days]].
one_month_days = move_result.days; one_month_days = move_result.days;
} }
// 12. Else // 12. Else
@ -7201,8 +7206,8 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
isolate, move_result, isolate, move_result,
MoveRelativeDate(isolate, calendar, relative_to, one_week, method_name), MoveRelativeDate(isolate, calendar, relative_to, one_week, method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// c. Set relativeTo to moveResult.[[RelativeTo]]. // c. Let newRelativeTo be moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; Handle<JSTemporalPlainDate> new_relative_to = move_result.relative_to;
// d. Let oneWeekDays be moveResult.[[Days]]. // d. Let oneWeekDays be moveResult.[[Days]].
double one_week_days = move_result.days; double one_week_days = move_result.days;
// e. Repeat, while abs(days) ≥ abs(oneWeekDays), // e. Repeat, while abs(days) ≥ abs(oneWeekDays),
@ -7211,16 +7216,18 @@ Maybe<DateDurationRecord> BalanceDurationRelative(
result.days -= one_week_days; result.days -= one_week_days;
// ii. Set weeks to weeks + sign. // ii. Set weeks to weeks + sign.
result.weeks += sign; result.weeks += sign;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, // iii. Set relativeTo to newRelativeTo.
relative_to = new_relative_to;
// v. Set moveResult to ? MoveRelativeDate(calendar, relativeTo,
// oneWeek). // oneWeek).
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, move_result, isolate, move_result,
MoveRelativeDate(isolate, calendar, relative_to, one_week, MoveRelativeDate(isolate, calendar, relative_to, one_week,
method_name), method_name),
Nothing<DateDurationRecord>()); Nothing<DateDurationRecord>());
// iv. Set relativeTo to moveResult.[[RelativeTo]]. // v. Set newRelativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to; new_relative_to = move_result.relative_to;
// v. Set oneWeekDays to moveResult.[[Days]]. // vi. Set oneWeekDays to moveResult.[[Days]].
one_week_days = move_result.days; one_week_days = move_result.days;
} }
} }