From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../test262/built-ins/BigInt/asIntN/arithmetic.js | 68 ++++++++ .../test262/built-ins/BigInt/asIntN/asIntN.js | 23 +++ .../BigInt/asIntN/bigint-tobigint-errors.js | 173 +++++++++++++++++++++ .../BigInt/asIntN/bigint-tobigint-toprimitive.js | 168 ++++++++++++++++++++ .../asIntN/bigint-tobigint-wrapped-values.js | 64 ++++++++ .../built-ins/BigInt/asIntN/bigint-tobigint.js | 51 ++++++ .../built-ins/BigInt/asIntN/bits-toindex-errors.js | 88 +++++++++++ .../BigInt/asIntN/bits-toindex-toprimitive.js | 169 ++++++++++++++++++++ .../BigInt/asIntN/bits-toindex-wrapped-values.js | 111 +++++++++++++ .../built-ins/BigInt/asIntN/bits-toindex.js | 37 +++++ .../test262/built-ins/BigInt/asIntN/browser.js | 0 .../test262/built-ins/BigInt/asIntN/length.js | 22 +++ .../tests/test262/built-ins/BigInt/asIntN/name.js | 22 +++ .../built-ins/BigInt/asIntN/not-a-constructor.js | 28 ++++ .../built-ins/BigInt/asIntN/order-of-steps.js | 34 ++++ .../tests/test262/built-ins/BigInt/asIntN/shell.js | 0 .../test262/built-ins/BigInt/asUintN/arithmetic.js | 71 +++++++++ .../test262/built-ins/BigInt/asUintN/asUintN.js | 23 +++ .../BigInt/asUintN/bigint-tobigint-errors.js | 173 +++++++++++++++++++++ .../BigInt/asUintN/bigint-tobigint-toprimitive.js | 169 ++++++++++++++++++++ .../asUintN/bigint-tobigint-wrapped-values.js | 64 ++++++++ .../built-ins/BigInt/asUintN/bigint-tobigint.js | 51 ++++++ .../BigInt/asUintN/bits-toindex-errors.js | 88 +++++++++++ .../BigInt/asUintN/bits-toindex-toprimitive.js | 169 ++++++++++++++++++++ .../BigInt/asUintN/bits-toindex-wrapped-values.js | 111 +++++++++++++ .../built-ins/BigInt/asUintN/bits-toindex.js | 37 +++++ .../test262/built-ins/BigInt/asUintN/browser.js | 0 .../test262/built-ins/BigInt/asUintN/length.js | 22 +++ .../tests/test262/built-ins/BigInt/asUintN/name.js | 22 +++ .../built-ins/BigInt/asUintN/not-a-constructor.js | 28 ++++ .../built-ins/BigInt/asUintN/order-of-steps.js | 34 ++++ .../test262/built-ins/BigInt/asUintN/shell.js | 0 js/src/tests/test262/built-ins/BigInt/browser.js | 0 .../BigInt/call-value-of-when-to-string-present.js | 26 ++++ .../built-ins/BigInt/constructor-coercion.js | 29 ++++ .../built-ins/BigInt/constructor-empty-string.js | 26 ++++ .../BigInt/constructor-from-binary-string.js | 45 ++++++ .../BigInt/constructor-from-decimal-string.js | 35 +++++ .../BigInt/constructor-from-hex-string.js | 33 ++++ .../BigInt/constructor-from-octal-string.js | 31 ++++ .../constructor-from-string-syntax-errors.js | 79 ++++++++++ .../built-ins/BigInt/constructor-integer.js | 60 +++++++ .../BigInt/constructor-trailing-leading-spaces.js | 30 ++++ .../built-ins/BigInt/infinity-throws-rangeerror.js | 44 ++++++ .../test262/built-ins/BigInt/is-a-constructor.js | 35 +++++ js/src/tests/test262/built-ins/BigInt/length.js | 34 ++++ js/src/tests/test262/built-ins/BigInt/name.js | 33 ++++ .../built-ins/BigInt/nan-throws-rangeerror.js | 44 ++++++ .../BigInt/negative-infinity-throws.rangeerror.js | 44 ++++++ .../built-ins/BigInt/non-integer-rangeerror.js | 59 +++++++ .../test262/built-ins/BigInt/parseInt/browser.js | 0 .../built-ins/BigInt/parseInt/nonexistent.js | 11 ++ .../test262/built-ins/BigInt/parseInt/shell.js | 0 js/src/tests/test262/built-ins/BigInt/prop-desc.js | 26 ++++ js/src/tests/test262/built-ins/BigInt/proto.js | 17 ++ .../BigInt/prototype/Symbol.toStringTag.js | 24 +++ .../test262/built-ins/BigInt/prototype/browser.js | 0 .../built-ins/BigInt/prototype/constructor.js | 31 ++++ .../built-ins/BigInt/prototype/prop-desc.js | 20 +++ .../test262/built-ins/BigInt/prototype/proto.js | 16 ++ .../test262/built-ins/BigInt/prototype/shell.js | 0 .../BigInt/prototype/toLocaleString/browser.js | 0 .../prototype/toLocaleString/not-a-constructor.js | 33 ++++ .../BigInt/prototype/toLocaleString/shell.js | 0 .../built-ins/BigInt/prototype/toString/a-z.js | 23 +++ .../built-ins/BigInt/prototype/toString/browser.js | 0 .../BigInt/prototype/toString/default-radix.js | 21 +++ .../built-ins/BigInt/prototype/toString/length.js | 22 +++ .../built-ins/BigInt/prototype/toString/name.js | 22 +++ .../BigInt/prototype/toString/not-a-constructor.js | 33 ++++ .../BigInt/prototype/toString/prop-desc.js | 21 +++ .../BigInt/prototype/toString/prototype-call.js | 24 +++ .../BigInt/prototype/toString/radix-2-to-36.js | 26 ++++ .../BigInt/prototype/toString/radix-err.js | 29 ++++ .../built-ins/BigInt/prototype/toString/shell.js | 0 .../string-is-code-units-of-decimal-digits-only.js | 22 +++ .../toString/thisbigintvalue-not-valid-throws.js | 79 ++++++++++ .../built-ins/BigInt/prototype/valueOf/browser.js | 0 .../BigInt/prototype/valueOf/cross-realm.js | 16 ++ .../built-ins/BigInt/prototype/valueOf/length.js | 22 +++ .../built-ins/BigInt/prototype/valueOf/name.js | 22 +++ .../BigInt/prototype/valueOf/not-a-constructor.js | 33 ++++ .../BigInt/prototype/valueOf/prop-desc.js | 21 +++ .../built-ins/BigInt/prototype/valueOf/return.js | 20 +++ .../built-ins/BigInt/prototype/valueOf/shell.js | 0 .../valueOf/this-value-invalid-object-throws.js | 33 ++++ .../valueOf/this-value-invalid-primitive-throws.js | 67 ++++++++ js/src/tests/test262/built-ins/BigInt/shell.js | 24 +++ .../test262/built-ins/BigInt/tostring-throws.js | 23 +++ .../test262/built-ins/BigInt/valueof-throws.js | 23 +++ .../BigInt/wrapper-object-ordinary-toprimitive.js | 74 +++++++++ 91 files changed, 3685 insertions(+) create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/arithmetic.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/asIntN.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-errors.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-errors.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/length.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/name.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/order-of-steps.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asIntN/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/arithmetic.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/asUintN.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-errors.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-errors.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/length.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/name.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/order-of-steps.js create mode 100644 js/src/tests/test262/built-ins/BigInt/asUintN/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/call-value-of-when-to-string-present.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-coercion.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-empty-string.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-from-binary-string.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-from-decimal-string.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-from-hex-string.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-from-octal-string.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-from-string-syntax-errors.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-integer.js create mode 100644 js/src/tests/test262/built-ins/BigInt/constructor-trailing-leading-spaces.js create mode 100644 js/src/tests/test262/built-ins/BigInt/infinity-throws-rangeerror.js create mode 100644 js/src/tests/test262/built-ins/BigInt/is-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/length.js create mode 100644 js/src/tests/test262/built-ins/BigInt/name.js create mode 100644 js/src/tests/test262/built-ins/BigInt/nan-throws-rangeerror.js create mode 100644 js/src/tests/test262/built-ins/BigInt/negative-infinity-throws.rangeerror.js create mode 100644 js/src/tests/test262/built-ins/BigInt/non-integer-rangeerror.js create mode 100644 js/src/tests/test262/built-ins/BigInt/parseInt/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/parseInt/nonexistent.js create mode 100644 js/src/tests/test262/built-ins/BigInt/parseInt/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/BigInt/proto.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/Symbol.toStringTag.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/proto.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/a-z.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/default-radix.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/length.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/name.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/prototype-call.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-2-to-36.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-err.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/string-is-code-units-of-decimal-digits-only.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/browser.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/cross-realm.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/length.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/name.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/return.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-object-throws.js create mode 100644 js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-primitive-throws.js create mode 100644 js/src/tests/test262/built-ins/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/BigInt/tostring-throws.js create mode 100644 js/src/tests/test262/built-ins/BigInt/valueof-throws.js create mode 100644 js/src/tests/test262/built-ins/BigInt/wrapper-object-ordinary-toprimitive.js (limited to 'js/src/tests/test262/built-ins/BigInt') diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/arithmetic.js b/js/src/tests/test262/built-ins/BigInt/asIntN/arithmetic.js new file mode 100644 index 0000000000..e12acd828e --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/arithmetic.js @@ -0,0 +1,68 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asintn +description: BigInt.asIntN arithmetic test cases +info: | + BigInt.asIntN ( bits, bigint ) + + 3. Let mod be a BigInt representing bigint modulo 2**bits. + 4. If mod ≥ 2**bits - 1, return mod - 2**bits; otherwise, return mod. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asIntN(0, -2n), 0n); +assert.sameValue(BigInt.asIntN(0, -1n), 0n); +assert.sameValue(BigInt.asIntN(0, 0n), 0n); +assert.sameValue(BigInt.asIntN(0, 1n), 0n); +assert.sameValue(BigInt.asIntN(0, 2n), 0n); + +assert.sameValue(BigInt.asIntN(1, -3n), -1n); +assert.sameValue(BigInt.asIntN(1, -2n), 0n); +assert.sameValue(BigInt.asIntN(1, -1n), -1n); +assert.sameValue(BigInt.asIntN(1, 0n), 0n); +assert.sameValue(BigInt.asIntN(1, 1n), -1n); +assert.sameValue(BigInt.asIntN(1, 2n), 0n); +assert.sameValue(BigInt.asIntN(1, 3n), -1n); +assert.sameValue(BigInt.asIntN(1, -123456789012345678901n), -1n); +assert.sameValue(BigInt.asIntN(1, -123456789012345678900n), 0n); +assert.sameValue(BigInt.asIntN(1, 123456789012345678900n), 0n); +assert.sameValue(BigInt.asIntN(1, 123456789012345678901n), -1n); + +assert.sameValue(BigInt.asIntN(2, -3n), 1n); +assert.sameValue(BigInt.asIntN(2, -2n), -2n); +assert.sameValue(BigInt.asIntN(2, -1n), -1n); +assert.sameValue(BigInt.asIntN(2, 0n), 0n); +assert.sameValue(BigInt.asIntN(2, 1n), 1n); +assert.sameValue(BigInt.asIntN(2, 2n), -2n); +assert.sameValue(BigInt.asIntN(2, 3n), -1n); +assert.sameValue(BigInt.asIntN(2, -123456789012345678901n), -1n); +assert.sameValue(BigInt.asIntN(2, -123456789012345678900n), 0n); +assert.sameValue(BigInt.asIntN(2, 123456789012345678900n), 0n); +assert.sameValue(BigInt.asIntN(2, 123456789012345678901n), 1n); + +assert.sameValue(BigInt.asIntN(8, 0xabn), -0x55n); +assert.sameValue(BigInt.asIntN(8, 0xabcdn), -0x33n); +assert.sameValue(BigInt.asIntN(8, 0xabcdef01n), 0x01n); +assert.sameValue(BigInt.asIntN(8, 0xabcdef0123456789abcdef0123n), 0x23n); +assert.sameValue(BigInt.asIntN(8, 0xabcdef0123456789abcdef0183n), -0x7dn); + +assert.sameValue(BigInt.asIntN(64, 0xabcdef0123456789abcdefn), 0x0123456789abcdefn); +assert.sameValue(BigInt.asIntN(65, 0xabcdef0123456789abcdefn), -0xfedcba9876543211n); + +assert.sameValue(BigInt.asIntN(200, + 0xcffffffffffffffffffffffffffffffffffffffffffffffffffn), -0x00000000000000000000000000000000000000000000000001n); +assert.sameValue(BigInt.asIntN(201, + 0xcffffffffffffffffffffffffffffffffffffffffffffffffffn), + 0xffffffffffffffffffffffffffffffffffffffffffffffffffn +); + +assert.sameValue(BigInt.asIntN(200, + 0xc89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), -0x761f7e209749a0124cd3001599f1aa2069fa9af59fc52a03acn); +assert.sameValue(BigInt.asIntN(201, + 0xc89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), + 0x89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/asIntN.js b/js/src/tests/test262/built-ins/BigInt/asIntN/asIntN.js new file mode 100644 index 0000000000..24536e95e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/asIntN.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asintn +description: BigInt.asIntN property descriptor +info: | + BigInt.asIntN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +assert.sameValue(typeof BigInt.asIntN, 'function'); + +verifyProperty(BigInt, "asIntN", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-errors.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-errors.js new file mode 100644 index 0000000000..ec4b9c273f --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-errors.js @@ -0,0 +1,173 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bigint parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asIntN, 'function'); + +assert.throws(TypeError, function () { + BigInt.asIntN(); +}, "ToBigInt: no argument => undefined => TypeError"); +assert.throws(TypeError, function () { + BigInt.asIntN(0); +}, "ToBigInt: no argument => undefined => TypeError"); + +assert.throws(TypeError, function() { + BigInt.asIntN(0, undefined); +}, "ToBigInt: undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return undefined; + } + }); +}, "ToBigInt: @@toPrimitive => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return undefined; + } + }); +}, "ToBigInt: valueOf => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + toString: function() { + return undefined; + } + }); +}, "ToBigInt: toString => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, null); +}, "ToBigInt: null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return null; + } + }); +}, "ToBigInt: @@toPrimitive => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return null; + } + }); +}, "ToBigInt: valueOf => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + toString: function() { + return null; + } + }); +}, "ToBigInt: toString => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, 0); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, Object(0)); +}, "ToBigInt: unbox object with internal slot => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return 0; + } + }); +}, "ToBigInt: @@toPrimitive => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return 0; + } + }); +}, "ToBigInt: valueOf => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + toString: function() { + return 0; + } + }); +}, "ToBigInt: toString => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, NaN); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, Infinity); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, Symbol("1")); +}, "ToBigInt: Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, Object(Symbol("1"))); +}, "ToBigInt: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + toString: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: toString => Symbol => TypeError"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, "a"); +}, "ToBigInt: unparseable BigInt"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, "0b2"); +}, "ToBigInt: unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, Object("0b2")); +}, "ToBigInt: unbox object with internal slot => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return "0b2"; + } + }); +}, "ToBigInt: @@toPrimitive => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return "0b2"; + } + }); +}, "ToBigInt: valueOf => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, { + toString: function() { + return "0b2"; + } + }); +}, "ToBigInt: toString => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, " 0b2 "); +}, "ToBigInt: unparseable BigInt with leading/trailing whitespace"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, "0o8"); +}, "ToBigInt: unparseable BigInt octal"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, "0xg"); +}, "ToBigInt: unparseable BigInt hex"); +assert.throws(SyntaxError, function() { + BigInt.asIntN(0, "1n"); +}, "ToBigInt: unparseable BigInt due to literal suffix"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js new file mode 100644 index 0000000000..7e2e322eea --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js @@ -0,0 +1,168 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bigint parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asIntN, 'function'); +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: function() { + return "1"; + }, + valueOf: err, + toString: err +}), 1n, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return "1"; + }, + toString: err +}), 1n, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(BigInt.asIntN(2, { + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: toString with no valueOf"); +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: null, + valueOf: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: null, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: 1, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: {}, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return {}; + }, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return Object(12345); + }, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + BigInt.asIntN(0, { + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + BigInt.asIntN(0, { + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + BigInt.asIntN(0, { + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN(0, { + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js new file mode 100644 index 0000000000..8b5801c65d --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js @@ -0,0 +1,64 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bigint parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ + +assert.sameValue(BigInt.asIntN(2, Object(0n)), 0n, "ToPrimitive: unbox object with internal slot"); +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: function() { + return 0n; + } +}), 0n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return 0n; + } +}), 0n, "ToPrimitive: valueOf"); +assert.sameValue(BigInt.asIntN(2, { + toString: function() { + return 0n; + } +}), 0n, "ToPrimitive: toString"); +assert.sameValue(BigInt.asIntN(2, Object(true)), 1n, + "ToBigInt: unbox object with internal slot => true => 1n"); +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: function() { + return true; + } +}), 1n, "ToBigInt: @@toPrimitive => true => 1n"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return true; + } +}), 1n, "ToBigInt: valueOf => true => 1n"); +assert.sameValue(BigInt.asIntN(2, { + toString: function() { + return true; + } +}), 1n, "ToBigInt: toString => true => 1n"); +assert.sameValue(BigInt.asIntN(2, Object("1")), 1n, + "ToBigInt: unbox object with internal slot => parse BigInt"); +assert.sameValue(BigInt.asIntN(2, { + [Symbol.toPrimitive]: function() { + return "1"; + } +}), 1n, "ToBigInt: @@toPrimitive => parse BigInt"); +assert.sameValue(BigInt.asIntN(2, { + valueOf: function() { + return "1"; + } +}), 1n, "ToBigInt: valueOf => parse BigInt"); +assert.sameValue(BigInt.asIntN(2, { + toString: function() { + return "1"; + } +}), 1n, "ToBigInt: toString => parse BigInt"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint.js new file mode 100644 index 0000000000..143245b835 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bigint-tobigint.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bigint parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asIntN(2, 0n), 0n); +assert.sameValue(BigInt.asIntN(2, -0n), 0n); +assert.sameValue(BigInt.asIntN(2, false), 0n, "ToBigInt: false => 0n"); +assert.sameValue(BigInt.asIntN(2, true), 1n, "ToBigInt: true => 1n"); +assert.sameValue(BigInt.asIntN(2, "1"), 1n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asIntN(2, "-0"), 0n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asIntN(2, ""), 0n, "ToBigInt: empty String => 0n"); +assert.sameValue(BigInt.asIntN(2, " "), 0n, "ToBigInt: String with only whitespace => 0n"); +assert.sameValue(BigInt.asIntN(2, []), 0n, "ToBigInt: .toString() => empty String => 0n"); +assert.sameValue(BigInt.asIntN(2, [1]), 1n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asIntN(3, 10n), 2n); +assert.sameValue(BigInt.asIntN(3, "10"), 2n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asIntN(3, "0b1010"), 2n, "ToBigInt: parse BigInt binary"); +assert.sameValue(BigInt.asIntN(3, "0o12"), 2n, "ToBigInt: parse BigInt octal"); +assert.sameValue(BigInt.asIntN(3, "0xa"), 2n, "ToBigInt: parse BigInt hex"); +assert.sameValue(BigInt.asIntN(3, " 0xa "), 2n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asIntN(3, " 10 "), 2n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asIntN(3, [10n]), 2n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asIntN(3, ["10"]), 2n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asIntN(4, 12345678901234567890003n), 3n); +assert.sameValue(BigInt.asIntN(4, "12345678901234567890003"), 3n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asIntN(4, + "0b10100111010100001010110110010011100111011001110001010000100100010001010011"), 3n, + "ToBigInt: parse BigInt binary"); +assert.sameValue(BigInt.asIntN(4, "0o2472412662347316120442123"), 3n, + "ToBigInt: parse BigInt octal"); +assert.sameValue(BigInt.asIntN(4, "0x29d42b64e7671424453"), 3n, "ToBigInt: parse BigInt hex"); +assert.sameValue(BigInt.asIntN(4, " 0x29d42b64e7671424453 "), 3n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asIntN(4, " 12345678901234567890003 "), 3n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asIntN(4, [12345678901234567890003n]), 3n, + "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asIntN(4, ["12345678901234567890003"]), 3n, + "ToBigInt: .toString() => parse BigInt"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-errors.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-errors.js new file mode 100644 index 0000000000..79ab560538 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-errors.js @@ -0,0 +1,88 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bits parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asIntN, 'function'); + +assert.throws(RangeError, function() { + BigInt.asIntN(-1, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asIntN(-2.5, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asIntN("-2.5", 0n); +}, "ToIndex: parse Number => throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asIntN(-Infinity, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asIntN(9007199254740992, 0n); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(RangeError, function() { + BigInt.asIntN(Infinity, 0n); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(TypeError, function() { + BigInt.asIntN(0n, 0n); +}, "ToIndex: BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(Object(0n), 0n); +}, "ToIndex: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return 0n; + } + }, 0n); +}, "ToIndex: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: function() { + return 0n; + } + }, 0n); +}, "ToIndex: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + toString: function() { + return 0n; + } + }, 0n); +}, "ToIndex: toString => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(Symbol("1"), 0n); +}, "ToIndex: Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN(Object(Symbol("1")), 0n); +}, "ToIndex: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + toString: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js new file mode 100644 index 0000000000..0e7ae76341 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js @@ -0,0 +1,169 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bits parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asIntN, 'function'); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}, 1n), -1n, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return 1; + }, + toString: err +}, 1n), -1n, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: toString with no valueOf"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(BigInt.asIntN({ + valueOf: null, + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN({ + valueOf: 1, + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN({ + valueOf: {}, + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}, 1n), -1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: 1 + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: {} + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return {}; + } + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + BigInt.asIntN({ + valueOf: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + BigInt.asIntN({ + toString: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: null, + toString: null + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: 1, + toString: 1 + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: {}, + toString: {} + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asIntN({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js new file mode 100644 index 0000000000..ad7dcb50e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js @@ -0,0 +1,111 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bits parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ + +assert.sameValue(BigInt.asIntN(Object(0), 1n), 0n, "ToPrimitive: unbox object with internal slot"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: valueOf"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: toString"); +assert.sameValue(BigInt.asIntN(Object(NaN), 1n), 0n, + "ToIndex: unbox object with internal slot => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: valueOf => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: toString => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: valueOf => undefined => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: toString => undefined => NaN => 0"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return null; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => null => 0"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return null; + } +}, 1n), 0n, "ToIndex: valueOf => null => 0"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return null; + } +}, 1n), 0n, "ToIndex: toString => null => 0"); +assert.sameValue(BigInt.asIntN(Object(true), 1n), -1n, + "ToIndex: unbox object with internal slot => true => 1"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return true; + } +}, 1n), -1n, "ToIndex: @@toPrimitive => true => 1"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return true; + } +}, 1n), -1n, "ToIndex: valueOf => true => 1"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return true; + } +}, 1n), -1n, "ToIndex: toString => true => 1"); +assert.sameValue(BigInt.asIntN(Object("1"), 1n), -1n, + "ToIndex: unbox object with internal slot => parse Number"); +assert.sameValue(BigInt.asIntN({ + [Symbol.toPrimitive]: function() { + return "1"; + } +}, 1n), -1n, "ToIndex: @@toPrimitive => parse Number"); +assert.sameValue(BigInt.asIntN({ + valueOf: function() { + return "1"; + } +}, 1n), -1n, "ToIndex: valueOf => parse Number"); +assert.sameValue(BigInt.asIntN({ + toString: function() { + return "1"; + } +}, 1n), -1n, "ToIndex: toString => parse Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex.js b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex.js new file mode 100644 index 0000000000..85a99c6abf --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/bits-toindex.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asIntN type coercion for bits parameter +esid: sec-bigint.asintn +info: | + BigInt.asIntN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asIntN(0, 1n), 0n); +assert.sameValue(BigInt.asIntN(1, 1n), -1n); +assert.sameValue(BigInt.asIntN(-0.9, 1n), 0n, "ToIndex: truncate towards 0"); +assert.sameValue(BigInt.asIntN(0.9, 1n), 0n, "ToIndex: truncate towards 0"); +assert.sameValue(BigInt.asIntN(NaN, 1n), 0n, "ToIndex: NaN => 0"); +assert.sameValue(BigInt.asIntN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0"); +assert.sameValue(BigInt.asIntN(null, 1n), 0n, "ToIndex: null => 0"); +assert.sameValue(BigInt.asIntN(false, 1n), 0n, "ToIndex: false => 0"); +assert.sameValue(BigInt.asIntN(true, 1n), -1n, "ToIndex: true => 1"); +assert.sameValue(BigInt.asIntN("0", 1n), 0n, "ToIndex: parse Number"); +assert.sameValue(BigInt.asIntN("1", 1n), -1n, "ToIndex: parse Number"); +assert.sameValue(BigInt.asIntN("", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asIntN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asIntN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asIntN(3, 10n), 2n); +assert.sameValue(BigInt.asIntN("3", 10n), 2n, "toIndex: parse Number"); +assert.sameValue(BigInt.asIntN(3.9, 10n), 2n, "toIndex: truncate towards 0"); +assert.sameValue(BigInt.asIntN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0"); +assert.sameValue(BigInt.asIntN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0'); +assert.sameValue(BigInt.asIntN(["1"], 1n), -1n, 'ToIndex: ["1"].toString() => "1" => 1'); +assert.sameValue(BigInt.asIntN({}, 1n), 0n, + 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue(BigInt.asIntN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/browser.js b/js/src/tests/test262/built-ins/BigInt/asIntN/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/length.js b/js/src/tests/test262/built-ins/BigInt/asIntN/length.js new file mode 100644 index 0000000000..57e6347ddc --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/length.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asintn +description: BigInt.asIntN.length descriptor +info: | + BigInt.asIntN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.asIntN, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/name.js b/js/src/tests/test262/built-ins/BigInt/asIntN/name.js new file mode 100644 index 0000000000..d1a4bc77a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asintn +description: BigInt.asIntN.name descriptor +info: | + BigInt.asIntN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.asIntN, "name", { + value: "asIntN", + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/not-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/asIntN/not-a-constructor.js new file mode 100644 index 0000000000..7875347fcf --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/not-a-constructor.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt.asIntN does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, arrow-function] +---*/ +assert.sameValue(isConstructor(BigInt.asIntN), false, 'isConstructor(BigInt.asIntN) must return false'); + +assert.throws(TypeError, () => { + new BigInt.asIntN(64, 1n); +}, '`new BigInt.asIntN(64, 1n)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/order-of-steps.js b/js/src/tests/test262/built-ins/BigInt/asIntN/order-of-steps.js new file mode 100644 index 0000000000..1311379be8 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asIntN/order-of-steps.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asintn +description: BigInt.asIntN order of parameter type coercion +info: | + BigInt.asIntN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). + 2. Let bigint ? ToBigInt(bigint). + +features: [BigInt] +---*/ + +var i = 0; +var bits = { + valueOf() { + assert.sameValue(i, 0); + i++; + return 0; + } +}; +var bigint = { + valueOf() { + assert.sameValue(i, 1); + i++; + return 0n; + } +}; + +BigInt.asIntN(bits, bigint); +assert.sameValue(i, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asIntN/shell.js b/js/src/tests/test262/built-ins/BigInt/asIntN/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/arithmetic.js b/js/src/tests/test262/built-ins/BigInt/asUintN/arithmetic.js new file mode 100644 index 0000000000..443f13c60c --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/arithmetic.js @@ -0,0 +1,71 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asuintn +description: BigInt.asUintN arithmetic test cases +info: | + BigInt.asUintN ( bits, bigint ) + + 3. Return a BigInt representing bigint modulo 2**bits. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asUintN(0, -2n), 0n); +assert.sameValue(BigInt.asUintN(0, -1n), 0n); +assert.sameValue(BigInt.asUintN(0, 0n), 0n); +assert.sameValue(BigInt.asUintN(0, 1n), 0n); +assert.sameValue(BigInt.asUintN(0, 2n), 0n); + +assert.sameValue(BigInt.asUintN(1, -3n), 1n); +assert.sameValue(BigInt.asUintN(1, -2n), 0n); +assert.sameValue(BigInt.asUintN(1, -1n), 1n); +assert.sameValue(BigInt.asUintN(1, 0n), 0n); +assert.sameValue(BigInt.asUintN(1, 1n), 1n); +assert.sameValue(BigInt.asUintN(1, 2n), 0n); +assert.sameValue(BigInt.asUintN(1, 3n), 1n); +assert.sameValue(BigInt.asUintN(1, -123456789012345678901n), 1n); +assert.sameValue(BigInt.asUintN(1, -123456789012345678900n), 0n); +assert.sameValue(BigInt.asUintN(1, 123456789012345678900n), 0n); +assert.sameValue(BigInt.asUintN(1, 123456789012345678901n), 1n); + +assert.sameValue(BigInt.asUintN(2, -3n), 1n); +assert.sameValue(BigInt.asUintN(2, -2n), 2n); +assert.sameValue(BigInt.asUintN(2, -1n), 3n); +assert.sameValue(BigInt.asUintN(2, 0n), 0n); +assert.sameValue(BigInt.asUintN(2, 1n), 1n); +assert.sameValue(BigInt.asUintN(2, 2n), 2n); +assert.sameValue(BigInt.asUintN(2, 3n), 3n); +assert.sameValue(BigInt.asUintN(2, -123456789012345678901n), 3n); +assert.sameValue(BigInt.asUintN(2, -123456789012345678900n), 0n); +assert.sameValue(BigInt.asUintN(2, 123456789012345678900n), 0n); +assert.sameValue(BigInt.asUintN(2, 123456789012345678901n), 1n); + +assert.sameValue(BigInt.asUintN(8, 0xabn), 0xabn); +assert.sameValue(BigInt.asUintN(8, 0xabcdn), 0xcdn); +assert.sameValue(BigInt.asUintN(8, 0xabcdef01n), 0x01n); +assert.sameValue(BigInt.asUintN(8, 0xabcdef0123456789abcdef0123n), 0x23n); +assert.sameValue(BigInt.asUintN(8, 0xabcdef0123456789abcdef0183n), 0x83n); + +assert.sameValue(BigInt.asUintN(64, 0xabcdef0123456789abcdefn), 0x0123456789abcdefn); +assert.sameValue(BigInt.asUintN(65, 0xabcdef0123456789abcdefn), 0x10123456789abcdefn); + +assert.sameValue(BigInt.asUintN(200, + 0xbffffffffffffffffffffffffffffffffffffffffffffffffffn), + 0x0ffffffffffffffffffffffffffffffffffffffffffffffffffn +); +assert.sameValue(BigInt.asUintN(201, + 0xbffffffffffffffffffffffffffffffffffffffffffffffffffn), + 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffn +); + +assert.sameValue(BigInt.asUintN(200, + 0xb89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), + 0x089e081df68b65fedb32cffea660e55df9605650a603ad5fc54n +); +assert.sameValue(BigInt.asUintN(201, + 0xb89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), + 0x189e081df68b65fedb32cffea660e55df9605650a603ad5fc54n +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/asUintN.js b/js/src/tests/test262/built-ins/BigInt/asUintN/asUintN.js new file mode 100644 index 0000000000..195b536eaf --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/asUintN.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asuintn +description: BigInt.asUintN property descriptor +info: | + BigInt.asUintN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +assert.sameValue(typeof BigInt.asUintN, 'function'); + +verifyProperty(BigInt, "asUintN", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-errors.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-errors.js new file mode 100644 index 0000000000..031b946704 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-errors.js @@ -0,0 +1,173 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bigint parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asUintN, 'function'); + +assert.throws(TypeError, function () { + BigInt.asUintN(); +}, "ToBigInt: no argument => undefined => TypeError"); +assert.throws(TypeError, function () { + BigInt.asUintN(0); +}, "ToBigInt: no argument => undefined => TypeError"); + +assert.throws(TypeError, function() { + BigInt.asUintN(0, undefined); +}, "ToBigInt: undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return undefined; + } + }); +}, "ToBigInt: @@toPrimitive => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return undefined; + } + }); +}, "ToBigInt: valueOf => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + toString: function() { + return undefined; + } + }); +}, "ToBigInt: toString => undefined => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, null); +}, "ToBigInt: null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return null; + } + }); +}, "ToBigInt: @@toPrimitive => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return null; + } + }); +}, "ToBigInt: valueOf => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + toString: function() { + return null; + } + }); +}, "ToBigInt: toString => null => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, 0); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, Object(0)); +}, "ToBigInt: unbox object with internal slot => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return 0; + } + }); +}, "ToBigInt: @@toPrimitive => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return 0; + } + }); +}, "ToBigInt: valueOf => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + toString: function() { + return 0; + } + }); +}, "ToBigInt: toString => Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, NaN); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, Infinity); +}, "ToBigInt: Number => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, Symbol("1")); +}, "ToBigInt: Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, Object(Symbol("1"))); +}, "ToBigInt: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + toString: function() { + return Symbol("1"); + } + }); +}, "ToBigInt: toString => Symbol => TypeError"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, "a"); +}, "ToBigInt: unparseable BigInt"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, "0b2"); +}, "ToBigInt: unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, Object("0b2")); +}, "ToBigInt: unbox object with internal slot => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return "0b2"; + } + }); +}, "ToBigInt: @@toPrimitive => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return "0b2"; + } + }); +}, "ToBigInt: valueOf => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, { + toString: function() { + return "0b2"; + } + }); +}, "ToBigInt: toString => unparseable BigInt binary"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, " 0b2 "); +}, "ToBigInt: unparseable BigInt with leading/trailing whitespace"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, "0o8"); +}, "ToBigInt: unparseable BigInt octal"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, "0xg"); +}, "ToBigInt: unparseable BigInt hex"); +assert.throws(SyntaxError, function() { + BigInt.asUintN(0, "1n"); +}, "ToBigInt: unparseable BigInt due to literal suffix"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js new file mode 100644 index 0000000000..bda1fca2d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js @@ -0,0 +1,169 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bigint parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asUintN, 'function'); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: function() { + return "1"; + }, + valueOf: err, + toString: err +}), 1n, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return "1"; + }, + toString: err +}), 1n, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(BigInt.asUintN(2, { + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: toString with no valueOf"); +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: null, + valueOf: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: null, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: 1, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: {}, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return {}; + }, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return Object(12345); + }, + toString: function() { + return "1"; + } +}), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + BigInt.asUintN(0, { + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + BigInt.asUintN(0, { + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + BigInt.asUintN(0, { + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN(0, { + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js new file mode 100644 index 0000000000..1c4105114a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js @@ -0,0 +1,64 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bigint parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ + +assert.sameValue(BigInt.asUintN(2, Object(0n)), 0n, "ToPrimitive: unbox object with internal slot"); +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: function() { + return 0n; + } +}), 0n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return 0n; + } +}), 0n, "ToPrimitive: valueOf"); +assert.sameValue(BigInt.asUintN(2, { + toString: function() { + return 0n; + } +}), 0n, "ToPrimitive: toString"); +assert.sameValue(BigInt.asUintN(2, Object(true)), 1n, + "ToBigInt: unbox object with internal slot => true => 1n"); +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: function() { + return true; + } +}), 1n, "ToBigInt: @@toPrimitive => true => 1n"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return true; + } +}), 1n, "ToBigInt: valueOf => true => 1n"); +assert.sameValue(BigInt.asUintN(2, { + toString: function() { + return true; + } +}), 1n, "ToBigInt: toString => true => 1n"); +assert.sameValue(BigInt.asUintN(2, Object("1")), 1n, + "ToBigInt: unbox object with internal slot => parse BigInt"); +assert.sameValue(BigInt.asUintN(2, { + [Symbol.toPrimitive]: function() { + return "1"; + } +}), 1n, "ToBigInt: @@toPrimitive => parse BigInt"); +assert.sameValue(BigInt.asUintN(2, { + valueOf: function() { + return "1"; + } +}), 1n, "ToBigInt: valueOf => parse BigInt"); +assert.sameValue(BigInt.asUintN(2, { + toString: function() { + return "1"; + } +}), 1n, "ToBigInt: toString => parse BigInt"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint.js new file mode 100644 index 0000000000..37e2da165a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bigint-tobigint.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bigint parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 2. Let bigint ? ToBigInt(bigint). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asUintN(2, 0n), 0n); +assert.sameValue(BigInt.asUintN(2, -0n), 0n); +assert.sameValue(BigInt.asUintN(2, false), 0n, "ToBigInt: false => 0n"); +assert.sameValue(BigInt.asUintN(2, true), 1n, "ToBigInt: true => 1n"); +assert.sameValue(BigInt.asUintN(2, "1"), 1n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asUintN(2, "-0"), 0n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asUintN(2, ""), 0n, "ToBigInt: empty String => 0n"); +assert.sameValue(BigInt.asUintN(2, " "), 0n, "ToBigInt: String with only whitespace => 0n"); +assert.sameValue(BigInt.asUintN(2, []), 0n, "ToBigInt: .toString() => empty String => 0n"); +assert.sameValue(BigInt.asUintN(2, [1]), 1n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asUintN(3, 10n), 2n); +assert.sameValue(BigInt.asUintN(3, "10"), 2n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asUintN(3, "0b1010"), 2n, "ToBigInt: parse BigInt binary"); +assert.sameValue(BigInt.asUintN(3, "0o12"), 2n, "ToBigInt: parse BigInt octal"); +assert.sameValue(BigInt.asUintN(3, "0xa"), 2n, "ToBigInt: parse BigInt hex"); +assert.sameValue(BigInt.asUintN(3, " 0xa "), 2n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asUintN(3, " 10 "), 2n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asUintN(3, [10n]), 2n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asUintN(3, ["10"]), 2n, "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asUintN(4, 12345678901234567890003n), 3n); +assert.sameValue(BigInt.asUintN(4, "12345678901234567890003"), 3n, "ToBigInt: parse BigInt"); +assert.sameValue(BigInt.asUintN(4, + "0b10100111010100001010110110010011100111011001110001010000100100010001010011"), 3n, + "ToBigInt: parse BigInt binary"); +assert.sameValue(BigInt.asUintN(4, "0o2472412662347316120442123"), 3n, + "ToBigInt: parse BigInt octal"); +assert.sameValue(BigInt.asUintN(4, "0x29d42b64e7671424453"), 3n, "ToBigInt: parse BigInt hex"); +assert.sameValue(BigInt.asUintN(4, " 0x29d42b64e7671424453 "), 3n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asUintN(4, " 12345678901234567890003 "), 3n, + "ToBigInt: parse BigInt ignore leading/trailing whitespace"); +assert.sameValue(BigInt.asUintN(4, [12345678901234567890003n]), 3n, + "ToBigInt: .toString() => parse BigInt"); +assert.sameValue(BigInt.asUintN(4, ["12345678901234567890003"]), 3n, + "ToBigInt: .toString() => parse BigInt"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-errors.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-errors.js new file mode 100644 index 0000000000..59280fbdc2 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-errors.js @@ -0,0 +1,88 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bits parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asUintN, 'function'); + +assert.throws(RangeError, function() { + BigInt.asUintN(-1, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asUintN(-2.5, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asUintN("-2.5", 0n); +}, "ToIndex: parse Number => throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asUintN(-Infinity, 0n); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + BigInt.asUintN(9007199254740992, 0n); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(RangeError, function() { + BigInt.asUintN(Infinity, 0n); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(TypeError, function() { + BigInt.asUintN(0n, 0n); +}, "ToIndex: BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(Object(0n), 0n); +}, "ToIndex: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return 0n; + } + }, 0n); +}, "ToIndex: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: function() { + return 0n; + } + }, 0n); +}, "ToIndex: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + toString: function() { + return 0n; + } + }, 0n); +}, "ToIndex: toString => BigInt => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(Symbol("1"), 0n); +}, "ToIndex: Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN(Object(Symbol("1")), 0n); +}, "ToIndex: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + toString: function() { + return Symbol("1"); + } + }, 0n); +}, "ToIndex: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-toprimitive.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-toprimitive.js new file mode 100644 index 0000000000..30008284c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-toprimitive.js @@ -0,0 +1,169 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bits parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ +assert.sameValue(typeof BigInt, 'function'); +assert.sameValue(typeof BigInt.asUintN, 'function'); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}, 1n), 1n, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return 1; + }, + toString: err +}, 1n), 1n, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: toString with no valueOf"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(BigInt.asUintN({ + valueOf: null, + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN({ + valueOf: 1, + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN({ + valueOf: {}, + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}, 1n), 1n, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: 1 + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: {} + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return {}; + } + }, 0n); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + BigInt.asUintN({ + valueOf: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + BigInt.asUintN({ + toString: function() { + throw new MyError(); + } + }, 0n); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: null, + toString: null + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: 1, + toString: 1 + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: {}, + toString: {} + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + BigInt.asUintN({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }, 0n); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js new file mode 100644 index 0000000000..ab18dcaf06 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js @@ -0,0 +1,111 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bits parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] +---*/ + +assert.sameValue(BigInt.asUintN(Object(0), 1n), 0n, "ToPrimitive: unbox object with internal slot"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: valueOf"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return 0; + } +}, 1n), 0n, "ToPrimitive: toString"); +assert.sameValue(BigInt.asUintN(Object(NaN), 1n), 0n, + "ToIndex: unbox object with internal slot => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: valueOf => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return NaN; + } +}, 1n), 0n, "ToIndex: toString => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: valueOf => undefined => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return undefined; + } +}, 1n), 0n, "ToIndex: toString => undefined => NaN => 0"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return null; + } +}, 1n), 0n, "ToIndex: @@toPrimitive => null => 0"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return null; + } +}, 1n), 0n, "ToIndex: valueOf => null => 0"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return null; + } +}, 1n), 0n, "ToIndex: toString => null => 0"); +assert.sameValue(BigInt.asUintN(Object(true), 1n), 1n, + "ToIndex: unbox object with internal slot => true => 1"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return true; + } +}, 1n), 1n, "ToIndex: @@toPrimitive => true => 1"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return true; + } +}, 1n), 1n, "ToIndex: valueOf => true => 1"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return true; + } +}, 1n), 1n, "ToIndex: toString => true => 1"); +assert.sameValue(BigInt.asUintN(Object("1"), 1n), 1n, + "ToIndex: unbox object with internal slot => parse Number"); +assert.sameValue(BigInt.asUintN({ + [Symbol.toPrimitive]: function() { + return "1"; + } +}, 1n), 1n, "ToIndex: @@toPrimitive => parse Number"); +assert.sameValue(BigInt.asUintN({ + valueOf: function() { + return "1"; + } +}, 1n), 1n, "ToIndex: valueOf => parse Number"); +assert.sameValue(BigInt.asUintN({ + toString: function() { + return "1"; + } +}, 1n), 1n, "ToIndex: toString => parse Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex.js b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex.js new file mode 100644 index 0000000000..f04dfa070e --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: BigInt.asUintN type coercion for bits parameter +esid: sec-bigint.asuintn +info: | + BigInt.asUintN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.asUintN(0, 1n), 0n); +assert.sameValue(BigInt.asUintN(1, 1n), 1n); +assert.sameValue(BigInt.asUintN(-0.9, 1n), 0n, "ToIndex: truncate towards 0"); +assert.sameValue(BigInt.asUintN(0.9, 1n), 0n, "ToIndex: truncate towards 0"); +assert.sameValue(BigInt.asUintN(NaN, 1n), 0n, "ToIndex: NaN => 0"); +assert.sameValue(BigInt.asUintN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0"); +assert.sameValue(BigInt.asUintN(null, 1n), 0n, "ToIndex: null => 0"); +assert.sameValue(BigInt.asUintN(false, 1n), 0n, "ToIndex: false => 0"); +assert.sameValue(BigInt.asUintN(true, 1n), 1n, "ToIndex: true => 1"); +assert.sameValue(BigInt.asUintN("0", 1n), 0n, "ToIndex: parse Number"); +assert.sameValue(BigInt.asUintN("1", 1n), 1n, "ToIndex: parse Number"); +assert.sameValue(BigInt.asUintN("", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asUintN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asUintN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(BigInt.asUintN(3, 10n), 2n); +assert.sameValue(BigInt.asUintN("3", 10n), 2n, "toIndex: parse Number"); +assert.sameValue(BigInt.asUintN(3.9, 10n), 2n, "toIndex: truncate towards 0"); +assert.sameValue(BigInt.asUintN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0"); +assert.sameValue(BigInt.asUintN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0'); +assert.sameValue(BigInt.asUintN(["1"], 1n), 1n, 'ToIndex: ["1"].toString() => "1" => 1'); +assert.sameValue(BigInt.asUintN({}, 1n), 0n, + 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue(BigInt.asUintN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/browser.js b/js/src/tests/test262/built-ins/BigInt/asUintN/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/length.js b/js/src/tests/test262/built-ins/BigInt/asUintN/length.js new file mode 100644 index 0000000000..8155411171 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/length.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asuintn +description: BigInt.asUintN.length descriptor +info: | + BigInt.asUintN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.asUintN, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/name.js b/js/src/tests/test262/built-ins/BigInt/asUintN/name.js new file mode 100644 index 0000000000..b3520892a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asuintn +description: BigInt.asUintN.name descriptor +info: | + BigInt.asUintN ( bits, bigint ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.asUintN, "name", { + value: "asUintN", + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/not-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/asUintN/not-a-constructor.js new file mode 100644 index 0000000000..e1208f5886 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/not-a-constructor.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt.asUintN does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, arrow-function] +---*/ +assert.sameValue(isConstructor(BigInt.asUintN), false, 'isConstructor(BigInt.asUintN) must return false'); + +assert.throws(TypeError, () => { + new BigInt.asUintN(64, 1n); +}, '`new BigInt.asUintN(64, 1n)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/order-of-steps.js b/js/src/tests/test262/built-ins/BigInt/asUintN/order-of-steps.js new file mode 100644 index 0000000000..d957e66859 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/asUintN/order-of-steps.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint.asuintn +description: BigInt.asUintN order of parameter type coercion +info: | + BigInt.asUintN ( bits, bigint ) + + 1. Let bits be ? ToIndex(bits). + 2. Let bigint ? ToBigInt(bigint). + +features: [BigInt] +---*/ + +var i = 0; +var bits = { + valueOf() { + assert.sameValue(i, 0); + i++; + return 0; + } +}; +var bigint = { + valueOf() { + assert.sameValue(i, 1); + i++; + return 0n; + } +}; + +BigInt.asUintN(bits, bigint); +assert.sameValue(i, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/asUintN/shell.js b/js/src/tests/test262/built-ins/BigInt/asUintN/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/browser.js b/js/src/tests/test262/built-ins/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/call-value-of-when-to-string-present.js b/js/src/tests/test262/built-ins/BigInt/call-value-of-when-to-string-present.js new file mode 100644 index 0000000000..05baf250a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/call-value-of-when-to-string-present.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: ToPrimitive receives "hint Number" as parameter, then valueOf needs to be called +esid: sec-bigint-constructor-number-value +info: | + 1. If NewTarget is not undefined, throw a TypeError exception. + 2. Let prim be ? ToPrimitive(value, hint Number). + ... +features: [BigInt] +---*/ + +let o = { + valueOf: function() { + return 44; + }, + + toString: function() { + throw new Test262Error("unreachable"); + } +} + +assert.sameValue(BigInt(o), 44n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-coercion.js b/js/src/tests/test262/built-ins/BigInt/constructor-coercion.js new file mode 100644 index 0000000000..8275c5b1ab --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-coercion.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: BigInt constructor only coerces its input once +esid: sec-bigint-constructor-number-value +info: | + BigInt ( value ) + 1. If NewTarget is not undefined, throw a TypeError exception. + 2. Let prim be ? ToPrimitive(value, number). + 3. If Type(prim) is Number, return ? NumberToBigInt(prim). + 4. Otherwise, return ? ToBigInt(prim). +features: [BigInt] +---*/ + +var first = true; +var v = { + [Symbol.toPrimitive]: function() { + if (first) { + first = false; + return "42"; + } + throw new Test262Error("Symbol.toPrimitive should only be invoked once"); + }, +}; + +assert.sameValue(BigInt(v), 42n, "BigInt constructor should use the post-ToPrimitive value as the argument to ToBigInt"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-empty-string.js b/js/src/tests/test262/built-ins/BigInt/constructor-empty-string.js new file mode 100644 index 0000000000..847aa37bb3 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-empty-string.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Empty String should in BigInt should result into 0n +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt(""), 0n); +assert.sameValue(BigInt(" "), 0n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-from-binary-string.js b/js/src/tests/test262/built-ins/BigInt/constructor-from-binary-string.js new file mode 100644 index 0000000000..eac13bc6e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-from-binary-string.js @@ -0,0 +1,45 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String should be parsed to BigInt according StringToBigInt +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt("0b1111"), 15n); +assert.sameValue(BigInt("0b10"), 2n); +assert.sameValue(BigInt("0b0"), 0n); +assert.sameValue(BigInt("0b1"), 1n); + +let binaryString = "0b1"; +for (let i = 0; i < 128; i++) + binaryString += "0"; + +assert.sameValue(BigInt(binaryString), 340282366920938463463374607431768211456n); + +assert.sameValue(BigInt("0B1111"), 15n); +assert.sameValue(BigInt("0B10"), 2n); +assert.sameValue(BigInt("0B0"), 0n); +assert.sameValue(BigInt("0B1"), 1n); + +binaryString = "0B1"; +for (let i = 0; i < 128; i++) + binaryString += "0"; + +assert.sameValue(BigInt(binaryString), 340282366920938463463374607431768211456n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-from-decimal-string.js b/js/src/tests/test262/built-ins/BigInt/constructor-from-decimal-string.js new file mode 100644 index 0000000000..8b5ea7b672 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-from-decimal-string.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String should be parsed to BigInt according StringToBigInt +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt("10"), 10n); +assert.sameValue(BigInt("18446744073709551616"), 18446744073709551616n); +assert.sameValue(BigInt("7"), 7n); +assert.sameValue(BigInt("88"), 88n); +assert.sameValue(BigInt("900"), 900n); + +assert.sameValue(BigInt("-10"), -10n); +assert.sameValue(BigInt("-18446744073709551616"), -18446744073709551616n); +assert.sameValue(BigInt("-7"), -7n); +assert.sameValue(BigInt("-88"), -88n); +assert.sameValue(BigInt("-900"), -900n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-from-hex-string.js b/js/src/tests/test262/built-ins/BigInt/constructor-from-hex-string.js new file mode 100644 index 0000000000..d6490a9ca5 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-from-hex-string.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Hexdecimal prefixed String should be parsed to BigInt according StringToBigInt +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt("0xa"), 10n); +assert.sameValue(BigInt("0xff"), 255n); +assert.sameValue(BigInt("0xfabc"), 64188n); +assert.sameValue(BigInt("0xfffffffffffffffffff"), 75557863725914323419135n); + +assert.sameValue(BigInt("0Xa"), 10n); +assert.sameValue(BigInt("0Xff"), 255n); +assert.sameValue(BigInt("0Xfabc"), 64188n); +assert.sameValue(BigInt("0Xfffffffffffffffffff"), 75557863725914323419135n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-from-octal-string.js b/js/src/tests/test262/built-ins/BigInt/constructor-from-octal-string.js new file mode 100644 index 0000000000..afef8ed7eb --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-from-octal-string.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Octal prefixed String should be parsed to BigInt according StringToBigInt +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt("0o7"), 7n); +assert.sameValue(BigInt("0o10"), 8n); +assert.sameValue(BigInt("0o20"), 16n); + +assert.sameValue(BigInt("0O7"), 7n); +assert.sameValue(BigInt("0O10"), 8n); +assert.sameValue(BigInt("0O20"), 16n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-from-string-syntax-errors.js b/js/src/tests/test262/built-ins/BigInt/constructor-from-string-syntax-errors.js new file mode 100644 index 0000000000..b0e580fbad --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-from-string-syntax-errors.js @@ -0,0 +1,79 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Invalid String into BigInt constructor should throw SyntaxError +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + +features: [BigInt] +---*/ + +assert.throws(SyntaxError, function() { + BigInt("10n"); +}); + +assert.throws(SyntaxError, function() { + BigInt("10x"); +}); + +assert.throws(SyntaxError, function() { + BigInt("10b"); +}); + +assert.throws(SyntaxError, function() { + BigInt("10.5"); +}); + +assert.throws(SyntaxError, function() { + BigInt("0b"); +}); + +assert.throws(SyntaxError, function() { + BigInt("-0x1"); +}); + +assert.throws(SyntaxError, function() { + BigInt("-0XFFab"); +}); + +assert.throws(SyntaxError, function() { + BigInt("0oa"); +}); + +assert.throws(SyntaxError, function() { + BigInt("000 12"); +}); + +assert.throws(SyntaxError, function() { + BigInt("0o"); +}); + +assert.throws(SyntaxError, function() { + BigInt("0x"); +}); + +assert.throws(SyntaxError, function() { + BigInt("00o"); +}); + +assert.throws(SyntaxError, function() { + BigInt("00b"); +}); + +assert.throws(SyntaxError, function() { + BigInt("00x"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-integer.js b/js/src/tests/test262/built-ins/BigInt/constructor-integer.js new file mode 100644 index 0000000000..c70dac79c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-integer.js @@ -0,0 +1,60 @@ +// Copyright (C) 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: BigInt constructor called with integer argument +esid: sec-bigint-constructor-number-value +info: | + BigInt ( value ) + + ... + 3. If Type(prim) is Number, return ? NumberToBigInt(prim). + + NumberToBigInt ( number ) + + ... + 3. Return a BigInt representing the mathematical value of number. +features: [BigInt] +---*/ + +assert.sameValue( + BigInt(Number.MAX_SAFE_INTEGER), 9007199254740991n, + "BigInt(Number.MAX_SAFE_INTEGER) === 9007199254740991n" +); + +assert.sameValue( + BigInt(-Number.MAX_SAFE_INTEGER), -9007199254740991n, + "BigInt(-Number.MAX_SAFE_INTEGER) === -9007199254740991n" +); + +assert.sameValue( + BigInt(Number.MAX_SAFE_INTEGER + 1), 9007199254740992n, + "BigInt(Number.MAX_SAFE_INTEGER + 1) === 9007199254740992n" +); + +assert.sameValue( + BigInt(-Number.MAX_SAFE_INTEGER - 1), -9007199254740992n, + "BigInt(-Number.MAX_SAFE_INTEGER - 1) === -9007199254740992n" +); + +assert.sameValue( + BigInt(Number.MAX_SAFE_INTEGER + 2), 9007199254740992n, + "BigInt(Number.MAX_SAFE_INTEGER + 2) === 9007199254740992n" +); + +assert.sameValue( + BigInt(-Number.MAX_SAFE_INTEGER - 2), -9007199254740992n, + "BigInt(-Number.MAX_SAFE_INTEGER - 2) === -9007199254740992n" +); + +assert.sameValue( + BigInt(Number.MAX_SAFE_INTEGER + 3), 9007199254740994n, + "BigInt(Number.MAX_SAFE_INTEGER + 3) === 9007199254740994n" +); + +assert.sameValue( + BigInt(-Number.MAX_SAFE_INTEGER - 3), -9007199254740994n, + "BigInt(-Number.MAX_SAFE_INTEGER - 3) === -9007199254740994n" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/constructor-trailing-leading-spaces.js b/js/src/tests/test262/built-ins/BigInt/constructor-trailing-leading-spaces.js new file mode 100644 index 0000000000..2fd8e74218 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/constructor-trailing-leading-spaces.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Trailing/Leading spaces should be ignored in BigInt constructor +esid: sec-string-to-bigint +info: | + ToBigInt ( argument ) + + String: + + Let n be StringToBigInt(prim). + If n is NaN, throw a SyntaxError exception. + Return n. + + StringToBigInt ( argument ) + + Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents. + + +features: [BigInt] +---*/ + +assert.sameValue(BigInt(" 0b1111"), 15n); +assert.sameValue(BigInt("18446744073709551616 "), 18446744073709551616n); +assert.sameValue(BigInt(" 7 "), 7n); +assert.sameValue(BigInt(" -197 "), -197n); +assert.sameValue(BigInt(" "), 0n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/infinity-throws-rangeerror.js b/js/src/tests/test262/built-ins/BigInt/infinity-throws-rangeerror.js new file mode 100644 index 0000000000..22e6a8e12a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/infinity-throws-rangeerror.js @@ -0,0 +1,44 @@ +// 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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/is-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/is-a-constructor.js new file mode 100644 index 0000000000..80cd2cf59a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/is-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt is a constructor, and does implement [[Construct]], but is not new target +info: | + sec-bigint-constructor + + - is not intended to be used with the new operator or to be subclassed. It may be used as the value of an extends clause of a class definition but a super call to the BigInt constructor will cause an exception. + + sec-bigint-constructor-number-value + + 1. If NewTarget is not undefined, throw a TypeError exception. +includes: [isConstructor.js] +features: [BigInt, Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(BigInt), + true, + 'isConstructor(BigInt) must return true' +); + +assert.throws(TypeError, () => { + new BigInt({ + valueOf() { + new Test262Error(); + } + }); +}, '`new BigInt({ valueOf() {new Test262Error();}})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/length.js b/js/src/tests/test262/built-ins/BigInt/length.js new file mode 100644 index 0000000000..47a4d07d07 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-constructor-number-value +description: BigInt.length property descriptor +info: | + BigInt ( value ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in + function object has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/name.js b/js/src/tests/test262/built-ins/BigInt/name.js new file mode 100644 index 0000000000..6568d1bdf7 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/name.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. + +/*--- +esid: sec-bigint-constructor-number-value +description: BigInt.name property descriptor +info: | + BigInt ( value ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. Unless otherwise specified, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt, "name", { + value: "BigInt", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/nan-throws-rangeerror.js b/js/src/tests/test262/built-ins/BigInt/nan-throws-rangeerror.js new file mode 100644 index 0000000000..cdbf3b5bbe --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/nan-throws-rangeerror.js @@ -0,0 +1,44 @@ +// 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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/negative-infinity-throws.rangeerror.js b/js/src/tests/test262/built-ins/BigInt/negative-infinity-throws.rangeerror.js new file mode 100644 index 0000000000..8e7779d0e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/negative-infinity-throws.rangeerror.js @@ -0,0 +1,44 @@ +// 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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/non-integer-rangeerror.js b/js/src/tests/test262/built-ins/BigInt/non-integer-rangeerror.js new file mode 100644 index 0000000000..2ef9f93918 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/non-integer-rangeerror.js @@ -0,0 +1,59 @@ +// 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/parseInt/browser.js b/js/src/tests/test262/built-ins/BigInt/parseInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/parseInt/nonexistent.js b/js/src/tests/test262/built-ins/BigInt/parseInt/nonexistent.js new file mode 100644 index 0000000000..87cc79b700 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/parseInt/nonexistent.js @@ -0,0 +1,11 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: BigInt does not have a static parseInt function +features: [BigInt] +---*/ + +assert(!BigInt.hasOwnProperty("parseInt")); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/parseInt/shell.js b/js/src/tests/test262/built-ins/BigInt/parseInt/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prop-desc.js b/js/src/tests/test262/built-ins/BigInt/prop-desc.js new file mode 100644 index 0000000000..5e9500e45f --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prop-desc.js @@ -0,0 +1,26 @@ +// 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] +features: [BigInt] +---*/ + +verifyProperty(this, "BigInt", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/proto.js b/js/src/tests/test262/built-ins/BigInt/proto.js new file mode 100644 index 0000000000..8e0ed21828 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/proto.js @@ -0,0 +1,17 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/BigInt/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..33e806a2e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/Symbol.toStringTag.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Igalia, S. L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-bigint-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "BigInt". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt, Symbol, Symbol.toStringTag] +---*/ + +verifyProperty(BigInt.prototype, Symbol.toStringTag, { + value: "BigInt", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/browser.js b/js/src/tests/test262/built-ins/BigInt/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/constructor.js b/js/src/tests/test262/built-ins/BigInt/prototype/constructor.js new file mode 100644 index 0000000000..c36f2e266e --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.constructor +description: BigInt.prototype.constructor property descriptor +info: | + BigInt.prototype.constructor + + The initial value of BigInt.prototype.constructor is the intrinsic + object %BigInt%. + + The BigInt Constructor + + The BigInt constructor is the %BigInt% intrinsic object and the + initial value of the BigInt property of the global object. When BigInt + is called as a function, it performs a type conversion. + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype, "constructor", { + value: BigInt, + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/prop-desc.js b/js/src/tests/test262/built-ins/BigInt/prototype/prop-desc.js new file mode 100644 index 0000000000..f8ac507a95 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/prop-desc.js @@ -0,0 +1,20 @@ +// 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 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/proto.js b/js/src/tests/test262/built-ins/BigInt/prototype/proto.js new file mode 100644 index 0000000000..df0b8edeaf --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/proto.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/shell.js b/js/src/tests/test262/built-ins/BigInt/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/browser.js b/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/not-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/not-a-constructor.js new file mode 100644 index 0000000000..e51206920a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/not-a-constructor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt.prototype.toLocaleString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, arrow-function] +---*/ +assert.sameValue( + isConstructor(BigInt.prototype.toLocaleString), + false, + 'isConstructor(BigInt.prototype.toLocaleString) must return false' +); + +assert.throws(TypeError, () => { + let n = 1n; + new n.toLocaleString(); +}, '`let n = 1n; new n.toLocaleString()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/shell.js b/js/src/tests/test262/built-ins/BigInt/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/a-z.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/a-z.js new file mode 100644 index 0000000000..c6b50f1943 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/a-z.js @@ -0,0 +1,23 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: > + Letters a-z are used for digits with values 10 through 35 +info: | + 6. Return the String representation of this Number value using + the radix specified by radixNumber. Letters a-z are used for + digits with values 10 through 35. The precise algorithm is + implementation-dependent, however the algorithm should be a + generalization of that specified in 6.1.6.2.23. +features: [BigInt] +---*/ + +for (let radix = 11; radix <= 36; radix++) { + for (let i = 10n; i < radix; i++) { + assert.sameValue(i.toString(radix), String.fromCharCode(Number(i + 87n))); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/browser.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/default-radix.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/default-radix.js new file mode 100644 index 0000000000..3ec85a7d95 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/default-radix.js @@ -0,0 +1,21 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: toString with default radix +features: [BigInt] +---*/ + +assert.sameValue((-100n).toString(), "-100", "(-100n).toString() === '-100'"); +assert.sameValue((0n).toString(), "0", "(0n).toString() === '0'"); +assert.sameValue((100n).toString(), "100", "(100n).toString() === '100'"); + +assert.sameValue((-100n).toString(undefined), "-100", + "(-100n).toString(undefined) === '-100'"); +assert.sameValue((0n).toString(undefined), "0", + "(0n).toString(undefined) === '0'"); +assert.sameValue((100n).toString(undefined), "100", + "(100n).toString(undefined) === '100'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/length.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/length.js new file mode 100644 index 0000000000..add932d601 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/length.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. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString.length property descriptor +info: | + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.toString, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/name.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/name.js new file mode 100644 index 0000000000..b5da17dff6 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/name.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. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString.name property descriptor +info: | + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.toString, "name", { + value: "toString", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/not-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000..ffa6c1491c --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/not-a-constructor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt.prototype.toString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, arrow-function] +---*/ +assert.sameValue( + isConstructor(BigInt.prototype.toString), + false, + 'isConstructor(BigInt.prototype.toString) must return false' +); + +assert.throws(TypeError, () => { + let n = 1n; + new n.toString(); +}, '`let n = 1n; new n.toString()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/prop-desc.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/prop-desc.js new file mode 100644 index 0000000000..50d85e610a --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: BigInt.prototype.toString property descriptor +info: | + BigInt.prototype.toString ( [ radix ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype, "toString", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/prototype-call.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/prototype-call.js new file mode 100644 index 0000000000..6de3725ea6 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/prototype-call.js @@ -0,0 +1,24 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: Direct toString on BigInt prototype +info: | + BigInt.prototype.toString ( [ radix ] ) + + Let x be ? thisBigIntValue(this value). + + Properties of the BigInt Prototype Object + + The BigInt prototype is not a BigInt object; it does not have a + [[BigIntData]] internal slot. +features: [BigInt] +---*/ +assert.sameValue(typeof BigInt, 'function'); + +assert.throws(TypeError, function() { + BigInt.prototype.toString(1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-2-to-36.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-2-to-36.js new file mode 100644 index 0000000000..24a95b0972 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-2-to-36.js @@ -0,0 +1,26 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: toString with radix between 2 and 36 +info: | + BigInt.prototype.toString ( [ radix ] ) + + [...] + 6. If radixNumber = 10, return ! ToString(x). + 7. Return the String representation of this Number value using the + radix specified by radixNumber. Letters a-z are used for digits + with values 10 through 35. The precise algorithm is + implementation-dependent, however the algorithm should be a + generalization of that specified in 3.1.4.1. +features: [BigInt] +---*/ + +for (let r = 2; r <= 36; r++) { + assert.sameValue((0n).toString(r), "0", "0, radix " + r); + assert.sameValue((-1n).toString(r), "-1", "-1, radix " + r); + assert.sameValue((1n).toString(r), "1", "1, radix " + r); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-err.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-err.js new file mode 100644 index 0000000000..e5ef637606 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/radix-err.js @@ -0,0 +1,29 @@ +// Copyright 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: toString with invalid radix +info: | + BigInt.prototype.toString ( [ radix ] ) + + [...] + 4. Else, let radixNumber be ? ToInteger(radix). + 5. If radixNumber < 2 or radixNumber > 36, throw a RangeError + exception. +features: [BigInt] +---*/ + +for (let r of [0, 1, 37, null]) { + assert.throws(RangeError, function() { + (0n).toString(r); + }, "0, radix " + r); + assert.throws(RangeError, function() { + (-1n).toString(r); + }, "-1, radix " + r); + assert.throws(RangeError, function() { + (1n).toString(r); + }, "1, radix " + r); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/shell.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/string-is-code-units-of-decimal-digits-only.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/string-is-code-units-of-decimal-digits-only.js new file mode 100644 index 0000000000..a3c11c2396 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/string-is-code-units-of-decimal-digits-only.js @@ -0,0 +1,22 @@ +// Copyright 2017 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-tostring-applied-to-the-bigint-type +description: BigInt .toString() returns only decimal digits, does not include BigIntLiteralSuffix +info: | + ToString Applied to the BigInt Type + + The abstract operation ToString converts a BigInt i to String format as follows: + + ... + Return the String consisting of the code units of the digits of the decimal representation of i. + +features: [BigInt] +---*/ + +assert.sameValue(BigInt(0).toString(), "0", "BigInt(0).toString() === '0'"); +assert.sameValue(BigInt(0n).toString(), "0", "BigInt(0n).toString() === '0'"); +assert.sameValue(0n.toString(), "0", "0n.toString() === '0'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js b/js/src/tests/test262/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js new file mode 100644 index 0000000000..d9aaed49c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js @@ -0,0 +1,79 @@ +// Copyright 2017 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tostring +description: Throws a TypeError if the this value is not a BigInt +info: | + BigInt.prototype.toString ( [ radix ] ) + + 1. Let x be ? thisBigIntValue(this value). + ... + + The abstract operation thisBigIntValue(value) performs the following steps: + + 1. If Type(value) is BigInt, return value. + 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then + ... + 3. Throw a TypeError exception. +features: [BigInt, Symbol, Symbol.toPrimitive] +---*/ + +var toString = BigInt.prototype.toString; + +assert.sameValue(typeof toString, 'function'); + +assert.throws(TypeError, function() { + toString.call({ + x: 1n + }); +}, '{x: 1n}'); + +assert.throws(TypeError, function() { + toString.call([1n]); +}, '[1n]'); + +var obj = { + valueOf: function() { + throw new Test262Error('no [[BigIntData]]') + }, + toString: function() { + throw new Test262Error('no [[BigIntData]]') + }, + [Symbol.toPrimitive]: function() { + throw new Test262Error('no [[BigIntData]]') + } +}; +assert.throws(TypeError, function() { + toString.call(obj); +}, '{valueOf, toString, toPrimitive}'); + +assert.throws(TypeError, function() { + toString.call(0); +}, '0'); + +assert.throws(TypeError, function() { + toString.call(1); +}, '1'); + +assert.throws(TypeError, function() { + toString.call(NaN); +}, 'NaN'); + +assert.throws(TypeError, function() { + toString.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toString.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + toString.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + toString.call(false); +}, 'false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/browser.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/cross-realm.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/cross-realm.js new file mode 100644 index 0000000000..96cb49dd2f --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/cross-realm.js @@ -0,0 +1,16 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.valueof +description: valueOf called with a BigInt object from another realm +features: [BigInt, cross-realm] +---*/ + +var other = $262.createRealm().global; +var wrapped = other.Object(other.BigInt(0)); + +assert.sameValue(BigInt.prototype.valueOf.call(wrapped), 0n, + "cross-realm valueOf"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/length.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/length.js new file mode 100644 index 0000000000..871b9d030c --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/length.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. + +/*--- +esid: sec-bigint.prototype.valueof +description: BigInt.prototype.valueOf.length property descriptor +info: | + BigInt.prototype.valueOf ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.valueOf, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/name.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/name.js new file mode 100644 index 0000000000..eb632fb265 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/name.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. + +/*--- +esid: sec-bigint.prototype.valueof +description: BigInt.prototype.valueOf.name property descriptor +info: | + BigInt.prototype.valueOf ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.valueOf, "name", { + value: "valueOf", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/not-a-constructor.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/not-a-constructor.js new file mode 100644 index 0000000000..1476cd46dd --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/not-a-constructor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + BigInt.prototype.valueOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, arrow-function] +---*/ +assert.sameValue( + isConstructor(BigInt.prototype.valueOf), + false, + 'isConstructor(BigInt.prototype.valueOf) must return false' +); + +assert.throws(TypeError, () => { + let n = 1n; + new n.valueOf(); +}, '`let n = 1n; new n.valueOf()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/prop-desc.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/prop-desc.js new file mode 100644 index 0000000000..22776b6d1b --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.valueof +description: BigInt.prototype.valueOf property descriptor +info: | + BigInt.prototype.valueOf ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype, "valueOf", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/return.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/return.js new file mode 100644 index 0000000000..c9a0472bcc --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/return.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.valueof +description: > + BigInt.prototype.valueOf returns the primitive BigInt value. +info: | + BigInt.prototype.valueOf ( ) + + Return ? thisBigIntValue(this value). +features: [BigInt] +---*/ + +var valueOf = BigInt.prototype.valueOf; + +assert.sameValue(valueOf.call(0n), 0n, "0n"); +assert.sameValue(valueOf.call(Object(0n)), 0n, "Object(0n)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/shell.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-object-throws.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-object-throws.js new file mode 100644 index 0000000000..994587d325 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-object-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. + +/*--- +esid: sec-bigint.prototype.valueof +description: > + Throws a TypeError if this is an Object without a [[BigIntData]] internal. +info: | + BigInt.prototype.valueOf ( ) + + 1. Return ? thisBigIntValue(this value). + + The abstract operation thisBigIntValue(value) performs the following steps: + + 1. If Type(value) is BigInt, return value. + 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then + ... + 3. Throw a TypeError exception. +features: [BigInt] +---*/ + +var valueOf = BigInt.prototype.valueOf; +assert.sameValue(typeof valueOf, 'function'); + +assert.throws(TypeError, function() { + valueOf.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + valueOf.call(Object(1)); +}, "Object(1)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-primitive-throws.js b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-primitive-throws.js new file mode 100644 index 0000000000..1956451d5e --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/prototype/valueOf/this-value-invalid-primitive-throws.js @@ -0,0 +1,67 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.valueof +description: > + Throws a TypeError if this is not a BigInt neither an Object. +info: | + BigInt.prototype.valueOf ( ) + + 1. Return ? thisBigIntValue(this value). + + The abstract operation thisBigIntValue(value) performs the following steps: + + 1. If Type(value) is BigInt, return value. + 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then + ... + 3. Throw a TypeError exception. +features: [BigInt, Symbol] +---*/ + +var valueOf = BigInt.prototype.valueOf; + +assert.sameValue(typeof valueOf, 'function'); + +assert.throws(TypeError, function() { + valueOf.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + valueOf.call(null); +}, "null"); + +assert.throws(TypeError, function() { + valueOf.call(false); +}, "false"); + +assert.throws(TypeError, function() { + valueOf.call(true); +}, "true"); + +assert.throws(TypeError, function() { + valueOf.call(""); +}, "the empty string"); + +assert.throws(TypeError, function() { + valueOf.call("1n"); +}, "string"); + +assert.throws(TypeError, function() { + valueOf.call(0); +}, "number (0)"); + +assert.throws(TypeError, function() { + valueOf.call(1); +}, "number (1)"); + +assert.throws(TypeError, function() { + valueOf.call(NaN); +}, "NaN"); + +var s = Symbol(); +assert.throws(TypeError, function() { + valueOf.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/shell.js b/js/src/tests/test262/built-ins/BigInt/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/BigInt/tostring-throws.js b/js/src/tests/test262/built-ins/BigInt/tostring-throws.js new file mode 100644 index 0000000000..e476803d12 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/tostring-throws.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Throws exception in BigIntConstructor if toString throws +esid: sec-bigint-constructor-number-value +info: | + 1. If NewTarget is not undefined, throw a TypeError exception. + 2. Let prim be ? ToPrimitive(value, hint Number). + 3. If Type(prim) is Number, return ? NumberToBigInt(prim). + 4. Otherwise, return ? ToBigInt(value). +features: [BigInt] +---*/ + +assert.throws(Test262Error, function() { + BigInt({ + toString: function() { + throw new Test262Error(); + } + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/valueof-throws.js b/js/src/tests/test262/built-ins/BigInt/valueof-throws.js new file mode 100644 index 0000000000..4d3a293b0e --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/valueof-throws.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Throws exception in BigIntConstructor if valueOf throws +esid: sec-bigint-constructor-number-value +info: | + 1. If NewTarget is not undefined, throw a TypeError exception. + 2. Let prim be ? ToPrimitive(value, hint Number). + 3. If Type(prim) is Number, return ? NumberToBigInt(prim). + 4. Otherwise, return ? ToBigInt(value). +features: [BigInt] +---*/ + +assert.throws(Test262Error, function() { + BigInt({ + valueOf: function() { + throw new Test262Error(); + } + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/BigInt/wrapper-object-ordinary-toprimitive.js b/js/src/tests/test262/built-ins/BigInt/wrapper-object-ordinary-toprimitive.js new file mode 100644 index 0000000000..99cd836ef2 --- /dev/null +++ b/js/src/tests/test262/built-ins/BigInt/wrapper-object-ordinary-toprimitive.js @@ -0,0 +1,74 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-toprimitive +description: > + BigInt wrapper object is converted to primitive via OrdinaryToPrimitive. +info: | + ToPrimitive ( input [ , preferredType ] ) + + [...] + 2. If Type(input) is Object, then + a. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + b. If exoticToPrim is not undefined, then + [...] + c. If preferredType is not present, let preferredType be number. + d. Return ? OrdinaryToPrimitive(input, preferredType). +features: [BigInt] +---*/ + +const BigIntToString = BigInt.prototype.toString; +let toStringGets = 0; +let toStringCalls = 0; +let toStringFunction = function() { ++toStringCalls; return `${BigIntToString.call(this)}foo`; }; +Object.defineProperty(BigInt.prototype, "toString", { + get: () => { ++toStringGets; return toStringFunction; }, +}); + +assert.sameValue("" + Object(1n), "1", "hint: default"); +assert.throws(TypeError, () => { +Object(1n); }, "hint: number"); +assert.sameValue(`${Object(1n)}`, "1foo", "hint: string"); + +assert.sameValue(toStringGets, 1); +assert.sameValue(toStringCalls, 1); + +const BigIntValueOf = BigInt.prototype.valueOf; +let valueOfGets = 0; +let valueOfCalls = 0; +let valueOfFunction = function() { ++valueOfCalls; return BigIntValueOf.call(this) * 2n; }; +Object.defineProperty(BigInt.prototype, "valueOf", { + get: () => { ++valueOfGets; return valueOfFunction; }, +}); + +assert(Object(1n) == 2n, "hint: default"); +assert.sameValue(Object(1n) + 1n, 3n, "hint: number"); +assert.sameValue({ "1foo": 1, "2": 2 }[Object(1n)], 1, "hint: string"); + +assert.sameValue(toStringGets, 2); +assert.sameValue(toStringCalls, 2); +assert.sameValue(valueOfGets, 2); +assert.sameValue(valueOfCalls, 2); + +toStringFunction = undefined; + +assert.throws(TypeError, () => { 1 + Object(1n); }, "hint: default"); +assert.sameValue(Object(1n) * 1n, 2n, "hint: number"); +assert.sameValue("".concat(Object(1n)), "2", "hint: string"); + +assert.sameValue(toStringGets, 3); +assert.sameValue(toStringCalls, 2); +assert.sameValue(valueOfGets, 5); +assert.sameValue(valueOfCalls, 5); + +valueOfFunction = null; + +assert.throws(TypeError, () => { new Date(Object(1n)); }, "hint: default"); +assert.throws(TypeError, () => { Number(Object(1n)); }, "hint: number"); +assert.throws(TypeError, () => { String(Object(1n)); }, "hint: string"); + +assert.sameValue(toStringGets, 6); +assert.sameValue(toStringCalls, 2); +assert.sameValue(valueOfGets, 8); +assert.sameValue(valueOfCalls, 5); + +reportCompare(0, 0); -- cgit v1.2.3