diff --git a/test/built-ins/TypedArray/invoked-as-ctor-with-arguments.js b/test/built-ins/TypedArray/invoked-as-ctor-with-arguments.js deleted file mode 100644 index 6bc266f56bfaf85482b704417ebf7845459384d5..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArray/invoked-as-ctor-with-arguments.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2016 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -es7id: pending -description: TypedArray(length) cannot be direclty invoked as a constructor -info: > - 22.2.1.1 %TypedArray%()# - - 1. If NewTarget is undefined, throw a TypeError exception. - 2. Let here be the active function object. - 3. If SameValue(NewTarget, here) is true, throw a TypeError exception. - ... - - Note: there's a breaking change from ES2015's 22.2.1.2 step 7 where calling - the %TypedArray% constructor with a floating number as the argument throws a - RangeError exception before checking `SameValue(NewTarget, here)`. -includes: [testTypedArray.js] ----*/ - -assert.throws(TypeError, function() { - new TypedArray(1); -}); - -assert.throws(TypeError, function() { - new TypedArray({}); -}); - -assert.throws(TypeError, function() { - new TypedArray(1.1); -}); diff --git a/test/built-ins/TypedArray/invoked-as-ctor.js b/test/built-ins/TypedArray/invoked-as-ctor.js deleted file mode 100644 index 668a963404d75250b6bc4b2f62b2c2ea031f9445..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArray/invoked-as-ctor.js +++ /dev/null @@ -1,17 +0,0 @@ -// 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.1.2.1 -description: TypedArray cannot be invoked as a constructor -info: > - 22.2.1.2.1 Runtime Semantics: AllocateTypedArray (newTarget, length ) - - ... - 2. If SameValue(%TypedArray%, newTarget) is true, throw a TypeError exception. - ... -includes: [testTypedArray.js] ----*/ - -assert.throws(TypeError, function() { - new TypedArray(); -}); diff --git a/test/built-ins/TypedArray/invoked-as-func.js b/test/built-ins/TypedArray/invoked-as-func.js deleted file mode 100644 index a7a5d990f2c7f1f6eaa4c9f1b58c30a1cbd6c56c..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArray/invoked-as-func.js +++ /dev/null @@ -1,16 +0,0 @@ -// 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.1.1 -description: If NewTarget is undefined, throw a TypeError exception. -info: > - 22.2.1.1 %TypedArray% ( ) - - 1. If NewTarget is undefined, throw a TypeError exception. - ... -includes: [testTypedArray.js] ----*/ - -assert.throws(TypeError, function() { - TypedArray(); -}); diff --git a/test/built-ins/TypedArray/invoked.js b/test/built-ins/TypedArray/invoked.js new file mode 100644 index 0000000000000000000000000000000000000000..e208677c6069576fb8b62386ad3cc2223394b8c9 --- /dev/null +++ b/test/built-ins/TypedArray/invoked.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es7id: pending +description: Throw a TypeError exception if directly invoked. +info: > + 22.2.1.1 %TypedArray% ( ) + + 1. Throw a TypeError Exception + ... + + Note: ES2016 replaces all the references for the %TypedArray% constructor to a + single chapter covering all arguments cases. +includes: [testTypedArray.js] +---*/ + +assert.throws(TypeError, function() { + TypedArray(); +}); + +assert.throws(TypeError, function() { + new TypedArray(); +}); + +assert.throws(TypeError, function() { + TypedArray(1); +}); + +assert.throws(TypeError, function() { + new TypedArray(1); +}); + +assert.throws(TypeError, function() { + TypedArray(1.1); +}); + +assert.throws(TypeError, function() { + new TypedArray(1.1); +}); + +assert.throws(TypeError, function() { + TypedArray({}); +}); + +assert.throws(TypeError, function() { + new TypedArray({}); +}); + +var typedArray = new Int8Array(4); +assert.throws(TypeError, function() { + TypedArray(typedArray); +}); + +assert.throws(TypeError, function() { + new TypedArray(typedArray); +}); + +var buffer = new ArrayBuffer(4); +assert.throws(TypeError, function() { + TypedArray(buffer); +}); + +assert.throws(TypeError, function() { + new TypedArray(buffer); +}); diff --git a/test/built-ins/TypedArray/length.js b/test/built-ins/TypedArray/length.js index b198205b63f8f6c094f2114cf4fc91c06961ad71..ea475c5dd41d86c79da33d9d5c1b0c3064edc86d 100644 --- a/test/built-ins/TypedArray/length.js +++ b/test/built-ins/TypedArray/length.js @@ -1,23 +1,22 @@ // 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 +es7id: pending description: > - TypedArray has a "length" property whose value is 3. + TypedArray has a "length" property whose value is 0. info: > - 22.2.2 Properties of the %TypedArray% Intrinsic Object + 22.2.1.1 %TypedArray% () - Besides a length property whose value is 3 and a name property whose value is - "TypedArray", %TypedArray% has the following properties: + The length property of the %TypedArray% constructor function is 0. ... - ES6 section 17: Unless otherwise specified, the length property of a built-in + ES7 section 17: 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] ---*/ -assert.sameValue(TypedArray.length, 3); +assert.sameValue(TypedArray.length, 0); verifyNotEnumerable(TypedArray, 'length'); verifyNotWritable(TypedArray, 'length'); diff --git a/test/built-ins/TypedArrays/Float32Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Float32Array/undefined-newtarget.js deleted file mode 100755 index 35478521bedb106f69714ccdb8ffc16093c29589..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Float32Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Float32Array(); -}, "Float32Array()"); - -assert.throws(TypeError, function() { - Float32Array(0); -}, "Float32Array(0)"); - -assert.throws(TypeError, function() { - Float32Array(new Float32Array(1)); -}, "Float32Array(float32Array)"); - -assert.throws(TypeError, function() { - Float32Array([]); -}, "Float32Array(array)"); - -assert.throws(TypeError, function() { - Float32Array(new ArrayBuffer(8)); -}, "Float32Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Float64Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Float64Array/undefined-newtarget.js deleted file mode 100755 index 32ed0fb33b69a9dfa2bbcbeca330de3894c631ae..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Float64Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Float64Array(); -}, "Float64Array()"); - -assert.throws(TypeError, function() { - Float64Array(0); -}, "Float64Array(0)"); - -assert.throws(TypeError, function() { - Float64Array(new Float64Array(1)); -}, "Float64Array(float64Array)"); - -assert.throws(TypeError, function() { - Float64Array([]); -}, "Float64Array(array)"); - -assert.throws(TypeError, function() { - Float64Array(new ArrayBuffer(8)); -}, "Float64Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Int16Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Int16Array/undefined-newtarget.js deleted file mode 100755 index 664fc5ba0a52b5336101288d285704edbc01a69f..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Int16Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Int16Array(); -}, "Int16Array()"); - -assert.throws(TypeError, function() { - Int16Array(0); -}, "Int16Array(0)"); - -assert.throws(TypeError, function() { - Int16Array(new Int16Array(1)); -}, "Int16Array(int16Array)"); - -assert.throws(TypeError, function() { - Int16Array([]); -}, "Int16Array(array)"); - -assert.throws(TypeError, function() { - Int16Array(new ArrayBuffer(8)); -}, "Int16Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Int32Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Int32Array/undefined-newtarget.js deleted file mode 100755 index 6f42e423c479479fd638c1b5b304ca63e1ecf650..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Int32Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Int32Array(); -}, "Int32Array()"); - -assert.throws(TypeError, function() { - Int32Array(0); -}, "Int32Array(0)"); - -assert.throws(TypeError, function() { - Int32Array(new Int32Array(1)); -}, "Int32Array(int32Array)"); - -assert.throws(TypeError, function() { - Int32Array([]); -}, "Int32Array(array)"); - -assert.throws(TypeError, function() { - Int32Array(new ArrayBuffer(8)); -}, "Int32Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Int8Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Int8Array/undefined-newtarget.js deleted file mode 100755 index 4a3f8dc17e14dc86322776b6153f81246935ba13..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Int8Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Int8Array(); -}, "Int8Array()"); - -assert.throws(TypeError, function() { - Int8Array(0); -}, "Int8Array(0)"); - -assert.throws(TypeError, function() { - Int8Array(new Int8Array(1)); -}, "Int8Array(int8Array)"); - -assert.throws(TypeError, function() { - Int8Array([]); -}, "Int8Array(array)"); - -assert.throws(TypeError, function() { - Int8Array(new ArrayBuffer(8)); -}, "Int8Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Uint16Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Uint16Array/undefined-newtarget.js deleted file mode 100755 index fbbd92d4dd34e9467ae1376917e0026287c1722c..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Uint16Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Uint16Array(); -}, "Uint16Array()"); - -assert.throws(TypeError, function() { - Uint16Array(0); -}, "Uint16Array(0)"); - -assert.throws(TypeError, function() { - Uint16Array(new Uint16Array(1)); -}, "Uint16Array(uint16Array)"); - -assert.throws(TypeError, function() { - Uint16Array([]); -}, "Uint16Array(array)"); - -assert.throws(TypeError, function() { - Uint16Array(new ArrayBuffer(8)); -}, "Uint16Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Uint32Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Uint32Array/undefined-newtarget.js deleted file mode 100755 index d74e02736a8ebab12ceb31f15b072f90621009fd..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Uint32Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Uint32Array(); -}, "Uint32Array()"); - -assert.throws(TypeError, function() { - Uint32Array(0); -}, "Uint32Array(0)"); - -assert.throws(TypeError, function() { - Uint32Array(new Uint32Array(1)); -}, "Uint32Array(uint32Array)"); - -assert.throws(TypeError, function() { - Uint32Array([]); -}, "Uint32Array(array)"); - -assert.throws(TypeError, function() { - Uint32Array(new ArrayBuffer(8)); -}, "Uint32Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Uint8Array/undefined-newtarget.js b/test/built-ins/TypedArrays/Uint8Array/undefined-newtarget.js deleted file mode 100755 index d592176d6fa1cbbc58bc839bd08bf16a402ce90a..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Uint8Array/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Uint8Array(); -}, "Uint8Array()"); - -assert.throws(TypeError, function() { - Uint8Array(0); -}, "Uint8Array(0)"); - -assert.throws(TypeError, function() { - Uint8Array(new Uint8Array(1)); -}, "Uint8Array(uint8Array)"); - -assert.throws(TypeError, function() { - Uint8Array([]); -}, "Uint8Array(array)"); - -assert.throws(TypeError, function() { - Uint8Array(new ArrayBuffer(8)); -}, "Uint8Array(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/Uint8ClampedArray/undefined-newtarget.js b/test/built-ins/TypedArrays/Uint8ClampedArray/undefined-newtarget.js deleted file mode 100755 index 63c1dbd767ac29e1aba02ede49808ca6fe1a2f6d..0000000000000000000000000000000000000000 --- a/test/built-ins/TypedArrays/Uint8ClampedArray/undefined-newtarget.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.2.4.1 -description: > - Throws a TypeError if NewTarget is undefined. -info: > - TypedArray( ... argumentsList) - - 1. If NewTarget is undefined, throw a TypeError exception. ----*/ - -assert.throws(TypeError, function() { - Uint8ClampedArray(); -}, "Uint8ClampedArray()"); - -assert.throws(TypeError, function() { - Uint8ClampedArray(0); -}, "Uint8ClampedArray(0)"); - -assert.throws(TypeError, function() { - Uint8ClampedArray(new Uint8ClampedArray(1)); -}, "Uint8ClampedArray(uint8clampedArray)"); - -assert.throws(TypeError, function() { - Uint8ClampedArray([]); -}, "Uint8ClampedArray(array)"); - -assert.throws(TypeError, function() { - Uint8ClampedArray(new ArrayBuffer(8)); -}, "Uint8ClampedArray(arrayBuffer)"); diff --git a/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000000000000000000000000000000000..5bf697b6ef4b0eb14aeee94c5f10a6c2eaee438c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.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-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength modulo elementSize ≠0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..a566ad061239f59aca5180ca41e07948e86caf6f --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArray/negative-zero-byteoffset.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-zero.js similarity index 100% rename from test/built-ins/TypedArray/negative-zero-byteoffset.js rename to test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-zero.js diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-throws.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0b11674b607c8585d5da6672f8cdc1782ca9e287 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-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-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000000000000000000000000000000000..0f0819e0cef17cae31b6423d8aef4b09dd73d59b --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size.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-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-throws.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f04bdce84c2f2a4d24f6dc70ffc5dc7bf2f85ab5 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e4864356d1d30eba8ebaa4aed3aab3e2c8b9a311 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset.js b/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..0b8f5ff0cded67370866d83bfbd40dc0e63b7b66 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset.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-buffer-byteoffset-length +description: > + Return new typedArray from defined length and offset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-length.js b/test/built-ins/TypedArrays/buffer-arg-defined-length.js new file mode 100644 index 0000000000000000000000000000000000000000..f30447bec79889d2b7aad0ee9d22a5d43cba0815 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-length.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-buffer-byteoffset-length +description: > + Return new typedArray from defined length +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new ArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-negative-length.js b/test/built-ins/TypedArrays/buffer-arg-defined-negative-length.js new file mode 100644 index 0000000000000000000000000000000000000000..c1cfec4afc527ec097c05d259a1b07543341458e --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-negative-length.js @@ -0,0 +1,44 @@ +// 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-buffer-byteoffset-length +description: > + Return new typedArray from negative defined length +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe * 2); + + var ta1 = new TA(buffer, 0, -1); + assert.sameValue(ta1.length, 0); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, -Infinity); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); + + var ta3 = new TA(buffer, bpe, -1); + assert.sameValue(ta3.length, 0); + assert.sameValue(ta3.buffer, buffer); + assert.sameValue(ta3.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta3), TA.prototype); + + var ta4 = new TA(buffer, bpe, -Infinity); + assert.sameValue(ta4.length, 0); + assert.sameValue(ta4.buffer, buffer); + assert.sameValue(ta4.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-offset.js b/test/built-ins/TypedArrays/buffer-arg-defined-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..82d28924bd12518827ed446f3ea7f148949560f1 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-offset.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-buffer-byteoffset-length +description: > + Return new typedArray from defined offset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws.js b/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7313edf2b1299b65f6c8aba15b7134bbd2d38e91 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws.js b/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..26c12c27eff260e738776c5b9fe5ffba17600206 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws.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-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget.js b/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..33bd136ace93cb5ae2e39ff9354ee44786ced904 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget.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-buffer-byteoffset-length +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-is-referenced.js b/test/built-ins/TypedArrays/buffer-arg-is-referenced.js new file mode 100644 index 0000000000000000000000000000000000000000..d9fbc5ead51927957772cd69a50a6f9e46d173e3 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-is-referenced.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-buffer-byteoffset-length +description: > + Reuse buffer argument instead of making a new clone +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new ArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-length-access-throws.js b/test/built-ins/TypedArrays/buffer-arg-length-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..76a5a160b578ce62b8150515a3afc18ef3aaf06b --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-length-access-throws.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Returns abrupt from ToLength(length) +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); +var length = { + valueOf() { + throw new Test262Error(); + } +} + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, length); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws.js b/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8b08b8b5ce868029c3a5357bf0831337c30f3453 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws.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-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var length = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, length); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-returns-new-instance.js b/test/built-ins/TypedArrays/buffer-arg-returns-new-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..2fcbf0a6fae0bd7d985f54af9909d469a07ce333 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-returns-new-instance.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from undefined offset and length +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new ArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2dc855cd9ca1c209f032513f29550072237586aa --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object.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. +/*--- +id: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ea90fbd350a96554f1435af2fcdaecfa5d7117b2 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object.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-buffer-byteoffset-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/length-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/length-arg-custom-proto-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..3c34d9f1b490d3a35286c7a11a2b670791907b7b --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-custom-proto-access-throws.js @@ -0,0 +1,43 @@ +// 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-length +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [1], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-float-throws-rangeerror.js b/test/built-ins/TypedArrays/length-arg-is-float-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..689dac6af0566c51d25bd056e390e5f3ccd3adcd --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-float-throws-rangeerror.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-length +description: > + Throws a RangeError if length is a float number +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(1.1); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-infinity-throws-rangeerror.js b/test/built-ins/TypedArrays/length-arg-is-infinity-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..523a03616de163a652bc978a1b63c6b94157060c --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-infinity-throws-rangeerror.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-length +description: > + Throws a RangeError if length is a Infinity value +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-nan-throws-rangeerror.js b/test/built-ins/TypedArrays/length-arg-is-nan-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..8d71bb0167e5b8d4b5f14f6a8fc8f12f3dcb34ca --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-nan-throws-rangeerror.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-length +description: > + Throws a RangeError if length is NaN +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(NaN); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-negative-number-throws-rangeerror.js b/test/built-ins/TypedArrays/length-arg-is-negative-number-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..0e3cc803fa4faae0cdf7844734f7c3699ecaa5fa --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-negative-number-throws-rangeerror.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-length +description: > + Throws a RangeError if length is a negative value +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(-1); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-not-valid-buffer-size-throws-rangeerror.js b/test/built-ins/TypedArrays/length-arg-is-not-valid-buffer-size-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..0ec0daa8f1fc681ae84e9235b3d13712709be051 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-not-valid-buffer-size-throws-rangeerror.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-length +description: > + Throws a RangeError when length argument is not a valid buffer size +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 6. Else, + a. Perform ? AllocateTypedArrayBuffer(obj, length). + ... + + 22.2.4.2.2 Runtime Semantics: AllocateTypedArrayBuffer ( O, length ) + + ... + 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). + ... + + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + ... + 3. Let block be ? CreateByteDataBlock(byteLength). + ... + + 6.2.6.1 CreateByteDataBlock (size) + + ... + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + ... + +includes: [testTypedArray.js] +---*/ + +var length = Math.pow(2, 53); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(length); + }) +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-symbol-throws.js b/test/built-ins/TypedArrays/length-arg-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8aba0022384e9b6644ef294a49359702c2c69ad7 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-symbol-throws.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-length +description: > + If length is a Symbol, throw a TypeError exception. +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + ... +features: [Symbol] +includes: [testTypedArray.js] +---*/ + +var s = Symbol('1'); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(s); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-is-undefined-throws.js b/test/built-ins/TypedArrays/length-arg-is-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..dff4229e3cf6cb7d02a1157fa173c3b1f65cb78d --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-is-undefined-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-length +description: > + If length is undefined, throw a TypeError exception. +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 3. If length is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-minus-signal-zero.js b/test/built-ins/TypedArrays/length-arg-minus-signal-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..56e685150fc86f56fe4ef55973dd6aed5e38d3c4 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-minus-signal-zero.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-length +description: > + Does not throw when length is -0 +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(-0); + + assert.sameValue(typedArray.length, 0, "length"); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/length-arg-returns-object.js b/test/built-ins/TypedArrays/length-arg-returns-object.js new file mode 100644 index 0000000000000000000000000000000000000000..0b12fc0c72af6cd8bc67c7e6b926df2dde1fc50d --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-returns-object.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. +/*--- +id: sec-typedarray-length +description: > + Return a TypedArray object +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 7. Return obj +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + var length = typedArray.length; + + assert.sameValue(length, 4, "length"); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/length-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/length-arg-undefined-newtarget-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7ff0af50271fa625a464e829ae22ff2a5e236f60 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-undefined-newtarget-throws.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. +/*--- +id: sec-typedarray-length +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var s = Symbol('1'); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(0); + }); + + assert.throws(TypeError, function() { + TA(NaN); + }); + + assert.throws(TypeError, function() { + TA(""); + }); + + assert.throws(TypeError, function() { + TA(true); + }); + + assert.throws(TypeError, function() { + TA(null); + }); + + assert.throws(TypeError, function() { + TA(undefined); + }); + + assert.throws(TypeError, function() { + TA(s); + }); +}); diff --git a/test/built-ins/TypedArrays/length-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/length-arg-use-custom-proto-if-object.js new file mode 100644 index 0000000000000000000000000000000000000000..23689ffd025e9c47d5d3191b4d773c595e79a6aa --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-use-custom-proto-if-object.js @@ -0,0 +1,44 @@ +// 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-length +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/length-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/length-arg-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b805c76599f5b544ff96f99686036f7dfb93aa34 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-use-default-proto-if-custom-proto-is-not-object.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-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/no-args-custom-proto-access-throws.js b/test/built-ins/TypedArrays/no-args-custom-proto-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..48c489da4fa71f9dddf7cb91192129ff904a70c4 --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-custom-proto-access-throws.js @@ -0,0 +1,43 @@ +// 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 +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/no-args-returns-object.js b/test/built-ins/TypedArrays/no-args-returns-object.js new file mode 100644 index 0000000000000000000000000000000000000000..d9e7d91318154b458b07441dbfd6e1516c82cd74 --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-returns-object.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 +description: > + Return a TypedArray object +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 7. Return obj +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(); + + assert.sameValue(typedArray.length, 0); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/no-args-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/no-args-undefined-newtarget-throws.js new file mode 100755 index 0000000000000000000000000000000000000000..4f76cb35200c709aa345481e25640295c0f4eb95 --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-undefined-newtarget-throws.js @@ -0,0 +1,22 @@ +// 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 +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(); + }); +}); diff --git a/test/built-ins/TypedArrays/no-args-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/no-args-use-custom-proto-if-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a2a645fa6bff923ce520dd59740fe140c32f3280 --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-use-custom-proto-if-object.js @@ -0,0 +1,44 @@ +// 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 +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/no-args-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/no-args-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c56e8f20a0bd16a58d6386e4b3546e09dfe2ceb0 --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-use-default-proto-if-custom-proto-is-not-object.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 +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-arg-as-array-returns.js b/test/built-ins/TypedArrays/object-arg-as-array-returns.js new file mode 100644 index 0000000000000000000000000000000000000000..8c532e2b7b01c4327f5b1ab004d40b9a385a3928 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-as-array-returns.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-object +description: > + Return typedArray from array argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + +includes: [testTypedArray.js] +---*/ + +var obj = [7, 42]; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7); + assert.sameValue(typedArray[1], 42); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-arg-as-generator-iterable-returns.js b/test/built-ins/TypedArrays/object-arg-as-generator-iterable-returns.js new file mode 100644 index 0000000000000000000000000000000000000000..2837e91e5aec654b6bf6dd2f31d4eeb99cfc0b95 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-as-generator-iterable-returns.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-object +description: > + Return typedArray from iterable argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 7; yield 42; + })(); + + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7); + assert.sameValue(typedArray[1], 42); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/object-arg-custom-proto-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..201a41c184f007f09b10fff3da895faaf9292859 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-custom-proto-access-throws.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. +/*--- +id: sec-typedarray-object +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var o = {}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [o], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-iterating-throws.js b/test/built-ins/TypedArrays/object-arg-iterating-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8f70545a90eabcc89c9e98803ed92134f821c49b --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-iterating-throws.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. +/*--- +id: sec-typedarray-object +description: > + Return abrupt from iterating object argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 0; + throw new Test262Error(); + })(); + + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-iterator-not-callable-throws.js b/test/built-ins/TypedArrays/object-arg-iterator-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..dc6ed9ac468f77ce4a1e0311df8bd49850acc5b9 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-iterator-not-callable-throws.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-object +description: > + Return abrupt when object @@iterator is not callable +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +features: [Symbol.iterator] +---*/ + +var obj = function () {} + +testWithTypedArrayConstructors(function(TA) { + obj[Symbol.iterator] = {}; + assert.throws(TypeError, function() { + new TA(obj); + }); + + obj[Symbol.iterator] = true; + assert.throws(TypeError, function() { + new TA(obj); + }); + + obj[Symbol.iterator] = 42; + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-iterator-throws.js b/test/built-ins/TypedArrays/object-arg-iterator-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b21043fe17b4c269909c584e0e01615464297ccb --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-iterator-throws.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-object +description: > + Return abrupt from getting object @@iterator +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +features: [Symbol.iterator] +---*/ + +var obj = function () {} + +Object.defineProperty(obj, Symbol.iterator, { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-length-excessive-throws.js b/test/built-ins/TypedArrays/object-arg-length-excessive-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f1d30341553b7a8820203e2bec8e63ebf1257ea0 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-length-excessive-throws.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-object +description: > + Return abrupt from allocating array buffer with excessive length +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 6. Perform ? AllocateTypedArrayBuffer(O, len). + ... +includes: [testTypedArray.js] +---*/ + +var obj = { + length: Math.pow(2, 53) +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-length-is-symbol-throws.js b/test/built-ins/TypedArrays/object-arg-length-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..757a861e1b04725a141ce7c04fc766a84b753902 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-length-is-symbol-throws.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. +/*--- +id: sec-typedarray-object +description: > + Return abrupt from length property as a Symbol on the object argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 5. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-length-throws.js b/test/built-ins/TypedArrays/object-arg-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..88bb9340e1b014aca710afcd5c80ff09763f476d --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-length-throws.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-object +description: > + Return abrupt from getting length property on the object argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 5. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testTypedArray.js] +---*/ + +var obj = {}; + +Object.defineProperty(obj, "length", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-returns.js b/test/built-ins/TypedArrays/object-arg-returns.js new file mode 100644 index 0000000000000000000000000000000000000000..6ac5b219a8338f6eb303e5903085711412f3fbcd --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-returns.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-object +description: > + Return typedArray from object argument +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var obj = { + "0": null, + "2": 42, + "3": "7", + "4": NaN, + "5": Symbol("1"), + length: 5 +}; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 5); + assert.sameValue(typedArray[0], 0); + assert.sameValue(typedArray[2], 42); + assert.sameValue(typedArray[3], 7); + assert.sameValue(typedArray[5], undefined); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); + + if (TA === Float32Array || TA === Float64Array) { + assert.sameValue(typedArray[1], NaN); + assert.sameValue(typedArray[4], NaN); + } else { + assert.sameValue(typedArray[1], 0); + assert.sameValue(typedArray[4], 0); + } +}); diff --git a/test/built-ins/TypedArrays/object-arg-throws-from-property.js b/test/built-ins/TypedArrays/object-arg-throws-from-property.js new file mode 100644 index 0000000000000000000000000000000000000000..2816f8f4391bfab01d2d617510d2f84ee54e00f5 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-throws-from-property.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. +/*--- +id: sec-typedarray-object +description: > + Return abrupt from getting object property +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + ... +includes: [testTypedArray.js] +---*/ + +var obj = { + length: 4 +}; + +Object.defineProperty(obj, "2", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-throws-setting-property.js b/test/built-ins/TypedArrays/object-arg-throws-setting-property.js new file mode 100644 index 0000000000000000000000000000000000000000..ee3f7c4c07ba4c5cfd400d55a9f7696125ae8010 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-throws-setting-property.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. +/*--- +id: sec-typedarray-object +description: > + Return abrupt from setting property +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... +includes: [testTypedArray.js] +---*/ + +var obj = { + "2": { + valueOf() { + throw new Test262Error(); + } + }, + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-throws-setting-symbol-property.js b/test/built-ins/TypedArrays/object-arg-throws-setting-symbol-property.js new file mode 100644 index 0000000000000000000000000000000000000000..c71516d2092ed08cc2bdea4f5a1bb4796b1b697c --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-throws-setting-symbol-property.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-object +description: > + Return abrupt from setting property +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var obj = { + "2": Symbol("1"), + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/object-arg-undefined-newtarget-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..3c2db157b68b0e2db89d77fab4c96a7b78bd5619 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-undefined-newtarget-throws.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-object +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA({}); + }); + + assert.throws(TypeError, function() { + TA([]); + }); +}); diff --git a/test/built-ins/TypedArrays/object-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/object-arg-use-custom-proto-if-object.js new file mode 100644 index 0000000000000000000000000000000000000000..1596d8d08ed69e4349a4abbb3e5f8739a74a87fb --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-use-custom-proto-if-object.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. +/*--- +id: sec-typedarray-object +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/object-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/object-arg-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c8c7acfc42bc6b63140cc12ba889fb97462c7671 --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-use-default-proto-if-custom-proto-is-not-object.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-object +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +newTarget.prototype = null; +var o = []; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [o], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/typedarray-arg-custom-proto-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e94b1d0569fe823b3771584bee5572271422d006 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-custom-proto-access-throws.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. +/*--- +id: sec-typedarray-typedarray +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var sample = new Int8Array(); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [sample], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..06ccdda33d8fca843bdcb01e8c83241e2eb34ffb --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-access-throws.js @@ -0,0 +1,41 @@ +// 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-typedarray +description: > + Return abrupt completion from getting typedArray argument's buffer.constructor +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = Int8Array; + var sample2 = Int16Array; + var sample = new (TA === Int8Array ? sample2 : sample1); + + Object.defineProperty(sample.buffer, "constructor", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-custom-species.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-custom-species.js new file mode 100644 index 0000000000000000000000000000000000000000..14436bf552bf8b0830370681082a736a263a14c0 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-custom-species.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. +/*--- +id: sec-typedarray-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + ... + +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + var called = 0; + var custom = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() { + called++; + }; + + ctor[Symbol.species].prototype = custom; + + var typedArray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..5ceb8d36869ebc40ce82190d7807751c340a8c73 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.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. +/*--- +id: sec-typedarray-typedarray +description: > + Return abrupt completion from typedArray argument's buffer.constructor's value +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + + sample.buffer.constructor = 1; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = true; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = ""; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = null; + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol("1"); + sample.buffer.constructor = s; + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..26a3178a8c8b0304c61bc4540956fa3986f8a52b --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.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-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + + sample.buffer.constructor = ctor; + Object.defineProperty(ctor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b082b0439d4373afda7f02c6954b3f265d3329d5 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.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. +/*--- +id: sec-typedarray-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +var ctor = function() { + throw new Test262Error(); +}; +var m = { m() {} }.m; +ctor[Symbol.species] = m; + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + + sample.buffer.constructor = ctor; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..895a2ea9f2cf024dc74c41ff9ac4e87be7457182 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-null.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-typedarray +description: > + Use default ArrayBuffer constructor on null buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {} + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = null; + var typedArray = new TA(sample); + + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is null" + ); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..12a2316d0064294cf8beddc07340bed2ef31c787 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.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. +/*--- +id: sec-typedarray-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + ... + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, + "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + var called = 0; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() {called++;}.bind(null); + Object.defineProperty(ctor[Symbol.species], "prototype", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..bf8d3a4b8a993949749d957432d62bcf616a9646 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-buffer-ctor-species-undefined.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-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {} + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = undefined; + var a = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(a.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is undefined" + ); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-other-ctor-returns-new-typedarray.js b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-returns-new-typedarray.js new file mode 100644 index 0000000000000000000000000000000000000000..6c0ba821e318c6b1beae402967c2742c6da248a6 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-other-ctor-returns-new-typedarray.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-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. +includes: [testTypedArray.js] +---*/ + +var sample1 = new Int8Array(7); +var sample2 = new Int16Array(7); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var typedArray = new TA(sample); + + assert.sameValue(typedArray.length, 7); + assert.notSameValue(typedArray, sample); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-returns-new-instance.js b/test/built-ins/TypedArrays/typedarray-arg-returns-new-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..6971dfcb180df830294e1781701ecfac436963cc --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-returns-new-instance.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. +/*--- +id: sec-typedarray-typedarray +description: > + Return a TypedArray object +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 20. Return O. + +includes: [testTypedArray.js] +---*/ + +var length = 10; +var typedArraySample = new Int8Array(length); + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(typedArraySample); + + assert.notSameValue(typedArray, typedArraySample); + assert.sameValue(typedArray.length, length); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-access-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f1d0afb65c349c5a56a579333ce284dbffc19c02 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-access-throws.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-typedarray +description: > + Return abrupt completion from getting typedArray argument's buffer.constructor +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-custom.js new file mode 100644 index 0000000000000000000000000000000000000000..09053c47d0badf6e4cf12715a65af20e5a598d27 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-custom.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. +/*--- +id: sec-typedarray-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + var called = 0; + var custom = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() { + called++; + }; + + ctor[Symbol.species].prototype = custom; + + var typedArray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..163c155e96e8e4e43c00881068b0562bd89b914b --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.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-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + var m = { m() {} }; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = m; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..b3c461b1c53a44d40391e7710b7a2be37952eb55 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-null.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-typedarray +description: > + Use default ArrayBuffer constructor on null buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var ctor = {} + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = null; + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is null" + ); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..fa60b0d58c69998fe1d21810902ff71b6d1cba82 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js @@ -0,0 +1,62 @@ +// 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-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + ... + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, + "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function(){}.bind(null); + Object.defineProperty(ctor[Symbol.species], "prototype", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-throws.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1ed0a514611939f1c7a94fb48d3077a4a3843dfc --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-throws.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-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + + sample.buffer.constructor = ctor; + Object.defineProperty(ctor, Symbol.species, { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..4fbdb7dce4a350b2f8b9ade13c582fd1c37a5bcf --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-species-undefined.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-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testTypedArray.js] +features: [Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var ctor = {} + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = undefined; + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is undefined" + ); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..6309a97ef34649a1dbf2866fa87503d23b1c18f0 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js @@ -0,0 +1,65 @@ +// 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-typedarray +description: > + Return abrupt completion from typedArray argument's buffer.constructor's value +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + sample.buffer.constructor = 1; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = true; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = ''; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = null; + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol('1'); + sample.buffer.constructor = s; + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js new file mode 100644 index 0000000000000000000000000000000000000000..5d78db9db2bb984537f19ffaf0e09f9354b4f2bc --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-same-ctor-returns-new-cloned-typedarray.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-typedarray +description: > + Same typedArray ctor argument returns a new cloned typedArray +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + 23. Return O. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(7); + var typedArray = new TA(sample); + + assert.sameValue(typedArray.length, 7); + assert.notSameValue(typedArray, sample); + assert.notSameValue(typedArray.buffer, sample.buffer); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/typedarray-arg-undefined-newtarget-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..22f444cdc4868c5ba7b7ba71486a99294eea9151 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-undefined-newtarget-throws.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-typedarray +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + + assert.throws(TypeError, function() { + TA(typedArray); + }); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/typedarray-arg-use-custom-proto-if-object.js new file mode 100644 index 0000000000000000000000000000000000000000..9a558e875f446d7cbff6edd9259d8b1f3bbcf8c5 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-use-custom-proto-if-object.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. +/*--- +id: sec-typedarray-typedarray +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +var sample = new Int8Array(8); + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [sample], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..f8248f39d80a292550068ba20504f34ef97fb1c3 --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.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-typedarray +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +var sample = new Int8Array(8); + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [sample], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +});