diff --git a/test/built-ins/TypedArray/from/this-is-not-constructor.js b/test/built-ins/TypedArray/from/this-is-not-constructor.js index 799d50a99c850450776d4bc3457757b3cc94304b..2a60584734b5f2a414dd55d2de32cbfc46ccc781 100644 --- a/test/built-ins/TypedArray/from/this-is-not-constructor.js +++ b/test/built-ins/TypedArray/from/this-is-not-constructor.js @@ -17,5 +17,5 @@ var from = TypedArray.from; var m = { m() {} }.m; assert.throws(TypeError, function() { - from.call(o.m, []); + from.call(m, []); }); diff --git a/test/built-ins/TypedArray/of/this-is-not-constructor.js b/test/built-ins/TypedArray/of/this-is-not-constructor.js index ff716ddac42dbd5c4b45ae46f8004319410c6f6d..262469ef924d8154c8241b7db06cd4e620d00f66 100644 --- a/test/built-ins/TypedArray/of/this-is-not-constructor.js +++ b/test/built-ins/TypedArray/of/this-is-not-constructor.js @@ -14,10 +14,8 @@ info: > includes: [testTypedArray.js] ---*/ -var o = { - m() {} -}; +var m = { m() {} }.m; assert.throws(TypeError, function() { - TypedArray.of.call(o.m, []); + TypedArray.of.call(m, []); }); diff --git a/test/built-ins/TypedArrays/from/custom-ctor-does-not-instantiate-ta-throws.js b/test/built-ins/TypedArrays/from/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8eecdf78d243200c72b6b4d5491e6f2fd9f9137e --- /dev/null +++ b/test/built-ins/TypedArrays/from/custom-ctor-does-not-instantiate-ta-throws.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. +/*--- +id: 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.from.call(ctor, []); + }); +}); diff --git a/test/built-ins/TypedArrays/from/custom-ctor.js b/test/built-ins/TypedArrays/from/custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..339e1e83c61328c0ac326520d096d02546f0f97b --- /dev/null +++ b/test/built-ins/TypedArrays/from/custom-ctor.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. +/*--- +id: 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] +---*/ + +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); +}); diff --git a/test/built-ins/TypedArrays/from/inherited.js b/test/built-ins/TypedArrays/from/inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc84de52d18686c05b4bc9fe9d50ca0d6a690e2 --- /dev/null +++ b/test/built-ins/TypedArrays/from/inherited.js @@ -0,0 +1,17 @@ +// 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: > + `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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.from, TypedArray.from); +}); diff --git a/test/built-ins/TypedArrays/from/mapfn-abrupt-completion.js b/test/built-ins/TypedArrays/from/mapfn-abrupt-completion.js new file mode 100644 index 0000000000000000000000000000000000000000..5c13d4a65348ddb1cd31a30b258b589e76d98d18 --- /dev/null +++ b/test/built-ins/TypedArrays/from/mapfn-abrupt-completion.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. +/*--- +id: 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] +---*/ + +var source = { + "0": 42, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); diff --git a/test/built-ins/TypedArrays/from/mapfn-arguments.js b/test/built-ins/TypedArrays/from/mapfn-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..f244bce15f310afa0c93449e6910119093a8fb57 --- /dev/null +++ b/test/built-ins/TypedArrays/from/mapfn-arguments.js @@ -0,0 +1,46 @@ +// 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: > + 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] +---*/ + +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); +}); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js b/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..67071d7d7328f3eb93e52e6032fd0db07dcc729d --- /dev/null +++ b/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.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. +/*--- +id: 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] +---*/ + +var source = [42, 43]; +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push(this); + }; + + TA.from(source, mapfn, thisArg); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], thisArg); + assert.sameValue(results[1], thisArg); +}); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..325505a81988cb57a3f1e575a94732a016536f1b --- /dev/null +++ b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.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. +/*--- +id: 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, fnGlobalObject.js] +flags: [noStrict] +---*/ + +var source = [42, 43]; +var global = fnGlobalObject(); + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push(this); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], global); + assert.sameValue(results[1], global); +}); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..cdf0f784348f9b686d361635398b2bf4a8fab7ea --- /dev/null +++ b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.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. +/*--- +id: 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] +---*/ + +var source = [42, 43]; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push(this); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], undefined); + assert.sameValue(results[1], undefined); +}); diff --git a/test/built-ins/TypedArrays/from/nan-conversion.js b/test/built-ins/TypedArrays/from/nan-conversion.js new file mode 100644 index 0000000000000000000000000000000000000000..fb43f2516ec377617f0558d1436e4e1dee1a4c06 --- /dev/null +++ b/test/built-ins/TypedArrays/from/nan-conversion.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. +/*--- +id: sec-%typedarray%.from +description: > + Test NaN conversions +info: > + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testTypedArray.js] +---*/ + +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 +]); \ No newline at end of file diff --git a/test/built-ins/TypedArrays/from/new-instance-empty.js b/test/built-ins/TypedArrays/from/new-instance-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..d33f7afce7092e826ac5ff9c9bc6e6071998004f --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-empty.js @@ -0,0 +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. +/*--- +id: sec-%typedarray%.from +description: > + Return a new empty TypedArray +includes: [testTypedArray.js] +---*/ + + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([]); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/from/new-instance-from-ordinary-object.js b/test/built-ins/TypedArrays/from/new-instance-from-ordinary-object.js new file mode 100644 index 0000000000000000000000000000000000000000..57df0d74167fcef4b60b047faeac545afd5c160a --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-from-ordinary-object.js @@ -0,0 +1,53 @@ +// 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: > + Return a new TypedArray from an ordinary object +includes: [testTypedArray.js] +features: [Array.prototype.values] +---*/ + +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 +]); diff --git a/test/built-ins/TypedArrays/from/new-instance-from-sparse-array.js b/test/built-ins/TypedArrays/from/new-instance-from-sparse-array.js new file mode 100644 index 0000000000000000000000000000000000000000..7bfb3f6041ca60b782e00fdeebc14e21e104c6eb --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-from-sparse-array.js @@ -0,0 +1,53 @@ +// 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: > + Return a new TypedArray from a sparse array +includes: [testTypedArray.js] +features: [Array.prototype.values] +---*/ + +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 +]); diff --git a/test/built-ins/TypedArrays/from/new-instance-from-zero.js b/test/built-ins/TypedArrays/from/new-instance-from-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..8ee2f23dc0b2db7d91360dcd5b2f342d6798038b --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-from-zero.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. +/*--- +id: sec-%typedarray%.from +description: > + Return a new TypedArray using -0 and +0 +includes: [testTypedArray.js] +---*/ + +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 +]); \ No newline at end of file diff --git a/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..d2f3830849139466c43568da87931f76b1ba0c00 --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js @@ -0,0 +1,29 @@ +// 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: > + Return a new TypedArray using a custom Constructor +includes: [testTypedArray.js] +---*/ + +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); +}); diff --git a/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js b/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js new file mode 100644 index 0000000000000000000000000000000000000000..8836d02be89b81350b5e450d9064a718300e26ef --- /dev/null +++ b/test/built-ins/TypedArrays/from/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. +/*--- +id: sec-%typedarray%.from +description: > + Return a new TypedArray using mapfn +includes: [testTypedArray.js] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(function(TA) { + var lastValue; + 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); +}); diff --git a/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js b/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js new file mode 100644 index 0000000000000000000000000000000000000000..e49df07fe5a89518ab3e6f727f9b701f893a0a57 --- /dev/null +++ b/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js @@ -0,0 +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. +/*--- +id: sec-%typedarray%.from +description: > + Return a new TypedArray +includes: [testTypedArray.js] +---*/ + +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); +}); diff --git a/test/built-ins/TypedArrays/from/property-abrupt-completion.js b/test/built-ins/TypedArrays/from/property-abrupt-completion.js new file mode 100644 index 0000000000000000000000000000000000000000..5e98feb230a8dc81423d643bf3ab92f468c57106 --- /dev/null +++ b/test/built-ins/TypedArrays/from/property-abrupt-completion.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. +/*--- +id: 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] +---*/ + +var source = { + length: 2 +}; +Object.defineProperty(source, "0", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); diff --git a/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js b/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js new file mode 100644 index 0000000000000000000000000000000000000000..2ae0ecb1013a8a585c8e75958a99b5d55463f43e --- /dev/null +++ b/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js @@ -0,0 +1,45 @@ +// 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: > + 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] +---*/ + +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); + }); +}); diff --git a/test/built-ins/TypedArrays/from/source-value-is-symbol-throws.js b/test/built-ins/TypedArrays/from/source-value-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..d863e31d261d0d151966f7f111711d8c5d0752b5 --- /dev/null +++ b/test/built-ins/TypedArrays/from/source-value-is-symbol-throws.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%.from +description: > + Throws a TypeError if argument is a Symbol +info: > + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); diff --git a/test/built-ins/TypedArrays/of/argument-is-symbol-throws.js b/test/built-ins/TypedArrays/of/argument-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9ccb26d535ac5cc71df768af64d92f8c25451ba1 --- /dev/null +++ b/test/built-ins/TypedArrays/of/argument-is-symbol-throws.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 if argument is a Symbol +info: > + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + var result = TA.of(s); + }); +}); diff --git a/test/built-ins/TypedArrays/of/argument-number-value-throws.js b/test/built-ins/TypedArrays/of/argument-number-value-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..c0ef535546e6c86a51e52882f0b65b01f064abdf --- /dev/null +++ b/test/built-ins/TypedArrays/of/argument-number-value-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. +/*--- +id: sec-%typedarray%.of +description: > + Return abrupt from object value +info: > + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 7. Repeat, while k < len + ... + c. Perform ? Set(newObj, Pk, kValue, true). + ... +includes: [testTypedArray.js] +---*/ + +var lastValue; + +var obj1 = { + valueOf() { + lastValue = "obj1"; + return 42; + } +}; +var obj2 = { + valueOf() { + lastValue = "obj2"; + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + lastValue = false; + + assert.throws(Test262Error, function() { + TA.of(obj1, obj2, obj1); + }); + + assert.sameValue(lastValue, "obj2"); +}); + diff --git a/test/built-ins/TypedArrays/of/custom-ctor-does-not-instantiate-ta-throws.js b/test/built-ins/TypedArrays/of/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..4b0cec382ab9ff7ef9a1fd21d72f0f724d6ef47e --- /dev/null +++ b/test/built-ins/TypedArrays/of/custom-ctor-does-not-instantiate-ta-throws.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. +/*--- +id: sec-%typedarray%.of +description: > + Custom constructor needs to instantiate a TypedArray +info: > + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 5. Let newObj 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.of.call(ctor, 42); + }); +}); diff --git a/test/built-ins/TypedArrays/of/custom-ctor.js b/test/built-ins/TypedArrays/of/custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..a351ce73d07ee8f0fa310a3d7a8bc79019a5065c --- /dev/null +++ b/test/built-ins/TypedArrays/of/custom-ctor.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. +/*--- +id: sec-%typedarray%.of +description: > + Calls and return abrupt from custom constructor +info: > + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 5. Let newObj 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.of.call(ctor, 42); + }); + + assert.sameValue(called, 1); +}); diff --git a/test/built-ins/TypedArrays/of/inherited.js b/test/built-ins/TypedArrays/of/inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..821b54111b901c3d8003b48a0fd241802138a735 --- /dev/null +++ b/test/built-ins/TypedArrays/of/inherited.js @@ -0,0 +1,17 @@ +// 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: > + `of` is %TypedArray%.of +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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.of, TypedArray.of); +}); diff --git a/test/built-ins/TypedArrays/of/nan-conversion.js b/test/built-ins/TypedArrays/of/nan-conversion.js new file mode 100644 index 0000000000000000000000000000000000000000..5b34fe0651e553d60cccd13ecd1030c23431c588 --- /dev/null +++ b/test/built-ins/TypedArrays/of/nan-conversion.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. +/*--- +id: sec-%typedarray%.of +description: > + Test NaN conversions +info: > + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(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.of(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 +]); diff --git a/test/built-ins/TypedArrays/of/new-instance-empty.js b/test/built-ins/TypedArrays/of/new-instance-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..80d658422f291b8aca0b5881d912330a020a3b27 --- /dev/null +++ b/test/built-ins/TypedArrays/of/new-instance-empty.js @@ -0,0 +1,15 @@ +// 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: > + Return a new empty TypedArray +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/of/new-instance-from-zero.js b/test/built-ins/TypedArrays/of/new-instance-from-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..d5a5904993b183290a389462535e8671f526772f --- /dev/null +++ b/test/built-ins/TypedArrays/of/new-instance-from-zero.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. +/*--- +id: sec-%typedarray%.of +description: > + Return a new TypedArray using -0 and +0 values +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(-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.of(-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 +]); diff --git a/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..a3069917d3dde91d0283133ebd4e279bbb0b2be8 --- /dev/null +++ b/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.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. +/*--- +id: sec-%typedarray%.of +description: > + Return a new TypedArray using a custom Constructor +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + var ctor = function(len) { + assert.sameValue(arguments.length, 1); + called++; + return new TA(len); + }; + + + var result = TA.of.call(ctor, 42, 43, 42); + 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(called, 1); +}); diff --git a/test/built-ins/TypedArrays/of/new-instance.js b/test/built-ins/TypedArrays/of/new-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..a2f5f88cb050cba36819ba8e1f6ab507880480b8 --- /dev/null +++ b/test/built-ins/TypedArrays/of/new-instance.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. +/*--- +id: sec-%typedarray%.of +description: > + Return a new TypedArray +info: > + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(42, 43, null); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +});