From 8ca8f06ba1b8ad4070d9cf977e6a976dd08101e0 Mon Sep 17 00:00:00 2001 From: Robin Templeton Date: Thu, 21 Sep 2017 18:38:51 -0400 Subject: [PATCH 1/2] BigInt.prototype.toString --- .../BigInt/prototype/toString/length.js | 19 +++++++++++++++ .../BigInt/prototype/toString/name.js | 19 +++++++++++++++ .../BigInt/prototype/toString/non-bigint.js | 16 +++++++++++++ .../BigInt/prototype/toString/prop-desc.js | 18 ++++++++++++++ .../prototype/toString/prototype-call.js | 20 ++++++++++++++++ .../prototype/toString/radix-2-to-36.js | 24 +++++++++++++++++++ .../BigInt/prototype/toString/radix-err.js | 21 ++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 test/built-ins/BigInt/prototype/toString/length.js create mode 100644 test/built-ins/BigInt/prototype/toString/name.js create mode 100644 test/built-ins/BigInt/prototype/toString/non-bigint.js create mode 100644 test/built-ins/BigInt/prototype/toString/prop-desc.js create mode 100644 test/built-ins/BigInt/prototype/toString/prototype-call.js create mode 100644 test/built-ins/BigInt/prototype/toString/radix-2-to-36.js create mode 100644 test/built-ins/BigInt/prototype/toString/radix-err.js diff --git a/test/built-ins/BigInt/prototype/toString/length.js b/test/built-ins/BigInt/prototype/toString/length.js new file mode 100644 index 0000000000..b5cc5fb399 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/length.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString.length property descriptor +info: > + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(BigInt.prototype.toString, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/prototype/toString/name.js b/test/built-ins/BigInt/prototype/toString/name.js new file mode 100644 index 0000000000..f78ba20c46 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/name.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString.name property descriptor +info: > + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(BigInt.prototype.toString, "name", { + value: "toString", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/prototype/toString/non-bigint.js b/test/built-ins/BigInt/prototype/toString/non-bigint.js new file mode 100644 index 0000000000..761cec1c33 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/non-bigint.js @@ -0,0 +1,16 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: Transferring toString to non-BigInt objects +info: > + BigInt.prototype.toString ( [ radix ] ) + + 1. Let x be ? thisBigIntValue(this value). +---*/ + +for (let x of [new String(), new Boolean(), new Date(), new Object(), {x: 1}]) { + x.toString = Number.prototype.toString; + assert.throws(TypeError, () => x.toString()); +} diff --git a/test/built-ins/BigInt/prototype/toString/prop-desc.js b/test/built-ins/BigInt/prototype/toString/prop-desc.js new file mode 100644 index 0000000000..b9840050e5 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString property descriptor +info: > + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(BigInt.prototype, "toString", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/prototype/toString/prototype-call.js b/test/built-ins/BigInt/prototype/toString/prototype-call.js new file mode 100644 index 0000000000..ae2b0e8cd9 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/prototype-call.js @@ -0,0 +1,20 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: Direct toString on BigInt prototype +info: > + BigInt.prototype.toString ( [ radix ] ) + + Let x be ? thisBigIntValue(this value). + + Properties of the BigInt Prototype Object + + The BigInt prototype is not a BigInt object; it does not have a + [[BigIntData]] internal slot. +---*/ + +assert.throws(TypeError, () => BigInt.prototype.toString()); +assert.throws(TypeError, () => BigInt.prototype.toString(10)); +assert.throws(TypeError, () => BigInt.prototype.toString(undefined)); diff --git a/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js b/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js new file mode 100644 index 0000000000..e03eb66d73 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js @@ -0,0 +1,24 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: toString with radix between 2 and 36 +info: > + BigInt.prototype.toString ( [ radix ] ) + + [...] + 6. If radixNumber = 10, return ! ToString(x). + 7. Return the String representation of this Number value using the + radix specified by radixNumber. Letters a-z are used for digits + with values 10 through 35. The precise algorithm is + implementation-dependent, however the algorithm should be a + generalization of that specified in 3.1.4.1. +---*/ + +for (let r = 2; r <= 36; r++) { + assert.throws(TypeError, () => BigInt.prototype.toString(r)); + assert.sameValue((0n).toString(r), "0", "0, radix " + r); + assert.sameValue((-1n).toString(r), "-1", "-1, radix " + r); + assert.sameValue((1n).toString(r), "1", "1, radix " + r); +} diff --git a/test/built-ins/BigInt/prototype/toString/radix-err.js b/test/built-ins/BigInt/prototype/toString/radix-err.js new file mode 100644 index 0000000000..18d6574a31 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/radix-err.js @@ -0,0 +1,21 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: toString with invalid radix +info: > + BigInt.prototype.toString ( [ radix ] ) + + [...] + 4. Else, let radixNumber be ? ToInteger(radix). + 5. If radixNumber < 2 or radixNumber > 36, throw a RangeError + exception. +---*/ + +for (let r of [0, 1, 37, null]) { + assert.throws(TypeError, () => BigInt.prototype.toString(r)); + assert.throws(RangeError, () => (0n).toString(r), "0, radix " + r); + assert.throws(RangeError, () => (-1n).toString(r), "-1, radix " + r); + assert.throws(RangeError, () => (1n).toString(r), "1, radix " + r); +} From b77af3aa0f4a1cc68d2e870fe3f6d9865ebf16d2 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Thu, 12 Oct 2017 16:19:46 -0400 Subject: [PATCH 2/2] Update tests for BigInt.prototype.toString --- .../BigInt/prototype/toString/length.js | 1 + .../BigInt/prototype/toString/name.js | 1 + .../BigInt/prototype/toString/non-bigint.js | 16 ----- .../BigInt/prototype/toString/prop-desc.js | 1 + .../prototype/toString/prototype-call.js | 7 +- .../prototype/toString/radix-2-to-36.js | 2 +- .../BigInt/prototype/toString/radix-err.js | 14 ++-- .../thisbigintvalue-not-valid-throws.js | 67 +++++++++++++++++++ 8 files changed, 85 insertions(+), 24 deletions(-) delete mode 100644 test/built-ins/BigInt/prototype/toString/non-bigint.js create mode 100644 test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js diff --git a/test/built-ins/BigInt/prototype/toString/length.js b/test/built-ins/BigInt/prototype/toString/length.js index b5cc5fb399..03975ff344 100644 --- a/test/built-ins/BigInt/prototype/toString/length.js +++ b/test/built-ins/BigInt/prototype/toString/length.js @@ -9,6 +9,7 @@ info: > 17 ECMAScript Standard Built-in Objects includes: [propertyHelper.js] +features: [BigInt] ---*/ verifyProperty(BigInt.prototype.toString, "length", { diff --git a/test/built-ins/BigInt/prototype/toString/name.js b/test/built-ins/BigInt/prototype/toString/name.js index f78ba20c46..6c7ed3243b 100644 --- a/test/built-ins/BigInt/prototype/toString/name.js +++ b/test/built-ins/BigInt/prototype/toString/name.js @@ -9,6 +9,7 @@ info: > 17 ECMAScript Standard Built-in Objects includes: [propertyHelper.js] +features: [BigInt] ---*/ verifyProperty(BigInt.prototype.toString, "name", { diff --git a/test/built-ins/BigInt/prototype/toString/non-bigint.js b/test/built-ins/BigInt/prototype/toString/non-bigint.js deleted file mode 100644 index 761cec1c33..0000000000 --- a/test/built-ins/BigInt/prototype/toString/non-bigint.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 Robin Templeton. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-bigint.prototype.tostring -description: Transferring toString to non-BigInt objects -info: > - BigInt.prototype.toString ( [ radix ] ) - - 1. Let x be ? thisBigIntValue(this value). ----*/ - -for (let x of [new String(), new Boolean(), new Date(), new Object(), {x: 1}]) { - x.toString = Number.prototype.toString; - assert.throws(TypeError, () => x.toString()); -} diff --git a/test/built-ins/BigInt/prototype/toString/prop-desc.js b/test/built-ins/BigInt/prototype/toString/prop-desc.js index b9840050e5..8706a599ef 100644 --- a/test/built-ins/BigInt/prototype/toString/prop-desc.js +++ b/test/built-ins/BigInt/prototype/toString/prop-desc.js @@ -9,6 +9,7 @@ info: > 17 ECMAScript Standard Built-in Objects includes: [propertyHelper.js] +features: [BigInt] ---*/ verifyProperty(BigInt.prototype, "toString", { diff --git a/test/built-ins/BigInt/prototype/toString/prototype-call.js b/test/built-ins/BigInt/prototype/toString/prototype-call.js index ae2b0e8cd9..a5aefa4e30 100644 --- a/test/built-ins/BigInt/prototype/toString/prototype-call.js +++ b/test/built-ins/BigInt/prototype/toString/prototype-call.js @@ -13,8 +13,9 @@ info: > The BigInt prototype is not a BigInt object; it does not have a [[BigIntData]] internal slot. +features: [BigInt] ---*/ -assert.throws(TypeError, () => BigInt.prototype.toString()); -assert.throws(TypeError, () => BigInt.prototype.toString(10)); -assert.throws(TypeError, () => BigInt.prototype.toString(undefined)); +assert.throws(TypeError, function() { + BigInt.prototype.toString(1); +}); diff --git a/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js b/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js index e03eb66d73..ca0985ad77 100644 --- a/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js +++ b/test/built-ins/BigInt/prototype/toString/radix-2-to-36.js @@ -14,10 +14,10 @@ info: > with values 10 through 35. The precise algorithm is implementation-dependent, however the algorithm should be a generalization of that specified in 3.1.4.1. +features: [BigInt] ---*/ for (let r = 2; r <= 36; r++) { - assert.throws(TypeError, () => BigInt.prototype.toString(r)); assert.sameValue((0n).toString(r), "0", "0, radix " + r); assert.sameValue((-1n).toString(r), "-1", "-1, radix " + r); assert.sameValue((1n).toString(r), "1", "1, radix " + r); diff --git a/test/built-ins/BigInt/prototype/toString/radix-err.js b/test/built-ins/BigInt/prototype/toString/radix-err.js index 18d6574a31..16f1c9fcd2 100644 --- a/test/built-ins/BigInt/prototype/toString/radix-err.js +++ b/test/built-ins/BigInt/prototype/toString/radix-err.js @@ -11,11 +11,17 @@ info: > 4. Else, let radixNumber be ? ToInteger(radix). 5. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. +features: [BigInt] ---*/ for (let r of [0, 1, 37, null]) { - assert.throws(TypeError, () => BigInt.prototype.toString(r)); - assert.throws(RangeError, () => (0n).toString(r), "0, radix " + r); - assert.throws(RangeError, () => (-1n).toString(r), "-1, radix " + r); - assert.throws(RangeError, () => (1n).toString(r), "1, radix " + r); + assert.throws(RangeError, function() { + (0n).toString(r); + }, "0, radix " + r); + assert.throws(RangeError, function() { + (-1n).toString(r); + }, "-1, radix " + r); + assert.throws(RangeError, function() { + (1n).toString(r); + }, "1, radix " + r); } diff --git a/test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js b/test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js new file mode 100644 index 0000000000..796b686bc3 --- /dev/null +++ b/test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js @@ -0,0 +1,67 @@ +// Copyright 2017 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: Throws a TypeError if the this value is not a BigInt +info: > + BigInt.prototype.toString ( [ radix ] ) + + 1. Let x be ? thisBigIntValue(this value). + ... + + The abstract operation thisBigIntValue(value) performs the following steps: + + 1. If Type(value) is BigInt, return value. + 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then + ... + 3. Throw a TypeError exception. +features: [BigInt, Symbol.toPrimitive] +---*/ + +var toString = BigInt.prototype.toString; + +assert.throws(TypeError, function() { + toString.call({x: 1n}); +}, '{x: 1n}'); + +assert.throws(TypeError, function() { + toString.call([1n]); +}, '[1n]'); + +var obj = { + valueOf: function() { throw new Test262Error('no [[BigIntData]]') }, + toString: function() { throw new Test262Error('no [[BigIntData]]') }, + [Symbol.toPrimitive]: function() { throw new Test262Error('no [[BigIntData]]') } +}; +assert.throws(TypeError, function() { + toString.call(obj); +}, '{valueOf, toString, toPrimitive}'); + +assert.throws(TypeError, function() { + toString.call(0); +}, '0'); + +assert.throws(TypeError, function() { + toString.call(1); +}, '1'); + +assert.throws(TypeError, function() { + toString.call(NaN); +}, 'NaN'); + +assert.throws(TypeError, function() { + toString.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toString.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + toString.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + toString.call(false); +}, 'false');