From 35dce20ec4c527b693b5dafa3deb74753c82e1c7 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 3 Feb 2016 11:43:20 -0200 Subject: [PATCH] Update tests for %TypedArray%.from and of --- .../TypedArray/from/arylk-get-length-error.js | 9 +++---- .../TypedArray/from/arylk-to-length-error.js | 14 +++++----- .../TypedArray/from/invoked-as-func.js | 2 +- .../TypedArray/from/invoked-as-method.js | 18 +++---------- .../TypedArray/from/iter-access-error.js | 13 ++++++---- .../TypedArray/from/iter-invoke-error.js | 16 +++++++----- .../TypedArray/from/iter-next-error.js | 15 +++++------ .../TypedArray/from/iter-next-value-error.js | 16 ++++++------ test/built-ins/TypedArray/from/length.js | 21 ++++++++------- .../TypedArray/from/mapfn-is-not-callable.js | 26 +++++++++++++++++++ .../from/this-is-not-constructor.js | 21 +++++++++++++++ .../TypedArray/of/invoked-as-method.js | 10 +++---- test/built-ins/TypedArray/of/length.js | 21 ++++++++------- .../TypedArray/of/this-is-not-constructor.js | 23 ++++++++++++++++ 14 files changed, 144 insertions(+), 81 deletions(-) create mode 100644 test/built-ins/TypedArray/from/mapfn-is-not-callable.js create mode 100644 test/built-ins/TypedArray/from/this-is-not-constructor.js create mode 100644 test/built-ins/TypedArray/of/this-is-not-constructor.js diff --git a/test/built-ins/TypedArray/from/arylk-get-length-error.js b/test/built-ins/TypedArray/from/arylk-get-length-error.js index b851406ba7..f3b09d0c35 100644 --- a/test/built-ins/TypedArray/from/arylk-get-length-error.js +++ b/test/built-ins/TypedArray/from/arylk-get-length-error.js @@ -1,21 +1,20 @@ // 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.1 +id: sec-%typedarray%.from description: Returns error produced by accessing array-like's length info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, thisArg ) + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) ... - 12. Let len be ToLength(Get(arrayLike, "length")). - 13. ReturnIfAbrupt(len). + 7. Let len be ? ToLength(? Get(arrayLike, "length")). ... includes: [testTypedArray.js] ---*/ var arrayLike = {}; -Object.defineProperty(arrayLike, 'length', { +Object.defineProperty(arrayLike, "length", { get: function() { throw new Test262Error(); } diff --git a/test/built-ins/TypedArray/from/arylk-to-length-error.js b/test/built-ins/TypedArray/from/arylk-to-length-error.js index b5907b2021..857a279a06 100644 --- a/test/built-ins/TypedArray/from/arylk-to-length-error.js +++ b/test/built-ins/TypedArray/from/arylk-to-length-error.js @@ -1,23 +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. /*--- -es6id: 22.2.2.1.1 +id: sec-%typedarray%.from description: Returns error produced by interpreting length property as a length info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, thisArg ) + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) ... - 12. Let len be ToLength(Get(arrayLike, "length")). - 13. ReturnIfAbrupt(len). + 7. Let len be ? ToLength(? Get(arrayLike, "length")). ... -features: [Symbol.toPrimitive] includes: [testTypedArray.js] ---*/ var arrayLike = { length: {} }; -arrayLike.length[Symbol.toPrimitive] = function() { - throw new Test262Error(); +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } }; assert.throws(Test262Error, function() { diff --git a/test/built-ins/TypedArray/from/invoked-as-func.js b/test/built-ins/TypedArray/from/invoked-as-func.js index 3574555e88..2fc2000dd2 100644 --- a/test/built-ins/TypedArray/from/invoked-as-func.js +++ b/test/built-ins/TypedArray/from/invoked-as-func.js @@ -1,7 +1,7 @@ // 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 +id: sec-%typedarray%.from description: > "from" cannot be invoked as a function info: > diff --git a/test/built-ins/TypedArray/from/invoked-as-method.js b/test/built-ins/TypedArray/from/invoked-as-method.js index a40f5299b1..ca880ec259 100644 --- a/test/built-ins/TypedArray/from/invoked-as-method.js +++ b/test/built-ins/TypedArray/from/invoked-as-method.js @@ -1,29 +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 +id: sec-%typedarray%.from description: > "from" cannot be invoked as a method of %TypedArray% info: > 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) ... - 6. Return TypedArrayFrom(C, source, f, t). - - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, - thisArg ) - + 8. Let targetObj be ? TypedArrayCreate(C, «len»). ... - 8. If usingIterator is not undefined, then - ... - g. Let targetObj be AllocateTypedArray(C, len). - h. ReturnIfAbrupt(targetObj). - ... - 22.2.1.2.1 Runtime Semantics: AllocateTypedArray (newTarget, length ) + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) - ... - 2. If SameValue(%TypedArray%, newTarget) is true, throw a TypeError exception. + 1. Let newTypedArray be ? Construct(constructor, argumentList). ... includes: [testTypedArray.js] ---*/ diff --git a/test/built-ins/TypedArray/from/iter-access-error.js b/test/built-ins/TypedArray/from/iter-access-error.js index 503ca0b131..036be68b67 100644 --- a/test/built-ins/TypedArray/from/iter-access-error.js +++ b/test/built-ins/TypedArray/from/iter-access-error.js @@ -1,15 +1,18 @@ // 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.1 +id: sec-%typedarray%.from description: Returns error produced by accessing @@iterator info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, - thisArg ) + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) ... - 6. Let usingIterator be GetMethod(items, @@iterator). - 7. ReturnIfAbrupt(usingIterator). + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). ... features: [Symbol.iterator] includes: [testTypedArray.js] diff --git a/test/built-ins/TypedArray/from/iter-invoke-error.js b/test/built-ins/TypedArray/from/iter-invoke-error.js index b846a37799..40f4088dc3 100644 --- a/test/built-ins/TypedArray/from/iter-invoke-error.js +++ b/test/built-ins/TypedArray/from/iter-invoke-error.js @@ -1,16 +1,20 @@ // 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.1 +id: sec-%typedarray%.from description: Returns error produced by invoking @@iterator info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, - thisArg ) + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) ... - 8. If usingIterator is not undefined, then - a. Let iterator be GetIterator(items, usingIterator). - b. ReturnIfAbrupt(iterator). + 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). ... features: [Symbol.iterator] includes: [testTypedArray.js] diff --git a/test/built-ins/TypedArray/from/iter-next-error.js b/test/built-ins/TypedArray/from/iter-next-error.js index 014e26b9c8..45ea827b7a 100644 --- a/test/built-ins/TypedArray/from/iter-next-error.js +++ b/test/built-ins/TypedArray/from/iter-next-error.js @@ -1,19 +1,16 @@ // 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.1 +id: sec-%typedarray%.from description: Returns error produced by advancing the iterator info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, - thisArg ) + 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). ... - 8. If usingIterator is not undefined, then - ... - e. Repeat, while next is not false - i. Let next be IteratorStep(iterator). - ii. ReturnIfAbrupt(next). - ... features: [Symbol.iterator] includes: [testTypedArray.js] ---*/ diff --git a/test/built-ins/TypedArray/from/iter-next-value-error.js b/test/built-ins/TypedArray/from/iter-next-value-error.js index 8081dc9830..8d0a4d8215 100644 --- a/test/built-ins/TypedArray/from/iter-next-value-error.js +++ b/test/built-ins/TypedArray/from/iter-next-value-error.js @@ -1,18 +1,18 @@ // 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.1 +id: sec-%typedarray%.from description: Returns error produced by accessing iterated value info: > - 22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, - thisArg ) + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) - ... - 8. If usingIterator is not undefined, then + 2. If usingIterator is not undefined, then ... - e. If next is not false, then - i. Let nextValue be IteratorValue(next). - ii. ReturnIfAbrupt(nextValue). + d. Repeat, while next is not false + ... + ii. If next is not false, then + 1. Let nextValue be ? IteratorValue(next). + ... features: [Symbol.iterator] includes: [testTypedArray.js] ---*/ diff --git a/test/built-ins/TypedArray/from/length.js b/test/built-ins/TypedArray/from/length.js index f01edd4d04..a6c95808f5 100755 --- a/test/built-ins/TypedArray/from/length.js +++ b/test/built-ins/TypedArray/from/length.js @@ -2,23 +2,24 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.2.1 +id: 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, including optional - parameters. However, rest parameters 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 }. + 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] ---*/ diff --git a/test/built-ins/TypedArray/from/mapfn-is-not-callable.js b/test/built-ins/TypedArray/from/mapfn-is-not-callable.js new file mode 100644 index 0000000000..76fb375ce1 --- /dev/null +++ b/test/built-ins/TypedArray/from/mapfn-is-not-callable.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. +/*--- +id: 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.iterator] +---*/ + +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(TypeError, function() { + TypedArray.from(arrayLike, 42); +}); diff --git a/test/built-ins/TypedArray/from/this-is-not-constructor.js b/test/built-ins/TypedArray/from/this-is-not-constructor.js new file mode 100644 index 0000000000..799d50a99c --- /dev/null +++ b/test/built-ins/TypedArray/from/this-is-not-constructor.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. +/*--- +id: 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] +---*/ + +var from = TypedArray.from; +var m = { m() {} }.m; + +assert.throws(TypeError, function() { + from.call(o.m, []); +}); diff --git a/test/built-ins/TypedArray/of/invoked-as-method.js b/test/built-ins/TypedArray/of/invoked-as-method.js index cb0f30b634..71ad8c195f 100644 --- a/test/built-ins/TypedArray/of/invoked-as-method.js +++ b/test/built-ins/TypedArray/of/invoked-as-method.js @@ -1,21 +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.2 +id: sec-%typedarray%.of description: > "of" cannot be invoked as a method of %TypedArray% info: > 22.2.2.2 %TypedArray%.of ( ...items ) ... - 5. Let newObj be AllocateTypedArray(C, len). - 6. ReturnIfAbrupt(newObj). + 5. Let newObj be ? TypedArrayCreate(C, «len»). ... - 22.2.1.2.1 Runtime Semantics: AllocateTypedArray (newTarget, length ) + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) - ... - 2. If SameValue(%TypedArray%, newTarget) is true, throw a TypeError exception. + 1. Let newTypedArray be ? Construct(constructor, argumentList). ... includes: [testTypedArray.js] ---*/ diff --git a/test/built-ins/TypedArray/of/length.js b/test/built-ins/TypedArray/of/length.js index 22142c18df..ffe86c0c68 100755 --- a/test/built-ins/TypedArray/of/length.js +++ b/test/built-ins/TypedArray/of/length.js @@ -2,23 +2,24 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.2.2 +id: sec-%typedarray%-of description: > %TypedArray%.of.length is 0. info: > %TypedArray%.of ( ...items ) 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, including optional - parameters. However, rest parameters 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 }. + 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] ---*/ diff --git a/test/built-ins/TypedArray/of/this-is-not-constructor.js b/test/built-ins/TypedArray/of/this-is-not-constructor.js new file mode 100644 index 0000000000..ff716ddac4 --- /dev/null +++ b/test/built-ins/TypedArray/of/this-is-not-constructor.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. +/*--- +id: sec-%typedarray%.of +description: > + Throws a TypeError exception if this is not a constructor +info: > + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 3. Let C be the this value. + 4. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +var o = { + m() {} +}; + +assert.throws(TypeError, function() { + TypedArray.of.call(o.m, []); +});