diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt')
30 files changed, 1007 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js new file mode 100644 index 0000000000..3dc905d154 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by accessing array-like's length +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var arrayLike = {}; + +Object.defineProperty(arrayLike, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js new file mode 100644 index 0000000000..a021fb9377 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by interpreting length property as a length +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var arrayLike = { length: {} }; + +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..7381016558 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Custom constructor needs to instantiate a TypedArray +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 8. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.from.call(ctor, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..616faeccbe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + Custom constructor can return any TypedArray instance with higher or same + length +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. If usingIterator is not undefined, then + a. Let values be ? IterableToList(source, usingIterator). + b. Let len be the number of elements in values. + c. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + 10. Let len be ? ToLength(? Get(arrayLike, "length")). + 11. Let targetObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sourceItor = [1n, 2n]; + var sourceObj = { + 0: 0n, + 1: 0n, + length: 2 + }; + + var result; + var custom = new TA(2); + var ctor = function() { + return custom; + }; + + result = TypedArray.from.call(ctor, sourceItor); + assert.sameValue(result, custom, "using iterator, same length"); + + result = TypedArray.from.call(ctor, sourceObj); + assert.sameValue(result, custom, "not using iterator, same length"); + + custom = new TA(3); + + result = TypedArray.from.call(ctor, sourceItor); + assert.sameValue(result, custom, "using iterator, higher length"); + + result = TypedArray.from.call(ctor, sourceObj); + assert.sameValue(result, custom, "not using iterator, higher length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..2982a4cd38 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + Throws a TypeError if a custom `this` returns a smaller instance +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. If usingIterator is not undefined, then + a. Let values be ? IterableToList(source, usingIterator). + b. Let len be the number of elements in values. + c. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + 10. Let len be ? ToLength(? Get(arrayLike, "length")). + 11. Let targetObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1n, 2n]; +var sourceObj = { + length: 2 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() { + return new TA(1); + }; + assert.throws(TypeError, function() { + TA.from.call(ctor, sourceItor); + }, "source is using iterator"); + + assert.throws(TypeError, function() { + TA.from.call(ctor, sourceObj); + }, "source is not using iterator"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js new file mode 100644 index 0000000000..538cce831f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Calls and return abrupt completion from custom constructor +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 8. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.from.call(ctor, []); + }); + + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js new file mode 100644 index 0000000000..8d4cf94da0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + `from` is %TypedArray%.from +info: | + 22.2.1 The %TypedArray% Intrinsic Object + + The %TypedArray% intrinsic object is a constructor function object that all of + the TypedArray constructor object inherit from. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue( + TA.from, TypedArray.from, + "method is inherited %TypedArray%.from" + ); + assert.sameValue( + TA.hasOwnProperty("from"), false, + "constructor does not define an own property named 'from'" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js new file mode 100644 index 0000000000..53ab9a7a3e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + "from" cannot be invoked as a function +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var from = TA.from; + + assert.throws(TypeError, function() { + from([]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js new file mode 100644 index 0000000000..b9831aaf5a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by accessing @@iterator +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js new file mode 100644 index 0000000000..4399a1956a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by invoking @@iterator +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + 2. If usingIterator is not undefined, then + a. Let iterator be ? GetIterator(items, usingIterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js new file mode 100644 index 0000000000..7b2007b15d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by advancing the iterator +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + i. Let next be ? IteratorStep(iterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js new file mode 100644 index 0000000000..cf3ba3e849 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Returns error produced by accessing iterated value +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + ... + ii. If next is not false, then + 1. Let nextValue be ? IteratorValue(next). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + var result = {}; + Object.defineProperty(result, 'value', { + get: function() { + throw new Test262Error(); + } + }); + + return result; + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js new file mode 100644 index 0000000000..f2464ac64c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return abrupt from mapfn +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = { + "0": 42n, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js new file mode 100644 index 0000000000..9f4de52fb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Assert mapfn arguments +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43, 44]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push({ + kValue: kValue, + k: k, + argsLength: arguments.length + }); + return 0n; + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 3); + + assert.sameValue(results[0].kValue, 42); + assert.sameValue(results[0].k, 0); + assert.sameValue(results[0].argsLength, 2); + + assert.sameValue(results[1].kValue, 43); + assert.sameValue(results[1].k, 1); + assert.sameValue(results[1].argsLength, 2); + + assert.sameValue(results[2].kValue, 44); + assert.sameValue(results[2].k, 2); + assert.sameValue(results[2].argsLength, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js new file mode 100644 index 0000000000..77921c51a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js @@ -0,0 +1,61 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Throw a TypeError exception is mapfn is not callable +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 3. If mapfn was supplied and mapfn is not undefined, then + a. If IsCallable(mapfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, Symbol.iterator, TypedArray] +---*/ + +var getIterator = 0; +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + getIterator++; + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from(arrayLike, null); + }, "mapfn is null"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, 42); + }, "mapfn is a number"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, ""); + }, "mapfn is a string"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, {}); + }, "mapfn is an ordinary object"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, []); + }, "mapfn is an array"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, true); + }, "mapfn is a boolean"); + + var s = Symbol("1"); + assert.throws(TypeError, function() { + TA.from(arrayLike, s); + }, "mapfn is a symbol"); + + assert.sameValue( + getIterator, 0, + "IsCallable(mapfn) check occurs before getting source[@@iterator]" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js new file mode 100644 index 0000000000..3c273cb9b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Assert mapfn `this` with thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43]; +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + return 0n; + }; + + TA.from(source, mapfn, thisArg); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], thisArg); + assert.sameValue(results[1], thisArg); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 0000000000..4cb1c28bf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Assert mapfn `this` without thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +flags: [noStrict] +features: [BigInt, TypedArray] +---*/ + +var global = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(x) { + results.push(this); + return x; + }; + + TA.from([42n, 43n], mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], global); + assert.sameValue(results[1], global); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js new file mode 100644 index 0000000000..aa79478973 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Assert mapfn `this` without thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +flags: [onlyStrict] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + return 0n; + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], undefined); + assert.sameValue(results[1], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js new file mode 100644 index 0000000000..cd2af5b6bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new empty TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([]); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js new file mode 100644 index 0000000000..a346a427ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray from an ordinary object +includes: [testBigIntTypedArray.js] +features: [BigInt, Array.prototype.values, TypedArray] +---*/ + +var source = { + "0": 42n, + "1": 44n, + length: 2 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 44n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js new file mode 100644 index 0000000000..336afe286c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Throws a TypeError casting undefined value from sparse array to BigInt +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [,42n]; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..5441898a3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray using a custom Constructor +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + var ctor = function(len) { + assert.sameValue(arguments.length, 1); + called++; + return new TA(len); + }; + + var result = TA.from.call(ctor, [42n, 43n, 42n]); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 42n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js new file mode 100644 index 0000000000..474f7ef675 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray using mapfn +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var mapfn = function(kValue) { + return kValue * 2n; + }; + + var result = TA.from([42n, 43n, 42n], mapfn); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 84n); + assert.sameValue(result[1], 86n); + assert.sameValue(result[2], 84n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js new file mode 100644 index 0000000000..e7b1585343 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([42n, 43n, 42n]); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 42n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js new file mode 100644 index 0000000000..1587324cf1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return abrupt from source property +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = { + length: 2 +}; +Object.defineProperty(source, "0", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js new file mode 100644 index 0000000000..b61d83c13d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return abrupt from setting a value on the new typedarray +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + d. Else, let mappedValue be kValue. + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var source = [42n, obj, 1n]; + var lastValue; + var mapfn = function(kValue) { + lastValue = kValue; + return kValue; + }; + + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); + + assert.sameValue(lastValue, obj, "interrupted source iteration"); + + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js new file mode 100644 index 0000000000..50db94969c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Throws a TypeError if argument is a Symbol +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js new file mode 100644 index 0000000000..9ad1a48462 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Throws a TypeError exception if this is not a constructor +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from.call(m, []); + }); +}); + +reportCompare(0, 0); |