mirror of https://github.com/tc39/test262.git
Merge pull request #1198 from leobalter/bigint-ctor
Basic tests for BigInt
This commit is contained in:
commit
dcf6b7b743
|
@ -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");
|
|
@ -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");
|
|
@ -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");
|
|
@ -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);
|
|
@ -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);
|
||||
});
|
|
@ -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);
|
||||
});
|
|
@ -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: BigInt string parsing
|
||||
esid: pending
|
||||
features: [BigInt]
|
||||
---*/
|
||||
|
||||
assert.throws(SyntaxError, () => BigInt.parseInt(""));
|
||||
assert.throws(SyntaxError, () => BigInt.parseInt("@"));
|
||||
assert.throws(SyntaxError, () => BigInt.parseInt("1", 1));
|
||||
assert.throws(SyntaxError, () => BigInt.parseInt("1", 37));
|
||||
assert.sameValue(BigInt.parseInt("0xf", 0), 0xfn);
|
||||
assert.sameValue(BigInt.parseInt("-0"), 0n);
|
||||
assert.sameValue(BigInt.parseInt(" 0@"), 0n);
|
||||
assert.sameValue(BigInt.parseInt("kf12oikf12oikf12oi", 36),
|
||||
5849853453554480289462428370n);
|
|
@ -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
|
||||
});
|
|
@ -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);
|
|
@ -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
|
||||
});
|
|
@ -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);
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: JSON serialization of BigInt values
|
||||
esid: pending
|
||||
features: [BigInt]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, () => JSON.stringify(0n));
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: BigInt to Number conversion
|
||||
esid: pending
|
||||
features: [BigInt]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number(0n), 0);
|
||||
assert.sameValue(+(new Number(0n)), +(new Number(0)));
|
|
@ -0,0 +1,11 @@
|
|||
// 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 Objects
|
||||
esid: pending
|
||||
features: [BigInt]
|
||||
---*/
|
||||
|
||||
assert(Object(0n) instanceof BigInt);
|
||||
assert.sameValue(Object(0n).valueOf(), 0n);
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: RequireObjectCoercible for BigInt values
|
||||
esid: pending
|
||||
features: [BigInt]
|
||||
---*/
|
||||
|
||||
try {
|
||||
let {} = 0n;
|
||||
} catch (e) {
|
||||
$ERROR('Expected RequireObjectCoercible to succeed for BigInt values');
|
||||
}
|
||||
|
||||
assert.sameValue(Object.setPrototypeOf(0n, null), 0n);
|
|
@ -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");
|
|
@ -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
|
||||
});
|
|
@ -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
|
||||
});
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -0,0 +1,23 @@
|
|||
// 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 booleans
|
||||
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, true, "!0n");
|
||||
assert.sameValue(!1n, false, "!1n");
|
||||
assert.sameValue(!-1n, false, "!-1n");
|
|
@ -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
|
||||
});
|
|
@ -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 });
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Binary BigInt literal containing an invalid digit
|
||||
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;
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
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;
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Hexadecimal BigInt literal containing an invalid digit
|
||||
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;
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Octal BigInt literal containing an invalid digit
|
||||
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;
|
Loading…
Reference in New Issue