Skip to content

Commit

Permalink
Bug 1842810: Handle number overflow in AddTimeDaysSlow. r=spidermonke…
Browse files Browse the repository at this point in the history
…y-reviewers,mgaudet

This code will likely be removed when <tc39/proposal-temporal#2612> lands.

Differential Revision: https://phabricator.services.mozilla.com/D189814
  • Loading branch information
anba committed Nov 6, 2023
1 parent fb3231b commit d337db4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/src/builtin/temporal/PlainDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ static bool AddDateTime(JSContext* cx, const PlainDateTime& dateTime,
// Step 4.
Duration dateDuration = {duration.years, duration.months, duration.weeks,
daysResult};
MOZ_ASSERT(IsValidDuration(duration));

// Step 5.
PlainDate addedDate;
Expand Down
11 changes: 10 additions & 1 deletion js/src/builtin/temporal/PlainTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,15 @@ static bool AddTimeDaysSlow(JSContext* cx, const PlainTime& time,
return false;
}

*result = BigInt::numberValue(days);
// The days number is used as the input for a duration. Throw if the BigInt
// when converted to a Number can't be represented in a duration.
double daysNumber = BigInt::numberValue(days);
if (!ThrowIfInvalidDuration(cx, {0, 0, 0, daysNumber})) {
return false;
}
MOZ_ASSERT(IsInteger(daysNumber));

*result = daysNumber;
return true;
}

Expand Down Expand Up @@ -1635,6 +1643,7 @@ bool js::temporal::AddTime(JSContext* cx, const PlainTime& time,
if (!AddTimeDays(cx, time, duration, &days)) {
return false;
}
MOZ_ASSERT(IsInteger(days));

*result = balanced;
*daysResult = days;
Expand Down

0 comments on commit d337db4

Please sign in to comment.