diff --git a/test/built-ins/BigInt/asIntN.js b/test/built-ins/BigInt/asIntN.js deleted file mode 100644 index 75338b420c6..00000000000 --- a/test/built-ins/BigInt/asIntN.js +++ /dev/null @@ -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); diff --git a/test/built-ins/BigInt/asUintN.js b/test/built-ins/BigInt/asUintN.js deleted file mode 100644 index 21a59d5d960..00000000000 --- a/test/built-ins/BigInt/asUintN.js +++ /dev/null @@ -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); diff --git a/test/built-ins/BigInt/constructor-prototype.js b/test/built-ins/BigInt/constructor-prototype.js deleted file mode 100644 index 6bc52c8839c..00000000000 --- a/test/built-ins/BigInt/constructor-prototype.js +++ /dev/null @@ -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); diff --git a/test/built-ins/BigInt/constructor.js b/test/built-ins/BigInt/constructor.js deleted file mode 100644 index 7e6fc788bf1..00000000000 --- a/test/built-ins/BigInt/constructor.js +++ /dev/null @@ -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); 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 00000000000..4636997ec5e --- /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 00000000000..3ca48bafcf2 --- /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 00000000000..4c53cfce8c5 --- /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 00000000000..73674c8b290 --- /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 00000000000..7f8f00ffcbe --- /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 00000000000..cae05d72bda --- /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.js b/test/built-ins/BigInt/parseInt/parseInt.js similarity index 100% rename from test/built-ins/BigInt/parseInt.js rename to test/built-ins/BigInt/parseInt/parseInt.js diff --git a/test/built-ins/BigInt/prop-desc.js b/test/built-ins/BigInt/prop-desc.js new file mode 100644 index 00000000000..30a731255a2 --- /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 00000000000..331e347aa69 --- /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/attributes.js b/test/built-ins/BigInt/prototype/attributes.js deleted file mode 100644 index dab18f374db..00000000000 --- a/test/built-ins/BigInt/prototype/attributes.js +++ /dev/null @@ -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"); 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 00000000000..804a7b1a80a --- /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 00000000000..0183c817ae9 --- /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/BigInt/prototype/prototype-is-object.js b/test/built-ins/BigInt/prototype/prototype-is-object.js deleted file mode 100644 index 83dddf1474d..00000000000 --- a/test/built-ins/BigInt/prototype/prototype-is-object.js +++ /dev/null @@ -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); diff --git a/test/built-ins/BigInt/prototype/toString.js b/test/built-ins/BigInt/prototype/toString.js deleted file mode 100644 index 88586dbaba6..00000000000 --- a/test/built-ins/BigInt/prototype/toString.js +++ /dev/null @@ -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]); - } -} diff --git a/test/built-ins/BigInt/prototype/valueOf.js b/test/built-ins/BigInt/prototype/valueOf.js deleted file mode 100644 index 87f7cdd657d..00000000000 --- a/test/built-ins/BigInt/prototype/valueOf.js +++ /dev/null @@ -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)); diff --git a/test/language/expressions/addition/bigint-to-string.js b/test/language/expressions/addition/bigint-to-string.js deleted file mode 100644 index f8f42ae7183..00000000000 --- a/test/language/expressions/addition/bigint-to-string.js +++ /dev/null @@ -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"); 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 00000000000..2a74718b78a --- /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 00000000000..636b28b65ba --- /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/division/bigint.js b/test/language/expressions/division/bigint.js deleted file mode 100644 index 2fa351c79f0..00000000000 --- a/test/language/expressions/division/bigint.js +++ /dev/null @@ -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); diff --git a/test/language/expressions/does-not-equals/bigint.js b/test/language/expressions/does-not-equals/bigint.js deleted file mode 100644 index 40d44ab9600..00000000000 --- a/test/language/expressions/does-not-equals/bigint.js +++ /dev/null @@ -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); diff --git a/test/language/expressions/equals/bigint.js b/test/language/expressions/equals/bigint.js deleted file mode 100644 index a70c2397d5b..00000000000 --- a/test/language/expressions/equals/bigint.js +++ /dev/null @@ -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); 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 00000000000..f46a9beac57 --- /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 00000000000..a1080f465b1 --- /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/exponentiation/bigint.js b/test/language/expressions/exponentiation/bigint.js deleted file mode 100644 index 86561acca48..00000000000 --- a/test/language/expressions/exponentiation/bigint.js +++ /dev/null @@ -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); 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 00000000000..4216193074c --- /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-or-equal/bigint.js b/test/language/expressions/greater-than-or-equal/bigint.js deleted file mode 100644 index 3477960b321..00000000000 --- a/test/language/expressions/greater-than-or-equal/bigint.js +++ /dev/null @@ -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); 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 00000000000..9210cf78749 --- /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/greater-than/bigint.js b/test/language/expressions/greater-than/bigint.js deleted file mode 100644 index 72b2dacab72..00000000000 --- a/test/language/expressions/greater-than/bigint.js +++ /dev/null @@ -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); 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 00000000000..f4b6619fa62 --- /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-or-equal/bigint.js b/test/language/expressions/less-than-or-equal/bigint.js deleted file mode 100644 index c096f15f5f0..00000000000 --- a/test/language/expressions/less-than-or-equal/bigint.js +++ /dev/null @@ -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); 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 00000000000..29de5f5d30e --- /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/less-than/bigint.js b/test/language/expressions/less-than/bigint.js deleted file mode 100644 index 7dc2e4bd0b9..00000000000 --- a/test/language/expressions/less-than/bigint.js +++ /dev/null @@ -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); diff --git a/test/language/expressions/logical-not/bigint.js b/test/language/expressions/logical-not/bigint.js index 6d08e146af2..294ebe93d01 100644 --- a/test/language/expressions/logical-not/bigint.js +++ b/test/language/expressions/logical-not/bigint.js @@ -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"); 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 00000000000..b309a7e676d --- /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/modulus/bigint.js b/test/language/expressions/modulus/bigint.js deleted file mode 100644 index 5e396b17615..00000000000 --- a/test/language/expressions/modulus/bigint.js +++ /dev/null @@ -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); 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 00000000000..f3960c740e6 --- /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/expressions/unary-plus/bigint.js b/test/language/expressions/unary-plus/bigint.js deleted file mode 100644 index f62109034d7..00000000000 --- a/test/language/expressions/unary-plus/bigint.js +++ /dev/null @@ -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); diff --git a/test/language/literals/bigint/binary-invalid-digit.js b/test/language/literals/bigint/binary-invalid-digit.js index a447930a699..25039b5d25e 100644 --- a/test/language/literals/bigint/binary-invalid-digit.js +++ b/test/language/literals/bigint/binary-invalid-digit.js @@ -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; diff --git a/test/language/literals/bigint/exponent-part.js b/test/language/literals/bigint/exponent-part.js index 1936d817862..bbf821fd017 100644 --- a/test/language/literals/bigint/exponent-part.js +++ b/test/language/literals/bigint/exponent-part.js @@ -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; diff --git a/test/language/literals/bigint/hexadecimal-invalid-digit.js b/test/language/literals/bigint/hexadecimal-invalid-digit.js index 93b3543e6e0..44b2856df0e 100644 --- a/test/language/literals/bigint/hexadecimal-invalid-digit.js +++ b/test/language/literals/bigint/hexadecimal-invalid-digit.js @@ -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; diff --git a/test/language/literals/bigint/octal-invalid-digit.js b/test/language/literals/bigint/octal-invalid-digit.js index 486054fcaf5..02914ad3396 100644 --- a/test/language/literals/bigint/octal-invalid-digit.js +++ b/test/language/literals/bigint/octal-invalid-digit.js @@ -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;