Add tests for TypedArrays constructors

This commit is contained in:
Leonardo Balter 2016-01-22 11:36:26 -05:00
parent 4bdd808d04
commit f8a4229bfd
84 changed files with 2926 additions and 288 deletions

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Float32Array();
}, "Float32Array()");
assert.throws(TypeError, function() {
Float32Array(0);
}, "Float32Array(0)");
assert.throws(TypeError, function() {
Float32Array(new Float32Array(1));
}, "Float32Array(float32Array)");
assert.throws(TypeError, function() {
Float32Array([]);
}, "Float32Array(array)");
assert.throws(TypeError, function() {
Float32Array(new ArrayBuffer(8));
}, "Float32Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Float64Array();
}, "Float64Array()");
assert.throws(TypeError, function() {
Float64Array(0);
}, "Float64Array(0)");
assert.throws(TypeError, function() {
Float64Array(new Float64Array(1));
}, "Float64Array(float64Array)");
assert.throws(TypeError, function() {
Float64Array([]);
}, "Float64Array(array)");
assert.throws(TypeError, function() {
Float64Array(new ArrayBuffer(8));
}, "Float64Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Int16Array();
}, "Int16Array()");
assert.throws(TypeError, function() {
Int16Array(0);
}, "Int16Array(0)");
assert.throws(TypeError, function() {
Int16Array(new Int16Array(1));
}, "Int16Array(int16Array)");
assert.throws(TypeError, function() {
Int16Array([]);
}, "Int16Array(array)");
assert.throws(TypeError, function() {
Int16Array(new ArrayBuffer(8));
}, "Int16Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Int32Array();
}, "Int32Array()");
assert.throws(TypeError, function() {
Int32Array(0);
}, "Int32Array(0)");
assert.throws(TypeError, function() {
Int32Array(new Int32Array(1));
}, "Int32Array(int32Array)");
assert.throws(TypeError, function() {
Int32Array([]);
}, "Int32Array(array)");
assert.throws(TypeError, function() {
Int32Array(new ArrayBuffer(8));
}, "Int32Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Int8Array();
}, "Int8Array()");
assert.throws(TypeError, function() {
Int8Array(0);
}, "Int8Array(0)");
assert.throws(TypeError, function() {
Int8Array(new Int8Array(1));
}, "Int8Array(int8Array)");
assert.throws(TypeError, function() {
Int8Array([]);
}, "Int8Array(array)");
assert.throws(TypeError, function() {
Int8Array(new ArrayBuffer(8));
}, "Int8Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Uint16Array();
}, "Uint16Array()");
assert.throws(TypeError, function() {
Uint16Array(0);
}, "Uint16Array(0)");
assert.throws(TypeError, function() {
Uint16Array(new Uint16Array(1));
}, "Uint16Array(uint16Array)");
assert.throws(TypeError, function() {
Uint16Array([]);
}, "Uint16Array(array)");
assert.throws(TypeError, function() {
Uint16Array(new ArrayBuffer(8));
}, "Uint16Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Uint32Array();
}, "Uint32Array()");
assert.throws(TypeError, function() {
Uint32Array(0);
}, "Uint32Array(0)");
assert.throws(TypeError, function() {
Uint32Array(new Uint32Array(1));
}, "Uint32Array(uint32Array)");
assert.throws(TypeError, function() {
Uint32Array([]);
}, "Uint32Array(array)");
assert.throws(TypeError, function() {
Uint32Array(new ArrayBuffer(8));
}, "Uint32Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Uint8Array();
}, "Uint8Array()");
assert.throws(TypeError, function() {
Uint8Array(0);
}, "Uint8Array(0)");
assert.throws(TypeError, function() {
Uint8Array(new Uint8Array(1));
}, "Uint8Array(uint8Array)");
assert.throws(TypeError, function() {
Uint8Array([]);
}, "Uint8Array(array)");
assert.throws(TypeError, function() {
Uint8Array(new ArrayBuffer(8));
}, "Uint8Array(arrayBuffer)");

View File

