BigInt.prototype.toString

This commit is contained in:
Robin Templeton 2017-09-21 18:38:51 -04:00 committed by Leo Balter
parent 1afb7c74fd
commit 8ca8f06ba1
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
7 changed files with 137 additions and 0 deletions

View File

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

View File

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

View File

@ -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());
}

View File

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

View File

@ -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));

View File

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

View File

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