Skip to content

Commit 76a552c

Browse files
bnoordhuisrvagg
authored andcommittedDec 3, 2015
deps: backport 6df9a1d from upstream v8
PR-URL: nodejs-private/node-private#6 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 12e70fa commit 76a552c

File tree

2 files changed

+14
-48
lines changed

2 files changed

+14
-48
lines changed
 

‎deps/v8/src/json-stringifier.h

+2-48
Original file line numberDiff line numberDiff line change
@@ -434,54 +434,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray(
434434
uint32_t length = 0;
435435
CHECK(object->length()->ToArrayLength(&length));
436436
builder_.AppendCharacter('[');
437-
switch (object->GetElementsKind()) {
438-
case FAST_SMI_ELEMENTS: {
439-
Handle<FixedArray> elements(
440-
FixedArray::cast(object->elements()), isolate_);
441-
for (uint32_t i = 0; i < length; i++) {
442-
if (i > 0) builder_.AppendCharacter(',');
443-
SerializeSmi(Smi::cast(elements->get(i)));
444-
}
445-
break;
446-
}
447-
case FAST_DOUBLE_ELEMENTS: {
448-
// Empty array is FixedArray but not FixedDoubleArray.
449-
if (length == 0) break;
450-
Handle<FixedDoubleArray> elements(
451-
FixedDoubleArray::cast(object->elements()), isolate_);
452-
for (uint32_t i = 0; i < length; i++) {
453-
if (i > 0) builder_.AppendCharacter(',');
454-
SerializeDouble(elements->get_scalar(i));
455-
}
456-
break;
457-
}
458-
case FAST_ELEMENTS: {
459-
Handle<FixedArray> elements(
460-
FixedArray::cast(object->elements()), isolate_);
461-
for (uint32_t i = 0; i < length; i++) {
462-
if (i > 0) builder_.AppendCharacter(',');
463-
Result result =
464-
SerializeElement(isolate_,
465-
Handle<Object>(elements->get(i), isolate_),
466-
i);
467-
if (result == SUCCESS) continue;
468-
if (result == UNCHANGED) {
469-
builder_.AppendCString("null");
470-
} else {
471-
return result;
472-
}
473-
}
474-
break;
475-
}
476-
// TODO(yangguo): The FAST_HOLEY_* cases could be handled in a faster way.
477-
// They resemble the non-holey cases except that a prototype chain lookup
478-
// is necessary for holes.
479-
default: {
480-
Result result = SerializeJSArraySlow(object, length);
481-
if (result != SUCCESS) return result;
482-
break;
483-
}
484-
}
437+
Result result = SerializeJSArraySlow(object, length);
438+
if (result != SUCCESS) return result;
485439
builder_.AppendCharacter(']');
486440
StackPop();
487441
return SUCCESS;
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)
Please sign in to comment.