зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1176214 - Part 9: tests changes. r=bbouvier
--HG-- extra : rebase_source : 6a9c2f9513efce47bc28b7321186c3ac6fe5d3d9
This commit is contained in:
Родитель
9031bb2c2c
Коммит
b5cd967500
|
@ -14,6 +14,9 @@ var someObjects = [
|
|||
Object(Symbol("table")),
|
||||
new Proxy({}, {})
|
||||
];
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
someObjects.push(new Uint8Array(new SharedArrayBuffer(64)));
|
||||
|
||||
for (var obj of someObjects) {
|
||||
assertEq(Reflect.isExtensible(obj), true);
|
||||
assertEq(Reflect.preventExtensions(obj), true);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertThrowsInstanceOf(() => constructor(), TypeError);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.prototype.entries.length, 0);
|
||||
|
@ -27,7 +36,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(iterator.next(), {value: undefined, done: true});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var entries = newGlobal()[constructor.name].prototype.entries;
|
||||
assertDeepEq([...entries.call(new constructor(2))], [[0, 0], [1, 0]]);
|
||||
arr = new (newGlobal()[constructor.name])(2);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
// Tests for TypedArray#every.
|
||||
for (var constructor of constructors) {
|
||||
|
@ -103,7 +112,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var every = newGlobal()[constructor.name].prototype.every;
|
||||
var sum = 0;
|
||||
assertEq(every.call(new constructor([1, 2, 3]), v => sum += v), true);
|
||||
|
@ -225,7 +234,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var some = newGlobal()[constructor.name].prototype.some;
|
||||
var sum = 0;
|
||||
assertEq(some.call(new constructor([1, 2, 3]), v => {
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertDeepEq(constructor.prototype.fill.length, 1);
|
||||
|
@ -47,7 +56,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(new constructor([1,1,1]).fill(2, 0, {valueOf: ()=>1}), new constructor([2,1,1]));
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var fill = newGlobal()[constructor.name].prototype.fill;
|
||||
assertDeepEq(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2]));
|
||||
}
|
||||
|
|
|
@ -16,8 +16,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
const methods = ["find", "findIndex"];
|
||||
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
// Tests for TypedArray#forEach
|
||||
for (var constructor of constructors) {
|
||||
|
@ -82,7 +91,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var forEach = newGlobal()[constructor.name].prototype.forEach;
|
||||
var sum = 0;
|
||||
forEach.call(new constructor([1, 2, 3]), v => {
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// 'from' method is identical for all typed array constructors.
|
||||
|
@ -17,7 +26,7 @@ for (var constructor of constructors) {
|
|||
// %TypedArray%.from copies arrays.
|
||||
var src = new constructor([1, 2, 3]), copy = constructor.from(src);
|
||||
assertEq(copy === src, false);
|
||||
assertEq(copy instanceof constructor, true);
|
||||
assertEq(isSharedConstructor(constructor) || copy instanceof constructor, true);
|
||||
assertDeepEq(copy, src);
|
||||
|
||||
// Non-element properties are not copied.
|
||||
|
@ -28,7 +37,7 @@ for (var constructor of constructors) {
|
|||
// %TypedArray%.from can copy non-iterable objects, if they're array-like.
|
||||
src = {0: 0, 1: 1, length: 2};
|
||||
copy = constructor.from(src);
|
||||
assertEq(copy instanceof constructor, true);
|
||||
assertEq(isSharedConstructor(constructor) || copy instanceof constructor, true);
|
||||
assertDeepEq(copy, new constructor([0, 1]));
|
||||
|
||||
// Properties past the .length are not copied.
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// %TypedArray%.from can be applied to any constructor.
|
||||
|
@ -63,6 +72,9 @@ for (var constructor of constructors) {
|
|||
}, TypeError);
|
||||
}
|
||||
|
||||
if (isSharedConstructor(constructor))
|
||||
continue;
|
||||
|
||||
// %TypedArray%.from does not get confused if global constructors for typed arrays
|
||||
// are replaced with another constructor.
|
||||
function NotArray() {
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// %TypedArray%.from throws if the argument is undefined or null.
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// %TypedArray%.from works on arguments objects.
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// If the mapfn argument to %TypedArray%.from is undefined, don't map.
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// Two tests involving %TypedArray%.from and a Proxy.
|
||||
|
|
|
@ -7,11 +7,20 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
if (typeof newGlobal !== 'function')
|
||||
if (typeof newGlobal !== 'function' || isSharedConstructor(constructor))
|
||||
break;
|
||||
|
||||
// G[constructor.name].from, where G is any global, produces an array whose prototype
|
||||
|
|
|
@ -7,15 +7,26 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// Check superficial features of %TypeArray%.from.
|
||||
var desc = Object.getOwnPropertyDescriptor(constructor.__proto__, "from");
|
||||
if (!isSharedConstructor(constructor)) {
|
||||
assertEq(desc.configurable, true);
|
||||
assertEq(desc.enumerable, false);
|
||||
assertEq(desc.writable, true);
|
||||
}
|
||||
assertEq(constructor.from.length, 1);
|
||||
assertThrowsInstanceOf(() => new constructor.from(), TypeError); // not a constructor
|
||||
}
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
// The third argument to %TypedArray%.from is passed as the 'this' value to the
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
var obj = new constructor(5);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.prototype.includes.length, 1);
|
||||
|
@ -26,7 +35,7 @@ for (var constructor of constructors) {
|
|||
assertEq(new constructor([1, 2, 3]).includes(2, 100), false);
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var includes = newGlobal()[constructor.name].prototype.includes;
|
||||
assertEq(includes.call(new constructor([1, 2, 3]), 2), true);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
// Tests for TypedArray#indexOf.
|
||||
for (var constructor of constructors) {
|
||||
|
@ -21,7 +30,7 @@ for (var constructor of constructors) {
|
|||
assertEq(new constructor([1, 2, 3, 4, 5]).indexOf(6), -1);
|
||||
assertEq(new constructor([1, 2, 1, 2, 1]).indexOf(1), 0);
|
||||
|
||||
if (constructor === Float32Array || constructor === Float64Array) {
|
||||
if (isFloatingConstructor(constructor)) {
|
||||
assertEq(new constructor([NaN, 0, -0]).indexOf(NaN), -1);
|
||||
assertEq(new constructor([NaN, 0, -0]).indexOf(0), 1);
|
||||
assertEq(new constructor([NaN, 0, -0]).indexOf(-0), 1);
|
||||
|
@ -73,7 +82,7 @@ for (var constructor of constructors) {
|
|||
assertEq(new constructor([1, 2, 3, 4, 5]).lastIndexOf(6), -1);
|
||||
assertEq(new constructor([1, 2, 1, 2, 1]).lastIndexOf(1), 4);
|
||||
|
||||
if (constructor === Float32Array || constructor === Float64Array) {
|
||||
if (isFloatingConstructor(constructor)) {
|
||||
assertEq(new constructor([NaN, 0, -0]).lastIndexOf(NaN), -1);
|
||||
assertEq(new constructor([NaN, 0, -0]).lastIndexOf(0), 2);
|
||||
assertEq(new constructor([NaN, 0, -0]).lastIndexOf(-0), 2);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.prototype.join.length, 1);
|
||||
|
@ -30,7 +39,7 @@ for (var constructor of constructors) {
|
|||
assertThrowsInstanceOf(() => new constructor().join(Symbol()), TypeError);
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var join = newGlobal()[constructor.name].prototype.join;
|
||||
assertEq(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3");
|
||||
}
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.prototype.keys.length, 0);
|
||||
|
@ -27,7 +36,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(iterator.next(), {value: undefined, done: true});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var keys = newGlobal()[constructor.name].prototype.keys;
|
||||
assertDeepEq([...keys.call(new constructor(2))], [0, 1]);
|
||||
arr = new (newGlobal()[constructor.name])(2);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
// Tests for TypedArray#map.
|
||||
for (var constructor of constructors) {
|
||||
|
@ -111,7 +120,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var map = newGlobal()[constructor.name].prototype.map;
|
||||
var sum = 0;
|
||||
assertDeepEq(map.call(new constructor([1, 2, 3]), v => sum += v), new constructor([1,3,6]));
|
||||
|
@ -235,7 +244,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var filter = newGlobal()[constructor.name].prototype.filter;
|
||||
var sum = 0;
|
||||
assertDeepEq(filter.call(new constructor([1, 2, 3]), v => {sum += v; return true}),
|
||||
|
|
|
@ -62,8 +62,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
constructors.forEach(constructor => {
|
||||
var obj = new constructor(4);
|
||||
|
|
|
@ -7,22 +7,35 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.of.length, 0);
|
||||
|
||||
if (!isSharedConstructor(constructor)) {
|
||||
assertDeepEq(Object.getOwnPropertyDescriptor(constructor.__proto__, "of"), {
|
||||
value: constructor.of,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
// Basic tests.
|
||||
if (!isSharedConstructor(constructor)) {
|
||||
assertEq(constructor.of().constructor, constructor);
|
||||
assertEq(constructor.of() instanceof constructor, true);
|
||||
}
|
||||
assertDeepEq(constructor.of(10), new constructor([10]));
|
||||
assertDeepEq(constructor.of(1, 2, 3), new constructor([1, 2, 3]));
|
||||
assertDeepEq(constructor.of("1", "2", "3"), new constructor([1, 2, 3]));
|
||||
|
@ -44,7 +57,7 @@ for (var constructor of constructors) {
|
|||
assertEq(hits, 1);
|
||||
|
||||
// Behavior across compartments.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var newC = newGlobal()[constructor.name];
|
||||
assertEq(newC.of() instanceof newC, true);
|
||||
assertEq(newC.of() instanceof constructor, false);
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
// Tests for TypedArray#reduce.
|
||||
for (var constructor of constructors) {
|
||||
|
@ -81,7 +90,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var reduce = newGlobal()[constructor.name].prototype.reduce;
|
||||
assertEq(reduce.call(arr, (previous, current) => Math.min(previous, current)), 1);
|
||||
}
|
||||
|
@ -174,7 +183,7 @@ for (var constructor of constructors) {
|
|||
});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var reduceRight = newGlobal()[constructor.name].prototype.reduceRight;
|
||||
assertEq(reduceRight.call(arr, (previous, current) => Math.min(previous, current)), 1);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertDeepEq(constructor.prototype.reverse.length, 0);
|
||||
|
@ -24,7 +33,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(new constructor([.1, .2, .3]).reverse(), new constructor([.3, .2, .1]));
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var reverse = newGlobal()[constructor.name].prototype.reverse;
|
||||
assertDeepEq(reverse.call(new constructor([3, 2, 1])), new constructor([1, 2, 3]));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// Synthesize a constructor for a shared memory array from the
|
||||
// constructor for unshared memory. This has "good enough" fidelity
|
||||
// for many uses. In cases where it's not good enough, use the
|
||||
// __isShared__ flags or call isSharedConstructor for local workarounds.
|
||||
|
||||
function sharedConstructor(constructor) {
|
||||
var c = function(...args) {
|
||||
if (!new.target)
|
||||
throw new TypeError("Not callable");
|
||||
var array = new constructor(...args);
|
||||
var buffer = array.buffer;
|
||||
var offset = array.byteOffset;
|
||||
var length = array.length;
|
||||
var sharedBuffer = new SharedArrayBuffer(buffer.byteLength);
|
||||
var sharedArray = new constructor(sharedBuffer, offset, length);
|
||||
for ( var i=0 ; i < length ; i++ )
|
||||
sharedArray[i] = array[i];
|
||||
assertEq(sharedArray.buffer, sharedBuffer);
|
||||
return sharedArray;
|
||||
};
|
||||
c.prototype = Object.create(constructor.prototype);
|
||||
c.__isShared__ = true;
|
||||
c.__baseConstructor__ = constructor;
|
||||
c.from = constructor.from;
|
||||
c.of = constructor.of;
|
||||
return c;
|
||||
}
|
||||
|
||||
function isSharedConstructor(x) {
|
||||
return typeof x == "function" && x.__isShared__;
|
||||
}
|
||||
|
||||
function isFloatingConstructor(c) {
|
||||
return c == Float32Array ||
|
||||
c == Float64Array ||
|
||||
(c.hasOwnProperty("__baseConstructor__") &&
|
||||
isFloatingConstructor(c.__baseConstructor__));
|
||||
}
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertDeepEq(constructor.prototype.slice.length, 2);
|
||||
|
@ -29,7 +38,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(new constructor([1, 2]).slice(1, 5), new constructor([2]));
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var slice = newGlobal()[constructor.name].prototype.slice;
|
||||
assertDeepEq(slice.call(new constructor([3, 2, 1]), 1),
|
||||
new constructor([2, 1]));
|
||||
|
|
|
@ -7,8 +7,17 @@ const constructors = [
|
|||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
];
|
||||
Float64Array ];
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
constructors.push(sharedConstructor(Int8Array),
|
||||
sharedConstructor(Uint8Array),
|
||||
sharedConstructor(Int16Array),
|
||||
sharedConstructor(Uint16Array),
|
||||
sharedConstructor(Int32Array),
|
||||
sharedConstructor(Uint32Array),
|
||||
sharedConstructor(Float32Array),
|
||||
sharedConstructor(Float64Array));
|
||||
|
||||
for (var constructor of constructors) {
|
||||
assertEq(constructor.prototype.values.length, 0);
|
||||
|
@ -28,7 +37,7 @@ for (var constructor of constructors) {
|
|||
assertDeepEq(iterator.next(), {value: undefined, done: true});
|
||||
|
||||
// Called from other globals.
|
||||
if (typeof newGlobal === "function") {
|
||||
if (typeof newGlobal === "function" && !isSharedConstructor(constructor)) {
|
||||
var values = newGlobal()[constructor.name].prototype.values;
|
||||
assertDeepEq([...values.call(new constructor([42, 36]))], [42, 36]);
|
||||
arr = new (newGlobal()[constructor.name])([42, 36]);
|
||||
|
|
|
@ -78,8 +78,8 @@ function testFloat32x4FromFloat64x2Bits() {
|
|||
}
|
||||
|
||||
function testFloat32x4FromInt8x16Bits() {
|
||||
function expected(v) {
|
||||
var i8 = new Int8Array(16);
|
||||
function expected(v, Buffer) {
|
||||
var i8 = new Int8Array(new Buffer(16));
|
||||
var f32 = new Float32Array(i8.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 16; i++) i8[i] = asArr[i];
|
||||
|
@ -91,13 +91,15 @@ function testFloat32x4FromInt8x16Bits() {
|
|||
INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN]];
|
||||
for (var v of vals) {
|
||||
var i = Int8x16(...v);
|
||||
assertEqX4(Float32x4.fromInt8x16Bits(i), expected(i));
|
||||
assertEqX4(Float32x4.fromInt8x16Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX4(Float32x4.fromInt8x16Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testFloat32x4FromInt16x8Bits() {
|
||||
function expected(v) {
|
||||
var i16 = new Int16Array(8);
|
||||
function expected(v, Buffer) {
|
||||
var i16 = new Int16Array(new Buffer(16));
|
||||
var f32 = new Float32Array(i16.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 8; i++) i16[i] = asArr[i];
|
||||
|
@ -108,7 +110,9 @@ function testFloat32x4FromInt16x8Bits() {
|
|||
[INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX]];
|
||||
for (var v of vals) {
|
||||
var i = Int16x8(...v);
|
||||
assertEqX4(Float32x4.fromInt16x8Bits(i), expected(i));
|
||||
assertEqX4(Float32x4.fromInt16x8Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX4(Float32x4.fromInt16x8Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,8 +209,8 @@ function testFloat64x2FromFloat32x4Bits() {
|
|||
}
|
||||
|
||||
function testFloat64x2FromInt8x16Bits() {
|
||||
function expected(v) {
|
||||
var i8 = new Int8Array(16);
|
||||
function expected(v, Buffer) {
|
||||
var i8 = new Int8Array(new Buffer(16));
|
||||
var f64 = new Float64Array(i8.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 16; i++) i8[i] = asArr[i];
|
||||
|
@ -219,13 +223,15 @@ function testFloat64x2FromInt8x16Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Int8x16(...v);
|
||||
assertEqX2(Float64x2.fromInt8x16Bits(f), expected(f));
|
||||
assertEqX2(Float64x2.fromInt8x16Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX2(Float64x2.fromInt8x16Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testFloat64x2FromInt16x8Bits() {
|
||||
function expected(v) {
|
||||
var i16 = new Int16Array(8);
|
||||
function expected(v, Buffer) {
|
||||
var i16 = new Int16Array(new Buffer(16));
|
||||
var f64 = new Float64Array(i16.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 8; i++) i16[i] = asArr[i];
|
||||
|
@ -237,7 +243,9 @@ function testFloat64x2FromInt16x8Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Int16x8(...v);
|
||||
assertEqX2(Float64x2.fromInt16x8Bits(f), expected(f));
|
||||
assertEqX2(Float64x2.fromInt16x8Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX2(Float64x2.fromInt16x8Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,8 +368,8 @@ function testInt32x4FromFloat64x2Bits() {
|
|||
}
|
||||
|
||||
function testInt32x4FromInt8x16Bits() {
|
||||
function expected(v) {
|
||||
var i8 = new Int8Array(16);
|
||||
function expected(v, Buffer) {
|
||||
var i8 = new Int8Array(new Buffer(16));
|
||||
var i32 = new Int32Array(i8.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 16; i++) i8[i] = asArr[i];
|
||||
|
@ -374,13 +382,15 @@ function testInt32x4FromInt8x16Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var i = Int8x16(...v);
|
||||
assertEqX4(Int32x4.fromInt8x16Bits(i), expected(i));
|
||||
assertEqX4(Int32x4.fromInt8x16Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX4(Int32x4.fromInt8x16Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt32x4FromInt16x8Bits() {
|
||||
function expected(v) {
|
||||
var i16 = new Int16Array(8);
|
||||
function expected(v, Buffer) {
|
||||
var i16 = new Int16Array(new Buffer(16));
|
||||
var i32 = new Int32Array(i16.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 8; i++) i16[i] = asArr[i];
|
||||
|
@ -392,13 +402,15 @@ function testInt32x4FromInt16x8Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var i = Int16x8(...v);
|
||||
assertEqX4(Int32x4.fromInt16x8Bits(i), expected(i));
|
||||
assertEqX4(Int32x4.fromInt16x8Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX4(Int32x4.fromInt16x8Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt8x16FromFloat32x4Bits() {
|
||||
function expected(v) {
|
||||
var f32 = new Float32Array(4);
|
||||
function expected(v, Buffer) {
|
||||
var f32 = new Float32Array(new Buffer(16));
|
||||
var i8 = new Int8Array(f32.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 4; i++) f32[i] = asArr[i];
|
||||
|
@ -410,13 +422,15 @@ function testInt8x16FromFloat32x4Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Float32x4(...v);
|
||||
assertEqX16(Int8x16.fromFloat32x4Bits(f), expected(f));
|
||||
assertEqX16(Int8x16.fromFloat32x4Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX16(Int8x16.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt8x16FromFloat64x2Bits() {
|
||||
function expected(v) {
|
||||
var f64 = new Float64Array(2);
|
||||
function expected(v, Buffer) {
|
||||
var f64 = new Float64Array(new Buffer(16));
|
||||
var i8 = new Int8Array(f64.buffer);
|
||||
f64[0] = Float64x2.extractLane(v, 0);
|
||||
f64[1] = Float64x2.extractLane(v, 1);
|
||||
|
@ -427,13 +441,15 @@ function testInt8x16FromFloat64x2Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Float64x2(...v);
|
||||
assertEqX16(Int8x16.fromFloat64x2Bits(f), expected(f));
|
||||
assertEqX16(Int8x16.fromFloat64x2Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX16(Int8x16.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt8x16FromInt16x8Bits() {
|
||||
function expected(v) {
|
||||
var i16 = new Int16Array(8);
|
||||
function expected(v, Buffer) {
|
||||
var i16 = new Int16Array(new Buffer(16));
|
||||
var i8 = new Int8Array(i16.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 8; i++) i16[i] = asArr[i];
|
||||
|
@ -444,13 +460,15 @@ function testInt8x16FromInt16x8Bits() {
|
|||
var vals = [[0, 1, -2, 3, INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX]];
|
||||
for (var v of vals) {
|
||||
var i = Int16x8(...v);
|
||||
assertEqX16(Int8x16.fromInt16x8Bits(i), expected(i));
|
||||
assertEqX16(Int8x16.fromInt16x8Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX16(Int8x16.fromInt16x8Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt8x16FromInt32x4Bits() {
|
||||
function expected(v) {
|
||||
var i32 = new Int32Array(4);
|
||||
function expected(v, Buffer) {
|
||||
var i32 = new Int32Array(new Buffer(16));
|
||||
var i8 = new Int8Array(i32.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 4; i++) i32[i] = asArr[i];
|
||||
|
@ -461,13 +479,15 @@ function testInt8x16FromInt32x4Bits() {
|
|||
var vals = [[0, 1, -2, 3], [INT8_MIN, INT8_MAX, INT32_MIN, INT32_MAX]];
|
||||
for (var v of vals) {
|
||||
var i = Int32x4(...v);
|
||||
assertEqX16(Int8x16.fromInt32x4Bits(i), expected(i));
|
||||
assertEqX16(Int8x16.fromInt32x4Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX16(Int8x16.fromInt32x4Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt16x8FromFloat32x4Bits() {
|
||||
function expected(v) {
|
||||
var f32 = new Float32Array(4);
|
||||
function expected(v, Buffer) {
|
||||
var f32 = new Float32Array(new Buffer(16));
|
||||
var i16 = new Int16Array(f32.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 4; i++) f32[i] = asArr[i];
|
||||
|
@ -478,13 +498,15 @@ function testInt16x8FromFloat32x4Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Float32x4(...v);
|
||||
assertEqX8(Int16x8.fromFloat32x4Bits(f), expected(f));
|
||||
assertEqX8(Int16x8.fromFloat32x4Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX8(Int16x8.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt16x8FromFloat64x2Bits() {
|
||||
function expected(v) {
|
||||
var f64 = new Float64Array(2);
|
||||
function expected(v, Buffer) {
|
||||
var f64 = new Float64Array(new Buffer(16));
|
||||
var i16 = new Int16Array(f64.buffer);
|
||||
f64[0] = Float64x2.extractLane(v, 0);
|
||||
f64[1] = Float64x2.extractLane(v, 1);
|
||||
|
@ -495,13 +517,15 @@ function testInt16x8FromFloat64x2Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var f = Float64x2(...v);
|
||||
assertEqX8(Int16x8.fromFloat64x2Bits(f), expected(f));
|
||||
assertEqX8(Int16x8.fromFloat64x2Bits(f), expected(f, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX8(Int16x8.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt16x8FromInt8x16Bits() {
|
||||
function expected(v) {
|
||||
var i8 = new Int8Array(16);
|
||||
function expected(v, Buffer) {
|
||||
var i8 = new Int8Array(new Buffer(16));
|
||||
var i16 = new Int16Array(i8.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 16; i++) i8[i] = asArr[i];
|
||||
|
@ -512,13 +536,15 @@ function testInt16x8FromInt8x16Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var i = Int8x16(...v);
|
||||
assertEqX8(Int16x8.fromInt8x16Bits(i), expected(i));
|
||||
assertEqX8(Int16x8.fromInt8x16Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX8(Int16x8.fromInt8x16Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
function testInt16x8FromInt32x4Bits() {
|
||||
function expected(v) {
|
||||
var i32 = new Int32Array(4);
|
||||
function expected(v, Buffer) {
|
||||
var i32 = new Int32Array(new Buffer(16));
|
||||
var i16 = new Int16Array(i32.buffer);
|
||||
var asArr = simdToArray(v);
|
||||
for (var i = 0; i < 4; i++) i32[i] = asArr[i];
|
||||
|
@ -529,7 +555,9 @@ function testInt16x8FromInt32x4Bits() {
|
|||
|
||||
for (var v of vals) {
|
||||
var i = Int32x4(...v);
|
||||
assertEqX8(Int16x8.fromInt32x4Bits(i), expected(i));
|
||||
assertEqX8(Int16x8.fromInt32x4Bits(i), expected(i, ArrayBuffer));
|
||||
if (typeof SharedArrayBuffer != "undefined")
|
||||
assertEqX8(Int16x8.fromInt32x4Bits(i), expected(i, SharedArrayBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,15 +13,9 @@ const SIZE_64_ARRAY = 8;
|
|||
|
||||
const SIZE_BYTES = SIZE_32_ARRAY * 4;
|
||||
|
||||
function IsSharedTypedArray(arr) {
|
||||
return arr && arr.buffer && arr.buffer instanceof SharedArrayBuffer;
|
||||
}
|
||||
|
||||
function MakeComparator(kind, arr, shared) {
|
||||
var bpe = arr.BYTES_PER_ELEMENT;
|
||||
var uint8 = (bpe != 1) ? (IsSharedTypedArray(arr) ? new SharedUint8Array(arr.buffer)
|
||||
: new Uint8Array(arr.buffer))
|
||||
: arr;
|
||||
var uint8 = (bpe != 1) ? new Uint8Array(arr.buffer) : arr;
|
||||
|
||||
// Size in bytes of a single element in the SIMD vector.
|
||||
var sizeOfLaneElem;
|
||||
|
@ -184,22 +178,19 @@ function testLoad(kind, TA) {
|
|||
}
|
||||
|
||||
function testSharedArrayBufferCompat() {
|
||||
if (!this.SharedArrayBuffer || !this.SharedFloat32Array || !this.Atomics)
|
||||
return;
|
||||
|
||||
var TA = new SharedFloat32Array(16);
|
||||
var TA = new Float32Array(new SharedArrayBuffer(16*4));
|
||||
for (var i = 0; i < 16; i++)
|
||||
TA[i] = i + 1;
|
||||
|
||||
for (var ta of [
|
||||
new SharedUint8Array(TA.buffer),
|
||||
new SharedInt8Array(TA.buffer),
|
||||
new SharedUint16Array(TA.buffer),
|
||||
new SharedInt16Array(TA.buffer),
|
||||
new SharedUint32Array(TA.buffer),
|
||||
new SharedInt32Array(TA.buffer),
|
||||
new SharedFloat32Array(TA.buffer),
|
||||
new SharedFloat64Array(TA.buffer)
|
||||
new Uint8Array(TA.buffer),
|
||||
new Int8Array(TA.buffer),
|
||||
new Uint16Array(TA.buffer),
|
||||
new Int16Array(TA.buffer),
|
||||
new Uint32Array(TA.buffer),
|
||||
new Int32Array(TA.buffer),
|
||||
new Float32Array(TA.buffer),
|
||||
new Float64Array(TA.buffer)
|
||||
])
|
||||
{
|
||||
for (var kind of ['Int32x4', 'Float32x4', 'Float64x2']) {
|
||||
|
@ -226,6 +217,15 @@ testLoad('Float64x2', new Float64Array(SIZE_64_ARRAY));
|
|||
testLoad('Int8x16', new Int8Array(SIZE_8_ARRAY));
|
||||
testLoad('Int16x8', new Int16Array(SIZE_16_ARRAY));
|
||||
testLoad('Int32x4', new Int32Array(SIZE_32_ARRAY));
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined") {
|
||||
testLoad('Float32x4', new Float32Array(new SharedArrayBuffer(SIZE_8_ARRAY)));
|
||||
testLoad('Float64x2', new Float64Array(new SharedArrayBuffer(SIZE_8_ARRAY)));
|
||||
testLoad('Int8x16', new Int8Array(new SharedArrayBuffer(SIZE_8_ARRAY)));
|
||||
testLoad('Int16x8', new Int16Array(new SharedArrayBuffer(SIZE_8_ARRAY)));
|
||||
testLoad('Int32x4', new Int32Array(new SharedArrayBuffer(SIZE_8_ARRAY)));
|
||||
}
|
||||
|
||||
testSharedArrayBufferCompat();
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
|
|
|
@ -51,8 +51,8 @@ function testStore(ta, kind, i, v) {
|
|||
}
|
||||
}
|
||||
|
||||
function testStoreInt8x16() {
|
||||
var I8 = new Int8Array(32);
|
||||
function testStoreInt8x16(Buffer) {
|
||||
var I8 = new Int8Array(new Buffer(32));
|
||||
|
||||
var v = SIMD.Int8x16(0, 1, INT8_MAX, INT8_MIN, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
testStore(I8, 'Int8x16', 0, v);
|
||||
|
@ -65,8 +65,8 @@ function testStoreInt8x16() {
|
|||
assertThrowsInstanceOf(() => SIMD.Int16x8.store(I8, 0, v), TypeError);
|
||||
}
|
||||
|
||||
function testStoreInt16x8() {
|
||||
var I16 = new Int16Array(32);
|
||||
function testStoreInt16x8(Buffer) {
|
||||
var I16 = new Int16Array(new Buffer(64));
|
||||
|
||||
var v = SIMD.Int16x8(0, 1, INT16_MAX, INT16_MIN, 4, 5, 6, 7);
|
||||
testStore(I16, 'Int16x8', 0, v);
|
||||
|
@ -79,8 +79,8 @@ function testStoreInt16x8() {
|
|||
assertThrowsInstanceOf(() => SIMD.Int8x16.store(I16, 0, v), TypeError);
|
||||
}
|
||||
|
||||
function testStoreInt32x4() {
|
||||
var I32 = new Int32Array(16);
|
||||
function testStoreInt32x4(Buffer) {
|
||||
var I32 = new Int32Array(new Buffer(64));
|
||||
|
||||
var v = SIMD.Int32x4(0, 1, Math.pow(2,31) - 1, -Math.pow(2, 31));
|
||||
testStore(I32, 'Int32x4', 0, v);
|
||||
|
@ -93,8 +93,8 @@ function testStoreInt32x4() {
|
|||
assertThrowsInstanceOf(() => SIMD.Float32x4.store(I32, 0, v), TypeError);
|
||||
}
|
||||
|
||||
function testStoreFloat32x4() {
|
||||
var F32 = new Float32Array(16);
|
||||
function testStoreFloat32x4(Buffer) {
|
||||
var F32 = new Float32Array(new Buffer(64));
|
||||
|
||||
var v = SIMD.Float32x4(1,2,3,4);
|
||||
testStore(F32, 'Float32x4', 0, v);
|
||||
|
@ -113,8 +113,8 @@ function testStoreFloat32x4() {
|
|||
assertThrowsInstanceOf(() => SIMD.Int32x4.store(F32, 0, v), TypeError);
|
||||
}
|
||||
|
||||
function testStoreFloat64x2() {
|
||||
var F64 = new Float64Array(16);
|
||||
function testStoreFloat64x2(Buffer) {
|
||||
var F64 = new Float64Array(new Buffer(128));
|
||||
|
||||
var v = SIMD.Float64x2(1, 2);
|
||||
testStore(F64, 'Float64x2', 0, v);
|
||||
|
@ -137,16 +137,13 @@ function testStoreFloat64x2() {
|
|||
}
|
||||
|
||||
function testSharedArrayBufferCompat() {
|
||||
if (!this.SharedArrayBuffer || !this.SharedFloat32Array || !this.Atomics)
|
||||
return;
|
||||
|
||||
var I32 = new SharedInt32Array(16);
|
||||
var I32 = new Int32Array(new SharedArrayBuffer(16*4));
|
||||
var TA = I32;
|
||||
|
||||
var I8 = new SharedInt8Array(TA.buffer);
|
||||
var I16 = new SharedInt16Array(TA.buffer);
|
||||
var F32 = new SharedFloat32Array(TA.buffer);
|
||||
var F64 = new SharedFloat64Array(TA.buffer);
|
||||
var I8 = new Int8Array(TA.buffer);
|
||||
var I16 = new Int16Array(TA.buffer);
|
||||
var F32 = new Float32Array(TA.buffer);
|
||||
var F64 = new Float64Array(TA.buffer);
|
||||
|
||||
var Int8x16 = SIMD.Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
||||
var Int16x8 = SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
@ -155,14 +152,14 @@ function testSharedArrayBufferCompat() {
|
|||
var Float64x2 = SIMD.Float64x2(1, 2);
|
||||
|
||||
for (var ta of [
|
||||
new SharedUint8Array(TA.buffer),
|
||||
new SharedInt8Array(TA.buffer),
|
||||
new SharedUint16Array(TA.buffer),
|
||||
new SharedInt16Array(TA.buffer),
|
||||
new SharedUint32Array(TA.buffer),
|
||||
new SharedInt32Array(TA.buffer),
|
||||
new SharedFloat32Array(TA.buffer),
|
||||
new SharedFloat64Array(TA.buffer)
|
||||
new Uint8Array(TA.buffer),
|
||||
new Int8Array(TA.buffer),
|
||||
new Uint16Array(TA.buffer),
|
||||
new Int16Array(TA.buffer),
|
||||
new Uint32Array(TA.buffer),
|
||||
new Int32Array(TA.buffer),
|
||||
new Float32Array(TA.buffer),
|
||||
new Float64Array(TA.buffer)
|
||||
])
|
||||
{
|
||||
SIMD.Int8x16.store(ta, 0, Int8x16);
|
||||
|
@ -188,12 +185,20 @@ function testSharedArrayBufferCompat() {
|
|||
}
|
||||
}
|
||||
|
||||
testStoreInt8x16();
|
||||
testStoreInt16x8();
|
||||
testStoreInt32x4();
|
||||
testStoreFloat32x4();
|
||||
testStoreFloat64x2();
|
||||
testStoreInt8x16(ArrayBuffer);
|
||||
testStoreInt16x8(ArrayBuffer);
|
||||
testStoreInt32x4(ArrayBuffer);
|
||||
testStoreFloat32x4(ArrayBuffer);
|
||||
testStoreFloat64x2(ArrayBuffer);
|
||||
|
||||
if (typeof SharedArrayBuffer != "undefined") {
|
||||
testStoreInt8x16(SharedArrayBuffer);
|
||||
testStoreInt16x8(SharedArrayBuffer);
|
||||
testStoreInt32x4(SharedArrayBuffer);
|
||||
testStoreFloat32x4(SharedArrayBuffer);
|
||||
testStoreFloat64x2(SharedArrayBuffer);
|
||||
testSharedArrayBufferCompat();
|
||||
}
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
|
|
@ -16,6 +16,14 @@ function runTests() {
|
|||
assertEq(ArrayBuffer.isView(new ArrayBuffer(10)), false);
|
||||
assertEq(ArrayBuffer.isView(new Int8Array(10)), true);
|
||||
assertEq(ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)), true);
|
||||
if (typeof SharedArrayBuffer != "undefined") {
|
||||
assertEq(ArrayBuffer.isView(new SharedArrayBuffer(10)), false);
|
||||
assertEq(ArrayBuffer.isView(new Int8Array(new SharedArrayBuffer(10))), true);
|
||||
// In the next case subarray should return an ArrayBuffer, so this is
|
||||
// similar to the subarray test above.
|
||||
assertEq(ArrayBuffer.isView(new Int8Array(new SharedArrayBuffer(10)).subarray(0, 3)),
|
||||
true);
|
||||
}
|
||||
|
||||
if (typeof reportCompare !== 'undefined')
|
||||
reportCompare(true, true);
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
//
|
||||
// These tests cannot test that sharing works across workers. There
|
||||
// are or will be tests, in dom/workers, that do that.
|
||||
//
|
||||
// Structured cloning is not tested here (there are no APIs).
|
||||
|
||||
if (!this.SharedArrayBuffer)
|
||||
quit(0);
|
||||
|
||||
var b;
|
||||
|
||||
|
@ -44,54 +45,16 @@ function testSharedArrayBuffer() {
|
|||
}
|
||||
|
||||
function testSharedTypedArray() {
|
||||
assertEq(SharedInt8Array.prototype.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedUint8Array.prototype.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedUint8ClampedArray.prototype.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedInt16Array.prototype.BYTES_PER_ELEMENT, 2);
|
||||
assertEq(SharedUint16Array.prototype.BYTES_PER_ELEMENT, 2);
|
||||
assertEq(SharedInt32Array.prototype.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedUint32Array.prototype.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat32Array.prototype.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat32Array.prototype.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat64Array.prototype.BYTES_PER_ELEMENT, 8);
|
||||
assertEq(SharedFloat64Array.prototype.BYTES_PER_ELEMENT, 8);
|
||||
|
||||
assertEq(SharedInt8Array.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedUint8Array.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedUint8ClampedArray.BYTES_PER_ELEMENT, 1);
|
||||
assertEq(SharedInt16Array.BYTES_PER_ELEMENT, 2);
|
||||
assertEq(SharedUint16Array.BYTES_PER_ELEMENT, 2);
|
||||
assertEq(SharedInt32Array.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedUint32Array.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat32Array.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat32Array.BYTES_PER_ELEMENT, 4);
|
||||
assertEq(SharedFloat64Array.BYTES_PER_ELEMENT, 8);
|
||||
assertEq(SharedFloat64Array.BYTES_PER_ELEMENT, 8);
|
||||
|
||||
// Distinct prototypes for distinct types
|
||||
SharedInt8Array.prototype.hello = "hi there";
|
||||
assertEq(SharedUint8Array.prototype.hello, undefined);
|
||||
|
||||
var x1 = new SharedInt8Array(b);
|
||||
var x2 = new SharedInt32Array(b);
|
||||
var x1 = new Int8Array(b);
|
||||
var x2 = new Int32Array(b);
|
||||
|
||||
assertEq(SharedArrayBuffer.isView(x1), true);
|
||||
assertEq(SharedArrayBuffer.isView(x2), true);
|
||||
assertEq(SharedArrayBuffer.isView({}), false);
|
||||
assertEq(SharedArrayBuffer.isView(new Int32Array(10)), false);
|
||||
|
||||
assertEq(x1.buffer, b);
|
||||
assertEq(x2.buffer, b);
|
||||
|
||||
assertEq(Object.getOwnPropertyDescriptor(SharedInt8Array.prototype,"buffer").get.call(x1), x1.buffer);
|
||||
assertEq(Object.getOwnPropertyDescriptor(SharedInt32Array.prototype,"buffer").get.call(x2), x2.buffer);
|
||||
|
||||
// Not generic
|
||||
assertThrowsInstanceOf(() => Object.getOwnPropertyDescriptor(SharedInt8Array.prototype,"buffer").get.call({}), TypeError);
|
||||
|
||||
// Not even to other shared typed arrays
|
||||
assertThrowsInstanceOf(() => Object.getOwnPropertyDescriptor(SharedInt8Array.prototype,"buffer").get.call(x2), TypeError);
|
||||
|
||||
assertEq(x1.byteLength, b.byteLength);
|
||||
assertEq(x2.byteLength, b.byteLength);
|
||||
|
||||
|
@ -101,50 +64,31 @@ function testSharedTypedArray() {
|
|||
assertEq(x1.length, b.byteLength);
|
||||
assertEq(x2.length, b.byteLength / 4);
|
||||
|
||||
// Conversions that should work
|
||||
assertEq(SharedInt8Array(x1), x1);
|
||||
assertEq(SharedInt32Array(x2), x2);
|
||||
|
||||
var x3 = new SharedInt8Array(b, 20);
|
||||
var x3 = new Int8Array(b, 20);
|
||||
assertEq(x3.length, b.byteLength - 20);
|
||||
assertEq(x3.byteOffset, 20);
|
||||
|
||||
var x3 = new SharedInt32Array(b, 20, 10);
|
||||
var x3 = new Int32Array(b, 20, 10);
|
||||
assertEq(x3.length, 10);
|
||||
assertEq(x3.byteOffset, 20);
|
||||
|
||||
// Mismatched type
|
||||
assertThrowsInstanceOf(() => SharedInt8Array(x2), TypeError);
|
||||
assertThrowsInstanceOf(() => Int8Array(x2), TypeError);
|
||||
|
||||
// Unconvertable object
|
||||
assertThrowsInstanceOf(() => SharedInt8Array({}), TypeError);
|
||||
assertThrowsInstanceOf(() => Int8Array({}), TypeError);
|
||||
|
||||
// negative start
|
||||
assertThrowsInstanceOf(() => new SharedInt8Array(b, -7), RangeError);
|
||||
assertThrowsInstanceOf(() => new Int8Array(b, -7), RangeError);
|
||||
|
||||
// not congruent mod element size
|
||||
assertThrowsInstanceOf(() => new SharedInt32Array(b, 3), RangeError);
|
||||
assertThrowsInstanceOf(() => new Int32Array(b, 3), TypeError); // Bug 1227207: should be RangeError
|
||||
|
||||
// start out of range
|
||||
assertThrowsInstanceOf(() => new SharedInt32Array(b, 4104), RangeError);
|
||||
assertThrowsInstanceOf(() => new Int32Array(b, 4104), TypeError); // Ditto
|
||||
|
||||
// end out of range
|
||||
assertThrowsInstanceOf(() => new SharedInt32Array(b, 4092, 2), RangeError);
|
||||
|
||||
var b2 = new SharedInt32Array(1024); // Should create a new buffer
|
||||
assertEq(b2.length, 1024);
|
||||
assertEq(b2.byteLength, 4096);
|
||||
assertEq(b2.byteOffset, 0);
|
||||
assertEq(b2.buffer != b, true);
|
||||
|
||||
var b3 = new SharedInt32Array("1024"); // Should create a new buffer
|
||||
assertEq(b3.length, 1024);
|
||||
assertEq(b3.byteLength, 4096);
|
||||
assertEq(b3.byteOffset, 0);
|
||||
assertEq(b3.buffer != b, true);
|
||||
|
||||
// bad length
|
||||
assertThrowsInstanceOf(() => new SharedInt32Array({}), TypeError);
|
||||
assertThrowsInstanceOf(() => new Int32Array(b, 4092, 2), TypeError); // Ditto
|
||||
|
||||
// Views alias the storage
|
||||
x2[0] = -1;
|
||||
|
@ -166,7 +110,7 @@ function testSharedTypedArray() {
|
|||
}
|
||||
|
||||
function testSharedTypedArrayMethods() {
|
||||
var v = new SharedInt32Array(b);
|
||||
var v = new Int32Array(b);
|
||||
for ( var i=0 ; i < v.length ; i++ )
|
||||
v[i] = i;
|
||||
|
||||
|
@ -228,10 +172,29 @@ function testSharedTypedArrayMethods() {
|
|||
assertEq(v[9], -5);
|
||||
}
|
||||
|
||||
if (typeof SharedArrayBuffer === "function") {
|
||||
function testClone1() {
|
||||
var sab1 = b;
|
||||
var blob = serialize(sab1, [sab1]);
|
||||
var sab2 = deserialize(blob);
|
||||
assertEq(sharedAddress(sab1), sharedAddress(sab2));
|
||||
}
|
||||
|
||||
function testClone2() {
|
||||
var sab = b;
|
||||
var ia1 = new Int32Array(sab);
|
||||
var blob = serialize(ia1, [sab]);
|
||||
var ia2 = deserialize(blob);
|
||||
assertEq(ia1.length, ia2.length);
|
||||
assertEq(ia1.buffer instanceof SharedArrayBuffer, true);
|
||||
assertEq(sharedAddress(ia1.buffer), sharedAddress(ia2.buffer));
|
||||
ia1[10] = 37;
|
||||
assertEq(ia2[10], 37);
|
||||
}
|
||||
|
||||
testSharedArrayBuffer();
|
||||
testSharedTypedArray();
|
||||
testSharedTypedArrayMethods();
|
||||
}
|
||||
testClone1();
|
||||
testClone2();
|
||||
|
||||
reportCompare(0, 0, 'ok');
|
||||
|
|
|
@ -19,7 +19,8 @@ function dprint(s) {
|
|||
// Tests the SharedArrayBuffer mailbox in the shell.
|
||||
// Tests the futex functionality in the shell.
|
||||
|
||||
var mem = new SharedInt32Array(3);
|
||||
var sab = new SharedArrayBuffer(12);
|
||||
var mem = new Int32Array(sab);
|
||||
|
||||
// SharedArrayBuffer mailbox tests
|
||||
|
||||
|
@ -30,7 +31,7 @@ assertEq(getSharedArrayBuffer() == null, false); // And then the mbx is no
|
|||
|
||||
var v = getSharedArrayBuffer();
|
||||
assertEq(v.byteLength, mem.buffer.byteLength); // Looks like what we put in?
|
||||
var w = new SharedInt32Array(v);
|
||||
var w = new Int32Array(v);
|
||||
mem[0] = 314159;
|
||||
assertEq(w[0], 314159); // Shares memory (locally) with what we put in?
|
||||
mem[0] = 0;
|
||||
|
@ -52,7 +53,6 @@ assertThrowsInstanceOf(() => setSharedArrayBuffer({x:10, y:20}), Error);
|
|||
assertThrowsInstanceOf(() => setSharedArrayBuffer([1,2]), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(new ArrayBuffer(10)), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(new Int32Array(10)), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(new SharedInt32Array(10)), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(false), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(3.14), Error);
|
||||
assertThrowsInstanceOf(() => setSharedArrayBuffer(mem), Error);
|
||||
|
@ -76,7 +76,7 @@ if (helperThreadCount() === 0) {
|
|||
}
|
||||
|
||||
evalInWorker(`
|
||||
var mem = new SharedInt32Array(getSharedArrayBuffer());
|
||||
var mem = new Int32Array(getSharedArrayBuffer());
|
||||
function dprint(s) {
|
||||
if (mem[2]) print(s);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче