| OLD | NEW | 
|    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  Loading... | 
|  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; }, | 
 |  114     a: "x" }; | 
 |  115 assertEquals('{"y":"xy"}', JSON.stringify({y: obj})); | 
 |  116  | 
|  112 // Test holes in arrays. |  117 // Test holes in arrays. | 
|  113 var fast_smi = [1, 2, 3, 4]; |  118 var fast_smi = [1, 2, 3, 4]; | 
|  114 fast_smi.__proto__ = [7, 7, 7, 7]; |  119 fast_smi.__proto__ = [7, 7, 7, 7]; | 
|  115 delete fast_smi[2]; |  120 delete fast_smi[2]; | 
|  116 assertTrue(%HasFastSmiElements(fast_smi)); |  121 assertTrue(%HasFastSmiElements(fast_smi)); | 
|  117 assertEquals("[1,2,7,4]", JSON.stringify(fast_smi)); |  122 assertEquals("[1,2,7,4]", JSON.stringify(fast_smi)); | 
|  118  |  123  | 
|  119 var fast_double = [1.1, 2, 3, 4]; |  124 var fast_double = [1.1, 2, 3, 4]; | 
|  120 fast_double.__proto__ = [7, 7, 7, 7]; |  125 fast_double.__proto__ = [7, 7, 7, 7]; | 
|  121  |  126  | 
|  122 delete fast_double[2]; |  127 delete fast_double[2]; | 
|  123 assertTrue(%HasFastDoubleElements(fast_double)); |  128 assertTrue(%HasFastDoubleElements(fast_double)); | 
|  124 assertEquals("[1.1,2,7,4]", JSON.stringify(fast_double)); |  129 assertEquals("[1.1,2,7,4]", JSON.stringify(fast_double)); | 
|  125  |  130  | 
|  126 var fast_obj = [1, 2, {}, {}]; |  131 var fast_obj = [1, 2, {}, {}]; | 
|  127 fast_obj.__proto__ = [7, 7, 7, 7]; |  132 fast_obj.__proto__ = [7, 7, 7, 7]; | 
|  128  |  133  | 
|  129 delete fast_obj[2]; |  134 delete fast_obj[2]; | 
|  130 assertTrue(%HasFastObjectElements(fast_obj)); |  135 assertTrue(%HasFastObjectElements(fast_obj)); | 
|  131 assertEquals("[1,2,7,{}]", JSON.stringify(fast_obj)); |  136 assertEquals("[1,2,7,{}]", JSON.stringify(fast_obj)); | 
| OLD | NEW |