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

Side by Side Diff: src/js/json.js

Issue 1994183002: [json] handle proxies in BasicJsonSerializer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comments Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « src/builtins.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } else { 194 } else {
195 return SerializeObject(value, replacer, stack, indent, gap); 195 return SerializeObject(value, replacer, stack, indent, gap);
196 } 196 }
197 } 197 }
198 // Undefined or a callable object. 198 // Undefined or a callable object.
199 return UNDEFINED; 199 return UNDEFINED;
200 } 200 }
201 201
202 202
203 function JSONStringify(value, replacer, space) { 203 function JSONStringify(value, replacer, space) {
204 if (arguments.length === 1 && !IS_PROXY(value)) { 204 if (arguments.length === 1) return %BasicJSONStringify(value, "");
205 return %BasicJSONStringify(value, "");
206 }
207 if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) { 205 if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) {
208 var property_list = new InternalArray(); 206 var property_list = new InternalArray();
209 var seen_properties = new GlobalSet(); 207 var seen_properties = new GlobalSet();
210 var length = TO_LENGTH(replacer.length); 208 var length = TO_LENGTH(replacer.length);
211 for (var i = 0; i < length; i++) { 209 for (var i = 0; i < length; i++) {
212 var v = replacer[i]; 210 var v = replacer[i];
213 var item; 211 var item;
214 if (IS_STRING(v)) { 212 if (IS_STRING(v)) {
215 item = v; 213 item = v;
216 } else if (IS_NUMBER(v)) { 214 } else if (IS_NUMBER(v)) {
(...skipping 24 matching lines...) Expand all
241 gap = %_SubString(" ", 0, space); 239 gap = %_SubString(" ", 0, space);
242 } else if (IS_STRING(space)) { 240 } else if (IS_STRING(space)) {
243 if (space.length > 10) { 241 if (space.length > 10) {
244 gap = %_SubString(space, 0, 10); 242 gap = %_SubString(space, 0, 10);
245 } else { 243 } else {
246 gap = space; 244 gap = space;
247 } 245 }
248 } else { 246 } else {
249 gap = ""; 247 gap = "";
250 } 248 }
251 if (!IS_CALLABLE(replacer) && !property_list && !IS_PROXY(value)) { 249 if (!IS_CALLABLE(replacer) && !property_list) {
252 return %BasicJSONStringify(value, gap); 250 return %BasicJSONStringify(value, gap);
253 } 251 }
254 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap); 252 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap);
255 } 253 }
256 254
257 // ------------------------------------------------------------------- 255 // -------------------------------------------------------------------
258 256
259 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); 257 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM);
260 258
261 // Set up non-enumerable properties of the JSON object. 259 // Set up non-enumerable properties of the JSON object.
(...skipping 29 matching lines...) Expand all
291 // No need to pass the actual holder since there is no replacer function. 289 // No need to pass the actual holder since there is no replacer function.
292 var current_indent = ""; 290 var current_indent = "";
293 for (var i = 0; i < indent; i++) current_indent += gap; 291 for (var i = 0; i < indent; i++) current_indent += gap;
294 return JSONSerialize( 292 return JSONSerialize(
295 key, holder, UNDEFINED, new Stack(), current_indent, gap); 293 key, holder, UNDEFINED, new Stack(), current_indent, gap);
296 } 294 }
297 295
298 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); 296 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]);
299 297
300 }) 298 })
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698