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

Side by Side Diff: test/mjsunit/json.js

Issue 3336001: Make JSON.stringify not quote non-ASCII characters. Fix bug 855. (Closed)
Patch Set: Created 10 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
« no previous file with comments | « src/json.js ('k') | 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 TestInvalid('1); throw "foo"; (1'); 311 TestInvalid('1); throw "foo"; (1');
312 312
313 var x = 0; 313 var x = 0;
314 eval("(1); x++; (1)"); 314 eval("(1); x++; (1)");
315 TestInvalid('1); x++; (1'); 315 TestInvalid('1); x++; (1');
316 316
317 // Test string conversion of argument. 317 // Test string conversion of argument.
318 var o = { toString: function() { return "42"; } }; 318 var o = { toString: function() { return "42"; } };
319 assertEquals(42, JSON.parse(o)); 319 assertEquals(42, JSON.parse(o));
320
321
322 for (var i = 0; i < 65536; i++) {
323 var string = String.fromCharCode(i);
324 var encoded = JSON.stringify(string);
325 var expected = "uninitialized";
326 // Following the ES5 specification of the abstraction function Quote.
327 if (string == '"' || string == '\\') {
328 // Step 2.a
329 expected = '\\' + string;
330 } else if ("\b\t\n\r\f".indexOf(string) >= 0) {
331 // Step 2.b
332 if (string == '\b') expected = '\\b';
333 else if (string == '\t') expected = '\\t';
334 else if (string == '\n') expected = '\\n';
335 else if (string == '\f') expected = '\\f';
336 else if (string == '\r') expected = '\\r';
337 } else if (i < 32) {
338 // Step 2.c
339 if (i < 16) {
340 expected = "\\u000" + i.toString(16);
Rico 2010/09/01 14:48:20 Indention off
341 } else {
342 expected = "\\u00" + i.toString(16);
Rico 2010/09/01 14:48:20 Indention off
343 }
344 } else {
345 expected = string;
346 }
347 assertEquals('"' + expected + '"', encoded, "Codepoint " + i);
348 }
OLDNEW
« no previous file with comments | « src/json.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698