Skip to content
Snippets Groups Projects
Commit 9737a5ff authored by Leo Balter's avatar Leo Balter Committed by Rick Waldron
Browse files

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
parent ba891c75
No related branches found
No related tags found
No related merge requests found
...@@ -407,19 +407,3 @@ function testNotCoercibleToBigInt(test) { ...@@ -407,19 +407,3 @@ function testNotCoercibleToBigInt(test) {
testStringValue("0xg"); testStringValue("0xg");
testStringValue("1n"); testStringValue("1n");
} }
function testCoercibleToBigIntThisValue(value, test) {
test(value);
test(Object(value));
}
function testNotCoercibleToBigIntThisValue(test) {
test(undefined);
test(null);
test(true);
test(false);
test("");
test(Symbol(""));
test(0);
test({});
}
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
/*--- /*---
esid: sec-bigint.prototype.valueof esid: sec-bigint.prototype.valueof
description: BigInt.prototype.valueOf this value coercion description: >
info: > BigInt.prototype.valueOf returns the primitive BigInt value.
info: |
BigInt.prototype.valueOf ( ) BigInt.prototype.valueOf ( )
Return ? thisBigIntValue(this value). Return ? thisBigIntValue(this value).
includes: [typeCoercion.js] features: [BigInt]
features: [BigInt, arrow-function, Symbol, Symbol.toPrimitive]
---*/ ---*/
testCoercibleToBigIntThisValue( var valueOf = BigInt.prototype.valueOf;
0n,
(x) => assert.sameValue(0n, BigInt.prototype.valueOf.call(x)) assert.sameValue(valueOf.call(0n), 0n, "0n");
); assert.sameValue(valueOf.call(Object(0n)), 0n, "Object(0n)");
// 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 this value coercion
info: >
BigInt.prototype.valueOf ( )
Return ? thisBigIntValue(this value).
includes: [typeCoercion.js]
features: [BigInt, arrow-function, Symbol, Symbol.toPrimitive]
---*/
testNotCoercibleToBigIntThisValue(
(x) => assert.throws(TypeError, () => BigInt.prototype.valueOf.call(x))
);
// 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)");
// 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");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment