Skip to content
Snippets Groups Projects
Commit ac7711e9 authored by Gorkem Yakin's avatar Gorkem Yakin
Browse files

Merge pull request #485 from bocoup/typedarray-constructor

Add tests for _TypedArray_ constructors
parents 5cb97c29 75952bee
No related branches found
No related tags found
No related merge requests found
Showing
with 338 additions and 295 deletions
...@@ -2,29 +2,64 @@ ...@@ -2,29 +2,64 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es7id: pending es7id: pending
description: TypedArray(length) cannot be direclty invoked as a constructor description: Throw a TypeError exception if directly invoked.
info: > info: >
22.2.1.1 %TypedArray%()# 22.2.1.1 %TypedArray% ( )
1. If NewTarget is undefined, throw a TypeError exception. 1. Throw a TypeError Exception
2. Let here be the active function object.
3. If SameValue(NewTarget, here) is true, throw a TypeError exception.
... ...
Note: there's a breaking change from ES2015's 22.2.1.2 step 7 where calling Note: ES2016 replaces all the references for the %TypedArray% constructor to a
the %TypedArray% constructor with a floating number as the argument throws a single chapter covering all arguments cases.
RangeError exception before checking `SameValue(NewTarget, here)`.
includes: [testTypedArray.js] includes: [testTypedArray.js]
---*/ ---*/
assert.throws(TypeError, function() {
TypedArray();
});
assert.throws(TypeError, function() {
new TypedArray();
});
assert.throws(TypeError, function() {
TypedArray(1);
});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TypedArray(1); new TypedArray(1);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TypedArray({}); TypedArray(1.1);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TypedArray(1.1); new TypedArray(1.1);
}); });
assert.throws(TypeError, function() {
TypedArray({});
});
assert.throws(TypeError, function() {
new TypedArray({});
});
var typedArray = new Int8Array(4);
assert.throws(TypeError, function() {
TypedArray(typedArray);
});
assert.throws(TypeError, function() {
new TypedArray(typedArray);
});
var buffer = new ArrayBuffer(4);
assert.throws(TypeError, function() {
TypedArray(buffer);
});
assert.throws(TypeError, function() {
new TypedArray(buffer);
});
// Copyright (C) 2016 the V8 project authors. All rights reserved. // Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es6id: 22.2.2 es7id: pending
description: > description: >
TypedArray has a "length" property whose value is 3. TypedArray has a "length" property whose value is 0.
info: > info: >
22.2.2 Properties of the %TypedArray% Intrinsic Object 22.2.1.1 %TypedArray% ()
Besides a length property whose value is 3 and a name property whose value is The length property of the %TypedArray% constructor function is 0.
"TypedArray", %TypedArray% has the following properties:
... ...
ES6 section 17: Unless otherwise specified, the length property of a built-in ES7 section 17: Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]: Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }. false, [[Configurable]]: true }.
includes: [propertyHelper.js, testTypedArray.js] includes: [propertyHelper.js, testTypedArray.js]
---*/ ---*/
assert.sameValue(TypedArray.length, 3); assert.sameValue(TypedArray.length, 0);
verifyNotEnumerable(TypedArray, 'length'); verifyNotEnumerable(TypedArray, 'length');
verifyNotWritable(TypedArray, 'length'); verifyNotWritable(TypedArray, 'length');
......
// 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)");
// 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)");
// 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)");
// 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)");
// 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)");
// 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)");
// 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)");
// 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)");
// 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)");
// 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);
});
});
// 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);
});
});
// 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);
});
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
...
10. If offset modulo elementSize ≠ 0, throw a RangeError exception.
...
includes: [testTypedArray.js]
---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) {
if (TA.BYTES_PER_ELEMENT === 1) {
// Impossible to trigger this step here.
return;
}
assert.throws(RangeError, function() {
new TA(buffer, 7);
});
});
// 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);
});
});
// 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);
});
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from defined length and offset
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var offset = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(3 * offset);
var ta1 = new TA(buffer, offset, 2);
assert.sameValue(ta1.length, 2, "ta1.length");
assert.sameValue(ta1.buffer, buffer, "ta1.buffer");
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, offset, 0);
assert.sameValue(ta2.length, 0, "ta2.length");
assert.sameValue(ta2.buffer, buffer, "ta2.buffer");
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from defined length
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has an [[ArrayBufferData]] internal slot.
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var length = 4;
var buffer = new ArrayBuffer(bpe * length * 4);
var ta1 = new TA(buffer, 0, length);
assert.sameValue(ta1.length, length);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0, 0);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment