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

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

Issue 655002: Merge revisions 3777-3813 from bleding_edge to partial snapshots ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 10 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 | « test/mjsunit/compiler/simple-global-access.js ('k') | test/mjsunit/mjsunit.status » ('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 // 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TestInvalid('"\\a invalid escape"'); 193 TestInvalid('"\\a invalid escape"');
194 TestInvalid('"\\v invalid escape"'); // Valid JavaScript 194 TestInvalid('"\\v invalid escape"'); // Valid JavaScript
195 TestInvalid('"\\\' invalid escape"'); // Valid JavaScript 195 TestInvalid('"\\\' invalid escape"'); // Valid JavaScript
196 TestInvalid('"\\x42 invalid escape"'); // Valid JavaScript 196 TestInvalid('"\\x42 invalid escape"'); // Valid JavaScript
197 TestInvalid('"\\u202 invalid escape"'); 197 TestInvalid('"\\u202 invalid escape"');
198 TestInvalid('"\\012 invalid escape"'); 198 TestInvalid('"\\012 invalid escape"');
199 TestInvalid('"Unterminated string'); 199 TestInvalid('"Unterminated string');
200 TestInvalid('"Unterminated string\\"'); 200 TestInvalid('"Unterminated string\\"');
201 TestInvalid('"Unterminated string\\\\\\"'); 201 TestInvalid('"Unterminated string\\\\\\"');
202 202
203 // JavaScript RegExp literals not valid in JSON.
204 TestInvalid('/true/');
205
203 // Test bad JSON that would be good JavaScript (ES5). 206 // Test bad JSON that would be good JavaScript (ES5).
204
205 TestInvalid("{true:42}"); 207 TestInvalid("{true:42}");
206 TestInvalid("{false:42}"); 208 TestInvalid("{false:42}");
207 TestInvalid("{null:42}"); 209 TestInvalid("{null:42}");
208 TestInvalid("{'foo':42}"); 210 TestInvalid("{'foo':42}");
209 TestInvalid("{42:42}"); 211 TestInvalid("{42:42}");
210 TestInvalid("{0:42}"); 212 TestInvalid("{0:42}");
211 TestInvalid("{-1:42}"); 213 TestInvalid("{-1:42}");
212 214
213 // Test for trailing garbage detection. 215 // Test for trailing garbage detection.
214
215 TestInvalid('42 px'); 216 TestInvalid('42 px');
216 TestInvalid('42 .2'); 217 TestInvalid('42 .2');
217 TestInvalid('42 2'); 218 TestInvalid('42 2');
218 TestInvalid('42 e1'); 219 TestInvalid('42 e1');
219 TestInvalid('"42" ""'); 220 TestInvalid('"42" ""');
220 TestInvalid('"42" ""'); 221 TestInvalid('"42" ""');
221 TestInvalid('"" ""'); 222 TestInvalid('"" ""');
222 TestInvalid('true ""'); 223 TestInvalid('true ""');
223 TestInvalid('false ""'); 224 TestInvalid('false ""');
224 TestInvalid('null ""'); 225 TestInvalid('null ""');
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 var singleton = []; 271 var singleton = [];
271 var multiOccurrence = [singleton, singleton, singleton]; 272 var multiOccurrence = [singleton, singleton, singleton];
272 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence)); 273 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence));
273 274
274 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6})); 275 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6}));
275 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x'])); 276 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x']));
276 assertEquals('{\n "a": "b",\n "c": "d"\n}', 277 assertEquals('{\n "a": "b",\n "c": "d"\n}',
277 JSON.stringify({a:"b",c:"d"}, null, 1)); 278 JSON.stringify({a:"b",c:"d"}, null, 1));
278 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x'])); 279 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x']));
279 280
281 // The gap is capped at ten characters if specified as string.
282 assertEquals('{\n "a": "b",\n "c": "d"\n}',
283 JSON.stringify({a:"b",c:"d"}, null,
284 " /*characters after 10th*/"));
285
286 //The gap is capped at ten characters if specified as number.
287 assertEquals('{\n "a": "b",\n "c": "d"\n}',
288 JSON.stringify({a:"b",c:"d"}, null, 15));
289
290 // Replaced wrapped primitives are unwrapped.
291 function newx(k, v) { return (k == "x") ? new v(42) : v; }
292 assertEquals('{"x":"42"}', JSON.stringify({x: String}, newx));
293 assertEquals('{"x":42}', JSON.stringify({x: Number}, newx));
294 assertEquals('{"x":true}', JSON.stringify({x: Boolean}, newx));
295
280 assertEquals(undefined, JSON.stringify(undefined)); 296 assertEquals(undefined, JSON.stringify(undefined));
281 assertEquals(undefined, JSON.stringify(function () { })); 297 assertEquals(undefined, JSON.stringify(function () { }));
298 // Arrays with missing, undefined or function elements have those elements
299 // replaced by null.
300 assertEquals("[null,null,null]",
301 JSON.stringify([undefined,,function(){}]));
302
303 // Objects with undefined or function properties (including replaced properties)
304 // have those properties ignored.
305 assertEquals('{}',
306 JSON.stringify({a: undefined, b: function(){}, c: 42, d: 42},
307 function(k, v) { if (k == "c") return undefined;
308 if (k == "d") return function(){};
309 return v; }));
282 310
283 TestInvalid('1); throw "foo"; (1'); 311 TestInvalid('1); throw "foo"; (1');
284 312
285 var x = 0; 313 var x = 0;
286 eval("(1); x++; (1)"); 314 eval("(1); x++; (1)");
287 TestInvalid('1); x++; (1'); 315 TestInvalid('1); x++; (1');
OLDNEW
« no previous file with comments | « test/mjsunit/compiler/simple-global-access.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698