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

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

Issue 12212011: Make __proto__ a foreign callback on Object.prototype. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added regression test for issue 2441. Created 7 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/harmony/proxies.js ('k') | test/mjsunit/regress/regress-2441.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
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 oddball2.__proto__ = { __proto__: null, 446 oddball2.__proto__ = { __proto__: null,
447 toJSON: function () { return oddball3; } } 447 toJSON: function () { return oddball3; } }
448 assertEquals('"true"', JSON.stringify(oddball2)); 448 assertEquals('"true"', JSON.stringify(oddball2));
449 449
450 450
451 var falseNum = Object("37"); 451 var falseNum = Object("37");
452 falseNum.__proto__ = Number.prototype; 452 falseNum.__proto__ = Number.prototype;
453 falseNum.toString = function() { return 42; }; 453 falseNum.toString = function() { return 42; };
454 assertEquals('"42"', JSON.stringify(falseNum)); 454 assertEquals('"42"', JSON.stringify(falseNum));
455 455
456 // We don't currently allow plain properties called __proto__ in JSON 456 // Parse an object value as __proto__.
457 // objects in JSON.parse. Instead we read them as we would JS object 457 var o1 = JSON.parse('{"__proto__":[]}');
458 // literals. If we change that, this test should change with it. 458 assertEquals([], o1.__proto__);
459 // 459 assertEquals(["__proto__"], Object.keys(o1));
460 // Parse a non-object value as __proto__. This must not create a 460 assertEquals([], Object.getOwnPropertyDescriptor(o1, "__proto__").value);
461 // __proto__ property different from the original, and should not 461 assertEquals(["__proto__"], Object.getOwnPropertyNames(o1));
462 // change the original. 462 assertTrue(o1.hasOwnProperty("__proto__"));
463 var o = JSON.parse('{"__proto__":5}'); 463 assertTrue(Object.prototype.isPrototypeOf(o1));
464 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. 464
465 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. 465 // Parse a non-object value as __proto__.
466 var o2 = JSON.parse('{"__proto__":5}');
467 assertEquals(5, o2.__proto__);
468 assertEquals(["__proto__"], Object.keys(o2));
469 assertEquals(5, Object.getOwnPropertyDescriptor(o2, "__proto__").value);
470 assertEquals(["__proto__"], Object.getOwnPropertyNames(o2));
471 assertTrue(o2.hasOwnProperty("__proto__"));
472 assertTrue(Object.prototype.isPrototypeOf(o2));
466 473
467 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; 474 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}';
468 assertEquals(json, JSON.stringify(JSON.parse(json))); 475 assertEquals(json, JSON.stringify(JSON.parse(json)));
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/proxies.js ('k') | test/mjsunit/regress/regress-2441.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698