diff --git a/test/built-ins/BigInt/infinity-throws-rangeerror.js b/test/built-ins/BigInt/infinity-throws-rangeerror.js new file mode 100644 index 0000000000..4636997ec5 --- /dev/null +++ b/test/built-ins/BigInt/infinity-throws-rangeerror.js @@ -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"); diff --git a/test/built-ins/BigInt/nan-throws-rangeerror.js b/test/built-ins/BigInt/nan-throws-rangeerror.js new file mode 100644 index 0000000000..3ca48bafcf --- /dev/null +++ b/test/built-ins/BigInt/nan-throws-rangeerror.js @@ -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"); diff --git a/test/built-ins/BigInt/negative-infinity-throws.rangeerror.js b/test/built-ins/BigInt/negative-infinity-throws.rangeerror.js new file mode 100644 index 0000000000..4c53cfce8c --- /dev/null +++ b/test/built-ins/BigInt/negative-infinity-throws.rangeerror.js @@ -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"); diff --git a/test/built-ins/BigInt/new-target-throws.js b/test/built-ins/BigInt/new-target-throws.js new file mode 100644 index 0000000000..73674c8b29 --- /dev/null +++ b/test/built-ins/BigInt/new-target-throws.js @@ -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); diff --git a/test/built-ins/BigInt/non-integer-rangeerror.js b/test/built-ins/BigInt/non-integer-rangeerror.js new file mode 100644 index 0000000000..7f8f00ffcb --- /dev/null +++ b/test/built-ins/BigInt/non-integer-rangeerror.js @@ -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); +}); diff --git a/test/built-ins/BigInt/out-of-bounds-integer-rangeerror.js b/test/built-ins/BigInt/out-of-bounds-integer-rangeerror.js new file mode 100644 index 0000000000..cae05d72bd --- /dev/null +++ b/test/built-ins/BigInt/out-of-bounds-integer-rangeerror.js @@ -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); +}); diff --git a/test/built-ins/BigInt/parseInt/parseInt.js b/test/built-ins/BigInt/parseInt/parseInt.js new file mode 100644 index 0000000000..e41681d66c --- /dev/null +++ b/test/built-ins/BigInt/parseInt/parseInt.js @@ -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); diff --git a/test/built-ins/BigInt/prop-desc.js b/test/built-ins/BigInt/prop-desc.js new file mode 100644 index 0000000000..30a731255a --- /dev/null +++ b/test/built-ins/BigInt/prop-desc.js @@ -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 +}); diff --git a/test/built-ins/BigInt/proto.js b/test/built-ins/BigInt/proto.js new file mode 100644 index 0000000000..331e347aa6 --- /dev/null +++ b/test/built-ins/BigInt/proto.js @@ -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); diff --git a/test/built-ins/BigInt/prototype/prop-desc.js b/test/built-ins/BigInt/prototype/prop-desc.js new file mode 100644 index 0000000000..804a7b1a80 --- /dev/null +++ b/test/built-ins/BigInt/prototype/prop-desc.js @@ -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 +}); diff --git a/test/built-ins/BigInt/prototype/proto.js b/test/built-ins/BigInt/prototype/proto.js new file mode 100644 index 0000000000..0183c817ae --- /dev/null +++ b/test/built-ins/BigInt/prototype/proto.js @@ -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); diff --git a/test/built-ins/JSON/stringify/bigint.js b/test/built-ins/JSON/stringify/bigint.js new file mode 100644 index 0000000000..7aa38a3220 --- /dev/null +++ b/test/built-ins/JSON/stringify/bigint.js @@ -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)); diff --git a/test/built-ins/Number/bigint-conversion.js b/test/built-ins/Number/bigint-conversion.js new file mode 100644 index 0000000000..12fe032295 --- /dev/null +++ b/test/built-ins/Number/bigint-conversion.js @@ -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))); diff --git a/test/built-ins/Object/bigint.js b/test/built-ins/Object/bigint.js new file mode 100644 index 0000000000..810247da66 --- /dev/null +++ b/test/built-ins/Object/bigint.js @@ -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); diff --git a/test/built-ins/Object/setPrototypeOf/bigint.js b/test/built-ins/Object/setPrototypeOf/bigint.js new file mode 100644 index 0000000000..63545034f8 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/bigint.js @@ -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); diff --git a/test/language/expressions/addition/coerce-bigint-to-string.js b/test/language/expressions/addition/coerce-bigint-to-string.js new file mode 100644 index 0000000000..2a74718b78 --- /dev/null +++ b/test/language/expressions/addition/coerce-bigint-to-string.js @@ -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"); diff --git a/test/language/expressions/division/bigint-complex-infinity.js b/test/language/expressions/division/bigint-complex-infinity.js new file mode 100644 index 0000000000..636b28b65b --- /dev/null +++ b/test/language/expressions/division/bigint-complex-infinity.js @@ -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 +}); diff --git a/test/language/expressions/exponentiation/bigint-exp-operator-negative-throws.js b/test/language/expressions/exponentiation/bigint-exp-operator-negative-throws.js new file mode 100644 index 0000000000..f46a9beac5 --- /dev/null +++ b/test/language/expressions/exponentiation/bigint-exp-operator-negative-throws.js @@ -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 +}); diff --git a/test/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js b/test/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js new file mode 100644 index 0000000000..a1080f465b --- /dev/null +++ b/test/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js @@ -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); diff --git a/test/language/expressions/greater-than-or-equal/bigint-and-number.js b/test/language/expressions/greater-than-or-equal/bigint-and-number.js new file mode 100644 index 0000000000..4216193074 --- /dev/null +++ b/test/language/expressions/greater-than-or-equal/bigint-and-number.js @@ -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); diff --git a/test/language/expressions/greater-than/bigint-and-number.js b/test/language/expressions/greater-than/bigint-and-number.js new file mode 100644 index 0000000000..9210cf7874 --- /dev/null +++ b/test/language/expressions/greater-than/bigint-and-number.js @@ -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); diff --git a/test/language/expressions/less-than-or-equal/bigint-and-number.js b/test/language/expressions/less-than-or-equal/bigint-and-number.js new file mode 100644 index 0000000000..f4b6619fa6 --- /dev/null +++ b/test/language/expressions/less-than-or-equal/bigint-and-number.js @@ -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); diff --git a/test/language/expressions/less-than/bigint-and-number.js b/test/language/expressions/less-than/bigint-and-number.js new file mode 100644 index 0000000000..29de5f5d30 --- /dev/null +++ b/test/language/expressions/less-than/bigint-and-number.js @@ -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); diff --git a/test/language/expressions/logical-not/bigint.js b/test/language/expressions/logical-not/bigint.js new file mode 100644 index 0000000000..294ebe93d0 --- /dev/null +++ b/test/language/expressions/logical-not/bigint.js @@ -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"); diff --git a/test/language/expressions/modulus/bigint-modulo-zero.js b/test/language/expressions/modulus/bigint-modulo-zero.js new file mode 100644 index 0000000000..b309a7e676 --- /dev/null +++ b/test/language/expressions/modulus/bigint-modulo-zero.js @@ -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 +}); diff --git a/test/language/expressions/unary-plus/bigint-throws.js b/test/language/expressions/unary-plus/bigint-throws.js new file mode 100644 index 0000000000..f3960c740e --- /dev/null +++ b/test/language/expressions/unary-plus/bigint-throws.js @@ -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 }); diff --git a/test/language/literals/bigint/binary-invalid-digit.js b/test/language/literals/bigint/binary-invalid-digit.js new file mode 100644 index 0000000000..25039b5d25 --- /dev/null +++ b/test/language/literals/bigint/binary-invalid-digit.js @@ -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; diff --git a/test/language/literals/bigint/exponent-part.js b/test/language/literals/bigint/exponent-part.js new file mode 100644 index 0000000000..bbf821fd01 --- /dev/null +++ b/test/language/literals/bigint/exponent-part.js @@ -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; diff --git a/test/language/literals/bigint/hexadecimal-invalid-digit.js b/test/language/literals/bigint/hexadecimal-invalid-digit.js new file mode 100644 index 0000000000..44b2856df0 --- /dev/null +++ b/test/language/literals/bigint/hexadecimal-invalid-digit.js @@ -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; diff --git a/test/language/literals/bigint/octal-invalid-digit.js b/test/language/literals/bigint/octal-invalid-digit.js new file mode 100644 index 0000000000..02914ad339 --- /dev/null +++ b/test/language/literals/bigint/octal-invalid-digit.js @@ -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;