Skip to content

Commit

Permalink
Add tests for BigInt.prototype.valueOf (#1234)
Browse files Browse the repository at this point in the history
* BigInt valueOf tests

* add features from typeCoercion.js
  • Loading branch information
Robin Templeton authored and leobalter committed Oct 2, 2017
1 parent 2889100 commit 5f338a3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions harness/typeCoercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,19 @@ function testNotCoercibleToBigInt(test) {
testStringValue("0xg");
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({});
}
20 changes: 20 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf/length.js
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.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
});
20 changes: 20 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf/name.js
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.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
});
19 changes: 19 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf/prop-desc.js
Original file line number Diff line number Diff line change
@@ -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
});
17 changes: 17 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf/this-value-err.js
Original file line number Diff line number Diff line change
@@ -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))
);
18 changes: 18 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf/this-value.js
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 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))
);

0 comments on commit 5f338a3

Please sign in to comment.