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

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

Issue 11312063: Fix JSON.stringify wrt harmony proxies. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 8 years, 1 month 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-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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 tojson_obj = { toJSON: function(key) { return key + key; } }; 102 tojson_obj = { toJSON: function(key) { return key + key; } };
103 var tojson_with_key_1 = { a: tojson_obj, b: tojson_obj }; 103 var tojson_with_key_1 = { a: tojson_obj, b: tojson_obj };
104 assertEquals('{"a":"aa","b":"bb"}', JSON.stringify(tojson_with_key_1)); 104 assertEquals('{"a":"aa","b":"bb"}', JSON.stringify(tojson_with_key_1));
105 var tojson_with_key_2 = [ tojson_obj, tojson_obj ]; 105 var tojson_with_key_2 = [ tojson_obj, tojson_obj ];
106 assertEquals('["00","11"]', JSON.stringify(tojson_with_key_2)); 106 assertEquals('["00","11"]', JSON.stringify(tojson_with_key_2));
107 107
108 // Test toJSON with exception. 108 // Test toJSON with exception.
109 var tojson_ex = { toJSON: function(key) { throw "123" } }; 109 var tojson_ex = { toJSON: function(key) { throw "123" } };
110 assertThrows(function() { JSON.stringify(tojson_ex); }); 110 assertThrows(function() { JSON.stringify(tojson_ex); });
111 111
112 // Test toJSON with access to this.
113 var obj = { toJSON: function(key) { return this.a + key; }, a: "x" };
114 assertEquals('{"y":"xy"}', JSON.stringify({y: obj}));
115
112 // Test holes in arrays. 116 // Test holes in arrays.
113 var fast_smi = [1, 2, 3, 4]; 117 var fast_smi = [1, 2, 3, 4];
114 fast_smi.__proto__ = [7, 7, 7, 7]; 118 fast_smi.__proto__ = [7, 7, 7, 7];
115 delete fast_smi[2]; 119 delete fast_smi[2];
116 assertTrue(%HasFastSmiElements(fast_smi)); 120 assertTrue(%HasFastSmiElements(fast_smi));
117 assertEquals("[1,2,7,4]", JSON.stringify(fast_smi)); 121 assertEquals("[1,2,7,4]", JSON.stringify(fast_smi));
118 122
119 var fast_double = [1.1, 2, 3, 4]; 123 var fast_double = [1.1, 2, 3, 4];
120 fast_double.__proto__ = [7, 7, 7, 7]; 124 fast_double.__proto__ = [7, 7, 7, 7];
121 125
122 delete fast_double[2]; 126 delete fast_double[2];
123 assertTrue(%HasFastDoubleElements(fast_double)); 127 assertTrue(%HasFastDoubleElements(fast_double));
124 assertEquals("[1.1,2,7,4]", JSON.stringify(fast_double)); 128 assertEquals("[1.1,2,7,4]", JSON.stringify(fast_double));
125 129
126 var fast_obj = [1, 2, {}, {}]; 130 var fast_obj = [1, 2, {}, {}];
127 fast_obj.__proto__ = [7, 7, 7, 7]; 131 fast_obj.__proto__ = [7, 7, 7, 7];
128 132
129 delete fast_obj[2]; 133 delete fast_obj[2];
130 assertTrue(%HasFastObjectElements(fast_obj)); 134 assertTrue(%HasFastObjectElements(fast_obj));
131 assertEquals("[1,2,7,{}]", JSON.stringify(fast_obj)); 135 assertEquals("[1,2,7,{}]", JSON.stringify(fast_obj));
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/proxies-json.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698