From f8a4229bfd64b8e8de7fc5b00b19b61cb8494e89 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 22 Jan 2016 11:36:26 -0500 Subject: [PATCH] Add tests for TypedArrays constructors --- .../Float32Array/undefined-newtarget.js | 32 ------- .../Float64Array/undefined-newtarget.js | 32 ------- .../Int16Array/undefined-newtarget.js | 32 ------- .../Int32Array/undefined-newtarget.js | 32 ------- .../Int8Array/undefined-newtarget.js | 32 ------- .../Uint16Array/undefined-newtarget.js | 32 ------- .../Uint32Array/undefined-newtarget.js | 32 ------- .../Uint8Array/undefined-newtarget.js | 32 ------- .../Uint8ClampedArray/undefined-newtarget.js | 32 ------- ...eoffset-throws-from-modulo-element-size.js | 36 +++++++ ...-argument-byteoffset-is-negative-throws.js | 30 ++++++ ...er-argument-byteoffset-is-symbol-throws.js | 28 ++++++ ...eoffset-throws-from-modulo-element-size.js | 31 ++++++ ...er-argument-byteoffset-to-number-throws.js | 31 ++++++ ...ffer-argument-defined-length-and-offset.js | 35 +++++++ .../buffer-argument-defined-length.js | 31 ++++++ ...buffer-argument-defined-negative-length.js | 41 ++++++++ .../buffer-argument-defined-offset.js | 29 ++++++ ...buffer-argument-excessive-length-throws.js | 29 ++++++ ...buffer-argument-excessive-offset-throws.js | 33 +++++++ .../buffer-argument-is-referenced.js | 29 ++++++ ...ument-returns-abrupt-from-length-symbol.js | 29 ++++++ ...fer-argument-returns-abrupt-from-length.js | 32 +++++++ .../buffer-single-argument-single.js | 30 ++++++ .../called-with-length-return-object.js | 35 +++++++ .../called-with-no-arguments-return-object.js | 31 ++++++ ...led-with-typedarray-return-new-instance.js | 31 ++++++ ...ith-buffer-argument-proto-is-not-object.js | 45 +++++++++ ...pe-with-buffer-argument-proto-is-object.js | 47 ++++++++++ ...ype-with-buffer-argument-returns-abrupt.js | 47 ++++++++++ ...ith-length-argument-proto-is-not-object.js | 41 ++++++++ ...pe-with-length-argument-proto-is-object.js | 43 +++++++++ ...ype-with-length-argument-returns-abrupt.js | 43 +++++++++ ...e-with-no-arguments-proto-is-not-object.js | 41 ++++++++ ...otype-with-no-arguments-proto-is-object.js | 43 +++++++++ ...totype-with-no-arguments-returns-abrupt.js | 43 +++++++++ ...ith-object-argument-proto-is-not-object.js | 45 +++++++++ ...pe-with-object-argument-proto-is-object.js | 46 +++++++++ ...ype-with-object-argument-returns-abrupt.js | 48 ++++++++++ ...typedarray-argument-proto-is-not-object.js | 45 +++++++++ ...ith-typedarray-argument-proto-is-object.js | 47 ++++++++++ ...with-typedarray-argument-returns-abrupt.js | 47 ++++++++++ .../length-is-float-throws-rangeerror.js | 26 +++++ .../length-is-infinity-throws-rangeerror.js | 26 +++++ .../length-is-nan-throws-rangeerror.js | 26 +++++ ...th-is-negative-number-throws-rangeerror.js | 26 +++++ ...not-valid-buffer-size-throws-rangeerror.js | 53 +++++++++++ .../TypedArrays/length-is-symbol-throws.js | 26 +++++ .../TypedArrays/length-is-undefined-throws.js | 23 +++++ .../object-argument-as-array-returns.js | 26 +++++ ...-argument-as-generator-iterable-returns.js | 28 ++++++ .../object-argument-iterating-throws.js | 30 ++++++ ...t-argument-iterator-not-callable-throws.js | 39 ++++++++ .../object-argument-iterator-throws.js | 34 +++++++ ...object-argument-length-excessive-throws.js | 30 ++++++ ...object-argument-length-is-symbol-throws.js | 30 ++++++ .../object-argument-length-throws.js | 33 +++++++ .../TypedArrays/object-argument-returns.js | 32 +++++++ .../object-argument-throws-from-property.js | 37 ++++++++ ...object-argument-throws-setting-property.js | 37 ++++++++ ...argument-throws-setting-symbol-property.js | 34 +++++++ ...tor-argument-buffer-ctor-species-custom.js | 52 ++++++++++ ...r-argument-buffer-ctor-species-not-ctor.js | 45 +++++++++ ...-ctor-argument-buffer-ctor-species-null.js | 46 +++++++++ ...nt-buffer-ctor-species-prototype-abrupt.js | 59 ++++++++++++ ...-argument-buffer-ctor-species-undefined.js | 45 +++++++++ ...returns-abrupt-from-constructor-species.js | 45 +++++++++ ...r-returns-abrupt-from-constructor-value.js | 90 ++++++++++++++++++ ...fer-returns-abrupt-from-get-constructor.js | 41 ++++++++ ...ay-ctor-argument-returns-new-typedarray.js | 27 ++++++ ...tor-argument-buffer-ctor-species-custom.js | 60 ++++++++++++ ...r-argument-buffer-ctor-species-not-ctor.js | 49 ++++++++++ ...-ctor-argument-buffer-ctor-species-null.js | 49 ++++++++++ ...nt-buffer-ctor-species-prototype-abrupt.js | 62 ++++++++++++ ...-argument-buffer-ctor-species-undefined.js | 49 ++++++++++ ...returns-abrupt-from-constructor-species.js | 49 ++++++++++ ...r-returns-abrupt-from-constructor-value.js | 94 +++++++++++++++++++ ...fer-returns-abrupt-from-get-constructor.js | 45 +++++++++ ...-argument-returns-new-cloned-typedarray.js | 29 ++++++ ...ined-newtarget-invoked-with-arraybuffer.js | 25 +++++ ...undefined-newtarget-invoked-with-length.js | 50 ++++++++++ ...ned-newtarget-invoked-with-no-arguments.js | 22 +++++ ...undefined-newtarget-invoked-with-object.js | 29 ++++++ ...fined-newtarget-invoked-with-typedarray.js | 26 +++++ 84 files changed, 2926 insertions(+), 288 deletions(-) delete mode 100755 test/built-ins/TypedArrays/Float32Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Float64Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Int16Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Int32Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Int8Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Uint16Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Uint32Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Uint8Array/undefined-newtarget.js delete mode 100755 test/built-ins/TypedArrays/Uint8ClampedArray/undefined-newtarget.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-bufferbyteoffset-throws-from-modulo-element-size.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-byteoffset-is-negative-throws.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-byteoffset-is-symbol-throws.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-byteoffset-throws-from-modulo-element-size.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-byteoffset-to-number-throws.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-defined-length-and-offset.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-defined-length.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-defined-negative-length.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-defined-offset.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-excessive-length-throws.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-excessive-offset-throws.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-is-referenced.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length-symbol.js create mode 100644 test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length.js create mode 100644 test/built-ins/TypedArrays/buffer-single-argument-single.js create mode 100644 test/built-ins/TypedArrays/called-with-length-return-object.js create mode 100644 test/built-ins/TypedArrays/called-with-no-arguments-return-object.js create mode 100644 test/built-ins/TypedArrays/called-with-typedarray-return-new-instance.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-not-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-buffer-argument-returns-abrupt.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-not-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-length-argument-returns-abrupt.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-not-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-no-arguments-returns-abrupt.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-not-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-object-argument-returns-abrupt.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-not-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-object.js create mode 100644 test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-returns-abrupt.js create mode 100644 test/built-ins/TypedArrays/length-is-float-throws-rangeerror.js create mode 100644 test/built-ins/TypedArrays/length-is-infinity-throws-rangeerror.js create mode 100644 test/built-ins/TypedArrays/length-is-nan-throws-rangeerror.js create mode 100644 test/built-ins/TypedArrays/length-is-negative-number-throws-rangeerror.js create mode 100644 test/built-ins/TypedArrays/length-is-not-valid-buffer-size-throws-rangeerror.js create mode 100644 test/built-ins/TypedArrays/length-is-symbol-throws.js create mode 100644 test/built-ins/TypedArrays/length-is-undefined-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-as-array-returns.js create mode 100644 test/built-ins/TypedArrays/object-argument-as-generator-iterable-returns.js create mode 100644 test/built-ins/TypedArrays/object-argument-iterating-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-iterator-not-callable-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-iterator-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-length-excessive-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-length-is-symbol-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-length-throws.js create mode 100644 test/built-ins/TypedArrays/object-argument-returns.js create mode 100644 test/built-ins/TypedArrays/object-argument-throws-from-property.js create mode 100644 test/built-ins/TypedArrays/object-argument-throws-setting-property.js create mode 100644 test/built-ins/TypedArrays/object-argument-throws-setting-symbol-property.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-custom.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-null.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-undefined.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js create mode 100644 test/built-ins/TypedArrays/other-typedarray-ctor-argument-returns-new-typedarray.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-custom.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-null.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-undefined.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js create mode 100644 test/built-ins/TypedArrays/same-typedarray-ctor-argument-returns-new-cloned-typedarray.js create mode 100644 test/built-ins/TypedArrays/undefined-newtarget-invoked-with-arraybuffer.js create mode 100644 test/built-ins/TypedArrays/undefined-newtarget-invoked-with-length.js create mode 100755 test/built-ins/TypedArrays/undefined-newtarget-invoked-with-no-arguments.js create mode 100644 test/built-ins/TypedArrays/undefined-newtarget-invoked-with-object.js create mode 100644 test/built-ins/TypedArrays/undefined-newtarget-invoked-with-typedarray.js 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 35478521be..0000000000 --- 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 32ed0fb33b..0000000000 --- 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 664fc5ba0a..0000000000 --- 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 6f42e423c4..0000000000 --- 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 4a3f8dc17e..0000000000 --- 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 fbbd92d4dd..0000000000 --- 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 d74e02736a..0000000000 --- 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 d592176d6f..0000000000 --- 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 63c1dbd767..0000000000 --- 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-argument-bufferbyteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/buffer-argument-bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..5bf697b6ef --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-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-argument-byteoffset-is-negative-throws.js b/test/built-ins/TypedArrays/buffer-argument-byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..a566ad0612 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-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/TypedArrays/buffer-argument-byteoffset-is-symbol-throws.js b/test/built-ins/TypedArrays/buffer-argument-byteoffset-is-symbol-throws.js new file mode 100644 index 0000000000..0b11674b60 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-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-argument-byteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/buffer-argument-byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..6bab1c7e1e --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-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. + + ... + 9. 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-argument-byteoffset-to-number-throws.js b/test/built-ins/TypedArrays/buffer-argument-byteoffset-to-number-throws.js new file mode 100644 index 0000000000..f04bdce84c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-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-argument-defined-length-and-offset.js b/test/built-ins/TypedArrays/buffer-argument-defined-length-and-offset.js new file mode 100644 index 0000000000..e305ab731e --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-defined-length-and-offset.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +id: sec-typedarray-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( + Object.getPrototypeOf(ta1), TA.prototype, + "Object.getPrototypeOf(ta1)" + ); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue( + Object.getPrototypeOf(ta2), TA.prototype, + "Object.getPrototypeOf(ta2)" + ); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-defined-length.js b/test/built-ins/TypedArrays/buffer-argument-defined-length.js new file mode 100644 index 0000000000..125c224c9b --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-defined-length.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 +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(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-defined-negative-length.js b/test/built-ins/TypedArrays/buffer-argument-defined-negative-length.js new file mode 100644 index 0000000000..8bb321f3da --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-defined-negative-length.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-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 length = 4; + var buffer = new ArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, -1); + assert.sameValue(ta1.length, 0); + assert.sameValue(ta1.buffer, buffer); + 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(Object.getPrototypeOf(ta2), TA.prototype); + + var ta3 = new TA(buffer, 8, -1); + assert.sameValue(ta3.length, 0); + assert.sameValue(ta3.buffer, buffer); + assert.sameValue(Object.getPrototypeOf(ta3), TA.prototype); + + var ta4 = new TA(buffer, 8, -Infinity); + assert.sameValue(ta4.length, 0); + assert.sameValue(ta4.buffer, buffer); + assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-defined-offset.js b/test/built-ins/TypedArrays/buffer-argument-defined-offset.js new file mode 100644 index 0000000000..bc7e49fc68 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-defined-offset.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: > + 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(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-excessive-length-throws.js b/test/built-ins/TypedArrays/buffer-argument-excessive-length-throws.js new file mode 100644 index 0000000000..439b550879 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-excessive-length-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: > + 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] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, 16); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-excessive-offset-throws.js b/test/built-ins/TypedArrays/buffer-argument-excessive-offset-throws.js new file mode 100644 index 0000000000..9270c51ebc --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-excessive-offset-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-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] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 16); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 16, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-is-referenced.js b/test/built-ins/TypedArrays/buffer-argument-is-referenced.js new file mode 100644 index 0000000000..ef331db521 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-is-referenced.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: > + 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 * 4); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, ta2.buffer); +}); diff --git a/test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length-symbol.js b/test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length-symbol.js new file mode 100644 index 0000000000..8b08b8b5ce --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length-symbol.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-argument-returns-abrupt-from-length.js b/test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length.js new file mode 100644 index 0000000000..76a5a160b5 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-argument-returns-abrupt-from-length.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-single-argument-single.js b/test/built-ins/TypedArrays/buffer-single-argument-single.js new file mode 100644 index 0000000000..62892b4c36 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-single-argument-single.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: > + Return new typedArray from undefined 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 buffer1 = new ArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + 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(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/called-with-length-return-object.js b/test/built-ins/TypedArrays/called-with-length-return-object.js new file mode 100644 index 0000000000..669c113550 --- /dev/null +++ b/test/built-ins/TypedArrays/called-with-length-return-object.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +id: sec-typedarray-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 bytesPerElement = TA.BYTES_PER_ELEMENT; + var length = typedArray.length; + + assert.sameValue(length, 4, "length"); + assert.sameValue( + Object.getPrototypeOf(typedArray), TA.prototype, + "Object.getPrototypeOf(typedArray)" + ); +}); diff --git a/test/built-ins/TypedArrays/called-with-no-arguments-return-object.js b/test/built-ins/TypedArrays/called-with-no-arguments-return-object.js new file mode 100644 index 0000000000..d9e7d91318 --- /dev/null +++ b/test/built-ins/TypedArrays/called-with-no-arguments-return-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/called-with-typedarray-return-new-instance.js b/test/built-ins/TypedArrays/called-with-typedarray-return-new-instance.js new file mode 100644 index 0000000000..232692fb69 --- /dev/null +++ b/test/built-ins/TypedArrays/called-with-typedarray-return-new-instance.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: > + 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); + var bytesPerElement = TA.BYTES_PER_ELEMENT; + + 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/get-prototype-with-buffer-argument-proto-is-not-object.js b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-not-object.js new file mode 100644 index 0000000000..db24d0bedd --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-not-object.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-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(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-object.js b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-object.js new file mode 100644 index 0000000000..e4efc7980a --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-proto-is-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-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(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-returns-abrupt.js b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-returns-abrupt.js new file mode 100644 index 0000000000..e4864356d1 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-buffer-argument-returns-abrupt.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/get-prototype-with-length-argument-proto-is-not-object.js b/test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-not-object.js new file mode 100644 index 0000000000..7276dbfb14 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-not-object.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-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(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-object.js b/test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-object.js new file mode 100644 index 0000000000..aa3faf6b87 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-length-argument-proto-is-object.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: > + 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(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-length-argument-returns-abrupt.js b/test/built-ins/TypedArrays/get-prototype-with-length-argument-returns-abrupt.js new file mode 100644 index 0000000000..3c34d9f1b4 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-length-argument-returns-abrupt.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/get-prototype-with-no-arguments-proto-is-not-object.js b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-not-object.js new file mode 100644 index 0000000000..2cb363d3aa --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-not-object.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 +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(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-object.js b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-object.js new file mode 100644 index 0000000000..779775fb80 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-proto-is-object.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: > + 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(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-no-arguments-returns-abrupt.js b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-returns-abrupt.js new file mode 100644 index 0000000000..48c489da4f --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-no-arguments-returns-abrupt.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/get-prototype-with-object-argument-proto-is-not-object.js b/test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-not-object.js new file mode 100644 index 0000000000..b2adc26a1b --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-not-object.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: > + 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(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-object.js b/test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-object.js new file mode 100644 index 0000000000..92c12d6f0f --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-object-argument-proto-is-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 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(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-object-argument-returns-abrupt.js b/test/built-ins/TypedArrays/get-prototype-with-object-argument-returns-abrupt.js new file mode 100644 index 0000000000..201a41c184 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-object-argument-returns-abrupt.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/get-prototype-with-typedarray-argument-proto-is-not-object.js b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-not-object.js new file mode 100644 index 0000000000..f9788039ce --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-not-object.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 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(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-object.js b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-object.js new file mode 100644 index 0000000000..0aae23913b --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-proto-is-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-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(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-returns-abrupt.js b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-returns-abrupt.js new file mode 100644 index 0000000000..e94b1d0569 --- /dev/null +++ b/test/built-ins/TypedArrays/get-prototype-with-typedarray-argument-returns-abrupt.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/length-is-float-throws-rangeerror.js b/test/built-ins/TypedArrays/length-is-float-throws-rangeerror.js new file mode 100644 index 0000000000..689dac6af0 --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-infinity-throws-rangeerror.js b/test/built-ins/TypedArrays/length-is-infinity-throws-rangeerror.js new file mode 100644 index 0000000000..523a03616d --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-nan-throws-rangeerror.js b/test/built-ins/TypedArrays/length-is-nan-throws-rangeerror.js new file mode 100644 index 0000000000..8d71bb0167 --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-negative-number-throws-rangeerror.js b/test/built-ins/TypedArrays/length-is-negative-number-throws-rangeerror.js new file mode 100644 index 0000000000..0e3cc803fa --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-not-valid-buffer-size-throws-rangeerror.js b/test/built-ins/TypedArrays/length-is-not-valid-buffer-size-throws-rangeerror.js new file mode 100644 index 0000000000..0ec0daa8f1 --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-symbol-throws.js b/test/built-ins/TypedArrays/length-is-symbol-throws.js new file mode 100644 index 0000000000..8aba002238 --- /dev/null +++ b/test/built-ins/TypedArrays/length-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-is-undefined-throws.js b/test/built-ins/TypedArrays/length-is-undefined-throws.js new file mode 100644 index 0000000000..dff4229e3c --- /dev/null +++ b/test/built-ins/TypedArrays/length-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/object-argument-as-array-returns.js b/test/built-ins/TypedArrays/object-argument-as-array-returns.js new file mode 100644 index 0000000000..eca1a8eae9 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-as-array-returns.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-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(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-argument-as-generator-iterable-returns.js b/test/built-ins/TypedArrays/object-argument-as-generator-iterable-returns.js new file mode 100644 index 0000000000..1ce0a86936 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-as-generator-iterable-returns.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-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(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-argument-iterating-throws.js b/test/built-ins/TypedArrays/object-argument-iterating-throws.js new file mode 100644 index 0000000000..8f70545a90 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-iterator-not-callable-throws.js b/test/built-ins/TypedArrays/object-argument-iterator-not-callable-throws.js new file mode 100644 index 0000000000..dc6ed9ac46 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-iterator-throws.js b/test/built-ins/TypedArrays/object-argument-iterator-throws.js new file mode 100644 index 0000000000..b21043fe17 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-length-excessive-throws.js b/test/built-ins/TypedArrays/object-argument-length-excessive-throws.js new file mode 100644 index 0000000000..1f802c2dd6 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-length-excessive-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 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] +features: [Symbol] +---*/ + +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-argument-length-is-symbol-throws.js b/test/built-ins/TypedArrays/object-argument-length-is-symbol-throws.js new file mode 100644 index 0000000000..757a861e1b --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-length-throws.js b/test/built-ins/TypedArrays/object-argument-length-throws.js new file mode 100644 index 0000000000..88bb9340e1 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-returns.js b/test/built-ins/TypedArrays/object-argument-returns.js new file mode 100644 index 0000000000..cabc2e2352 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-returns.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-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 = { + "2": 42, + "3": "7", + "4": Symbol("1"), + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 4); + assert.sameValue(typedArray[2], 42); + assert.sameValue(typedArray[3], 7); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/object-argument-throws-from-property.js b/test/built-ins/TypedArrays/object-argument-throws-from-property.js new file mode 100644 index 0000000000..2816f8f439 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-throws-setting-property.js b/test/built-ins/TypedArrays/object-argument-throws-setting-property.js new file mode 100644 index 0000000000..ee3f7c4c07 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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-argument-throws-setting-symbol-property.js b/test/built-ins/TypedArrays/object-argument-throws-setting-symbol-property.js new file mode 100644 index 0000000000..c71516d209 --- /dev/null +++ b/test/built-ins/TypedArrays/object-argument-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/other-typedarray-ctor-argument-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-custom.js new file mode 100644 index 0000000000..240a2b58c7 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-custom.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 tarray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js new file mode 100644 index 0000000000..c8721e25c5 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-not-ctor.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 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(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + var o = { m() {} }; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = o.m; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-null.js new file mode 100644 index 0000000000..895a2ea9f2 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-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/other-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js new file mode 100644 index 0000000000..12a2316d00 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.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/other-typedarray-ctor-argument-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000..bf8d3a4b8a --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-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/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js new file mode 100644 index 0000000000..26a3178a8c --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.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/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js new file mode 100644 index 0000000000..5055fa2f84 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js @@ -0,0 +1,90 @@ +// 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; + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return 1; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return true; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return ''; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return null; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol('1'); + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return s; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js new file mode 100644 index 0000000000..59483279f8 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.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: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/other-typedarray-ctor-argument-returns-new-typedarray.js b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-returns-new-typedarray.js new file mode 100644 index 0000000000..6c0ba821e3 --- /dev/null +++ b/test/built-ins/TypedArrays/other-typedarray-ctor-argument-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/same-typedarray-ctor-argument-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-custom.js new file mode 100644 index 0000000000..5189f01b20 --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-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 tarray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-not-ctor.js new file mode 100644 index 0000000000..1f0414068b --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-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 o = { m() {} }; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = o.m; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-null.js new file mode 100644 index 0000000000..b3c461b1c5 --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-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/same-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.js new file mode 100644 index 0000000000..5eace03d87 --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-prototype-abrupt.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: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000..e07620e5d1 --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-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 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/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.js new file mode 100644 index 0000000000..04de7110ee --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-species.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: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js new file mode 100644 index 0000000000..f85aa5da7a --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-constructor-value.js @@ -0,0 +1,94 @@ +// 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(); + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return 1; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return true; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return ''; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return null; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol('1'); + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + return s; + }, + configurable: true + }); + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.js new file mode 100644 index 0000000000..f1d0afb65c --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-buffer-returns-abrupt-from-get-constructor.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/same-typedarray-ctor-argument-returns-new-cloned-typedarray.js b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-returns-new-cloned-typedarray.js new file mode 100644 index 0000000000..4f67a1b930 --- /dev/null +++ b/test/built-ins/TypedArrays/same-typedarray-ctor-argument-returns-new-cloned-typedarray.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-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.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-arraybuffer.js b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-arraybuffer.js new file mode 100644 index 0000000000..33bd136ace --- /dev/null +++ b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-arraybuffer.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/undefined-newtarget-invoked-with-length.js b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-length.js new file mode 100644 index 0000000000..7ff0af5027 --- /dev/null +++ b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-length.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/undefined-newtarget-invoked-with-no-arguments.js b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-no-arguments.js new file mode 100755 index 0000000000..4f76cb3520 --- /dev/null +++ b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-no-arguments.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/undefined-newtarget-invoked-with-object.js b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-object.js new file mode 100644 index 0000000000..3c2db157b6 --- /dev/null +++ b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-object.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/undefined-newtarget-invoked-with-typedarray.js b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-typedarray.js new file mode 100644 index 0000000000..22f444cdc4 --- /dev/null +++ b/test/built-ins/TypedArrays/undefined-newtarget-invoked-with-typedarray.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); + }); +});