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

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

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 years 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/instanceof-2.js ('k') | test/mjsunit/keyed-call-generic.js » ('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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Date toJSON 28 // Date toJSON
29 assertEquals("1970-01-01T00:00:00.000Z", new Date(0).toJSON()); 29 assertEquals("1970-01-01T00:00:00.000Z", new Date(0).toJSON());
30 assertEquals("1979-01-11T08:00:00.000Z", new Date("1979-01-11 08:00 GMT").toJSON ()); 30 assertEquals("1979-01-11T08:00:00.000Z",
31 assertEquals("2005-05-05T05:05:05.000Z", new Date("2005-05-05 05:05:05 GMT").toJ SON()); 31 new Date("1979-01-11 08:00 GMT").toJSON());
32 assertEquals("2005-05-05T05:05:05.000Z",
33 new Date("2005-05-05 05:05:05 GMT").toJSON());
32 var n1 = new Date(10000); 34 var n1 = new Date(10000);
33 n1.toISOString = function () { return "foo"; }; 35 n1.toISOString = function () { return "foo"; };
34 assertEquals("foo", n1.toJSON()); 36 assertEquals("foo", n1.toJSON());
35 var n2 = new Date(10001); 37 var n2 = new Date(10001);
36 n2.toISOString = null; 38 n2.toISOString = null;
37 assertThrows(function () { n2.toJSON(); }, TypeError); 39 assertThrows(function () { n2.toJSON(); }, TypeError);
38 var n4 = new Date(10003); 40 var n4 = new Date(10003);
39 n4.toISOString = function () { 41 n4.toISOString = function () {
40 assertEquals(0, arguments.length); 42 assertEquals(0, arguments.length);
41 assertEquals(this, n4); 43 assertEquals(this, n4);
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 for (var i = 0; i < 65536; i++) { 324 for (var i = 0; i < 65536; i++) {
323 var string = String.fromCharCode(i); 325 var string = String.fromCharCode(i);
324 var encoded = JSON.stringify(string); 326 var encoded = JSON.stringify(string);
325 var expected = "uninitialized"; 327 var expected = "uninitialized";
326 // Following the ES5 specification of the abstraction function Quote. 328 // Following the ES5 specification of the abstraction function Quote.
327 if (string == '"' || string == '\\') { 329 if (string == '"' || string == '\\') {
328 // Step 2.a 330 // Step 2.a
329 expected = '\\' + string; 331 expected = '\\' + string;
330 } else if ("\b\t\n\r\f".indexOf(string) >= 0) { 332 } else if ("\b\t\n\r\f".indexOf(string) >= 0) {
331 // Step 2.b 333 // Step 2.b
332 if (string == '\b') expected = '\\b'; 334 if (string == '\b') {
333 else if (string == '\t') expected = '\\t'; 335 expected = '\\b';
334 else if (string == '\n') expected = '\\n'; 336 } else if (string == '\t') {
335 else if (string == '\f') expected = '\\f'; 337 expected = '\\t';
336 else if (string == '\r') expected = '\\r'; 338 } else if (string == '\n') {
339 expected = '\\n';
340 } else if (string == '\f') {
341 expected = '\\f';
342 } else if (string == '\r') {
343 expected = '\\r';
344 }
337 } else if (i < 32) { 345 } else if (i < 32) {
338 // Step 2.c 346 // Step 2.c
339 if (i < 16) { 347 if (i < 16) {
340 expected = "\\u000" + i.toString(16); 348 expected = "\\u000" + i.toString(16);
341 } else { 349 } else {
342 expected = "\\u00" + i.toString(16); 350 expected = "\\u00" + i.toString(16);
343 } 351 }
344 } else { 352 } else {
345 expected = string; 353 expected = string;
346 } 354 }
347 assertEquals('"' + expected + '"', encoded, "Codepoint " + i); 355 assertEquals('"' + expected + '"', encoded, "Codepoint " + i);
348 } 356 }
349 357
350 358
351 // Ensure that wrappers and callables are handled correctly. 359 // Ensure that wrappers and callables are handled correctly.
352 var num37 = new Number(42); 360 var num37 = new Number(42);
353 num37.valueOf = function() { return 37; }; 361 num37.valueOf = function() { return 37; };
354 362
355 var numFoo = new Number(42); 363 var numFoo = new Number(42);
356 numFoo.valueOf = "not callable"; 364 numFoo.valueOf = "not callable";
357 numFoo.toString = function() { return "foo"; }; 365 numFoo.toString = function() { return "foo"; };
358 366
359 var numTrue = new Number(42); 367 var numTrue = new Number(42);
360 numTrue.valueOf = function() { return true; } 368 numTrue.valueOf = function() { return true; };
361 369
362 var strFoo = new String("bar"); 370 var strFoo = new String("bar");
363 strFoo.toString = function() { return "foo"; }; 371 strFoo.toString = function() { return "foo"; };
364 372
365 var str37 = new String("bar"); 373 var str37 = new String("bar");
366 str37.toString = "not callable"; 374 str37.toString = "not callable";
367 str37.valueOf = function() { return 37; }; 375 str37.valueOf = function() { return 37; };
368 376
369 var strTrue = new String("bar"); 377 var strTrue = new String("bar");
370 strTrue.toString = function() { return true; } 378 strTrue.toString = function() { return true; };
371 379
372 var func = function() { /* Is callable */ }; 380 var func = function() { /* Is callable */ };
373 381
374 var funcJSON = function() { /* Is callable */ }; 382 var funcJSON = function() { /* Is callable */ };
375 funcJSON.toJSON = function() { return "has toJSON"; }; 383 funcJSON.toJSON = function() { return "has toJSON"; };
376 384
377 var re = /Is callable/; 385 var re = /Is callable/;
378 386
379 var reJSON = /Is callable/; 387 var reJSON = /Is callable/;
380 reJSON.toJSON = function() { return "has toJSON"; }; 388 reJSON.toJSON = function() { return "has toJSON"; };
(...skipping 20 matching lines...) Expand all
401 assertEquals('42', JSON.stringify(counter)); 409 assertEquals('42', JSON.stringify(counter));
402 assertEquals(1, getCount); 410 assertEquals(1, getCount);
403 assertEquals(1, callCount); 411 assertEquals(1, callCount);
404 412
405 var oddball2 = Object(42); 413 var oddball2 = Object(42);
406 var oddball3 = Object("foo"); 414 var oddball3 = Object("foo");
407 oddball3.__proto__ = { __proto__: null, 415 oddball3.__proto__ = { __proto__: null,
408 toString: "not callable", 416 toString: "not callable",
409 valueOf: function() { return true; } }; 417 valueOf: function() { return true; } };
410 oddball2.__proto__ = { __proto__: null, 418 oddball2.__proto__ = { __proto__: null,
411 toJSON: function () { return oddball3; } } 419 toJSON: function () { return oddball3; } };
412 assertEquals('"true"', JSON.stringify(oddball2)); 420 assertEquals('"true"', JSON.stringify(oddball2));
413 421
414 422
415 var falseNum = Object("37"); 423 var falseNum = Object("37");
416 falseNum.__proto__ = Number.prototype; 424 falseNum.__proto__ = Number.prototype;
417 falseNum.toString = function() { return 42; }; 425 falseNum.toString = function() { return 42; };
418 assertEquals('"42"', JSON.stringify(falseNum)); 426 assertEquals('"42"', JSON.stringify(falseNum));
419 427
420 // We don't currently allow plain properties called __proto__ in JSON 428 // We don't currently allow plain properties called __proto__ in JSON
421 // objects in JSON.parse. Instead we read them as we would JS object 429 // objects in JSON.parse. Instead we read them as we would JS object
422 // literals. If we change that, this test should change with it. 430 // literals. If we change that, this test should change with it.
423 // 431 //
424 // Parse a non-object value as __proto__. This must not create a 432 // Parse a non-object value as __proto__. This must not create a
425 // __proto__ property different from the original, and should not 433 // __proto__ property different from the original, and should not
426 // change the original. 434 // change the original.
427 var o = JSON.parse('{"__proto__":5}'); 435 var o = JSON.parse('{"__proto__":5}');
428 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. 436 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed.
429 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. 437 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable.
430
431
432
OLDNEW
« no previous file with comments | « test/mjsunit/instanceof-2.js ('k') | test/mjsunit/keyed-call-generic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698