Merge pull request #1272 from leobalter/cxielarko-bigint-tostring

Updated tests for BigInt.prototype.toString
This commit is contained in:
Rick Waldron 2017-10-13 13:39:54 -04:00 committed by GitHub
commit 56e02611d4
7 changed files with 198 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// 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]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype.toString, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true
});

View File

@ -0,0 +1,20 @@
// 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]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype.toString, "name", {
value: "toString",
writable: false,
enumerable: false,
configurable: true
});

View File

@ -0,0 +1,19 @@
// 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]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype, "toString", {
writable: true,
enumerable: false,
configurable: true
});

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: 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.
features: [BigInt]
---*/
assert.throws(TypeError, function() {
BigInt.prototype.toString(1);
});

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.
features: [BigInt]
---*/
for (let r = 2; r <= 36; 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,27 @@
// 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.
features: [BigInt]
---*/
for (let r of [0, 1, 37, null]) {
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);
}

View File

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