From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../from/BigInt/arylk-get-length-error.js | 30 +++++ .../from/BigInt/arylk-to-length-error.js | 30 +++++ .../TypedArrayConstructors/from/BigInt/browser.js | 0 .../custom-ctor-does-not-instantiate-ta-throws.js | 31 ++++++ .../BigInt/custom-ctor-returns-other-instance.js | 54 +++++++++ .../custom-ctor-returns-smaller-instance-throws.js | 42 +++++++ .../from/BigInt/custom-ctor.js | 36 ++++++ .../from/BigInt/inherited.js | 27 +++++ .../from/BigInt/invoked-as-func.js | 25 +++++ .../from/BigInt/iter-access-error.js | 34 ++++++ .../from/BigInt/iter-invoke-error.js | 34 ++++++ .../from/BigInt/iter-next-error.js | 33 ++++++ .../from/BigInt/iter-next-value-error.js | 42 +++++++ .../from/BigInt/mapfn-abrupt-completion.js | 34 ++++++ .../from/BigInt/mapfn-arguments.js | 50 +++++++++ .../from/BigInt/mapfn-is-not-callable.js | 61 ++++++++++ .../from/BigInt/mapfn-this-with-thisarg.js | 39 +++++++ .../mapfn-this-without-thisarg-non-strict.js | 39 +++++++ .../mapfn-this-without-thisarg-strict-strict.js | 40 +++++++ .../from/BigInt/new-instance-empty.js | 19 ++++ .../BigInt/new-instance-from-ordinary-object.js | 27 +++++ .../from/BigInt/new-instance-from-sparse-array.js | 19 ++++ .../from/BigInt/new-instance-using-custom-ctor.js | 30 +++++ .../from/BigInt/new-instance-with-mapfn.js | 25 +++++ .../from/BigInt/new-instance-without-mapfn.js | 21 ++++ .../from/BigInt/property-abrupt-completion.js | 34 ++++++ .../from/BigInt/set-value-abrupt-completion.js | 47 ++++++++ .../TypedArrayConstructors/from/BigInt/shell.js | 42 +++++++ .../from/BigInt/source-value-is-symbol-throws.js | 37 ++++++ .../from/BigInt/this-is-not-constructor.js | 25 +++++ .../from/arylk-get-length-error.js | 30 +++++ .../from/arylk-to-length-error.js | 30 +++++ .../TypedArrayConstructors/from/browser.js | 0 .../custom-ctor-does-not-instantiate-ta-throws.js | 31 ++++++ .../from/custom-ctor-returns-other-instance.js | 52 +++++++++ .../custom-ctor-returns-smaller-instance-throws.js | 42 +++++++ .../TypedArrayConstructors/from/custom-ctor.js | 36 ++++++ .../TypedArrayConstructors/from/inherited.js | 27 +++++ .../TypedArrayConstructors/from/invoked-as-func.js | 25 +++++ .../from/iter-access-error.js | 34 ++++++ .../from/iter-invoke-error.js | 34 ++++++ .../TypedArrayConstructors/from/iter-next-error.js | 33 ++++++ .../from/iter-next-value-error.js | 42 +++++++ .../from/mapfn-abrupt-completion.js | 34 ++++++ .../TypedArrayConstructors/from/mapfn-arguments.js | 49 ++++++++ .../from/mapfn-is-not-callable.js | 61 ++++++++++ .../from/mapfn-this-with-thisarg.js | 38 +++++++ .../from/mapfn-this-without-thisarg-non-strict.js | 39 +++++++ .../mapfn-this-without-thisarg-strict-strict.js | 39 +++++++ .../TypedArrayConstructors/from/nan-conversion.js | 60 ++++++++++ .../from/new-instance-empty.js | 19 ++++ .../from/new-instance-from-ordinary-object.js | 55 +++++++++ .../from/new-instance-from-sparse-array.js | 55 +++++++++ .../from/new-instance-from-zero.js | 42 +++++++ .../from/new-instance-using-custom-ctor.js | 32 ++++++ .../from/new-instance-with-mapfn.js | 27 +++++ .../from/new-instance-without-mapfn.js | 23 ++++ .../from/property-abrupt-completion.js | 34 ++++++ .../from/set-value-abrupt-completion.js | 48 ++++++++ .../built-ins/TypedArrayConstructors/from/shell.js | 124 +++++++++++++++++++++ .../from/source-value-is-symbol-throws.js | 35 ++++++ .../from/this-is-not-constructor.js | 25 +++++ 62 files changed, 2262 insertions(+) create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-smaller-instance-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/inherited.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/invoked-as-func.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-access-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-is-not-callable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/property-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.js (limited to 'js/src/tests/test262/built-ins/TypedArrayConstructors/from') 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 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); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.js new file mode 100644 index 0000000000..a81e83852d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = {}; + +Object.defineProperty(arrayLike, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.js new file mode 100644 index 0000000000..55eb5749ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = { length: {} }; + +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..c7e4907e32 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..9083ca3c08 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js @@ -0,0 +1,52 @@ +// 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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; + +testWithTypedArrayConstructors(function(TA) { + 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/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..044910acbf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; + +testWithTypedArrayConstructors(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/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor.js new file mode 100644 index 0000000000..292093d14d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/inherited.js new file mode 100644 index 0000000000..9577e35aab --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/invoked-as-func.js new file mode 100644 index 0000000000..b5dd5512cb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-access-error.js new file mode 100644 index 0000000000..e5c3737c29 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.js new file mode 100644 index 0000000000..5ff5bcc32e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.js new file mode 100644 index 0000000000..709c8026f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.js new file mode 100644 index 0000000000..221433130d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [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; + } + }; +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.js new file mode 100644 index 0000000000..9d32ab9524 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = { + "0": 42, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js new file mode 100644 index 0000000000..28b04f06da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js @@ -0,0 +1,49 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 44]; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push({ + kValue: kValue, + k: k, + argsLength: arguments.length + }); + }; + + 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/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-is-not-callable.js new file mode 100644 index 0000000000..f5b9b7865b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [Symbol, Symbol.iterator, TypedArray] +---*/ + +var getIterator = 0; +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + getIterator++; + } +}); + +testWithTypedArrayConstructors(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/mapfn-this-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.js new file mode 100644 index 0000000000..4be11060b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.js @@ -0,0 +1,38 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43]; +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + 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/mapfn-this-without-thisarg-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 0000000000..b6ff0005da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +flags: [noStrict] +features: [TypedArray] +---*/ + +var source = [42, 43]; +var global = this; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + TA.from(source, 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/mapfn-this-without-thisarg-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js new file mode 100644 index 0000000000..8a136b75bc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js @@ -0,0 +1,39 @@ +'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: [testTypedArray.js] +flags: [onlyStrict] +features: [TypedArray] +---*/ + +var source = [42, 43]; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + 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/nan-conversion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.js new file mode 100644 index 0000000000..5eed829650 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.js @@ -0,0 +1,60 @@ +// 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: > + Test NaN conversions +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). + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([NaN, undefined]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], NaN); + assert.sameValue(result[1], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([NaN, undefined]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0); + assert.sameValue(result[1], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js new file mode 100644 index 0000000000..0a276b5b58 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + + +testWithTypedArrayConstructors(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/new-instance-from-ordinary-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.js new file mode 100644 index 0000000000..b49dc011ef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.js @@ -0,0 +1,55 @@ +// 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: [testTypedArray.js] +features: [Array.prototype.values, TypedArray] +---*/ + +var source = { + "0": 42, + "2": 44, + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 4); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], NaN); + assert.sameValue(result[2], 44); + assert.sameValue(result[3], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 4); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 0); + assert.sameValue(result[2], 44); + assert.sameValue(result[3], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js new file mode 100644 index 0000000000..c246dde70a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js @@ -0,0 +1,55 @@ +// 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 a sparse array +includes: [testTypedArray.js] +features: [Array.prototype.values, TypedArray] +---*/ + +var source = [,,42,,44,,]; + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 6); + assert.sameValue(result[0], NaN); + assert.sameValue(result[1], NaN); + assert.sameValue(result[2], 42); + assert.sameValue(result[3], NaN); + assert.sameValue(result[4], 44); + assert.sameValue(result[5], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 6); + assert.sameValue(result[0], 0); + assert.sameValue(result[1], 0); + assert.sameValue(result[2], 42); + assert.sameValue(result[3], 0); + assert.sameValue(result[4], 44); + assert.sameValue(result[5], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.js new file mode 100644 index 0000000000..b37287c67e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.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: > + Return a new TypedArray using -0 and +0 +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([-0, +0]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], -0, "-0 => -0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([-0, +0]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0, "-0 => 0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int16Array, + Int32Array, + Int8Array, + Uint16Array, + Uint32Array, + Uint8Array, + Uint8ClampedArray +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..375458c109 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js @@ -0,0 +1,32 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(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, source); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); + 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/new-instance-with-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.js new file mode 100644 index 0000000000..9a17d2db77 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.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 using mapfn +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(function(TA) { + var mapfn = function(kValue) { + return kValue * 2; + }; + + var result = TA.from(source, mapfn); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 84); + assert.sameValue(result[1], 86); + assert.sameValue(result[2], 84); + 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/new-instance-without-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.js new file mode 100644 index 0000000000..f5aa405987 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.js @@ -0,0 +1,23 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); + 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/property-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/property-abrupt-completion.js new file mode 100644 index 0000000000..20b1934e03 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = { + length: 2 +}; +Object.defineProperty(source, "0", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js new file mode 100644 index 0000000000..e94d807876 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js @@ -0,0 +1,48 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf() { + throw new Test262Error(); + } +}; + +var source = [42, obj, 1]; + +testWithTypedArrayConstructors(function(TA) { + 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/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.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 TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js new file mode 100644 index 0000000000..e5a1ff264b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js @@ -0,0 +1,35 @@ +// 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). + +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.js new file mode 100644 index 0000000000..3369baef9b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from.call(m, []); + }); +}); + +reportCompare(0, 0); -- cgit v1.2.3