[json] Fix stringifier gap length above maxint

Change-Id: I296b7e2012bc8b1a141a382793b977e67ebf2a97
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3168343
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76940}
This commit is contained in:
Toon Verwaest 2021-09-20 16:21:54 +02:00 committed by V8 LUCI CQ
parent 5dde281c87
commit 3003422804
2 changed files with 8 additions and 3 deletions

View File

@ -315,9 +315,9 @@ bool JsonStringifier::InitializeGap(Handle<Object> gap) {
gap_[gap_length] = '\0';
}
} else if (gap->IsNumber()) {
int num_value = DoubleToInt32(gap->Number());
if (num_value > 0) {
int gap_length = std::min(num_value, 10);
double value = std::min(gap->Number(), 10.0);
if (value > 0) {
int gap_length = DoubleToInt32(value);
gap_ = NewArray<base::uc16>(gap_length + 1);
for (int i = 0; i < gap_length; i++) gap_[i] = ' ';
gap_[gap_length] = '\0';

View File

@ -523,3 +523,8 @@ assertEquals('{"":"inf"}', JSON.stringify({"":Infinity}, reviver));
assertEquals([10.4, "\u1234"], JSON.parse("[10.4, \"\u1234\"]"));
assertEquals(10, JSON.parse('{"10":10}')["10"]);
assertEquals(`[
1,
2
]`, JSON.stringify([1,2], undefined, 1000000000000000));