summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg')
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.js30
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js72
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js64
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js39
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js596
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js89
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js87
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js100
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js101
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js94
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js49
28 files changed, 1946 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.js
new file mode 100644
index 0000000000..abbc8b5979
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+var obj = [7, 42];
+
+testWithTypedArrayConstructors(function(TA) {
+ var typedArray = new TA(obj);
+ assert.sameValue(typedArray.length, 2);
+ assert.sameValue(typedArray[0], 7);
+ assert.sameValue(typedArray[1], 42);
+ assert.sameValue(typedArray.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.js
new file mode 100644
index 0000000000..a86d9ef1a5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj = (function *() {
+ yield 7; yield 42;
+ })();
+
+ var typedArray = new TA(obj);
+ assert.sameValue(typedArray.length, 2);
+ assert.sameValue(typedArray[0], 7);
+ assert.sameValue(typedArray[1], 42);
+ assert.sameValue(typedArray.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js
new file mode 100644
index 0000000000..f766adaa22
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js
@@ -0,0 +1,72 @@
+// 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-object
+description: Consistent canonicalization of NaN values
+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.
+
+ ...
+ 9. Repeat, while k < len
+ ...
+ c. Perform ? Set(O, Pk, kValue, true).
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
+ isLittleEndian ] )
+
+ ...
+ 8. If type is "Float32", then
+ a. Set rawBytes to a List containing the 4 bytes that are the result
+ of converting value to IEEE 754-2008 binary32 format using “Round to
+ nearest, ties to even” rounding mode. If isLittleEndian is false, the
+ bytes are arranged in big endian order. Otherwise, the bytes are
+ arranged in little endian order. If value is NaN, rawValue may be set
+ to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number
+ encoding. An implementation must always choose the same encoding for
+ each implementation distinguishable NaN value.
+ 9. Else, if type is "Float64", then
+ a. Set rawBytes to a List containing the 8 bytes that are the IEEE
+ 754-2008 binary64 format encoding of value. If isLittleEndian is false,
+ the bytes are arranged in big endian order. Otherwise, the bytes are
+ arranged in little endian order. If value is NaN, rawValue may be set
+ to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number
+ encoding. An implementation must always choose the same encoding for
+ each implementation distinguishable NaN value.
+ ...
+includes: [nans.js, testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+function body(FloatArray) {
+ var first = new FloatArray(NaNs);
+ var second = new FloatArray(NaNs);
+ var firstBytes = new Uint8Array(first.buffer);
+ var secondBytes = new Uint8Array(second.buffer);
+
+ assert(compareArray(firstBytes, secondBytes));
+}
+
+testWithTypedArrayConstructors(body, [Float32Array, Float64Array]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js
new file mode 100644
index 0000000000..b8c41f1de1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js
@@ -0,0 +1,64 @@
+// 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-object
+description: >
+ Verify conversion values on returned instance
+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.
+
+ ...
+ 9. Repeat, while k < len
+ ...
+ c. Perform ? Set(O, Pk, kValue, true).
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
+ isLittleEndian ] )
+
+ ...
+ 8. If type is "Float32", then
+ ...
+ 9. Else, if type is "Float64", then
+ ...
+ 10. Else,
+ ...
+ b. Let convOp be the abstract operation named in the Conversion Operation
+ column in Table 50 for Element Type type.
+ c. Let intValue be convOp(value).
+ d. If intValue ≥ 0, then
+ ...
+ e. Else,
+ ...
+includes: [byteConversionValues.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testTypedArrayConversions(byteConversionValues, function(TA, value, expected) {
+ var sample = new TA([value]);
+
+ assert.sameValue(sample[0], expected, value + " converts to " + expected);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js
new file mode 100644
index 0000000000..c34af4e31b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js
@@ -0,0 +1,50 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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").
+ ...
+includes: [testTypedArray.js]
+features: [Reflect, TypedArray]
+---*/
+
+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);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js
new file mode 100644
index 0000000000..7867b4a3a1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-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.
+/*---
+esid: 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]
+features: [generators, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj = (function *() {
+ yield 0;
+ throw new Test262Error();
+ })();
+
+ assert.throws(Test262Error, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js
new file mode 100644
index 0000000000..de906f06b4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js
@@ -0,0 +1,44 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-typedarray-object
+description: >
+ If object's @@iterator is `null`, it is considered an array-like object.
+info: |
+ 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 usingIterator be ? GetMethod(object, @@iterator).
+ 6. If usingIterator is not undefined, then
+ [...]
+ 7. NOTE: object is not an Iterable so assume it is already an array-like object.
+ [...]
+
+ GetMethod ( V, P )
+
+ [...]
+ 2. Let func be ? GetV(V, P).
+ 3. If func is either undefined or null, return undefined.
+includes: [testTypedArray.js]
+features: [Symbol.iterator, TypedArray]
+---*/
+
+var obj = {length: 2, 0: 1, 1: 2};
+obj[Symbol.iterator] = null;
+
+testWithTypedArrayConstructors(function(TypedArray) {
+ var typedArray = new TypedArray(obj);
+
+ assert(typedArray instanceof TypedArray);
+ assert.sameValue(typedArray.length, 2);
+ assert.sameValue(typedArray[0], 1);
+ assert.sameValue(typedArray[1], 2);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-throws.js
new file mode 100644
index 0000000000..500437a3ed
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-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-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, TypedArray]
+---*/
+
+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);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.js
new file mode 100644
index 0000000000..9b9c57a11b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.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.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var obj = function () {};
+
+Object.defineProperty(obj, Symbol.iterator, {
+ get() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(Test262Error, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js
new file mode 100644
index 0000000000..1d681cfe61
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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: [TypedArray]
+---*/
+
+var obj = {
+ length: Math.pow(2, 53)
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(RangeError, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js
new file mode 100644
index 0000000000..1e2f7e23c9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var obj = {
+ length: Symbol("1")
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(TypeError, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.js
new file mode 100644
index 0000000000..8dccea8901
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.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.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+var obj = {};
+
+Object.defineProperty(obj, "length", {
+ get() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(Test262Error, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.js
new file mode 100644
index 0000000000..25345c0979
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.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-object
+description: >
+ The new typedArray instance from an object argument is extensible
+info: |
+ 22.2.4.4 TypedArray ( object )
+
+ ...
+ 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 obj = {
+ "0": 0,
+ "1": 1,
+ "2": 2,
+ length: 3
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(obj);
+
+ assert(Object.isExtensible(sample));
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js
new file mode 100644
index 0000000000..213fbfbdd8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.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.
+/*---
+esid: sec-typedarray-object
+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, [{}], C);
+
+ assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.js
new file mode 100644
index 0000000000..d807ea95a6
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.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-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, TypedArray]
+---*/
+
+var obj = {
+ "0": null,
+ "2": 42,
+ "3": "7",
+ "4": NaN,
+ "5": Symbol("1"),
+ length: 5
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var typedArray = new TA(obj);
+ assert.sameValue(typedArray.length, 5);
+ assert.sameValue(typedArray[0], 0);
+ assert.sameValue(typedArray[2], 42);
+ assert.sameValue(typedArray[3], 7);
+ assert.sameValue(typedArray[5], undefined);
+ assert.sameValue(typedArray.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
+
+ if (TA === Float32Array || TA === Float64Array) {
+ assert.sameValue(typedArray[1], NaN);
+ assert.sameValue(typedArray[4], NaN);
+ } else {
+ assert.sameValue(typedArray[1], 0);
+ assert.sameValue(typedArray[4], 0);
+ }
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js
new file mode 100644
index 0000000000..d29e7ddcc3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js
@@ -0,0 +1,596 @@
+// GENERATED, DO NOT EDIT
+// file: byteConversionValues.js
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ Provide a list for original and expected values for different byte
+ conversions.
+ This helper is mostly used on tests for TypedArray and DataView, and each
+ array from the expected values must match the original values array on every
+ index containing its original value.
+defines: [byteConversionValues]
+---*/
+var byteConversionValues = {
+ values: [
+ 127, // 2 ** 7 - 1
+ 128, // 2 ** 7
+ 32767, // 2 ** 15 - 1
+ 32768, // 2 ** 15
+ 2147483647, // 2 ** 31 - 1
+ 2147483648, // 2 ** 31
+ 255, // 2 ** 8 - 1
+ 256, // 2 ** 8
+ 65535, // 2 ** 16 - 1
+ 65536, // 2 ** 16
+ 4294967295, // 2 ** 32 - 1
+ 4294967296, // 2 ** 32
+ 9007199254740991, // 2 ** 53 - 1
+ 9007199254740992, // 2 ** 53
+ 1.1,
+ 0.1,
+ 0.5,
+ 0.50000001,
+ 0.6,
+ 0.7,
+ undefined,
+ -1,
+ -0,
+ -0.1,
+ -1.1,
+ NaN,
+ -127, // - ( 2 ** 7 - 1 )
+ -128, // - ( 2 ** 7 )
+ -32767, // - ( 2 ** 15 - 1 )
+ -32768, // - ( 2 ** 15 )
+ -2147483647, // - ( 2 ** 31 - 1 )
+ -2147483648, // - ( 2 ** 31 )
+ -255, // - ( 2 ** 8 - 1 )
+ -256, // - ( 2 ** 8 )
+ -65535, // - ( 2 ** 16 - 1 )
+ -65536, // - ( 2 ** 16 )
+ -4294967295, // - ( 2 ** 32 - 1 )
+ -4294967296, // - ( 2 ** 32 )
+ Infinity,
+ -Infinity,
+ 0
+ ],
+
+ expected: {
+ Int8: [
+ 127, // 127
+ -128, // 128
+ -1, // 32767
+ 0, // 32768
+ -1, // 2147483647
+ 0, // 2147483648
+ -1, // 255
+ 0, // 256
+ -1, // 65535
+ 0, // 65536
+ -1, // 4294967295
+ 0, // 4294967296
+ -1, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ -1, // -1
+ 0, // -0
+ 0, // -0.1
+ -1, // -1.1
+ 0, // NaN
+ -127, // -127
+ -128, // -128
+ 1, // -32767
+ 0, // -32768
+ 1, // -2147483647
+ 0, // -2147483648
+ 1, // -255
+ 0, // -256
+ 1, // -65535
+ 0, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Uint8: [
+ 127, // 127
+ 128, // 128
+ 255, // 32767
+ 0, // 32768
+ 255, // 2147483647
+ 0, // 2147483648
+ 255, // 255
+ 0, // 256
+ 255, // 65535
+ 0, // 65536
+ 255, // 4294967295
+ 0, // 4294967296
+ 255, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ 255, // -1
+ 0, // -0
+ 0, // -0.1
+ 255, // -1.1
+ 0, // NaN
+ 129, // -127
+ 128, // -128
+ 1, // -32767
+ 0, // -32768
+ 1, // -2147483647
+ 0, // -2147483648
+ 1, // -255
+ 0, // -256
+ 1, // -65535
+ 0, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Uint8Clamped: [
+ 127, // 127
+ 128, // 128
+ 255, // 32767
+ 255, // 32768
+ 255, // 2147483647
+ 255, // 2147483648
+ 255, // 255
+ 255, // 256
+ 255, // 65535
+ 255, // 65536
+ 255, // 4294967295
+ 255, // 4294967296
+ 255, // 9007199254740991
+ 255, // 9007199254740992
+ 1, // 1.1,
+ 0, // 0.1
+ 0, // 0.5
+ 1, // 0.50000001,
+ 1, // 0.6
+ 1, // 0.7
+ 0, // undefined
+ 0, // -1
+ 0, // -0
+ 0, // -0.1
+ 0, // -1.1
+ 0, // NaN
+ 0, // -127
+ 0, // -128
+ 0, // -32767
+ 0, // -32768
+ 0, // -2147483647
+ 0, // -2147483648
+ 0, // -255
+ 0, // -256
+ 0, // -65535
+ 0, // -65536
+ 0, // -4294967295
+ 0, // -4294967296
+ 255, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Int16: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ -32768, // 32768
+ -1, // 2147483647
+ 0, // 2147483648
+ 255, // 255
+ 256, // 256
+ -1, // 65535
+ 0, // 65536
+ -1, // 4294967295
+ 0, // 4294967296
+ -1, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ -1, // -1
+ 0, // -0
+ 0, // -0.1
+ -1, // -1.1
+ 0, // NaN
+ -127, // -127
+ -128, // -128
+ -32767, // -32767
+ -32768, // -32768
+ 1, // -2147483647
+ 0, // -2147483648
+ -255, // -255
+ -256, // -256
+ 1, // -65535
+ 0, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Uint16: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ 32768, // 32768
+ 65535, // 2147483647
+ 0, // 2147483648
+ 255, // 255
+ 256, // 256
+ 65535, // 65535
+ 0, // 65536
+ 65535, // 4294967295
+ 0, // 4294967296
+ 65535, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ 65535, // -1
+ 0, // -0
+ 0, // -0.1
+ 65535, // -1.1
+ 0, // NaN
+ 65409, // -127
+ 65408, // -128
+ 32769, // -32767
+ 32768, // -32768
+ 1, // -2147483647
+ 0, // -2147483648
+ 65281, // -255
+ 65280, // -256
+ 1, // -65535
+ 0, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Int32: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ 32768, // 32768
+ 2147483647, // 2147483647
+ -2147483648, // 2147483648
+ 255, // 255
+ 256, // 256
+ 65535, // 65535
+ 65536, // 65536
+ -1, // 4294967295
+ 0, // 4294967296
+ -1, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ -1, // -1
+ 0, // -0
+ 0, // -0.1
+ -1, // -1.1
+ 0, // NaN
+ -127, // -127
+ -128, // -128
+ -32767, // -32767
+ -32768, // -32768
+ -2147483647, // -2147483647
+ -2147483648, // -2147483648
+ -255, // -255
+ -256, // -256
+ -65535, // -65535
+ -65536, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Uint32: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ 32768, // 32768
+ 2147483647, // 2147483647
+ 2147483648, // 2147483648
+ 255, // 255
+ 256, // 256
+ 65535, // 65535
+ 65536, // 65536
+ 4294967295, // 4294967295
+ 0, // 4294967296
+ 4294967295, // 9007199254740991
+ 0, // 9007199254740992
+ 1, // 1.1
+ 0, // 0.1
+ 0, // 0.5
+ 0, // 0.50000001,
+ 0, // 0.6
+ 0, // 0.7
+ 0, // undefined
+ 4294967295, // -1
+ 0, // -0
+ 0, // -0.1
+ 4294967295, // -1.1
+ 0, // NaN
+ 4294967169, // -127
+ 4294967168, // -128
+ 4294934529, // -32767
+ 4294934528, // -32768
+ 2147483649, // -2147483647
+ 2147483648, // -2147483648
+ 4294967041, // -255
+ 4294967040, // -256
+ 4294901761, // -65535
+ 4294901760, // -65536
+ 1, // -4294967295
+ 0, // -4294967296
+ 0, // Infinity
+ 0, // -Infinity
+ 0
+ ],
+ Float32: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ 32768, // 32768
+ 2147483648, // 2147483647
+ 2147483648, // 2147483648
+ 255, // 255
+ 256, // 256
+ 65535, // 65535
+ 65536, // 65536
+ 4294967296, // 4294967295
+ 4294967296, // 4294967296
+ 9007199254740992, // 9007199254740991
+ 9007199254740992, // 9007199254740992
+ 1.100000023841858, // 1.1
+ 0.10000000149011612, // 0.1
+ 0.5, // 0.5
+ 0.5, // 0.50000001,
+ 0.6000000238418579, // 0.6
+ 0.699999988079071, // 0.7
+ NaN, // undefined
+ -1, // -1
+ -0, // -0
+ -0.10000000149011612, // -0.1
+ -1.100000023841858, // -1.1
+ NaN, // NaN
+ -127, // -127
+ -128, // -128
+ -32767, // -32767
+ -32768, // -32768
+ -2147483648, // -2147483647
+ -2147483648, // -2147483648
+ -255, // -255
+ -256, // -256
+ -65535, // -65535
+ -65536, // -65536
+ -4294967296, // -4294967295
+ -4294967296, // -4294967296
+ Infinity, // Infinity
+ -Infinity, // -Infinity
+ 0
+ ],
+ Float64: [
+ 127, // 127
+ 128, // 128
+ 32767, // 32767
+ 32768, // 32768
+ 2147483647, // 2147483647
+ 2147483648, // 2147483648
+ 255, // 255
+ 256, // 256
+ 65535, // 65535
+ 65536, // 65536
+ 4294967295, // 4294967295
+ 4294967296, // 4294967296
+ 9007199254740991, // 9007199254740991
+ 9007199254740992, // 9007199254740992
+ 1.1, // 1.1
+ 0.1, // 0.1
+ 0.5, // 0.5
+ 0.50000001, // 0.50000001,
+ 0.6, // 0.6
+ 0.7, // 0.7
+ NaN, // undefined
+ -1, // -1
+ -0, // -0
+ -0.1, // -0.1
+ -1.1, // -1.1
+ NaN, // NaN
+ -127, // -127
+ -128, // -128
+ -32767, // -32767
+ -32768, // -32768
+ -2147483647, // -2147483647
+ -2147483648, // -2147483648
+ -255, // -255
+ -256, // -256
+ -65535, // -65535
+ -65536, // -65536
+ -4294967295, // -4294967295
+ -4294967296, // -4294967296
+ Infinity, // Infinity
+ -Infinity, // -Infinity
+ 0
+ ]
+ }
+};
+
+// file: nans.js
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ A collection of NaN values produced from expressions that have been observed
+ to create distinct bit representations on various platforms. These provide a
+ weak basis for assertions regarding the consistent canonicalization of NaN
+ values in Array buffers.
+defines: [NaNs]
+---*/
+
+var NaNs = [
+ NaN,
+ Number.NaN,
+ NaN * 0,
+ 0/0,
+ Infinity/Infinity,
+ -(0/0),
+ Math.pow(-1, 0.5),
+ -Math.pow(-1, 0.5),
+ Number("Not-a-Number"),
+];
+
+// file: testTypedArray.js
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ Collection of functions used to assert the correctness of TypedArray objects.
+defines:
+ - typedArrayConstructors
+ - floatArrayConstructors
+ - intArrayConstructors
+ - TypedArray
+ - testWithTypedArrayConstructors
+ - testWithAtomicsFriendlyTypedArrayConstructors
+ - testWithNonAtomicsFriendlyTypedArrayConstructors
+ - testTypedArrayConversions
+---*/
+
+/**
+ * Array containing every typed array constructor.
+ */
+var typedArrayConstructors = [
+ Float64Array,
+ Float32Array,
+ Int32Array,
+ Int16Array,
+ Int8Array,
+ Uint32Array,
+ Uint16Array,
+ Uint8Array,
+ Uint8ClampedArray
+];
+
+var floatArrayConstructors = typedArrayConstructors.slice(0, 2);
+var intArrayConstructors = typedArrayConstructors.slice(2, 7);
+
+/**
+ * The %TypedArray% intrinsic constructor function.
+ */
+var TypedArray = Object.getPrototypeOf(Int8Array);
+
+/**
+ * Callback for testing a typed array constructor.
+ *
+ * @callback typedArrayConstructorCallback
+ * @param {Function} Constructor the constructor object to test with.
+ */
+
+/**
+ * Calls the provided function for every typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithTypedArrayConstructors(f, selected) {
+ var constructors = selected || typedArrayConstructors;
+ for (var i = 0; i < constructors.length; ++i) {
+ var constructor = constructors[i];
+ try {
+ f(constructor);
+ } catch (e) {
+ e.message += " (Testing with " + constructor.name + ".)";
+ throw e;
+ }
+ }
+}
+
+/**
+ * Calls the provided function for every non-"Atomics Friendly" typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithNonAtomicsFriendlyTypedArrayConstructors(f) {
+ testWithTypedArrayConstructors(f, [
+ Float64Array,
+ Float32Array,
+ Uint8ClampedArray
+ ]);
+}
+
+/**
+ * Calls the provided function for every "Atomics Friendly" typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithAtomicsFriendlyTypedArrayConstructors(f) {
+ testWithTypedArrayConstructors(f, [
+ Int32Array,
+ Int16Array,
+ Int8Array,
+ Uint32Array,
+ Uint16Array,
+ Uint8Array,
+ ]);
+}
+
+/**
+ * Helper for conversion operations on TypedArrays, the expected values
+ * properties are indexed in order to match the respective value for each
+ * TypedArray constructor
+ * @param {Function} fn - the function to call for each constructor and value.
+ * will be called with the constructor, value, expected
+ * value, and a initial value that can be used to avoid
+ * a false positive with an equivalent expected value.
+ */
+function testTypedArrayConversions(byteConversionValues, fn) {
+ var values = byteConversionValues.values;
+ var expected = byteConversionValues.expected;
+
+ testWithTypedArrayConstructors(function(TA) {
+ var name = TA.name.slice(0, -5);
+
+ return values.forEach(function(value, index) {
+ var exp = expected[name][index];
+ var initial = 0;
+ if (exp === 0) {
+ initial = 1;
+ }
+ fn(TA, value, exp, initial);
+ });
+ });
+}
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js
new file mode 100644
index 0000000000..574b628f9e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js
@@ -0,0 +1,40 @@
+// 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-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]
+features: [TypedArray]
+---*/
+
+var obj = {
+ length: 4
+};
+
+Object.defineProperty(obj, "2", {
+ get() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(Test262Error, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js
new file mode 100644
index 0000000000..1e0cba0b5a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js
@@ -0,0 +1,89 @@
+// 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-object
+description: >
+ Throw TypeError from @@toPrimitive returning an Object when setting a 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).
+ ...
+
+ 9.4.5.5 [[Set]] ( P, V, Receiver)
+
+ ...
+ 2. If Type(P) is String and if SameValue(O, Receiver) is true, then
+ a. Let numericIndex be ! CanonicalNumericIndexString(P).
+ b. If numericIndex is not undefined, then
+ i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
+ ii. Return true.
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ ToNumber ( argument )
+
+ Object, Apply the following steps:
+
+ 1. Let primValue be ? ToPrimitive(argument, hint Number).
+ 2. Return ? ToNumber(primValue).
+
+ 7.1.1 ToPrimitive ( input [ , PreferredType ] )
+
+ ...
+ 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
+ 5. If exoticToPrim is not undefined, then
+ a. Let result be ? Call(exoticToPrim, input, « hint »).
+ b. If Type(result) is not Object, return result.
+ c. Throw a TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol.toPrimitive, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new Int8Array(1);
+ var toPrimitive = 0;
+ var valueOf = 0;
+
+ sample[Symbol.toPrimitive] = function() {
+ toPrimitive++;
+ return {};
+ };
+
+ sample.valueOf = function() {
+ valueOf++;
+ };
+
+ assert.throws(TypeError, function() {
+ new TA([8, sample]);
+ }, "abrupt completion from sample @@toPrimitive");
+
+ assert.sameValue(toPrimitive, 1, "toPrimitive was called once");
+ assert.sameValue(valueOf, 0, "sample.valueOf is not called");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js
new file mode 100644
index 0000000000..b70a039911
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js
@@ -0,0 +1,87 @@
+// 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-object
+description: >
+ Return abrupt from @@toPrimitive when setting a 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).
+ ...
+
+ 9.4.5.5 [[Set]] ( P, V, Receiver)
+
+ ...
+ 2. If Type(P) is String and if SameValue(O, Receiver) is true, then
+ a. Let numericIndex be ! CanonicalNumericIndexString(P).
+ b. If numericIndex is not undefined, then
+ i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
+ ii. Return true.
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ ToNumber ( argument )
+
+ Object, Apply the following steps:
+
+ 1. Let primValue be ? ToPrimitive(argument, hint Number).
+ 2. Return ? ToNumber(primValue).
+
+ 7.1.1 ToPrimitive ( input [ , PreferredType ] )
+
+ ...
+ 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
+ 5. If exoticToPrim is not undefined, then
+ a. Let result be ? Call(exoticToPrim, input, « hint »).
+ ...
+includes: [testTypedArray.js]
+features: [Symbol.toPrimitive, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new Int8Array(1);
+ var toPrimitive = 0;
+ var valueOf = 0;
+
+ sample[Symbol.toPrimitive] = function() {
+ toPrimitive++;
+ throw new Test262Error();
+ };
+
+ sample.valueOf = function() {
+ valueOf++;
+ };
+
+ assert.throws(Test262Error, function() {
+ new TA([8, sample]);
+ }, "abrupt completion from sample @@toPrimitive");
+
+ assert.sameValue(toPrimitive, 1, "toPrimitive was called once");
+ assert.sameValue(valueOf, 0, "it does not call sample.valueOf");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js
new file mode 100644
index 0000000000..9940e1e608
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js
@@ -0,0 +1,100 @@
+// 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-object
+description: >
+ Return abrupt from toString() when setting a 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).
+ ...
+
+ 9.4.5.5 [[Set]] ( P, V, Receiver)
+
+ ...
+ 2. If Type(P) is String and if SameValue(O, Receiver) is true, then
+ a. Let numericIndex be ! CanonicalNumericIndexString(P).
+ b. If numericIndex is not undefined, then
+ i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
+ ii. Return true.
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ ToNumber ( argument )
+
+ Object, Apply the following steps:
+
+ 1. Let primValue be ? ToPrimitive(argument, hint Number).
+ 2. Return ? ToNumber(primValue).
+
+ 7.1.1 ToPrimitive ( input [ , PreferredType ] )
+
+ ...
+ 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
+ 5. If exoticToPrim is not undefined, then
+ a. Let result be ? Call(exoticToPrim, input, « hint »).
+ b. If Type(result) is not Object, return result.
+ c. Throw a TypeError exception.
+ ...
+ 7. Return ? OrdinaryToPrimitive(input, hint).
+
+ OrdinaryToPrimitive
+
+ ...
+ 5. For each name in methodNames in List order, do
+ a. Let method be ? Get(O, name).
+ b. If IsCallable(method) is true, then
+ i. Let result be ? Call(method, O).
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new Int8Array(1);
+ var valueOf = 0;
+ var toString = 0;
+
+ sample.valueOf = function() {
+ valueOf++;
+ return {};
+ };
+
+ sample.toString = function() {
+ toString++;
+ throw new Test262Error();
+ };
+
+ assert.throws(Test262Error, function() {
+ new TA([8, sample]);
+ }, "abrupt completion from ToNumber(sample)");
+
+ assert.sameValue(valueOf, 1, "valueOf called once");
+ assert.sameValue(toString, 1, "toString called once");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js
new file mode 100644
index 0000000000..746e244537
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js
@@ -0,0 +1,101 @@
+// 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-object
+description: >
+ Throw TypeError from OrdinaryToPrimitive when setting a 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).
+ ...
+
+ 9.4.5.5 [[Set]] ( P, V, Receiver)
+
+ ...
+ 2. If Type(P) is String and if SameValue(O, Receiver) is true, then
+ a. Let numericIndex be ! CanonicalNumericIndexString(P).
+ b. If numericIndex is not undefined, then
+ i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
+ ii. Return true.
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ ToNumber ( argument )
+
+ Object, Apply the following steps:
+
+ 1. Let primValue be ? ToPrimitive(argument, hint Number).
+ 2. Return ? ToNumber(primValue).
+
+ 7.1.1 ToPrimitive ( input [ , PreferredType ] )
+
+ ...
+ 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
+ 5. If exoticToPrim is not undefined, then
+ a. Let result be ? Call(exoticToPrim, input, « hint »).
+ b. If Type(result) is not Object, return result.
+ c. Throw a TypeError exception.
+ ...
+ 7. Return ? OrdinaryToPrimitive(input, hint).
+
+ OrdinaryToPrimitive
+
+ ...
+ 5. For each name in methodNames in List order, do
+ a. Let method be ? Get(O, name).
+ b. If IsCallable(method) is true, then
+ i. Let result be ? Call(method, O).
+ ii. If Type(result) is not Object, return result.
+ 6. Throw a TypeError exception.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new Int8Array(1);
+ var valueOf = 0;
+ var toString = 0;
+
+ sample.valueOf = function() {
+ valueOf++;
+ return {};
+ };
+
+ sample.toString = function() {
+ toString++;
+ return {};
+ };
+
+ assert.throws(TypeError, function() {
+ new TA([8, sample]);
+ }, "abrupt completion from ToNumber(sample)");
+
+ assert.sameValue(valueOf, 1, "valueOf called once");
+ assert.sameValue(toString, 1, "toString called once");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js
new file mode 100644
index 0000000000..7bb03318c0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.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.
+/*---
+esid: sec-typedarray-object
+description: >
+ Return abrupt from valueOf() when setting a 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).
+ ...
+
+ 9.4.5.5 [[Set]] ( P, V, Receiver)
+
+ ...
+ 2. If Type(P) is String and if SameValue(O, Receiver) is true, then
+ a. Let numericIndex be ! CanonicalNumericIndexString(P).
+ b. If numericIndex is not undefined, then
+ i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
+ ii. Return true.
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ ToNumber ( argument )
+
+ Object, Apply the following steps:
+
+ 1. Let primValue be ? ToPrimitive(argument, hint Number).
+ 2. Return ? ToNumber(primValue).
+
+ 7.1.1 ToPrimitive ( input [ , PreferredType ] )
+
+ ...
+ 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
+ 5. If exoticToPrim is not undefined, then
+ a. Let result be ? Call(exoticToPrim, input, « hint »).
+ b. If Type(result) is not Object, return result.
+ c. Throw a TypeError exception.
+ ...
+ 7. Return ? OrdinaryToPrimitive(input, hint).
+
+ OrdinaryToPrimitive
+
+ ...
+ 5. For each name in methodNames in List order, do
+ a. Let method be ? Get(O, name).
+ b. If IsCallable(method) is true, then
+ i. Let result be ? Call(method, O).
+ ii. If Type(result) is not Object, return result.
+ 6. Throw a TypeError exception.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new Int8Array(1);
+ var valueOf = 0;
+
+ sample.valueOf = function() {
+ valueOf++;
+ throw new Test262Error();
+ };
+
+ assert.throws(Test262Error, function() {
+ new TA([8, sample]);
+ }, "abrupt completion from ToNumber(sample)");
+
+ assert.sameValue(valueOf, 1, "valueOf called once");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js
new file mode 100644
index 0000000000..0e5f93d30a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js
@@ -0,0 +1,40 @@
+// 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-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: [TypedArray]
+---*/
+
+var obj = {
+ "2": {
+ valueOf() {
+ throw new Test262Error();
+ }
+ },
+ length: 4
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(Test262Error, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.js
new file mode 100644
index 0000000000..f30ef12f5c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.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.
+/*---
+esid: 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, TypedArray]
+---*/
+
+var obj = {
+ "2": Symbol("1"),
+ length: 4
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(TypeError, function() {
+ new TA(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js
new file mode 100644
index 0000000000..b5b6b00fa1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: 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]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert.throws(TypeError, function() {
+ TA({});
+ });
+
+ assert.throws(TypeError, function() {
+ TA([]);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js
new file mode 100644
index 0000000000..996f9d659a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.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-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.
+includes: [testTypedArray.js]
+features: [Reflect, TypedArray]
+---*/
+
+function newTarget() {}
+var proto = {};
+newTarget.prototype = proto;
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = Reflect.construct(TA, [], newTarget);
+
+ assert.sameValue(ta.constructor, Object);
+ assert.sameValue(Object.getPrototypeOf(ta), proto);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js
new file mode 100644
index 0000000000..7ae957d8a1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.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-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]
+features: [TypedArray]
+---*/
+
+function newTarget() {}
+newTarget.prototype = null;
+var o = [];
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = Reflect.construct(TA, [o], newTarget);
+
+ assert.sameValue(ta.constructor, TA);
+ assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
+});
+
+reportCompare(0, 0);