summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArrays/ctors/typedarray-arg
diff options
context:
space:
mode:
Diffstat (limited to 'test/built-ins/TypedArrays/ctors/typedarray-arg')
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js47
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js61
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js64
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.js46
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js41
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js59
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js52
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js61
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js45
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js47
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js44
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js59
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js43
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js28
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js37
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js31
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js46
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js68
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js60
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js49
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js49
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js62
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js49
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js49
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js65
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js32
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js27
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js48
-rw-r--r--test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js47
29 files changed, 1416 insertions, 0 deletions
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js
new file mode 100644
index 000000000..281d09353
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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").
+ ...
+includes: [testTypedArray.js]
+features: [Reflect, TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js
new file mode 100644
index 000000000..8ee2fba54
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js
@@ -0,0 +1,61 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-typedarray-typedarray
+description: >
+ When a TypedArray is created from another TypedArray with a different element-type
+ and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
+ executed.
+info: |
+ 22.2.4.3 TypedArray ( typedArray )
+
+ ...
+ 16. If IsSharedArrayBuffer(srcData) is false, then
+ a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
+ ...
+ 18. If SameValue(elementType, srcType) is true, then
+ ...
+ 19. Else,
+ a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
+ b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
+ ...
+
+ 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
+
+ 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
+ « [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray, Symbol.species]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var speciesCallCount = 0;
+ var bufferConstructor = Object.defineProperty({}, Symbol.species, {
+ get: function() {
+ speciesCallCount += 1;
+ $DETACHBUFFER(ta.buffer);
+ return speciesConstructor;
+ }
+ });
+
+ var prototypeCallCount = 0;
+ var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
+ get: function() {
+ prototypeCallCount += 1;
+ return null;
+ }
+ });
+
+ var ta = new TA(0);
+ ta.buffer.constructor = bufferConstructor;
+
+ assert.throws(TypeError, function() {
+ var targetType = TA !== Int32Array ? Int32Array : Uint32Array;
+ new targetType(ta);
+ }, "TypeError thrown for detached source buffer");
+
+ assert.sameValue(speciesCallCount, 1, "@@species getter called once");
+ assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js
new file mode 100644
index 000000000..978f42af6
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js
@@ -0,0 +1,64 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-typedarray-typedarray
+description: >
+ When a TypedArray is created from another TypedArray with the same element-type
+ and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
+ executed.
+info: |
+ 22.2.4.3 TypedArray ( typedArray )
+
+ ...
+ 16. If IsSharedArrayBuffer(srcData) is false, then
+ a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
+ ...
+ 18. If SameValue(elementType, srcType) is true, then
+ a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor).
+ ...
+
+ 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor )
+
+ ...
+ 3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
+ 4. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
+ ...
+
+ 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
+
+ 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
+ « [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray, Symbol.species]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var speciesCallCount = 0;
+ var bufferConstructor = Object.defineProperty({}, Symbol.species, {
+ get: function() {
+ speciesCallCount += 1;
+ $DETACHBUFFER(ta.buffer);
+ return speciesConstructor;
+ }
+ });
+
+ var prototypeCallCount = 0;
+ var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
+ get: function() {
+ prototypeCallCount += 1;
+ return null;
+ }
+ });
+
+ var ta = new TA(0);
+ ta.buffer.constructor = bufferConstructor;
+
+ assert.throws(TypeError, function() {
+ new TA(ta);
+ }, "TypeError thrown for detached source buffer");
+
+ assert.sameValue(speciesCallCount, 1, "@@species getter called once");
+ assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.js
new file mode 100644
index 000000000..d29848bf8
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.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.
+/*---
+esid: sec-typedarray-typedarray
+description: >
+ The new typedArray instance from a typedArray argument is extensible
+info: |
+ 22.2.4.3 TypedArray ( typedArray )
+
+ ...
+ 4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
+ "%TypedArrayPrototype%").
+ ...
+
+ 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
+ defaultProto [ , length ])
+
+ ...
+ 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
+ [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
+ ...
+
+ 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
+
+ ...
+ 11. Set the [[Extensible]] internal slot of A to true.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var typedArraySample1 = new Int8Array();
+var typedArraySample2 = new Int8Array();
+Object.preventExtensions(typedArraySample2);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample1 = new TA(typedArraySample1);
+
+ assert(Object.isExtensible(sample1), "new instance is extensible");
+
+ var sample2 = new TA(typedArraySample2);
+ assert(
+ Object.isExtensible(sample2),
+ "new instance does not inherit extensibility from typedarray argument"
+ );
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js
new file mode 100644
index 000000000..b8976d696
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
+ var sample = new OtherCtor();
+
+ Object.defineProperty(sample.buffer, "constructor", {
+ get() {
+ throw new Test262Error();
+ }
+ });
+
+ assert.throws(Test262Error, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js
new file mode 100644
index 000000000..03860d1a7
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js
@@ -0,0 +1,59 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-typedarray-typedarray
+description: >
+ Derive the ArrayBuffer prototype from the realm of the species 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%).
+ 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.
+ ...
+
+ 9.1.14 GetPrototypeFromConstructor
+
+ ...
+ 3. Let proto be ? Get(constructor, "prototype").
+ 4. If Type(proto) is not Object, then
+ a. Let realm be ? GetFunctionRealm(constructor).
+ b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
+ ...
+includes: [testTypedArray.js]
+features: [cross-realm, Symbol.species, TypedArray]
+---*/
+
+var sample1 = new Int8Array();
+var sample2 = new Int16Array();
+var other = $262.createRealm().global;
+var C = new other.Function();
+C.prototype = null;
+
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = TA === Int8Array ? sample2 : sample1;
+ var ctor = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = C;
+
+ var typedArray = new TA(sample);
+ assert.sameValue(
+ Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
+ );
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js
new file mode 100644
index 000000000..a510d7806
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js
@@ -0,0 +1,52 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var sample1 = new Int8Array();
+var sample2 = new Int16Array();
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = TA === Int8Array ? sample2 : sample1;
+ var ctor = {};
+ var called = 0;
+ var custom = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = function() {
+ called++;
+ };
+
+ ctor[Symbol.species].prototype = custom;
+
+ var typedArray = new TA(sample);
+ assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
+ assert.sameValue(called, 0);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js
new file mode 100644
index 000000000..cfb79f1a9
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js
@@ -0,0 +1,61 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var sample1 = new Int8Array();
+var sample2 = new Int16Array();
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = TA === Int8Array ? sample2 : sample1;
+
+ sample.buffer.constructor = 1;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = true;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = "";
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = null;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ var s = Symbol("1");
+ sample.buffer.constructor = s;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js
new file mode 100644
index 000000000..4b0b19aca
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js
@@ -0,0 +1,45 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js
new file mode 100644
index 000000000..c485cae13
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var sample1 = new Int8Array();
+var sample2 = new Int16Array();
+
+var ctor = function() {
+ throw new Test262Error();
+};
+var m = { m() {} }.m;
+ctor[Symbol.species] = m;
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = TA === Int8Array ? sample2 : sample1;
+
+ sample.buffer.constructor = ctor;
+
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js
new file mode 100644
index 000000000..96ba9009d
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js
@@ -0,0 +1,44 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
+ var sample = new OtherCtor();
+ 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/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js
new file mode 100644
index 000000000..135634646
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js
@@ -0,0 +1,59 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js
new file mode 100644
index 000000000..32e78a37d
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.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.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
+ var sample = new OtherCtor();
+ 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/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js
new file mode 100644
index 000000000..411248ffd
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-typedarray-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]
+features: [TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js
new file mode 100644
index 000000000..6e58746cd
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.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.
+/*---
+esid: sec-typedarray-typedarray
+description: Default [[Prototype]] value derived from realm of the newTarget
+info: |
+ [...]
+ 4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
+ "%TypedArrayPrototype%").
+ [...]
+
+ 22.2.4.2.1 Runtime Semantics: AllocateTypedArray
+
+ 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
+ [...]
+
+ 9.1.14 GetPrototypeFromConstructor
+
+ [...]
+ 3. Let proto be ? Get(constructor, "prototype").
+ 4. If Type(proto) is not Object, then
+ a. Let realm be ? GetFunctionRealm(constructor).
+ b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
+ 5. Return proto.
+includes: [testTypedArray.js]
+features: [cross-realm, Reflect, TypedArray]
+---*/
+
+var other = $262.createRealm().global;
+var C = new other.Function();
+C.prototype = null;
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = Reflect.construct(TA, [new TA()], C);
+
+ assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js
new file mode 100644
index 000000000..357730df5
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+var len = 10;
+var typedArraySample = new Int8Array(len);
+
+testWithTypedArrayConstructors(function(TA) {
+ var typedArray = new TA(typedArraySample);
+
+ assert.notSameValue(typedArray, typedArraySample);
+ assert.sameValue(typedArray.length, len);
+ assert.sameValue(typedArray.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js
new file mode 100644
index 000000000..f8e75d209
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js
new file mode 100644
index 000000000..43743b956
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js
@@ -0,0 +1,68 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-typedarray-typedarray
+description: >
+ Derive the ArrayBuffer prototype from the realm of the species 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 )
+
+ ...
+ 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).
+ ...
+
+ 9.1.14 GetPrototypeFromConstructor
+
+ ...
+ 3. Let proto be ? Get(constructor, "prototype").
+ 4. If Type(proto) is not Object, then
+ a. Let realm be ? GetFunctionRealm(constructor).
+ b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
+ ...
+includes: [testTypedArray.js]
+features: [cross-realm, Symbol.species, TypedArray]
+---*/
+
+var other = $262.createRealm().global;
+var C = new other.Function();
+C.prototype = null;
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ var ctor = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = C;
+
+ var typedArray = new TA(sample);
+ assert.sameValue(
+ Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
+ );
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js
new file mode 100644
index 000000000..7ed3aca0d
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js
@@ -0,0 +1,60 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ var ctor = {};
+ var called = 0;
+ var custom = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = function() {
+ called++;
+ };
+
+ ctor[Symbol.species].prototype = custom;
+
+ var typedArray = new TA(sample);
+ assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
+ assert.sameValue(called, 0);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js
new file mode 100644
index 000000000..2072aa96d
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ var ctor = {};
+ var m = { m() {} };
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = m;
+
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js
new file mode 100644
index 000000000..e42780610
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+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/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js
new file mode 100644
index 000000000..b171826cf
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js
@@ -0,0 +1,62 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ var ctor = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = function(){}.bind(null);
+ Object.defineProperty(ctor[Symbol.species], "prototype", {
+ get() {
+ throw new Test262Error();
+ }
+ });
+
+ assert.throws(Test262Error, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js
new file mode 100644
index 000000000..ec2aaf3c1
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ var ctor = {};
+
+ sample.buffer.constructor = ctor;
+ Object.defineProperty(ctor, Symbol.species, {
+ get() {
+ throw new Test262Error();
+ }
+ });
+
+ assert.throws(Test262Error, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js
new file mode 100644
index 000000000..339d3041b
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(4);
+ var ctor = {};
+
+ sample.buffer.constructor = ctor;
+
+ ctor[Symbol.species] = undefined;
+ var typedArray = new TA(sample);
+ assert.sameValue(
+ Object.getPrototypeOf(typedArray.buffer),
+ ArrayBuffer.prototype,
+ "buffer ctor is not called when species is undefined"
+ );
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js
new file mode 100644
index 000000000..ef9709749
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js
@@ -0,0 +1,65 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+
+ sample.buffer.constructor = 1;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = true;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = '';
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ sample.buffer.constructor = null;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+
+ var s = Symbol('1');
+ sample.buffer.constructor = s;
+ assert.throws(TypeError, function() {
+ new TA(sample);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js
new file mode 100644
index 000000000..4d9b442c9
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-typedarray-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]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(7);
+ var typedArray = new TA(sample);
+
+ assert.sameValue(typedArray.length, 7);
+ assert.notSameValue(typedArray, sample);
+ assert.notSameValue(typedArray.buffer, sample.buffer);
+ assert.sameValue(typedArray.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js
new file mode 100644
index 000000000..12839b2d7
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var typedArray = new TA(4);
+
+ assert.throws(TypeError, function() {
+ TA(typedArray);
+ });
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js
new file mode 100644
index 000000000..8af612edc
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js
@@ -0,0 +1,48 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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.
+includes: [testTypedArray.js]
+features: [Reflect, TypedArray]
+---*/
+
+function newTarget() {}
+var proto = {};
+newTarget.prototype = proto;
+
+var sample = new Int8Array(8);
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = Reflect.construct(TA, [sample], newTarget);
+
+ assert.sameValue(ta.constructor, Object);
+ assert.sameValue(Object.getPrototypeOf(ta), proto);
+});
diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js
new file mode 100644
index 000000000..b31bd96e4
--- /dev/null
+++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+function newTarget() {}
+newTarget.prototype = null;
+
+var sample = new Int8Array(8);
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = Reflect.construct(TA, [sample], newTarget);
+
+ assert.sameValue(ta.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
+});