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

Unified Diff: src/json-delay.js

Issue 562034: Updated JSON.stringify to newest version of ES5. (Closed)
Patch Set: Created 10 years, 11 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 | « no previous file | test/mjsunit/json.js » ('j') | test/mjsunit/json.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-delay.js
diff --git a/src/json-delay.js b/src/json-delay.js
index 7788f516b8049d0fb7da2b7ac31a69f6faa5d8e2..641f31cec3e5c2e3a92cef35ddbff779eeb48b85 100644
--- a/src/json-delay.js
+++ b/src/json-delay.js
@@ -80,8 +80,9 @@ var characterQuoteCache = {
};
function QuoteSingleJSONCharacter(c) {
- if (c in characterQuoteCache)
+ if (c in characterQuoteCache) {
return characterQuoteCache[c];
+ }
var charCode = c.charCodeAt(0);
var result;
if (charCode < 16) result = '\\u000';
@@ -108,8 +109,9 @@ function StackContains(stack, val) {
}
function SerializeArray(value, replacer, stack, indent, gap) {
- if (StackContains(stack, value))
+ if (StackContains(stack, value)) {
throw MakeTypeError('circular_structure', []);
+ }
stack.push(value);
var stepback = indent;
indent += gap;
@@ -117,9 +119,10 @@ function SerializeArray(value, replacer, stack, indent, gap) {
var len = value.length;
for (var i = 0; i < len; i++) {
var strP = JSONSerialize($String(i), value, replacer, stack,
- indent, gap);
- if (IS_UNDEFINED(strP))
+ indent, gap);
+ if (IS_UNDEFINED(strP)) {
strP = "null";
+ }
partial.push(strP);
}
var final;
@@ -137,8 +140,9 @@ function SerializeArray(value, replacer, stack, indent, gap) {
}
function SerializeObject(value, replacer, stack, indent, gap) {
- if (StackContains(stack, value))
+ if (StackContains(stack, value)) {
throw MakeTypeError('circular_structure', []);
+ }
stack.push(value);
var stepback = indent;
indent += gap;
@@ -188,17 +192,21 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
var value = holder[key];
if (IS_OBJECT(value) && value) {
var toJSON = value.toJSON;
- if (IS_FUNCTION(toJSON))
+ if (IS_FUNCTION(toJSON)) {
value = toJSON.call(value, key);
+ }
}
- if (IS_FUNCTION(replacer))
+ if (IS_FUNCTION(replacer)) {
value = replacer.call(holder, key, value);
+ }
// Unwrap value if necessary
if (IS_OBJECT(value)) {
if (IS_NUMBER_WRAPPER(value)) {
value = $Number(value);
} else if (IS_STRING_WRAPPER(value)) {
value = $String(value);
+ } else if (IS_BOOLEAN_WRAPPER(value)) {
+ value = $Boolean(value);
}
}
switch (typeof value) {
@@ -232,12 +240,17 @@ function JSONStringify(value, replacer, space) {
}
var gap;
if (IS_NUMBER(space)) {
- space = $Math.min(space, 100);
+ space = $Math.min(space, 10);
gap = "";
- for (var i = 0; i < space; i++)
+ for (var i = 0; i < space; i++) {
gap += " ";
+ }
} else if (IS_STRING(space)) {
- gap = space;
+ if (space.length > 10) {
+ gap = space.substring(0, 10);
+ } else {
+ gap = space;
+ }
} else {
gap = "";
}
« no previous file with comments | « no previous file | test/mjsunit/json.js » ('j') | test/mjsunit/json.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698