Refactor tests for the BigInt construtor

This commit is contained in:
Leo Balter 2017-08-24 15:56:21 -04:00
parent 37beb36524
commit 7765873c3e
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
45 changed files with 724 additions and 295 deletions

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt.asIntN
esid: pending
features: [BigInt]
---*/
assert.sameValue(BigInt.asIntN(1, 3n), -1n);

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt.asUintN
esid: pending
features: [BigInt]
---*/
assert.sameValue(BigInt.asUintN(1, 3n), 1n);

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Prototype of BigInt constructor
esid: pending
features: [BigInt]
---*/
assert.sameValue(Object.getPrototypeOf(BigInt), Function.prototype);

View File

@ -1,16 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt constructor
esid: pending
features: [BigInt]
---*/
assert.throws(TypeError, () => new BigInt(0));
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);

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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
});

View File

@ -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);

View File

@ -1,13 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt prototype object attributes
esid: pending
features: [BigInt]
includes: [propertyHelper.js]
---*/
verifyNotWritable(BigInt, "prototype");
verifyNotEnumerable(BigInt, "prototype");
verifyNotConfigurable(BigInt, "prototype");

View File

@ -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
});

View File

@ -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);

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Prototype of BigInt.prototype
esid: pending
features: [BigInt]
---*/
assert.sameValue(Object.getPrototypeOf(BigInt.prototype), Object.prototype);

View File

@ -1,61 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt toString method
esid: pending
features: [BigInt]
---*/
const n = 1234567890n;
const strs = {
2: "1001001100101100000001011010010",
3: "10012001001112202200",
4: "1021211200023102",
5: "10012022133030",
6: "322301024030",
7: "42410440203",
8: "11145401322",
9: "3161045680",
10: "1234567890",
11: "583977146",
12: "2a5555016",
13: "168a0865a",
14: "b9d6b5aa",
15: "735b7d60",
16: "499602d2",
17: "30288g3a",
18: "20568ad0",
19: "174b57c7",
20: "j5g0jea",
21: "e8605e3",
22: "ajc3e26",
23: "87ifcgi",
24: "6b1230i",
25: "51ac8ff",
26: "3pnfhma",
27: "3511eki",
28: "2fkfbqa",
29: "225ep2g",
30: "1ko4m30",
31: "1c3ou0k",
32: "14pc0mi",
33: "vi0m56",
34: "r5spaa",
35: "nhokia",
36: "kf12oi"
};
assert.throws(TypeError, () => BigInt.prototype.toString.call(null));
assert.sameValue(n.toString(), n.toString(10));
assert.sameValue(n.toString(undefined), n.toString(10));
for (let radix of [1, 37, NaN, 0, Infinity]) {
assert.throws(RangeError, () => n.toString(radix));
assert.throws(RangeError, () => n.toString(-radix));
}
for (let i = 2; i < 37; i++) {
for (let x of [n, Object(n)]) {
assert.sameValue(x.toString(i), strs[i]);
assert.sameValue(x.toString(i + 0.5), strs[i]);
}
}

View File

@ -1,12 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt valueOf method and thisBigIntValue operation
esid: pending
features: [BigInt]
---*/
assert.sameValue(BigInt.prototype.valueOf.call(0n), 0n);
assert.sameValue(BigInt.prototype.valueOf.call(Object(0n)), 0n);
assert.throws(TypeError, () => BigInt.prototype.valueOf.call(null));

View File

@ -1,16 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: ToString for BigInt values
esid: pending
features: [BigInt]
---*/
const ToString = (x) => x + "";
assert.sameValue(ToString(-1n), "-1");
assert.sameValue(ToString(0n), "0");
assert.sameValue(ToString(1n), "1");
assert.sameValue(ToString(1234567890n), "1234567890");
assert.sameValue(ToString(-1234567890n), "-1234567890");

View File

