diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/from')
16 files changed, 459 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js new file mode 100644 index 0000000000..705df14bf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js @@ -0,0 +1,28 @@ +// 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(); + } +}); + +assert.throws(Test262Error, function() { + TypedArray.from(arrayLike); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js new file mode 100644 index 0000000000..e4ab814d5f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js @@ -0,0 +1,28 @@ +// 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(); + } +}; + +assert.throws(Test262Error, function() { + TypedArray.from(arrayLike); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/browser.js b/js/src/tests/test262/built-ins/TypedArray/from/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js new file mode 100644 index 0000000000..97ce6b2ff9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.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: > + "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] +---*/ + +var from = TypedArray.from; + +assert.throws(TypeError, function() { + from([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js new file mode 100644 index 0000000000..d2414e0923 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js @@ -0,0 +1,26 @@ +// 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 method of %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). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + TypedArray.from([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js new file mode 100644 index 0000000000..b37537d19e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.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: 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(); + } +}); + +assert.throws(Test262Error, function() { + TypedArray.from(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js new file mode 100644 index 0000000000..de395eb2dc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.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: 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(); +}; + +assert.throws(Test262Error, function() { + TypedArray.from(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js new file mode 100644 index 0000000000..7cbea13246 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.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: 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(); + } + }; +}; + +assert.throws(Test262Error, function() { + TypedArray.from(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js new file mode 100644 index 0000000000..a1674c417b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js @@ -0,0 +1,40 @@ +// 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; + } + }; +}; + +assert.throws(Test262Error, function() { + TypedArray.from(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/length.js b/js/src/tests/test262/built-ins/TypedArray/from/length.js new file mode 100644 index 0000000000..6ec675f750 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + %TypedArray%.from.length is 1. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.from.length, 1); + +verifyNotEnumerable(TypedArray.from, "length"); +verifyNotWritable(TypedArray.from, "length"); +verifyConfigurable(TypedArray.from, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js new file mode 100644 index 0000000000..ece0766bee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js @@ -0,0 +1,59 @@ +// 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++; + } +}); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, null); +}, "mapfn is null"); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, 42); +}, "mapfn is a number"); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, ""); +}, "mapfn is a string"); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, {}); +}, "mapfn is an ordinary object"); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, []); +}, "mapfn is an array"); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, true); +}, "mapfn is a boolean"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + TypedArray.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/TypedArray/from/name.js b/js/src/tests/test262/built-ins/TypedArray/from/name.js new file mode 100644 index 0000000000..9fa98be4e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.2.1 +description: > + %TypedArray%.from.name is "from". +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.from.name, "from"); + +verifyNotEnumerable(TypedArray.from, "name"); +verifyNotWritable(TypedArray.from, "name"); +verifyConfigurable(TypedArray.from, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js new file mode 100644 index 0000000000..41a794dfca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + TypedArray.from does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, testTypedArray.js] +features: [Reflect.construct, TypedArray, arrow-function] +---*/ + +assert.sameValue(isConstructor(TypedArray.from), false, 'isConstructor(TypedArray.from) must return false'); + +assert.throws(TypeError, () => { + new TypedArray.from([]); +}, '`new TypedArray.from([])` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js new file mode 100644 index 0000000000..7dd61adf7d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.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. +/*--- +es6id: 22.2.2.1 +description: > + "from" property of TypedArray +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +verifyNotEnumerable(TypedArray, 'from'); +verifyWritable(TypedArray, 'from'); +verifyConfigurable(TypedArray, 'from'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/shell.js b/js/src/tests/test262/built-ins/TypedArray/from/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js new file mode 100644 index 0000000000..7838753ba5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js @@ -0,0 +1,24 @@ +// 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 from = TypedArray.from; +var m = { m() {} }.m; + +assert.throws(TypeError, function() { + from.call(m, []); +}); + +reportCompare(0, 0); |