| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Test toJSON produced by a getter. | 98 // Test toJSON produced by a getter. |
| 99 var tojson_via_getter = { get toJSON() { | 99 var tojson_via_getter = { get toJSON() { |
| 100 return function(x) { | 100 return function(x) { |
| 101 counter++; | 101 counter++; |
| 102 return 321; | 102 return 321; |
| 103 }; | 103 }; |
| 104 }, | 104 }, |
| 105 a: 1 }; | 105 a: 1 }; |
| 106 TestStringify('321', tojson_via_getter); | 106 TestStringify('321', tojson_via_getter); |
| 107 | 107 |
| 108 assertThrows(function() { |
| 109 JSON.stringify({ get toJSON() { throw "error"; } }); |
| 110 }); |
| 111 |
| 108 // Test toJSON with key. | 112 // Test toJSON with key. |
| 109 tojson_obj = { toJSON: function(key) { return key + key; } }; | 113 tojson_obj = { toJSON: function(key) { return key + key; } }; |
| 110 var tojson_with_key_1 = { a: tojson_obj, b: tojson_obj }; | 114 var tojson_with_key_1 = { a: tojson_obj, b: tojson_obj }; |
| 111 TestStringify('{"a":"aa","b":"bb"}', tojson_with_key_1); | 115 TestStringify('{"a":"aa","b":"bb"}', tojson_with_key_1); |
| 112 var tojson_with_key_2 = [ tojson_obj, tojson_obj ]; | 116 var tojson_with_key_2 = [ tojson_obj, tojson_obj ]; |
| 113 TestStringify('["00","11"]', tojson_with_key_2); | 117 TestStringify('["00","11"]', tojson_with_key_2); |
| 114 | 118 |
| 115 // Test toJSON with exception. | 119 // Test toJSON with exception. |
| 116 var tojson_ex = { toJSON: function(key) { throw "123" } }; | 120 var tojson_ex = { toJSON: function(key) { throw "123" } }; |
| 117 assertThrows(function() { JSON.stringify(tojson_ex); }); | 121 assertThrows(function() { JSON.stringify(tojson_ex); }); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 non_enum.a = 1; | 176 non_enum.a = 1; |
| 173 Object.defineProperty(non_enum, "b", { value: 2, enumerable: false }); | 177 Object.defineProperty(non_enum, "b", { value: 2, enumerable: false }); |
| 174 non_enum.c = 3; | 178 non_enum.c = 3; |
| 175 TestStringify('{"a":1,"c":3}', non_enum); | 179 TestStringify('{"a":1,"c":3}', non_enum); |
| 176 | 180 |
| 177 var str = "external"; | 181 var str = "external"; |
| 178 try { | 182 try { |
| 179 externalizeString(str, true); | 183 externalizeString(str, true); |
| 180 } catch (e) { } | 184 } catch (e) { } |
| 181 TestStringify("\"external\"", str, null, 0); | 185 TestStringify("\"external\"", str, null, 0); |
| OLD | NEW |