-
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.
Improve tests for BigInt.prototype.valueOf (#1256)
* Improve tests for BigInt.prototype.valueOf * fixup! Improve tests for BigInt.prototype.valueOf * fixup! Improve tests for BigInt.prototype.valueOf * fixup! Improve tests for BigInt.prototype.valueOf
- Loading branch information
Showing
6 changed files
with
111 additions
and
51 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
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,18 @@ | ||
// 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.valueof | ||
description: > | ||
BigInt.prototype.valueOf returns the primitive BigInt value. | ||
info: | | ||
BigInt.prototype.valueOf ( ) | ||
Return ? thisBigIntValue(this value). | ||
features: [BigInt] | ||
---*/ | ||
|
||
var valueOf = BigInt.prototype.valueOf; | ||
|
||
assert.sameValue(valueOf.call(0n), 0n, "0n"); | ||
assert.sameValue(valueOf.call(Object(0n)), 0n, "Object(0n)"); |
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
test/built-ins/BigInt/prototype/valueOf/this-value-invalid-object-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,30 @@ | ||
// 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.valueof | ||
description: > | ||
Throws a TypeError if this is an Object without a [[BigIntData]] internal. | ||
info: | | ||
BigInt.prototype.valueOf ( ) | ||
1. Return ? 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] | ||
---*/ | ||
|
||
var valueOf = BigInt.prototype.valueOf; | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call({}); | ||
}, "{}"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(Object(1)); | ||
}, "Object(1)"); |
63 changes: 63 additions & 0 deletions
63
test/built-ins/BigInt/prototype/valueOf/this-value-invalid-primitive-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,63 @@ | ||
// 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.valueof | ||
description: > | ||
Throws a TypeError if this is not a BigInt neither an Object. | ||
info: | | ||
BigInt.prototype.valueOf ( ) | ||
1. Return ? 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] | ||
---*/ | ||
|
||
var valueOf = BigInt.prototype.valueOf; | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(undefined); | ||
}, "undefined"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(null); | ||
}, "null"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(false); | ||
}, "false"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(true); | ||
}, "true"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(""); | ||
}, "the empty string"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call("1n"); | ||
}, "string"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(0); | ||
}, "number (0)"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(1); | ||
}, "number (1)"); | ||
|
||
assert.throws(TypeError, function() { | ||
valueOf.call(NaN); | ||
}, "NaN"); | ||
|
||
var s = Symbol(); | ||
assert.throws(TypeError, function() { | ||
valueOf.call(s); | ||
}, "symbol"); |
This file was deleted.
Oops, something went wrong.