Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1265)

Unified Diff: src/json.js

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector.cc ('k') | src/jsregexp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
===================================================================
--- src/json.js (revision 6800)
+++ src/json.js (working copy)
@@ -38,7 +38,7 @@
}
} else {
for (var p in val) {
- if (ObjectHasOwnProperty.call(val, p)) {
+ if (%_CallFunction(val, p, ObjectHasOwnProperty)) {
var newElement = Revive(val, p, reviver);
if (IS_UNDEFINED(newElement)) {
delete val[p];
@@ -101,7 +101,7 @@
if (IS_ARRAY(replacer)) {
var length = replacer.length;
for (var i = 0; i < length; i++) {
- if (ObjectHasOwnProperty.call(replacer, i)) {
+ if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) {
var p = replacer[i];
var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) {
@@ -114,7 +114,7 @@
}
} else {
for (var p in value) {
- if (ObjectHasOwnProperty.call(value, p)) {
+ if (%_CallFunction(value, p, ObjectHasOwnProperty)) {
var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) {
var member = %QuoteJSONString(p) + ":";
@@ -179,24 +179,60 @@
function BasicSerializeArray(value, stack, builder) {
+ var len = value.length;
+ if (len == 0) {
+ builder.push("[]");
+ return;
+ }
if (!%PushIfAbsent(stack, value)) {
throw MakeTypeError('circular_structure', []);
}
builder.push("[");
- var len = value.length;
- for (var i = 0; i < len; i++) {
+ 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";
+ }
+ }
+ } 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");
+ 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");
+ } else {
+ var before = builder.length;
+ BasicJSONSerialize(i, value[i], stack, builder);
+ if (before == builder.length) builder[before - 1] = ",null";
+ }
+ }
+ } else {
var before = builder.length;
- BasicJSONSerialize(i, value, stack, builder);
+ BasicJSONSerialize(0, val, stack, builder);
if (before == builder.length) builder.push("null");
- builder.push(",");
+ for (var i = 1; i < len; i++) {
+ builder.push(",");
+ before = builder.length;
+ val = value[i];
+ BasicJSONSerialize(i, val, stack, builder);
+ if (before == builder.length) builder[before - 1] = ",null";
+ }
}
stack.pop();
- if (builder.pop() != ",") {
- builder.push("[]"); // Zero length array. Push "[" back on.
- } else {
- builder.push("]");
- }
-
+ builder.push("]");
}
@@ -205,31 +241,31 @@
throw MakeTypeError('circular_structure', []);
}
builder.push("{");
+ var first = true;
for (var p in value) {
if (%HasLocalProperty(value, p)) {
- builder.push(%QuoteJSONString(p));
+ if (!first) {
+ builder.push(%QuoteJSONStringComma(p));
+ } else {
+ builder.push(%QuoteJSONString(p));
+ }
builder.push(":");
var before = builder.length;
- BasicJSONSerialize(p, value, stack, builder);
+ BasicJSONSerialize(p, value[p], stack, builder);
if (before == builder.length) {
builder.pop();
builder.pop();
} else {
- builder.push(",");
+ first = false;
}
}
}
stack.pop();
- if (builder.pop() != ",") {
- builder.push("{}"); // Object has no own properties. Push "{" back on.
- } else {
- builder.push("}");
- }
+ builder.push("}");
}
-function BasicJSONSerialize(key, holder, stack, builder) {
- var value = holder[key];
+function BasicJSONSerialize(key, value, stack, builder) {
if (IS_SPEC_OBJECT(value)) {
var toJSON = value.toJSON;
if (IS_FUNCTION(toJSON)) {
@@ -266,7 +302,7 @@
function JSONStringify(value, replacer, space) {
if (%_ArgumentsLength() == 1) {
var builder = [];
- BasicJSONSerialize('', {'': value}, [], builder);
+ BasicJSONSerialize('', value, [], builder);
if (builder.length == 0) return;
var result = %_FastAsciiArrayJoin(builder, "");
if (!IS_UNDEFINED(result)) return result;
Property changes on: src/json.js
___________________________________________________________________
Modified: svn:mergeinfo
Merged /branches/bleeding_edge/src/json.js:r6169-6800
« no previous file with comments | « src/inspector.cc ('k') | src/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698