Skip to content

Commit 0723320

Browse files
bnoordhuisrvagg
authored andcommitted
deps: backport 6df9a1d from upstream v8
PR-URL: nodejs-private/node-private#8 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent 1c8e6de commit 0723320

File tree

2 files changed

+14
-48
lines changed

2 files changed

+14
-48
lines changed

deps/v8/src/json-stringifier.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -440,54 +440,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray(
440440
uint32_t length = 0;
441441
CHECK(object->length()->ToArrayLength(&length));
442442
builder_.AppendCharacter('[');
443-
switch (object->GetElementsKind()) {
444-
case FAST_SMI_ELEMENTS: {
445-
Handle<FixedArray> elements(
446-
FixedArray::cast(object->elements()), isolate_);
447-
for (uint32_t i = 0; i < length; i++) {
448-
if (i > 0) builder_.AppendCharacter(',');
449-
SerializeSmi(Smi::cast(elements->get(i)));
450-
}
451-
break;
452-
}
453-
case FAST_DOUBLE_ELEMENTS: {
454-
// Empty array is FixedArray but not FixedDoubleArray.
455-
if (length == 0) break;
456-
Handle<FixedDoubleArray> elements(
457-
FixedDoubleArray::cast(object->elements()), isolate_);
458-
for (uint32_t i = 0; i < length; i++) {
459-
if (i > 0) builder_.AppendCharacter(',');
460-
SerializeDouble(elements->get_scalar(i));
461-
}
462-
break;
463-
}
464-
case FAST_ELEMENTS: {
465-
Handle<FixedArray> elements(
466-
FixedArray::cast(object->elements()), isolate_);
467-
for (uint32_t i = 0; i < length; i++) {
468-
if (i > 0) builder_.AppendCharacter(',');
469-
Result result =
470-
SerializeElement(isolate_,
471-
Handle<Object>(elements->get(i), isolate_),
472-
i);
473-
if (result == SUCCESS) continue;
474-
if (result == UNCHANGED) {
475-
builder_.AppendCString("null");
476-
} else {
477-
return result;
478-
}
479-
}
480-
break;
481-
}
482-
// TODO(yangguo): The FAST_HOLEY_* cases could be handled in a faster way.
483-
// They resemble the non-holey cases except that a prototype chain lookup
484-
// is necessary for holes.
485-
default: {
486-
Result result = SerializeJSArraySlow(object, length);
487-
if (result != SUCCESS) return result;
488-
break;
489-
}
490-
}
443+
Result result = SerializeJSArraySlow(object, length);
444+
if (result != SUCCESS) return result;
491445
builder_.AppendCharacter(']');
492446
StackPop();
493447
return SUCCESS;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
var array = [];
6+
var funky = {
7+
toJSON: function() { array.length = 1; return "funky"; }
8+
};
9+
for (var i = 0; i < 10; i++) array[i] = i;
10+
array[0] = funky;
11+
assertEquals('["funky",null,null,null,null,null,null,null,null,null]',
12+
JSON.stringify(array));

0 commit comments

Comments
 (0)