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

Side by Side Diff: src/json.js

Issue 10905059: Directly use %ObjectKeys in json stringify. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 builder.push("]"); 240 builder.push("]");
241 } 241 }
242 242
243 243
244 function BasicSerializeObject(value, stack, builder) { 244 function BasicSerializeObject(value, stack, builder) {
245 if (!%PushIfAbsent(stack, value)) { 245 if (!%PushIfAbsent(stack, value)) {
246 throw MakeTypeError('circular_structure', $Array()); 246 throw MakeTypeError('circular_structure', $Array());
247 } 247 }
248 builder.push("{"); 248 builder.push("{");
249 var first = true; 249 var first = true;
250 for (var p in value) { 250 var keys = %ObjectKeys(value);
251 if (%HasLocalProperty(value, p)) { 251 var len = keys.length;
252 if (!first) { 252 for (var i = 0; i < len; i++) {
253 builder.push(%QuoteJSONStringComma(p)); 253 var p = keys[i];
254 } else { 254 if (!first) {
255 builder.push(%QuoteJSONString(p)); 255 builder.push(%QuoteJSONStringComma(p));
256 } 256 } else {
257 builder.push(":"); 257 builder.push(%QuoteJSONString(p));
258 var before = builder.length; 258 }
259 BasicJSONSerialize(p, value[p], stack, builder); 259 builder.push(":");
260 if (before == builder.length) { 260 var before = builder.length;
261 builder.pop(); 261 BasicJSONSerialize(p, value[p], stack, builder);
262 builder.pop(); 262 if (before == builder.length) {
263 } else { 263 builder.pop();
264 first = false; 264 builder.pop();
265 } 265 } else {
266 first = false;
266 } 267 }
267 } 268 }
268 stack.pop(); 269 stack.pop();
269 builder.push("}"); 270 builder.push("}");
270 } 271 }
271 272
272 273
273 function BasicJSONSerialize(key, value, stack, builder) { 274 function BasicJSONSerialize(key, value, stack, builder) {
274 if (IS_SPEC_OBJECT(value)) { 275 if (IS_SPEC_OBJECT(value)) {
275 var toJSON = value.toJSON; 276 var toJSON = value.toJSON;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 340
340 function SetUpJSON() { 341 function SetUpJSON() {
341 %CheckIsBootstrapping(); 342 %CheckIsBootstrapping();
342 InstallFunctions($JSON, DONT_ENUM, $Array( 343 InstallFunctions($JSON, DONT_ENUM, $Array(
343 "parse", JSONParse, 344 "parse", JSONParse,
344 "stringify", JSONStringify 345 "stringify", JSONStringify
345 )); 346 ));
346 } 347 }
347 348
348 SetUpJSON(); 349 SetUpJSON();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698