mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for _TypedArray_.from and of
This commit is contained in:
parent
4388f2869c
commit
048073a29a
@ -17,5 +17,5 @@ var from = TypedArray.from;
|
||||
var m = { m() {} }.m;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
from.call(o.m, []);
|
||||
from.call(m, []);
|
||||
});
|
||||
|
@ -14,10 +14,8 @@ info: >
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
m() {}
|
||||
};
|
||||
var m = { m() {} }.m;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.of.call(o.m, []);
|
||||
TypedArray.of.call(m, []);
|
||||
});
|
||||
|
@ -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%.from
|
||||
description: >
|
||||
Custom constructor needs to instantiate a TypedArray
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
8. Let targetObj be ? TypedArrayCreate(C, «len»).
|
||||
...
|
||||
|
||||
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
|
||||
|
||||
1. Let newTypedArray be ? Construct(constructor, argumentList).
|
||||
2. Perform ? ValidateTypedArray(newTypedArray).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var ctor = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from.call(ctor, []);
|
||||
});
|
||||
});
|
33
test/built-ins/TypedArrays/from/custom-ctor.js
Normal file
33
test/built-ins/TypedArrays/from/custom-ctor.js
Normal 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%.from
|
||||
description: >
|
||||
Calls and return abrupt completion from custom constructor
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
8. Let targetObj be ? TypedArrayCreate(C, «len»).
|
||||
...
|
||||
|
||||
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
|
||||
|
||||
1. Let newTypedArray be ? Construct(constructor, argumentList).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
var ctor = function() {
|
||||
called++;
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from.call(ctor, []);
|
||||
});
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
});
|
17
test/built-ins/TypedArrays/from/inherited.js
Normal file
17
test/built-ins/TypedArrays/from/inherited.js
Normal file
@ -0,0 +1,17 @@
|
||||
// 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%.from
|
||||
description: >
|
||||
`from` is %TypedArray%.from
|
||||
info: >
|
||||
22.2.1 The %TypedArray% Intrinsic Object
|
||||
|
||||
The %TypedArray% intrinsic object is a constructor function object that all of
|
||||
the TypedArray constructor object inherit from.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.sameValue(TA.from, TypedArray.from);
|
||||
});
|
31
test/built-ins/TypedArrays/from/mapfn-abrupt-completion.js
Normal file
31
test/built-ins/TypedArrays/from/mapfn-abrupt-completion.js
Normal 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%.from
|
||||
description: >
|
||||
Return abrupt from mapfn
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = {
|
||||
"0": 42,
|
||||
length: 2
|
||||
};
|
||||
var mapfn = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(source, mapfn);
|
||||
});
|
||||
});
|
46
test/built-ins/TypedArrays/from/mapfn-arguments.js
Normal file
46
test/built-ins/TypedArrays/from/mapfn-arguments.js
Normal 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%.from
|
||||
description: >
|
||||
Assert mapfn arguments
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = [42, 43, 44];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var results = [];
|
||||
var mapfn = function(kValue, k) {
|
||||
results.push({
|
||||
kValue: kValue,
|
||||
k: k,
|
||||
argsLength: arguments.length
|
||||
});
|
||||
};
|
||||
|
||||
TA.from(source, mapfn);
|
||||
|
||||
assert.sameValue(results.length, 3);
|
||||
|
||||
assert.sameValue(results[0].kValue, 42);
|
||||
assert.sameValue(results[0].k, 0);
|
||||
assert.sameValue(results[0].argsLength, 2);
|
||||
|
||||
assert.sameValue(results[1].kValue, 43);
|
||||
assert.sameValue(results[1].k, 1);
|
||||
assert.sameValue(results[1].argsLength, 2);
|
||||
|
||||
assert.sameValue(results[2].kValue, 44);
|
||||
assert.sameValue(results[2].k, 2);
|
||||
assert.sameValue(results[2].argsLength, 2);
|
||||
});
|
35
test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js
Normal file
35
test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js
Normal 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%.from
|
||||
description: >
|
||||
Assert mapfn `this` with thisArg
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = [42, 43];
|
||||
var thisArg = {};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var results = [];
|
||||
var mapfn = function(kValue, k) {
|
||||
results.push(this);
|
||||
};
|
||||
|
||||
TA.from(source, mapfn, thisArg);
|
||||
|
||||
assert.sameValue(results.length, 2);
|
||||
assert.sameValue(results[0], thisArg);
|
||||
assert.sameValue(results[1], thisArg);
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Assert mapfn `this` without thisArg
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
...
|
||||
includes: [testTypedArray.js, fnGlobalObject.js]
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var source = [42, 43];
|
||||
var global = fnGlobalObject();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var results = [];
|
||||
var mapfn = function(kValue, k) {
|
||||
results.push(this);
|
||||
};
|
||||
|
||||
TA.from(source, mapfn);
|
||||
|
||||
assert.sameValue(results.length, 2);
|
||||
assert.sameValue(results[0], global);
|
||||
assert.sameValue(results[1], global);
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Assert mapfn `this` without thisArg
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
flags: [onlyStrict]
|
||||
---*/
|
||||
|
||||
var source = [42, 43];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var results = [];
|
||||
var mapfn = function(kValue, k) {
|
||||
results.push(this);
|
||||
};
|
||||
|
||||
TA.from(source, mapfn);
|
||||
|
||||
assert.sameValue(results.length, 2);
|
||||
assert.sameValue(results[0], undefined);
|
||||
assert.sameValue(results[1], undefined);
|
||||
});
|
49
test/built-ins/TypedArrays/from/nan-conversion.js
Normal file
49
test/built-ins/TypedArrays/from/nan-conversion.js
Normal 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%.from
|
||||
description: >
|
||||
Test NaN conversions
|
||||
info: >
|
||||
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
|
||||
|
||||
...
|
||||
3. Let numValue be ? ToNumber(value).
|
||||
...
|
||||
|
||||
24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
|
||||
isLittleEndian ] )
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from([NaN, undefined]);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], NaN);
|
||||
assert.sameValue(result[1], NaN);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from([NaN, undefined]);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 0);
|
||||
assert.sameValue(result[1], 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int8Array,
|
||||
Int32Array,
|
||||
Int16Array,
|
||||
Int8Array,
|
||||
Uint32Array,
|
||||
Uint16Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
16
test/built-ins/TypedArrays/from/new-instance-empty.js
Normal file
16
test/built-ins/TypedArrays/from/new-instance-empty.js
Normal file
@ -0,0 +1,16 @@
|
||||
// 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%.from
|
||||
description: >
|
||||
Return a new empty TypedArray
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from([]);
|
||||
assert.sameValue(result.length, 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Return a new TypedArray from an ordinary object
|
||||
includes: [testTypedArray.js]
|
||||
features: [Array.prototype.values]
|
||||
---*/
|
||||
|
||||
var source = {
|
||||
"0": 42,
|
||||
"2": 44,
|
||||
length: 4
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from(source);
|
||||
|
||||
assert.sameValue(result.length, 4);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], NaN);
|
||||
assert.sameValue(result[2], 44);
|
||||
assert.sameValue(result[3], NaN);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from(source);
|
||||
|
||||
assert.sameValue(result.length, 4);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], 0);
|
||||
assert.sameValue(result[2], 44);
|
||||
assert.sameValue(result[3], 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int8Array,
|
||||
Int32Array,
|
||||
Int16Array,
|
||||
Int8Array,
|
||||
Uint32Array,
|
||||
Uint16Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
@ -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%.from
|
||||
description: >
|
||||
Return a new TypedArray from a sparse array
|
||||
includes: [testTypedArray.js]
|
||||
features: [Array.prototype.values]
|
||||
---*/
|
||||
|
||||
var source = [,,42,,44,,];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from(source);
|
||||
|
||||
assert.sameValue(result.length, 6);
|
||||
assert.sameValue(result[0], NaN);
|
||||
assert.sameValue(result[1], NaN);
|
||||
assert.sameValue(result[2], 42);
|
||||
assert.sameValue(result[3], NaN);
|
||||
assert.sameValue(result[4], 44);
|
||||
assert.sameValue(result[5], NaN);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from(source);
|
||||
|
||||
assert.sameValue(result.length, 6);
|
||||
assert.sameValue(result[0], 0);
|
||||
assert.sameValue(result[1], 0);
|
||||
assert.sameValue(result[2], 42);
|
||||
assert.sameValue(result[3], 0);
|
||||
assert.sameValue(result[4], 44);
|
||||
assert.sameValue(result[5], 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int8Array,
|
||||
Int32Array,
|
||||
Int16Array,
|
||||
Int8Array,
|
||||
Uint32Array,
|
||||
Uint16Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
39
test/built-ins/TypedArrays/from/new-instance-from-zero.js
Normal file
39
test/built-ins/TypedArrays/from/new-instance-from-zero.js
Normal 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%.from
|
||||
description: >
|
||||
Return a new TypedArray using -0 and +0
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from([-0, +0]);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], -0, "-0 => -0");
|
||||
assert.sameValue(result[1], 0, "+0 => 0");
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from([-0, +0]);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 0, "-0 => 0");
|
||||
assert.sameValue(result[1], 0, "+0 => 0");
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Int8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
@ -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%.from
|
||||
description: >
|
||||
Return a new TypedArray using a custom Constructor
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = [42, 43, 42];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
var ctor = function(len) {
|
||||
assert.sameValue(arguments.length, 1);
|
||||
called++;
|
||||
return new TA(len)
|
||||
};
|
||||
|
||||
var result = TA.from.call(ctor, source);
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], 43);
|
||||
assert.sameValue(result[2], 42);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
assert.sameValue(called, 1);
|
||||
});
|
25
test/built-ins/TypedArrays/from/new-instance-with-mapfn.js
Normal file
25
test/built-ins/TypedArrays/from/new-instance-with-mapfn.js
Normal 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%.from
|
||||
description: >
|
||||
Return a new TypedArray using mapfn
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = [42, 43, 42];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var lastValue;
|
||||
var mapfn = function(kValue) {
|
||||
return kValue * 2;
|
||||
};
|
||||
|
||||
var result = TA.from(source, mapfn);
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 84);
|
||||
assert.sameValue(result[1], 86);
|
||||
assert.sameValue(result[2], 84);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
});
|
@ -0,0 +1,20 @@
|
||||
// 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%.from
|
||||
description: >
|
||||
Return a new TypedArray
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = [42, 43, 42];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.from(source);
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], 43);
|
||||
assert.sameValue(result[2], 42);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Return abrupt from source property
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
b. Let kValue be ? Get(arrayLike, Pk).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var source = {
|
||||
length: 2
|
||||
};
|
||||
Object.defineProperty(source, "0", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(source);
|
||||
});
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Return abrupt from setting a value on the new typedarray
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
10. Repeat, while k < len
|
||||
...
|
||||
c. If mapping is true, then
|
||||
i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
|
||||
d. Else, let mappedValue be kValue.
|
||||
e. Perform ? Set(targetObj, Pk, mappedValue, true).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var source = [42, obj, 1];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var lastValue;
|
||||
var mapfn = function(kValue) {
|
||||
lastValue = kValue;
|
||||
return kValue;
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(source, mapfn);
|
||||
});
|
||||
|
||||
assert.sameValue(lastValue, obj, "interrupted source iteration");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(source);
|
||||
});
|
||||
});
|
@ -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%.from
|
||||
description: >
|
||||
Throws a TypeError if argument is a Symbol
|
||||
info: >
|
||||
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
|
||||
|
||||
...
|
||||
3. Let numValue be ? ToNumber(value).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol("1");
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from([s]);
|
||||
});
|
||||
});
|
23
test/built-ins/TypedArrays/of/argument-is-symbol-throws.js
Normal file
23
test/built-ins/TypedArrays/of/argument-is-symbol-throws.js
Normal 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%.of
|
||||
description: >
|
||||
Throws a TypeError if argument is a Symbol
|
||||
info: >
|
||||
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
|
||||
|
||||
...
|
||||
3. Let numValue be ? ToNumber(value).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol("1");
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(TypeError, function() {
|
||||
var result = TA.of(s);
|
||||
});
|
||||
});
|
@ -0,0 +1,42 @@
|
||||
// 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%.of
|
||||
description: >
|
||||
Return abrupt from object value
|
||||
info: >
|
||||
22.2.2.2 %TypedArray%.of ( ...items )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
...
|
||||
c. Perform ? Set(newObj, Pk, kValue, true).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var lastValue;
|
||||
|
||||
var obj1 = {
|
||||
valueOf() {
|
||||
lastValue = "obj1";
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
var obj2 = {
|
||||
valueOf() {
|
||||
lastValue = "obj2";
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
lastValue = false;
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.of(obj1, obj2, obj1);
|
||||
});
|
||||
|
||||
assert.sameValue(lastValue, "obj2");
|
||||
});
|
||||
|
@ -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%.of
|
||||
description: >
|
||||
Custom constructor needs to instantiate a TypedArray
|
||||
info: >
|
||||
22.2.2.2 %TypedArray%.of ( ...items )
|
||||
|
||||
...
|
||||
5. Let newObj be ? TypedArrayCreate(C, «len»).
|
||||
...
|
||||
|
||||
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
|
||||
|
||||
1. Let newTypedArray be ? Construct(constructor, argumentList).
|
||||
2. Perform ? ValidateTypedArray(newTypedArray).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var ctor = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.of.call(ctor, 42);
|
||||
});
|
||||
});
|
34
test/built-ins/TypedArrays/of/custom-ctor.js
Normal file
34
test/built-ins/TypedArrays/of/custom-ctor.js
Normal 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%.of
|
||||
description: >
|
||||
Calls and return abrupt from custom constructor
|
||||
info: >
|
||||
22.2.2.2 %TypedArray%.of ( ...items )
|
||||
|
||||
...
|
||||
5. Let newObj be ? TypedArrayCreate(C, «len»).
|
||||
...
|
||||
|
||||
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
|
||||
|
||||
1. Let newTypedArray be ? Construct(constructor, argumentList).
|
||||
2. Perform ? ValidateTypedArray(newTypedArray).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
var ctor = function() {
|
||||
called++;
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.of.call(ctor, 42);
|
||||
});
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
});
|
17
test/built-ins/TypedArrays/of/inherited.js
Normal file
17
test/built-ins/TypedArrays/of/inherited.js
Normal file
@ -0,0 +1,17 @@
|
||||
// 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%.of
|
||||
description: >
|
||||
`of` is %TypedArray%.of
|
||||
info: >
|
||||
22.2.1 The %TypedArray% Intrinsic Object
|
||||
|
||||
The %TypedArray% intrinsic object is a constructor function object that all of
|
||||
the TypedArray constructor object inherit from.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.sameValue(TA.of, TypedArray.of);
|
||||
});
|
49
test/built-ins/TypedArrays/of/nan-conversion.js
Normal file
49
test/built-ins/TypedArrays/of/nan-conversion.js
Normal 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%.of
|
||||
description: >
|
||||
Test NaN conversions
|
||||
info: >
|
||||
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
|
||||
|
||||
...
|
||||
3. Let numValue be ? ToNumber(value).
|
||||
...
|
||||
|
||||
24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
|
||||
isLittleEndian ] )
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of(NaN, undefined);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], NaN);
|
||||
assert.sameValue(result[1], NaN);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of(NaN, undefined);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 0);
|
||||
assert.sameValue(result[1], 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int8Array,
|
||||
Int32Array,
|
||||
Int16Array,
|
||||
Int8Array,
|
||||
Uint32Array,
|
||||
Uint16Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
15
test/built-ins/TypedArrays/of/new-instance-empty.js
Normal file
15
test/built-ins/TypedArrays/of/new-instance-empty.js
Normal file
@ -0,0 +1,15 @@
|
||||
// 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%.of
|
||||
description: >
|
||||
Return a new empty TypedArray
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of();
|
||||
assert.sameValue(result.length, 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
});
|
39
test/built-ins/TypedArrays/of/new-instance-from-zero.js
Normal file
39
test/built-ins/TypedArrays/of/new-instance-from-zero.js
Normal 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%.of
|
||||
description: >
|
||||
Return a new TypedArray using -0 and +0 values
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of(-0, +0);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], -0, "-0 => 0");
|
||||
assert.sameValue(result[1], 0, "+0 => 0");
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Float32Array,
|
||||
Float64Array
|
||||
]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of(-0, +0);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 0, "-0 => 0");
|
||||
assert.sameValue(result[1], 0, "+0 => 0");
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
},
|
||||
[
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Int8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
]);
|
@ -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%.of
|
||||
description: >
|
||||
Return a new TypedArray using a custom Constructor
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
var ctor = function(len) {
|
||||
assert.sameValue(arguments.length, 1);
|
||||
called++;
|
||||
return new TA(len);
|
||||
};
|
||||
|
||||
|
||||
var result = TA.of.call(ctor, 42, 43, 42);
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], 43);
|
||||
assert.sameValue(result[2], 42);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(called, 1);
|
||||
});
|
33
test/built-ins/TypedArrays/of/new-instance.js
Normal file
33
test/built-ins/TypedArrays/of/new-instance.js
Normal 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%.of
|
||||
description: >
|
||||
Return a new TypedArray
|
||||
info: >
|
||||
9.4.5.5 [[Set]] ( P, V, Receiver)
|
||||
|
||||
...
|
||||
2. If Type(P) is String and if SameValue(O, Receiver) is true, then
|
||||
a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||
b. If numericIndex is not undefined, then
|
||||
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
|
||||
...
|
||||
|
||||
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
|
||||
|
||||
...
|
||||
3. Let numValue be ? ToNumber(value).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var result = TA.of(42, 43, null);
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 42);
|
||||
assert.sameValue(result[1], 43);
|
||||
assert.sameValue(result[2], 0);
|
||||
assert.sameValue(result.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(result), TA.prototype);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user