From 5f338a30a127df80934f72adf6285ec3b5ed309e Mon Sep 17 00:00:00 2001 From: Robin Templeton Date: Mon, 2 Oct 2017 16:13:09 -0400 Subject: [PATCH] Add tests for BigInt.prototype.valueOf (#1234) * BigInt valueOf tests * add features from typeCoercion.js --- harness/typeCoercion.js | 16 +++++++++++++++ .../BigInt/prototype/valueOf/length.js | 20 +++++++++++++++++++ .../BigInt/prototype/valueOf/name.js | 20 +++++++++++++++++++ .../BigInt/prototype/valueOf/prop-desc.js | 19 ++++++++++++++++++ .../prototype/valueOf/this-value-err.js | 17 ++++++++++++++++ .../BigInt/prototype/valueOf/this-value.js | 18 +++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 test/built-ins/BigInt/prototype/valueOf/length.js create mode 100644 test/built-ins/BigInt/prototype/valueOf/name.js create mode 100644 test/built-ins/BigInt/prototype/valueOf/prop-desc.js create mode 100644 test/built-ins/BigInt/prototype/valueOf/this-value-err.js create mode 100644 test/built-ins/BigInt/prototype/valueOf/this-value.js diff --git a/harness/typeCoercion.js b/harness/typeCoercion.js index 7cd6a9de3c2..76d366d7628 100644 --- a/harness/typeCoercion.js +++ b/harness/typeCoercion.js @@ -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({}); +} diff --git a/test/built-ins/BigInt/prototype/valueOf/length.js b/test/built-ins/BigInt/prototype/valueOf/length.js new file mode 100644 index 00000000000..bf61b877f08 --- /dev/null +++ b/test/built-ins/BigInt/prototype/valueOf/length.js @@ -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 +}); diff --git a/test/built-ins/BigInt/prototype/valueOf/name.js b/test/built-ins/BigInt/prototype/valueOf/name.js new file mode 100644 index 00000000000..c179e0c1457 --- /dev/null +++ b/test/built-ins/BigInt/prototype/valueOf/name.js @@ -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 +}); diff --git a/test/built-ins/BigInt/prototype/valueOf/prop-desc.js b/test/built-ins/BigInt/prototype/valueOf/prop-desc.js new file mode 100644 index 00000000000..324fc8f3041 --- /dev/null +++ b/test/built-ins/BigInt/prototype/valueOf/prop-desc.js @@ -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 +}); diff --git a/test/built-ins/BigInt/prototype/valueOf/this-value-err.js b/test/built-ins/BigInt/prototype/valueOf/this-value-err.js new file mode 100644 index 00000000000..b707455e646 --- /dev/null +++ b/test/built-ins/BigInt/prototype/valueOf/this-value-err.js @@ -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)) +); diff --git a/test/built-ins/BigInt/prototype/valueOf/this-value.js b/test/built-ins/BigInt/prototype/valueOf/this-value.js new file mode 100644 index 00000000000..4d383aa9cf7 --- /dev/null +++ b/test/built-ins/BigInt/prototype/valueOf/this-value.js @@ -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)) +);