value-bigint-tojson-receiver.js (820B)
1 // Copyright 2019 Igalia, S.L. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 // Test case written by André Bargull. 4 5 /*--- 6 esid: sec-serializejsonproperty 7 description: toJSON method called with BigInt as receiver 8 features: [BigInt] 9 ---*/ 10 11 assert.throws(TypeError, () => JSON.stringify(1n), 12 "toString throws for BigInt object"); 13 14 // The BigInt proposal changes the SerializeJSONProperty algorithm to 15 // specifically allow passing BigInt objects as receivers for the toJSON 16 // method. 17 Object.defineProperty(BigInt.prototype, "toJSON", { 18 get() { 19 "use strict"; 20 return () => typeof this; 21 } 22 }); 23 24 assert.sameValue(JSON.stringify(1n), "\"bigint\"", 25 "BigInt toJSON method called with value as receiver"); 26 27 reportCompare(0, 0);