Add tests for BigInt.prototype.valueOf (#1234)

* BigInt valueOf tests

* add features from typeCoercion.js
This commit is contained in:
Robin Templeton 2017-10-02 16:13:09 -04:00 committed by Leo Balter
parent 2889100f21
commit 5f338a30a1
6 changed files with 110 additions and 0 deletions

View File

@ -407,3 +407,19 @@ 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({});
}

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.valueof
description: BigInt.prototype.valueOf.length property descriptor
info: >
BigInt.prototype.valueOf ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype.valueOf, "length", {
value: 0,
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.valueof
description: BigInt.prototype.valueOf.name property descriptor
info: >
BigInt.prototype.valueOf ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype.valueOf, "name", {
value: "valueOf",
writable: false,
enumerable: false,
configurable: true
});

View File

@ -0,0 +1,19 @@
// 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 property descriptor
info: >
BigInt.prototype.valueOf ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [BigInt]
---*/
verifyProperty(BigInt.prototype, "valueOf", {
writable: true,
enumerable: false,
configurable: true
});

View File

@ -0,0 +1,17 @@
// 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))
);

View File

@ -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 this value coercion
info: >
BigInt.prototype.valueOf ( )
Return ? thisBigIntValue(this value).
includes: [typeCoercion.js]
features: [BigInt, arrow-function, Symbol, Symbol.toPrimitive]
---*/
testCoercibleToBigIntThisValue(
0n,
(x) => assert.sameValue(0n, BigInt.prototype.valueOf.call(x))
);