From dbf1362cbc1274273b7bd21aa591bb5361e1b40e Mon Sep 17 00:00:00 2001 From: Robin Templeton <robin@igalia.com> Date: Mon, 28 May 2018 19:58:02 -0400 Subject: [PATCH] Check that JSON.stringify works with BigInt objects from other realms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is based on André Bargull's test case in <https://bugzilla.mozilla.org/show_bug.cgi?id=1464757>. --- .../JSON/stringify/bigint-cross-realm.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/built-ins/JSON/stringify/bigint-cross-realm.js diff --git a/test/built-ins/JSON/stringify/bigint-cross-realm.js b/test/built-ins/JSON/stringify/bigint-cross-realm.js new file mode 100644 index 0000000000..d2307ddcff --- /dev/null +++ b/test/built-ins/JSON/stringify/bigint-cross-realm.js @@ -0,0 +1,19 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-serializejsonproperty +description: JSON.stringify called with a BigInt object from another realm +features: [BigInt, cross-realm] +---*/ + +var other = $262.createRealm().global; +var wrapped = other.Object(other.BigInt(100)); + +assert.throws(TypeError, () => JSON.stringify(wrapped), + "cross-realm BigInt object without toJSON method"); + +other.BigInt.prototype.toJSON = function () { return this.toString(); }; + +assert.sameValue(JSON.stringify(wrapped), "\"100\"", + "cross-realm BigInt object with toJSON method"); -- GitLab