Add tests for _TypedArray_.from and of

This commit is contained in:
Leonardo Balter 2016-02-03 17:06:59 -02:00 committed by Gorkem Yakin
parent 4388f2869c
commit 048073a29a
31 changed files with 954 additions and 5 deletions

View File

@ -17,5 +17,5 @@ var from = TypedArray.from;
var m = { m() {} }.m;
assert.throws(TypeError, function() {
from.call(o.m, []);
from.call(m, []);
});

View File

@ -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, []);
});

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%.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, []);
});
});

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%.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);
});

View 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);
});

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%.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);
});
});

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%.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);
});

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%.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);
});

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%.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);
});

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%.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);
});

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%.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
]);

View 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);
});

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%.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
]);

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%.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
]);

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%.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
]);

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%.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);
});

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%.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);
});

View File

@ -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);
});

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%.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);
});
});

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%.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);
});
});

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%.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]);
});
});

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%.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);
});
});

View File

@ -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");
});

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%.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);
});
});

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%.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);
});

View 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);
});

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%.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
]);

View 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);
});

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%.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
]);

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%.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);
});

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%.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);
});