mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 13:04:39 +02:00
Update tests for BigInt.prototype.toString
This commit is contained in:
parent
8ca8f06ba1
commit
b77af3aa0f
@ -9,6 +9,7 @@ info: >
|
|||||||
|
|
||||||
17 ECMAScript Standard Built-in Objects
|
17 ECMAScript Standard Built-in Objects
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
verifyProperty(BigInt.prototype.toString, "length", {
|
verifyProperty(BigInt.prototype.toString, "length", {
|
||||||
|
@ -9,6 +9,7 @@ info: >
|
|||||||
|
|
||||||
17 ECMAScript Standard Built-in Objects
|
17 ECMAScript Standard Built-in Objects
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
verifyProperty(BigInt.prototype.toString, "name", {
|
verifyProperty(BigInt.prototype.toString, "name", {
|
||||||
|
@ -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());
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ info: >
|
|||||||
|
|
||||||
17 ECMAScript Standard Built-in Objects
|
17 ECMAScript Standard Built-in Objects
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
verifyProperty(BigInt.prototype, "toString", {
|
verifyProperty(BigInt.prototype, "toString", {
|
||||||
|
@ -13,8 +13,9 @@ info: >
|
|||||||
|
|
||||||
The BigInt prototype is not a BigInt object; it does not have a
|
The BigInt prototype is not a BigInt object; it does not have a
|
||||||
[[BigIntData]] internal slot.
|
[[BigIntData]] internal slot.
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
assert.throws(TypeError, () => BigInt.prototype.toString());
|
assert.throws(TypeError, function() {
|
||||||
assert.throws(TypeError, () => BigInt.prototype.toString(10));
|
BigInt.prototype.toString(1);
|
||||||
assert.throws(TypeError, () => BigInt.prototype.toString(undefined));
|
});
|
||||||
|
@ -14,10 +14,10 @@ info: >
|
|||||||
with values 10 through 35. The precise algorithm is
|
with values 10 through 35. The precise algorithm is
|
||||||
implementation-dependent, however the algorithm should be a
|
implementation-dependent, however the algorithm should be a
|
||||||
generalization of that specified in 3.1.4.1.
|
generalization of that specified in 3.1.4.1.
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
for (let r = 2; r <= 36; r++) {
|
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((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);
|
||||||
assert.sameValue((1n).toString(r), "1", "1, radix " + r);
|
assert.sameValue((1n).toString(r), "1", "1, radix " + r);
|
||||||
|
@ -11,11 +11,17 @@ info: >
|
|||||||
4. Else, let radixNumber be ? ToInteger(radix).
|
4. Else, let radixNumber be ? ToInteger(radix).
|
||||||
5. If radixNumber < 2 or radixNumber > 36, throw a RangeError
|
5. If radixNumber < 2 or radixNumber > 36, throw a RangeError
|
||||||
exception.
|
exception.
|
||||||
|
features: [BigInt]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
for (let r of [0, 1, 37, null]) {
|
for (let r of [0, 1, 37, null]) {
|
||||||
assert.throws(TypeError, () => BigInt.prototype.toString(r));
|
assert.throws(RangeError, function() {
|
||||||
assert.throws(RangeError, () => (0n).toString(r), "0, radix " + r);
|
(0n).toString(r);
|
||||||
assert.throws(RangeError, () => (-1n).toString(r), "-1, radix " + r);
|
}, "0, radix " + r);
|
||||||
assert.throws(RangeError, () => (1n).toString(r), "1, radix " + r);
|
assert.throws(RangeError, function() {
|
||||||
|
(-1n).toString(r);
|
||||||
|
}, "-1, radix " + r);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
(1n).toString(r);
|
||||||
|
}, "1, radix " + r);
|
||||||
}
|
}
|
||||||
|
67
test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
vendored
Normal file
67
test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
vendored
Normal 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');
|
Loading…
x
Reference in New Issue
Block a user