Skip to content

Commit 34b7b49

Browse files
committed
Bug 1842810: Handle number overflow in AddTimeDaysSlow. r=spidermonkey-reviewers,mgaudet
This code will likely be removed when <tc39/proposal-temporal#2612> lands. Differential Revision: https://phabricator.services.mozilla.com/D189814
1 parent d925f31 commit 34b7b49

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

js/src/builtin/temporal/PlainDateTime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ static bool AddDateTime(JSContext* cx, const PlainDateTime& dateTime,
714714
// Step 4.
715715
Duration dateDuration = {duration.years, duration.months, duration.weeks,
716716
daysResult};
717+
MOZ_ASSERT(IsValidDuration(duration));
717718

718719
// Step 5.
719720
PlainDate addedDate;

js/src/builtin/temporal/PlainTime.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,15 @@ static bool AddTimeDaysSlow(JSContext* cx, const PlainTime& time,
14821482
return false;
14831483
}
14841484

1485-
*result = BigInt::numberValue(days);
1485+
// The days number is used as the input for a duration. Throw if the BigInt
1486+
// when converted to a Number can't be represented in a duration.
1487+
double daysNumber = BigInt::numberValue(days);
1488+
if (!ThrowIfInvalidDuration(cx, {0, 0, 0, daysNumber})) {
1489+
return false;
1490+
}
1491+
MOZ_ASSERT(IsInteger(daysNumber));
1492+
1493+
*result = daysNumber;
14861494
return true;
14871495
}
14881496

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

16391648
*result = balanced;
16401649
*daysResult = days;

0 commit comments

Comments
 (0)