@ -1,32 +0,0 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4.1
description: >
Throws a TypeError if NewTarget is undefined.
info: >
TypedArray( ... argumentsList)
1. If NewTarget is undefined, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Uint8ClampedArray();
}, "Uint8ClampedArray()");
assert.throws(TypeError, function() {
Uint8ClampedArray(0);
}, "Uint8ClampedArray(0)");
assert.throws(TypeError, function() {
Uint8ClampedArray(new Uint8ClampedArray(1));
}, "Uint8ClampedArray(uint8clampedArray)");
assert.throws(TypeError, function() {
Uint8ClampedArray([]);
}, "Uint8ClampedArray(array)");
assert.throws(TypeError, function() {
Uint8ClampedArray(new ArrayBuffer(8));
}, "Uint8ClampedArray(arrayBuffer)");

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a RangeError if bufferByteLength modulo elementSize 0
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
13. If length is undefined, then
a. If bufferByteLength modulo elementSize 0, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(1);
testWithTypedArrayConstructors(function(TA) {
if (TA.BYTES_PER_ELEMENT === 1) {
// Impossible to trigger this step here.
return;
}
assert.throws(RangeError, function() {
new TA(buffer);
});
assert.throws(RangeError, function() {
new TA(buffer, 0, undefined);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a RangeError if ToInteger(byteOffset) is < 0
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
7. Let offset be ? ToInteger(byteOffset).
8. If offset < 0, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(buffer, -1);
});
assert.throws(RangeError, function() {
new TA(buffer, -Infinity);
});
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return abrupt from parsing integer value from byteOffset as a symbol
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
7. Let offset be ? ToInteger(byteOffset).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var byteOffset = Symbol("1");
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(buffer, byteOffset);
});
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
9. If offset modulo elementSize 0, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
if (TA.BYTES_PER_ELEMENT === 1) {
// Impossible to trigger this step here.
return;
}
assert.throws(RangeError, function() {
new TA(buffer, 7);
});
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return abrupt from parsing integer value from byteOffset
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
7. Let offset be ? ToInteger(byteOffset).
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
var byteOffset = {
valueOf: function() {
throw new Test262Error();
}
};
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(buffer, byteOffset);
});
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from defined length and offset
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var offset = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(3 * offset);
var ta1 = new TA(buffer, offset, 2);
assert.sameValue(ta1.length, 2, "ta1.length");
assert.sameValue(ta1.buffer, buffer, "ta1.buffer");
assert.sameValue(
Object.getPrototypeOf(ta1), TA.prototype,
"Object.getPrototypeOf(ta1)"
);
var ta2 = new TA(buffer, offset, 0);
assert.sameValue(ta2.length, 0, "ta2.length");
assert.sameValue(ta2.buffer, buffer, "ta2.buffer");
assert.sameValue(
Object.getPrototypeOf(ta2), TA.prototype,
"Object.getPrototypeOf(ta2)"
);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from defined length
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var length = 4;
var buffer = new ArrayBuffer(bpe * length * 4);
var ta1 = new TA(buffer, 0, length);
assert.sameValue(ta1.length, length);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0, 0);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from negative defined length
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var length = 4;
var buffer = new ArrayBuffer(bpe * length * 4);
var ta1 = new TA(buffer, 0, -1);
assert.sameValue(ta1.length, 0);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0, -Infinity);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
var ta3 = new TA(buffer, 8, -1);
assert.sameValue(ta3.length, 0);
assert.sameValue(ta3.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta3), TA.prototype);
var ta4 = new TA(buffer, 8, -Infinity);
assert.sameValue(ta4.length, 0);
assert.sameValue(ta4.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from defined offset
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe * 4);
var ta1 = new TA(buffer, bpe * 2);
assert.sameValue(ta1.length, 2);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0);
assert.sameValue(ta2.length, 4);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
If offset + newByteLength > bufferByteLength, throw a RangeError exception.
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
14. Else,
a. Let newLength be ? ToLength(length).
b. Let newByteLength be newLength × elementSize.
c. If offset+newByteLength > bufferByteLength, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(buffer, 0, 16);
});
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
13. If length is undefined, then
a. If bufferByteLength modulo elementSize 0, throw a RangeError exception.
b. Let newByteLength be bufferByteLength - offset.
c. If newByteLength < 0, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(buffer, 16);
});
assert.throws(RangeError, function() {
new TA(buffer, 16, undefined);
});
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Reuse buffer argument instead of making a new clone
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
15. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe * 4);
var ta1 = new TA(buffer);
var ta2 = new TA(buffer);
assert.sameValue(ta1.buffer, ta2.buffer);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a TypeError if length is a Symbol
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
14. Else,
a. Let newLength be ? ToLength(length).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var buffer = new ArrayBuffer(8);
var length = Symbol("1");
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(buffer, 0, length);
});
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Returns abrupt from ToLength(length)
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
14. Else,
a. Let newLength be ? ToLength(length).
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
var length = {
valueOf() {
throw new Test262Error();
}
}
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(buffer, 0, length);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from undefined defined offset
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer1 = new ArrayBuffer(bpe * 4);
var ta1 = new TA(buffer1);
assert.sameValue(ta1.length, 4);
assert.sameValue(ta1.buffer, buffer1);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var buffer2 = new ArrayBuffer(0);
var ta2 = new TA(buffer2);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer2);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Return a TypedArray object
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
7. Return obj
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(4);
var bytesPerElement = TA.BYTES_PER_ELEMENT;
var length = typedArray.length;
assert.sameValue(length, 4, "length");
assert.sameValue(
Object.getPrototypeOf(typedArray), TA.prototype,
"Object.getPrototypeOf(typedArray)"
);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray
description: >
Return a TypedArray object
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
...
3. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, 0).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
7. Return obj
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA();
assert.sameValue(typedArray.length, 0);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return a TypedArray object
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
20. Return O.
includes: [testTypedArray.js]
---*/
var length = 10;
var typedArraySample = new Int8Array(length);
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(typedArraySample);
var bytesPerElement = TA.BYTES_PER_ELEMENT;
assert.notSameValue(typedArray, typedArraySample);
assert.sameValue(typedArray.length, length);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Use prototype from %TypedArray% if newTarget's prototype is not an Object
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
function newTarget() {}
newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Use prototype from new target if it's an Object
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
features: [Reflect]
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
function newTarget() {}
var proto = {};
newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return abrupt completion getting newTarget's prototype
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
...
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
3. Let proto be ? Get(constructor, "prototype").
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, "prototype", {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
Reflect.construct(TA, [buffer], newTarget);
});
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Use prototype from %TypedArray% if newTarget's prototype is not an Object
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
includes: [testTypedArray.js]
---*/
function newTarget() {}
newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Use prototype from new target if it's an Object
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
features: [Reflect]
includes: [testTypedArray.js]
---*/
function newTarget() {}
var proto = {};
newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Return abrupt completion getting newTarget's prototype
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
...
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
3. Let proto be ? Get(constructor, "prototype").
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, "prototype", {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
Reflect.construct(TA, [1], newTarget);
});
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray
description: >
Use prototype from %TypedArray% if newTarget's prototype is not an Object
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
...
3. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, 0).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
includes: [testTypedArray.js]
---*/
function newTarget() {}
newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray
description: >
Use prototype from new target if it's an Object
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
...
3. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, 0).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
features: [Reflect]
includes: [testTypedArray.js]
---*/
function newTarget() {}
var proto = {};
newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray
description: >
Return abrupt completion getting newTarget's prototype
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
...
3. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, 0).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
...
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
3. Let proto be ? Get(constructor, "prototype").
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, "prototype", {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
Reflect.construct(TA, [], newTarget);
});
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Use prototype from %TypedArray% if newTarget's prototype is not an Object
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]],
NewTarget, "%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
includes: [testTypedArray.js]
---*/
function newTarget() {}
newTarget.prototype = null;
var o = [];
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [o], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Use prototype from new target if it's an Object
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]],
NewTarget, "%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
features: [Reflect]
includes: [testTypedArray.js]
---*/
function newTarget() {}
var proto = {};
newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});

