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); +}