-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1272 from leobalter/cxielarko-bigint-tostring
Updated tests for BigInt.prototype.toString
- Loading branch information
Showing
7 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/built-ins/BigInt/prototype/toString/prototype-call.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
67 changes: 67 additions & 0 deletions
67
test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |