-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests for the BigInt construtor
- Loading branch information
Showing
45 changed files
with
724 additions
and
295 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: BigInt throws a RangeError if value is Infinity | ||
esid: sec-bigint-constructor | ||
info: | | ||
BigInt ( value ) | ||
... | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
3. If Type(prim) is Number, return ? NumberToBigInt(prim). | ||
... | ||
NumberToBigInt ( number ) | ||
... | ||
2. If IsSafeInteger(number) is false, throw a RangeError exception. | ||
... | ||
IsSafeInteger ( number ) | ||
... | ||
2. If number is NaN, +∞, or -∞, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(Infinity); | ||
}); | ||
|
||
var calls = 0; | ||
var obj = { | ||
valueOf: function() { | ||
calls++; | ||
return Infinity; | ||
} | ||
} | ||
assert.throws(RangeError, function() { | ||
BigInt(obj); | ||
}); | ||
assert.sameValue(calls, 1, "it fails after fetching the primitive value"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: BigInt throws a RangeError if value is NaN | ||
esid: sec-bigint-constructor | ||
info: | | ||
BigInt ( value ) | ||
... | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
3. If Type(prim) is Number, return ? NumberToBigInt(prim). | ||
... | ||
NumberToBigInt ( number ) | ||
... | ||
2. If IsSafeInteger(number) is false, throw a RangeError exception. | ||
... | ||
IsSafeInteger ( number ) | ||
... | ||
2. If number is NaN, +∞, or -∞, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(NaN); | ||
}); | ||
|
||
var calls = 0; | ||
var obj = { | ||
valueOf: function() { | ||
calls++; | ||
return NaN; | ||
} | ||
} | ||
assert.throws(RangeError, function() { | ||
BigInt(obj); | ||
}); | ||
assert.sameValue(calls, 1, "it fails after fetching the primitive value"); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/BigInt/negative-infinity-throws.rangeerror.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2017 The V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: BigInt throws a RangeError if value is Infinity | ||
esid: sec-bigint-constructor | ||
info: | | ||
BigInt ( value ) | ||
... | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
3. If Type(prim) is Number, return ? NumberToBigInt(prim). | ||
... | ||
NumberToBigInt ( number ) | ||
... | ||
2. If IsSafeInteger(number) is false, throw a RangeError exception. | ||
... | ||
IsSafeInteger ( number ) | ||
... | ||
2. If number is NaN, +∞, or -∞, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(-Infinity); | ||
}); | ||
|
||
var calls = 0; | ||
var obj = { | ||
valueOf: function() { | ||
calls++; | ||
return -Infinity; | ||
} | ||
} | ||
assert.throws(RangeError, function() { | ||
BigInt(obj); | ||
}); | ||
assert.sameValue(calls, 1, "it fails after fetching the primitive value"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Throws a TypeError if BigInt is called with a new target | ||
esid: sec-bigint-constructor | ||
info: | | ||
1. If NewTarget is not undefined, throw a TypeError exception. | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
... | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.throws(TypeError, function() { | ||
new BigInt(); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
new BigInt(NaN); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
new BigInt({ | ||
valueOf: function() { throw new Test262Error("unreachable"); } | ||
}); | ||
}); | ||
|
||
for (let x of [NaN, Infinity, 0.5, 2**53]) { | ||
assert.throws(RangeError, () => BigInt(x)); | ||
assert.throws(RangeError, () => BigInt(-x)); | ||
} | ||
assert.sameValue(BigInt(9007199254740991), 9007199254740991n); | ||
assert.sameValue(BigInt(-9007199254740991), -9007199254740991n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Non integer number values will throw a RangeError | ||
esid: sec-bigint-constructor | ||
info: | | ||
BigInt ( value ) | ||
... | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
3. If Type(prim) is Number, return ? NumberToBigInt(prim). | ||
... | ||
NumberToBigInt ( number ) | ||
... | ||
2. If IsSafeInteger(number) is false, throw a RangeError exception. | ||
... | ||
IsSafeInteger ( number ) | ||
... | ||
2. If number is NaN, +∞, or -∞, return false. | ||
3. Let integer be ToInteger(number). | ||
4. If integer is not equal to number, return false. | ||
... | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(0.00005); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(-0.00005); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(.1); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(-.1); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(1.1); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(-1.1); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(Number.MIN_VALUE); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: BigInt throws a RangeError if value is not a safe integer. | ||
esid: sec-bigint-constructor | ||
info: | | ||
BigInt ( value ) | ||
... | ||
2. Let prim be ? ToPrimitive(value, hint Number). | ||
3. If Type(prim) is Number, return ? NumberToBigInt(prim). | ||
... | ||
NumberToBigInt ( number ) | ||
... | ||
2. If IsSafeInteger(number) is false, throw a RangeError exception. | ||
... | ||
IsSafeInteger ( number ) | ||
... | ||
3. Let integer be ToInteger(number). | ||
4. If integer is not equal to number, return false. | ||
5. If abs(integer) ≤ 2**53-1, return true. | ||
6. Otherwise, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
var pos = Math.pow(2, 53); | ||
var neg = -pos; | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(pos); | ||
}); | ||
|
||
assert.throws(RangeError, function() { | ||
BigInt(neg); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2017 The V8 Project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-bigint-constructor | ||
description: > | ||
Property descriptor of BigInt | ||
info: | | ||
The BigInt Object | ||
ECMAScript Standard Built-in Objects: | ||
Every other data property described in clauses 18 through 26 and in Annex B.2 | ||
has the attributes { [[Writable]]: true, [[Enumerable]]: false, | ||
[[Configurable]]: true } unless otherwise specified. | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyProperty(this, "BigInt", { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: The prototype of BigInt constructor is Function.prototype | ||
esid: sec-properties-of-the-bigint-constructor | ||
info: > | ||
The value of the [[Prototype]] internal slot of the BigInt constructor is the | ||
intrinsic object %FunctionPrototype%. | ||
features: [BigInt] | ||
---*/ | ||
|
||
var proto = Object.getPrototypeOf(BigInt); | ||
|
||
assert.sameValue(proto, Function.prototype); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
/*--- | ||
description: The property descriptor BigInt.prototype | ||
esid: sec-bigint.prototype | ||
info: > | ||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, | ||
[[Configurable]]: false }. | ||
features: [BigInt] | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyProperty(BigInt, "prototype", { | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: The prototype of BigInt.prototype is Object.prototype | ||
esid: sec-properties-of-the-bigint-prototype-object | ||
info: > | ||
The value of the [[Prototype]] internal slot of the BigInt prototype object | ||
is the intrinsic object %ObjectPrototype%. | ||
features: [BigInt] | ||
---*/ | ||
|
||
var proto = Object.getPrototypeOf(BigInt.prototype); | ||
assert.sameValue(proto, Object.prototype); |
Oops, something went wrong.