Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests for BigInt.prototype.valueOf #1256

Merged
merged 4 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions harness/typeCoercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,3 @@ 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({});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

/*---
esid: sec-bigint.prototype.valueof
description: BigInt.prototype.valueOf this value coercion
info: >
description: >
BigInt.prototype.valueOf returns the primitive BigInt value.
info: |
BigInt.prototype.valueOf ( )

Return ? thisBigIntValue(this value).
includes: [typeCoercion.js]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to remove the includes... That's why the linter triggered an error

features: [BigInt, arrow-function, Symbol, Symbol.toPrimitive]
features: [BigInt]
---*/

testCoercibleToBigIntThisValue(
0n,
(x) => assert.sameValue(0n, BigInt.prototype.valueOf.call(x))
);
var valueOf = BigInt.prototype.valueOf;

assert.sameValue(valueOf.call(0n), 0n, "0n");
assert.sameValue(valueOf.call(Object(0n)), 0n, "Object(0n)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

17 changes: 0 additions & 17 deletions test/built-ins/BigInt/prototype/valueOf/this-value-err.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.
includes: [typeCoercion.js]
features: [BigInt, Symbol]
---*/

var valueOf = BigInt.prototype.valueOf;

assert.throws(TypeError, function() {
valueOf.call({});
}, "{}");

assert.throws(TypeError, function() {
valueOf.call(Object(1));
}, "Object(1)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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.
includes: [typeCoercion.js]
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clear, glad to see the helper going away where possible. Thanks for taking the extra time to refine these.