@ -0,0 +1,35 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: ToString is applied BigInt values in an additive expression with another string
esid: prod-AdditiveExpression
info: |
AdditiveExpression: AdditiveExpression + MultiplicativeExpression
...
7. If Type(lprim) is String or Type(rprim) is String, then
a. Let lstr be ? ToString(lprim).
b. Let rstr be ? ToString(rprim).
c. Return the String that is the result of concatenating lstr and rstr.
...
ToString Applied to the BigInt Type
1. If i is less than zero, return the String concatenation of the String "-" and ToString(-i).
2. Return the String consisting of the code units of the digits of the decimal representation of i.
features: [BigInt]
---*/
function ToString(x) { return x + ""; }
assert.sameValue(-1n + "", "-1");
assert.sameValue("" + -1n, "-1");
assert.sameValue(0n + "", "0");
assert.sameValue("" + 0n, "0");
assert.sameValue(1n + "", "1");
assert.sameValue("" + 1n, "1");
assert.sameValue(123456789000000000000000n + "", "123456789000000000000000");
assert.sameValue("" + 123456789000000000000000n, "123456789000000000000000");
assert.sameValue(-123456789000000000000000n + "", "-123456789000000000000000");
assert.sameValue("" + -123456789000000000000000n, "-123456789000000000000000");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt division of complex infinity (1/0)
esid: sec-multiplicative-operators-runtime-semantics-evaluation
info: |
Runtime Semantics: Evaluation
MultiplicativeExpression: MultiplicativeExpression MultiplicativeOperator ExponentiationExpression
...
11. If MultiplicativeOperator is /, return T::divide(lnum, rnum).
...
BigInt::divide (x, y)
1. If y is 0n, throw a RangeError exception.
...
features: [BigInt]
---*/
assert.throws(RangeError, function() {
1n / 0n
});
assert.throws(RangeError, function() {
10n / 0n
});
assert.throws(RangeError, function() {
0n / 0n
});
assert.throws(RangeError, function() {
1000000000000000000n / 0n
});

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt division
esid: pending
features: [BigInt]
---*/
assert.throws(RangeError, () => 1n / 0n);

View File

@ -1,18 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt equality
esid: pending
features: [BigInt]
---*/
assert("x" != 0n);
assert(0n != "x");
assert(true != 0n);
assert(false != 1n);
assert(0n != true);
assert(1n != false);
assert(0n != NaN);
assert(0n != Infinity);
assert(0n != -Infinity);

View File

@ -1,19 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt equality
esid: pending
features: [BigInt]
---*/
assert("" == 0n);
assert("0" == 0n);
assert(0n == "");
assert(0n == "0");
assert(true == 1n);
assert(false == 0n);
assert(1n == true);
assert(0n == false);
assert(0n == 0);
assert(0 == 0n);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: If the BigInt exponent is < 0, throw a RangeError exception
esid: sec-exp-operator-runtime-semantics-evaluation
info: |
ExponentiationExpression: UpdateExpression ** ExponentiationExpression
...
9. Return ? Type(base)::exponentiate(base, exponent).
BigInt::exponentiate (base, exponent)
1. If exponent < 0, throw a RangeError exception.
2. If base is 0n and exponent is 0n, return 1n.
3. Return a BigInt representing the mathematical value of base raised to the power exponent.
...
features: [BigInt]
---*/
assert.throws(RangeError, function() {
1n ** -1n
});
assert.throws(RangeError, function() {
0n ** -1n
});
assert.throws(RangeError, function() {
(-1n) ** -1n
});
assert.throws(RangeError, function() {
1n ** -100000000000000000n
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: If the BigInt base and exponent are both 0n, return 1n
esid: sec-exp-operator-runtime-semantics-evaluation
info: |
ExponentiationExpression: UpdateExpression ** ExponentiationExpression
...
9. Return ? Type(base)::exponentiate(base, exponent).
BigInt::exponentiate (base, exponent)
1. If exponent < 0, throw a RangeError exception.
2. If base is 0n and exponent is 0n, return 1n.
3. Return a BigInt representing the mathematical value of base raised to the power exponent.
...
features: [BigInt]
---*/
assert.sameValue(0n ** 0n, 1n);

View File

@ -1,11 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt exponentiation
esid: pending
features: [BigInt]
---*/
assert.throws(RangeError, () => 1n ** -1n);
assert.sameValue(0n ** 0n, 1n);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Comparisons of BigInt and Number values
esid: sec-abstract-relational-comparison
info: |
...
3. If both px and py are Strings, then
...
4. Else,
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important.
b. Let ny be ? ToNumeric(py).
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny).
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt.
e. If x or y are any of NaN, return undefined.
f. If x is -, or y is +, return true.
g. If x is +, or y is -, return false.
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false.
features: [BigInt]
---*/
assert.sameValue(1n >= 0, true);
assert.sameValue(1n >= 0.999999999999, true);
assert.sameValue(1 >= 0n, true);
assert.sameValue(0.000000000001 >= 0n, true);
assert.sameValue(1n >= 1, true);
assert.sameValue(1 >= 1n, true);
assert.sameValue(0n >= 1, false);
assert.sameValue(0 >= 1n, false);
assert.sameValue(0 >= 0n, true);
assert.sameValue(0n >= 0, true);
assert.sameValue(1n >= Number.MAX_VALUE, false);
assert.sameValue(Number.MIN_VALUE >= 0n, false);
assert.sameValue(-10n >= Number.MIN_VALUE, true);
assert.sameValue(Number.MAX_VALUE >= 10000000000n, true);

View File

@ -1,13 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/
assert(1n >= 0);
assert(1 >= 0n);
assert(1n >= 1);
assert(1 >= 1n);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Comparisons of BigInt and Number values
esid: sec-abstract-relational-comparison
info: |
...
3. If both px and py are Strings, then
...
4. Else,
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important.
b. Let ny be ? ToNumeric(py).
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny).
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt.
e. If x or y are any of NaN, return undefined.
f. If x is -, or y is +, return true.
g. If x is +, or y is -, return false.
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false.
features: [BigInt]
---*/
assert.sameValue(1n > 0, true);
assert.sameValue(1n > 0.999999999999, true);
assert.sameValue(1 > 0n, true);
assert.sameValue(0.000000000001 > 0n, true);
assert.sameValue(1n > 1, false);
assert.sameValue(1 > 1n, false);
assert.sameValue(0n > 1, false);
assert.sameValue(0 > 1n, false);
assert.sameValue(0 > 0n, false);
assert.sameValue(0n > 0, false);
assert.sameValue(1n > Number.MAX_VALUE, false);
assert.sameValue(Number.MIN_VALUE > 0n, false);
assert.sameValue(-10n > Number.MIN_VALUE, true);
assert.sameValue(Number.MAX_VALUE > 10000000000n, true);

