summaryrefslogtreecommitdiff
path: root/deps/v8/src/json.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/json.js')
-rw-r--r--deps/v8/src/json.js69
1 files changed, 37 insertions, 32 deletions
diff --git a/deps/v8/src/json.js b/deps/v8/src/json.js
index e6ada51b48..6c984a157d 100644
--- a/deps/v8/src/json.js
+++ b/deps/v8/src/json.js
@@ -49,7 +49,7 @@ function Revive(holder, name, reviver) {
}
}
}
- return reviver.call(holder, name, val);
+ return %_CallFunction(holder, name, val, reviver);
}
function JSONParse(text, reviver) {
@@ -63,11 +63,11 @@ function JSONParse(text, reviver) {
function SerializeArray(value, replacer, stack, indent, gap) {
if (!%PushIfAbsent(stack, value)) {
- throw MakeTypeError('circular_structure', []);
+ throw MakeTypeError('circular_structure', $Array());
}
var stepback = indent;
indent += gap;
- var partial = [];
+ var partial = new InternalArray();
var len = value.length;
for (var i = 0; i < len; i++) {
var strP = JSONSerialize($String(i), value, replacer, stack,
@@ -93,11 +93,11 @@ function SerializeArray(value, replacer, stack, indent, gap) {
function SerializeObject(value, replacer, stack, indent, gap) {
if (!%PushIfAbsent(stack, value)) {
- throw MakeTypeError('circular_structure', []);
+ throw MakeTypeError('circular_structure', $Array());
}
var stepback = indent;
indent += gap;
- var partial = [];
+ var partial = new InternalArray();
if (IS_ARRAY(replacer)) {
var length = replacer.length;
for (var i = 0; i < length; i++) {
@@ -153,7 +153,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
if (IS_STRING(value)) {
return %QuoteJSONString(value);
} else if (IS_NUMBER(value)) {
- return NUMBER_IS_FINITE(value) ? $String(value) : "null";
+ return JSON_NUMBER_TO_STRING(value);
} else if (IS_BOOLEAN(value)) {
return value ? "true" : "false";
} else if (IS_NULL(value)) {
@@ -164,7 +164,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
return SerializeArray(value, replacer, stack, indent, gap);
} else if (IS_NUMBER_WRAPPER(value)) {
value = ToNumber(value);
- return NUMBER_IS_FINITE(value) ? ToString(value) : "null";
+ return JSON_NUMBER_TO_STRING(value);
} else if (IS_STRING_WRAPPER(value)) {
return %QuoteJSONString(ToString(value));
} else if (IS_BOOLEAN_WRAPPER(value)) {
@@ -185,37 +185,43 @@ function BasicSerializeArray(value, stack, builder) {
return;
}
if (!%PushIfAbsent(stack, value)) {
- throw MakeTypeError('circular_structure', []);
+ throw MakeTypeError('circular_structure', $Array());
}
builder.push("[");
var val = value[0];
if (IS_STRING(val)) {
// First entry is a string. Remaining entries are likely to be strings too.
- builder.push(%QuoteJSONString(val));
- for (var i = 1; i < len; i++) {
- val = value[i];
- if (IS_STRING(val)) {
- builder.push(%QuoteJSONStringComma(val));
- } else {
- builder.push(",");
- var before = builder.length;
- BasicJSONSerialize(i, value[i], stack, builder);
- if (before == builder.length) builder[before - 1] = ",null";
+ var array_string = %QuoteJSONStringArray(value);
+ if (!IS_UNDEFINED(array_string)) {
+ // array_string also includes bracket characters so we are done.
+ builder[builder.length - 1] = array_string;
+ stack.pop();
+ return;
+ } else {
+ builder.push(%QuoteJSONString(val));
+ for (var i = 1; i < len; i++) {
+ val = value[i];
+ if (IS_STRING(val)) {
+ builder.push(%QuoteJSONStringComma(val));
+ } else {
+ builder.push(",");
+ var before = builder.length;
+ BasicJSONSerialize(i, val, stack, builder);
+ if (before == builder.length) builder[before - 1] = ",null";
+ }
}
}
} else if (IS_NUMBER(val)) {
// First entry is a number. Remaining entries are likely to be numbers too.
- builder.push(NUMBER_IS_FINITE(val) ? %_NumberToString(val) : "null");
+ builder.push(JSON_NUMBER_TO_STRING(val));
for (var i = 1; i < len; i++) {
builder.push(",");
val = value[i];
if (IS_NUMBER(val)) {
- builder.push(NUMBER_IS_FINITE(val)
- ? %_NumberToString(val)
- : "null");
+ builder.push(JSON_NUMBER_TO_STRING(val));
} else {
var before = builder.length;
- BasicJSONSerialize(i, value[i], stack, builder);
+ BasicJSONSerialize(i, val, stack, builder);
if (before == builder.length) builder[before - 1] = ",null";
}
}
@@ -226,8 +232,7 @@ function BasicSerializeArray(value, stack, builder) {
for (var i = 1; i < len; i++) {
builder.push(",");
before = builder.length;
- val = value[i];
- BasicJSONSerialize(i, val, stack, builder);
+ BasicJSONSerialize(i, value[i], stack, builder);
if (before == builder.length) builder[before - 1] = ",null";
}
}
@@ -238,7 +243,7 @@ function BasicSerializeArray(value, stack, builder) {
function BasicSerializeObject(value, stack, builder) {
if (!%PushIfAbsent(stack, value)) {
- throw MakeTypeError('circular_structure', []);
+ throw MakeTypeError('circular_structure', $Array());
}
builder.push("{");
var first = true;
@@ -273,9 +278,9 @@ function BasicJSONSerialize(key, value, stack, builder) {
}
}
if (IS_STRING(value)) {
- builder.push(%QuoteJSONString(value));
+ builder.push(value !== "" ? %QuoteJSONString(value) : '""');
} else if (IS_NUMBER(value)) {
- builder.push(NUMBER_IS_FINITE(value) ? %_NumberToString(value) : "null");
+ builder.push(JSON_NUMBER_TO_STRING(value));
} else if (IS_BOOLEAN(value)) {
builder.push(value ? "true" : "false");
} else if (IS_NULL(value)) {
@@ -285,7 +290,7 @@ function BasicJSONSerialize(key, value, stack, builder) {
// Unwrap value if necessary
if (IS_NUMBER_WRAPPER(value)) {
value = ToNumber(value);
- builder.push(NUMBER_IS_FINITE(value) ? %_NumberToString(value) : "null");
+ builder.push(JSON_NUMBER_TO_STRING(value));
} else if (IS_STRING_WRAPPER(value)) {
builder.push(%QuoteJSONString(ToString(value)));
} else if (IS_BOOLEAN_WRAPPER(value)) {
@@ -301,8 +306,8 @@ function BasicJSONSerialize(key, value, stack, builder) {
function JSONStringify(value, replacer, space) {
if (%_ArgumentsLength() == 1) {
- var builder = [];
- BasicJSONSerialize('', value, [], builder);
+ var builder = new InternalArray();
+ BasicJSONSerialize('', value, new InternalArray(), builder);
if (builder.length == 0) return;
var result = %_FastAsciiArrayJoin(builder, "");
if (!IS_UNDEFINED(result)) return result;
@@ -329,7 +334,7 @@ function JSONStringify(value, replacer, space) {
} else {
gap = "";
}
- return JSONSerialize('', {'': value}, replacer, [], "", gap);
+ return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
}
function SetupJSON() {