View File

@ -0,0 +1,48 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt completion getting newTarget's prototype
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]],
NewTarget, "%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
...
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
3. Let proto be ? Get(constructor, "prototype").
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, "prototype", {
get() {
throw new Test262Error();
}
});
var o = {};
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
Reflect.construct(TA, [o], newTarget);
});
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use prototype from %TypedArray% if newTarget's prototype is not an Object
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
includes: [testTypedArray.js]
---*/
function newTarget() {}
newTarget.prototype = null;
var sample = new Int8Array(8);
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [sample], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use prototype from new target if it's an Object
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
10. Set the [[Prototype]] internal slot of A to prototype.
...
12. Return A.
features: [Reflect]
includes: [testTypedArray.js]
---*/
function newTarget() {}
var proto = {};
newTarget.prototype = proto;
var sample = new Int8Array(8);
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [sample], newTarget);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt completion getting newTarget's prototype
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%).
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
...
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
3. Let proto be ? Get(constructor, "prototype").
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, "prototype", {
get() {
throw new Test262Error();
}
});
var sample = new Int8Array();
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
Reflect.construct(TA, [sample], newTarget);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a RangeError if length is a float number
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(1.1);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a RangeError if length is a Infinity value
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(Infinity);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a RangeError if length is NaN
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(NaN);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a RangeError if length is a negative value
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(-1);
});
});