View File

@ -1,11 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/
assert(1 > 0n);
assert(1n > 0);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Comparisons of BigInt and Number values
esid: sec-abstract-relational-comparison
info: |
...
3. If both px and py are Strings, then
...
4. Else,
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important.
b. Let ny be ? ToNumeric(py).
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny).
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt.
e. If x or y are any of NaN, return undefined.
f. If x is -, or y is +, return true.
g. If x is +, or y is -, return false.
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false.
features: [BigInt]
---*/
assert.sameValue(1n <= 0, false);
assert.sameValue(1n <= 0.999999999999, false);
assert.sameValue(1 <= 0n, false);
assert.sameValue(0.000000000001 <= 0n, false);
assert.sameValue(1n <= 1, true);
assert.sameValue(1 <= 1n, true);
assert.sameValue(0n <= 1, true);
assert.sameValue(0 <= 1n, true);
assert.sameValue(0 <= 0n, true);
assert.sameValue(0n <= 0, true);
assert.sameValue(1n <= Number.MAX_VALUE, true);
assert.sameValue(Number.MIN_VALUE <= 0n, true);
assert.sameValue(-10n <= Number.MIN_VALUE, false);
assert.sameValue(Number.MAX_VALUE <= 10000000000n, false);

View File

@ -1,13 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/
assert(0n <= 1);
assert(0 <= 1n);
assert(1n <= 1);
assert(1 <= 1n);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Comparisons of BigInt and Number values
esid: sec-abstract-relational-comparison
info: |
...
3. If both px and py are Strings, then
...
4. Else,
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important.
b. Let ny be ? ToNumeric(py).
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny).
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt.
e. If x or y are any of NaN, return undefined.
f. If x is -, or y is +, return true.
g. If x is +, or y is -, return false.
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false.
features: [BigInt]
---*/
assert.sameValue(1n < 0, false);
assert.sameValue(1n < 0.999999999999, false);
assert.sameValue(1 < 0n, false);
assert.sameValue(0.000000000001 < 0n, false);
assert.sameValue(1n < 1, true);
assert.sameValue(1 < 1n, true);
assert.sameValue(0n < 1, true);
assert.sameValue(0 < 1n, true);
assert.sameValue(0 < 0n, true);
assert.sameValue(0n < 0, true);
assert.sameValue(1n < Number.MAX_VALUE, true);
assert.sameValue(Number.MIN_VALUE < 0n, true);
assert.sameValue(-10n < Number.MIN_VALUE, false);
assert.sameValue(Number.MAX_VALUE < 10000000000n, false);

View File

