-
Notifications
You must be signed in to change notification settings - Fork 464
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
Changes from 2 commits
7bf5510
1d7c0eb
d729577
b307b80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
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)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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