View File

@ -0,0 +1,53 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a RangeError when length argument is not a valid buffer size
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
6. Else,
a. Perform ? AllocateTypedArrayBuffer(obj, length).
...
22.2.4.2.2 Runtime Semantics: AllocateTypedArrayBuffer ( O, length )
...
7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
...
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
...
3. Let block be ? CreateByteDataBlock(byteLength).
...
6.2.6.1 CreateByteDataBlock (size)
...
2. Let db be a new Data Block value consisting of size bytes. If it is
impossible to create such a Data Block, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var length = Math.pow(2, 53);
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(length);
})
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
If length is a Symbol, throw a TypeError exception.
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
...
features: [Symbol]
includes: [testTypedArray.js]
---*/
var s = Symbol('1');
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(s);
});
});

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
If length is undefined, throw a TypeError exception.
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
3. If length is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(undefined);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return typedArray from array argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
includes: [testTypedArray.js]
---*/
var obj = [7, 42];
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(obj);
assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return typedArray from iterable argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var obj = (function *() {
yield 7; yield 42;
})();
var typedArray = new TA(obj);
assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from iterating object argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
4. Let arrayLike be ? IterableToArrayLike(object).
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var obj = (function *() {
yield 0;
throw new Test262Error();
})();
assert.throws(Test262Error, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,39 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt when object @@iterator is not callable
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
4. Let arrayLike be ? IterableToArrayLike(object).
...
includes: [testTypedArray.js]
features: [Symbol.iterator]
---*/
var obj = function () {}
testWithTypedArrayConstructors(function(TA) {
obj[Symbol.iterator] = {};
assert.throws(TypeError, function() {
new TA(obj);
});
obj[Symbol.iterator] = true;
assert.throws(TypeError, function() {
new TA(obj);
});
obj[Symbol.iterator] = 42;
assert.throws(TypeError, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from getting object @@iterator
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
4. Let arrayLike be ? IterableToArrayLike(object).
...
includes: [testTypedArray.js]
features: [Symbol.iterator]
---*/
var obj = function () {}
Object.defineProperty(obj, Symbol.iterator, {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from allocating array buffer with excessive length
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
6. Perform ? AllocateTypedArrayBuffer(O, len).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var obj = {
length: Math.pow(2, 53)
};
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from length property as a Symbol on the object argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
5. Let len be ? ToLength(? Get(arrayLike, "length")).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var obj = {
length: Symbol("1")
};
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from getting length property on the object argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
5. Let len be ? ToLength(? Get(arrayLike, "length")).
...
includes: [testTypedArray.js]
---*/
var obj = {};
Object.defineProperty(obj, "length", {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return typedArray from object argument
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
includes: [testTypedArray.js]
features: [Symbol]
---*/
var obj = {
"2": 42,
"3": "7",
"4": Symbol("1"),
length: 4
};
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(obj);
assert.sameValue(typedArray.length, 4);
assert.sameValue(typedArray[2], 42);
assert.sameValue(typedArray[3], 7);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from getting object property
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
8. Repeat, while k < len
...
b. Let kValue be ? Get(arrayLike, Pk).
...
includes: [testTypedArray.js]
---*/
var obj = {
length: 4
};
Object.defineProperty(obj, "2", {
get() {
throw new Test262Error();
}
});
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from setting property
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
8. Repeat, while k < len
...
b. Let kValue be ? Get(arrayLike, Pk).
c. Perform ? Set(O, Pk, kValue, true).
...
includes: [testTypedArray.js]
---*/
var obj = {
"2": {
valueOf() {
throw new Test262Error();
}
},
length: 4
};
testWithTypedArrayConstructors(function(TA) {
assert.throws(Test262Error, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Return abrupt from setting property
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
8. Repeat, while k < len
...
b. Let kValue be ? Get(arrayLike, Pk).
c. Perform ? Set(O, Pk, kValue, true).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var obj = {
"2": Symbol("1"),
length: 4
};
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
new TA(obj);
});
});

View File

@ -0,0 +1,52 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {};
var called = 0;
var custom = {};
sample.buffer.constructor = ctor;
ctor[Symbol.species] = function() {
called++;
};
ctor[Symbol.species].prototype = custom;
var tarray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom);
assert.sameValue(called, 0);
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from buffer.constructor.@@species.prototype
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
8. Throw a TypeError exception.
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {};
var o = { m() {} };
sample.buffer.constructor = ctor;
ctor[Symbol.species] = o.m;
assert.throws(TypeError, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on null buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {}
sample.buffer.constructor = ctor;
ctor[Symbol.species] = null;
var typedArray = new TA(sample);
assert.sameValue(
Object.getPrototypeOf(typedArray.buffer),
ArrayBuffer.prototype,
"buffer ctor is not called when species is null"
);
});

View File

@ -0,0 +1,59 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from buffer.constructor.@@species.prototype
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
...
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
...
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {};
var called = 0;
sample.buffer.constructor = ctor;
ctor[Symbol.species] = function() {called++;}.bind(null);
Object.defineProperty(ctor[Symbol.species], "prototype", {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
assert.sameValue(called, 0);
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {}
sample.buffer.constructor = ctor;
ctor[Symbol.species] = undefined;
var a = new TA(sample);
assert.sameValue(
Object.getPrototypeOf(a.buffer),
ArrayBuffer.prototype,
"buffer ctor is not called when species is undefined"
);
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from getting typedArray argument's buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var ctor = {};
sample.buffer.constructor = ctor;
Object.defineProperty(ctor, Symbol.species, {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,90 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt completion from typedArray argument's buffer.constructor's value
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
2. Let C be ? Get(O, "constructor").
...
4. If Type(C) is not Object, throw a TypeError exception.
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var sample1 = new Int8Array();
var sample2 = new Int16Array();
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return 1;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return true;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return '';
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return null;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
var s = Symbol('1');
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return s;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt completion from getting typedArray argument's buffer.constructor
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
18. Else,
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
2. Let C be ? Get(O, "constructor").
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample1 = Int8Array;
var sample2 = Int16Array;
var sample = new (TA === Int8Array ? sample2 : sample1);
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from getting typedArray argument's buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
includes: [testTypedArray.js]
---*/
var sample1 = new Int8Array(7);
var sample2 = new Int16Array(7);
testWithTypedArrayConstructors(function(TA) {
var sample = TA === Int8Array ? sample2 : sample1;
var typedArray = new TA(sample);
assert.sameValue(typedArray.length, 7);
assert.notSameValue(typedArray, sample);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,60 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
var ctor = {};
var called = 0;
var custom = {};
sample.buffer.constructor = ctor;
ctor[Symbol.species] = function() {
called++;
};
ctor[Symbol.species].prototype = custom;
var tarray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom);
assert.sameValue(called, 0);
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from buffer.constructor.@@species.prototype
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
8. Throw a TypeError exception.
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
var ctor = {};
var o = { m() {} };
sample.buffer.constructor = ctor;
ctor[Symbol.species] = o.m;
assert.throws(TypeError, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on null buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(4);
var ctor = {}
sample.buffer.constructor = ctor;
ctor[Symbol.species] = null;
var typedArray = new TA(sample);
assert.sameValue(
Object.getPrototypeOf(typedArray.buffer),
ArrayBuffer.prototype,
"buffer ctor is not called when species is null"
);
});

View File

@ -0,0 +1,62 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from buffer.constructor.@@species.prototype
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
7. If IsConstructor(S) is true, return S.
...
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
...
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
var ctor = {};
sample.buffer.constructor = ctor;
ctor[Symbol.species] = function(){}.bind(null);
Object.defineProperty(ctor[Symbol.species], "prototype", {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
6. If S is either undefined or null, return defaultConstructor.
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(4);
var ctor = {}
sample.buffer.constructor = ctor;
ctor[Symbol.species] = undefined;
var a = new TA(sample);
assert.sameValue(
Object.getPrototypeOf(a.buffer),
ArrayBuffer.prototype,
"buffer ctor is not called when species is undefined"
);
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt from getting typedArray argument's buffer.constructor.@@species
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
5. Let S be ? Get(C, @@species).
...
includes: [testTypedArray.js]
features: [Symbol.species]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
var ctor = {};
sample.buffer.constructor = ctor;
Object.defineProperty(ctor, Symbol.species, {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,94 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt completion from typedArray argument's buffer.constructor's value
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
2. Let C be ? Get(O, "constructor").
...
4. If Type(C) is not Object, throw a TypeError exception.
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return 1;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return true;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return '';
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return null;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
var s = Symbol('1');
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return s;
},
configurable: true
});
assert.throws(TypeError, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Return abrupt completion from getting typedArray argument's buffer.constructor
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
...
2. If cloneConstructor is not present, then
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
...
7.3.20 SpeciesConstructor ( O, defaultConstructor )
...
2. Let C be ? Get(O, "constructor").
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
new TA(sample);
});
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Same typedArray ctor argument returns a new cloned typedArray
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
17. If SameValue(elementType, srcType) is true, then
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
...
23. Return O.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(7);
var typedArray = new TA(sample);
assert.sameValue(typedArray.length, 7);
assert.notSameValue(typedArray, sample);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a TypeError if NewTarget is undefined.
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
2. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var buffer = new ArrayBuffer(4);
assert.throws(TypeError, function() {
TA(buffer);
});
});

View File

@ -0,0 +1,50 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Throws a TypeError if NewTarget is undefined.
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
2. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
var s = Symbol('1');
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
TA(0);
});
assert.throws(TypeError, function() {
TA(NaN);
});
assert.throws(TypeError, function() {
TA("");
});
assert.throws(TypeError, function() {
TA(true);
});
assert.throws(TypeError, function() {
TA(null);
});
assert.throws(TypeError, function() {
TA(undefined);
});
assert.throws(TypeError, function() {
TA(s);
});
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray
description: >
Throws a TypeError if NewTarget is undefined.
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
1. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
TA();
});
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-object
description: >
Throws a TypeError if NewTarget is undefined.
info: >
22.2.4.4 TypedArray ( object )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]]
internal slot.
...
2. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
TA({});
});
assert.throws(TypeError, function() {
TA([]);
});
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-typedarray
description: >
Throws a TypeError if NewTarget is undefined.
info: >
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
2. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(4);
assert.throws(TypeError, function() {
TA(typedArray);
});
});