@ -1,11 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/
assert(0n < 1);
assert(0 < 1n);

View File

@ -3,9 +3,21 @@
/*---
description: Conversion of BigInt values to booleans
esid: pending
esid: sec-logical-not-operator-runtime-semantics-evaluation
info: |
UnaryExpression: ! UnaryExpression
1. Let expr be the result of evaluating UnaryExpression.
2. Let oldValue be ToBoolean(? GetValue(expr)).
3. If oldValue is true, return false.
4. Return true.
ToBoolean ( argument )
BigInt: Return false if argument is 0n; otherwise return true.
features: [BigInt]
---*/
assert.sameValue(!!0n, false, "Expected ToBoolean(0n) to be false");
assert.sameValue(!!1n, true, "Expected ToBoolean(1n) to be true");
assert.sameValue(!0n, true, "!0n");
assert.sameValue(!1n, false, "!1n");
assert.sameValue(!-1n, false, "!-1n");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt modulo 0 throws a range error
esid: sec-multiplicative-operators-runtime-semantics-evaluation
info: |
Runtime Semantics: Evaluation
MultiplicativeExpression: MultiplicativeExpression MultiplicativeOperator ExponentiationExpression
...
12. Otherwise, MultiplicativeOperator is %; return T::remainder(lnum, rnum).
...
BigInt::remainder (x, y)
1. If y is 0n, throw a RangeError exception.
2. Return the BigInt representing x modulo y.
features: [BigInt]
---*/
assert.throws(RangeError, function() {
1n % 0n
});
assert.throws(RangeError, function() {
10n % 0n
});
assert.throws(RangeError, function() {
0n % 0n
});
assert.throws(RangeError, function() {
1000000000000000000n % 0n
});

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt modulus
esid: pending
features: [BigInt]
---*/
assert.throws(RangeError, () => 1n % 0n);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The Unary + Operator throws a TypeError on BigInt numbers
esid: sec-unary-plus-operator-runtime-semantics-evaluation
info: |
UnaryExpression: + UnaryExpression
1. Let expr be the result of evaluating UnaryExpression.
2. Return ? ToNumber(? GetValue(expr)).
ToNumber ( argument )
BigInt: Throw a TypeError exception
features: [BigInt]
---*/
assert.throws(TypeError, function() { +0n });
assert.throws(TypeError, function() { +1n });
assert.throws(TypeError, function() { +-1n });
assert.throws(TypeError, function() { +1000000000000000n });

View File

@ -1,10 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Conversion of BigInt values to numbers
esid: pending
features: [BigInt]
---*/
assert.throws(TypeError, () => +0n);

View File

@ -3,11 +3,24 @@
/*---
description: Binary BigInt literal containing an invalid digit
esid: pending
features: [BigInt]
esid: prod-NumericLiteral
info: |
NumericLiteral ::
NumericLiteralBase NumericLiteralSuffix
NumericLiteralBase ::
DecimalLiteral
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral
NumericLiteralSuffix :: n
negative:
phase: early
type: SyntaxError
features: [BigInt]
---*/
throw "Test262: This statement should not be evaluated.";
0b2n;

View File

@ -2,12 +2,15 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt literal containing an exponent part
esid: pending
description: >
It is a Syntax Error if the NumericLiteralBase contains an ExponentPart.
esid: sec-numeric-literal-static-semantics-early-errors
features: [BigInt]
negative:
phase: early
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
0e0n;

View File

@ -3,11 +3,24 @@
/*---
description: Hexadecimal BigInt literal containing an invalid digit
esid: pending
features: [BigInt]
esid: prod-NumericLiteral
info: |
NumericLiteral ::
NumericLiteralBase NumericLiteralSuffix
NumericLiteralBase ::
DecimalLiteral
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral
NumericLiteralSuffix :: n
negative:
phase: early
type: SyntaxError
features: [BigInt]
---*/
throw "Test262: This statement should not be evaluated.";
0xgn;

View File

@ -3,11 +3,24 @@
/*---
description: Octal BigInt literal containing an invalid digit
esid: pending
features: [BigInt]
esid: prod-NumericLiteral
info: |
NumericLiteral ::
NumericLiteralBase NumericLiteralSuffix
NumericLiteralBase ::
DecimalLiteral
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral
NumericLiteralSuffix :: n
negative:
phase: early
type: SyntaxError
features: [BigInt]
---*/
throw "Test262: This statement should not be evaluated.";
0o9n;