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

Unified Diff: src/json.js

Issue 1200373003: JSON.stringify should handle the replacer before the space (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 6 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-replacer-order.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
diff --git a/src/json.js b/src/json.js
index fe820f9b06f928ffe657c478f71360fb297f775d..e405f87bab6b39a6905304adbc66ebd8f421d00d 100644
--- a/src/json.js
+++ b/src/json.js
@@ -183,27 +183,6 @@ function JSONStringify(value, replacer, space) {
if (%_ArgumentsLength() == 1) {
return %BasicJSONStringify(value);
}
- if (IS_OBJECT(space)) {
- // Unwrap 'space' if it is wrapped
- if (IS_NUMBER_WRAPPER(space)) {
- space = $toNumber(space);
- } else if (IS_STRING_WRAPPER(space)) {
- space = $toString(space);
- }
- }
- var gap;
- if (IS_NUMBER(space)) {
- space = MathMax(0, MathMin($toInteger(space), 10));
- gap = %_SubString(" ", 0, space);
- } else if (IS_STRING(space)) {
- if (space.length > 10) {
- gap = %_SubString(space, 0, 10);
- } else {
- gap = space;
- }
- } else {
- gap = "";
- }
if (IS_ARRAY(replacer)) {
// Deduplicate replacer array items.
var property_list = new InternalArray();
@@ -228,6 +207,27 @@ function JSONStringify(value, replacer, space) {
}
replacer = property_list;
}
+ if (IS_OBJECT(space)) {
+ // Unwrap 'space' if it is wrapped
+ if (IS_NUMBER_WRAPPER(space)) {
+ space = $toNumber(space);
+ } else if (IS_STRING_WRAPPER(space)) {
+ space = $toString(space);
+ }
+ }
+ var gap;
+ if (IS_NUMBER(space)) {
+ space = MathMax(0, MathMin($toInteger(space), 10));
+ gap = %_SubString(" ", 0, space);
+ } else if (IS_STRING(space)) {
+ if (space.length > 10) {
+ gap = %_SubString(space, 0, 10);
+ } else {
+ gap = space;
+ }
+ } else {
+ gap = "";
+ }
return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
}
« no previous file with comments | « no previous file | test/mjsunit/json-replacer-order.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698