Chromium Code Reviews| Index: test/mjsunit/harmony/simd.js |
| diff --git a/test/mjsunit/harmony/simd.js b/test/mjsunit/harmony/simd.js |
| index 941eff8034358b140ba44f70839e3d89c49f1a2d..a86e1b034c6097e65b4b15de3d30234ce728fbb4 100644 |
| --- a/test/mjsunit/harmony/simd.js |
| +++ b/test/mjsunit/harmony/simd.js |
| @@ -5,10 +5,21 @@ |
| // Flags: --harmony-simd --harmony-tostring --harmony-reflect |
| // Flags: --allow-natives-syntax --expose-natives-as natives --noalways-opt |
| +var floatType = 0; |
| +var intType = 1; |
| +var boolType = 2; |
| + |
| function lanesForType(typeName) { |
| // The lane count follows the first 'x' in the type name, which begins with |
| // 'float', 'int', or 'bool'. |
| - return Number.parseInt(typeName[typeName.indexOf('x') + 1]); |
| + return Number.parseInt(typeName.substr(typeName.indexOf('x') + 1)); |
| +} |
| + |
| + |
| +// Creates an instance that has been zeroed, so it can be used for equality |
| +// testing. |
| +function createInstance(type) { |
| + return SIMD[type](0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| } |
| @@ -35,244 +46,329 @@ function isValidSimdString(string, value, type, lanes) { |
| } |
| -// Test for structural equivalence. |
| -function areEquivalent(type, lanes, a, b) { |
| - var simdFn = SIMD[type]; |
| - for (var i = 0; i < lanes; i++) { |
| - if (simdFn.extractLane(a, i) !== simdFn.extractLane(b, i)) |
| - return false; |
| - } |
| - return true; |
| -} |
| - |
| - |
| -var sameValue = natives.$sameValue; |
| -var sameValueZero = natives.$sameValueZero; |
| - |
| -// Calls SameValue and SameValueZero and checks that their results match. Also |
| -// checks the internal SameValue checks using Object freeze and defineProperty. |
| -function sameValueBoth(a, b) { |
| - var result = sameValue(a, b); |
| - assertTrue(result === sameValueZero(a, b)); |
| - return result; |
| -} |
| - |
| - |
| -// Calls SameValue and SameValueZero and checks that their results don't match. |
| -function sameValueZeroOnly(a, b) { |
| - var result = sameValueZero(a, b); |
| - assertTrue(result && !sameValue(a, b)); |
| - return result; |
| -} |
| - |
| - |
| -// Tests for the global SIMD object. |
| -function TestSIMDObject() { |
| - assertSame(typeof SIMD, 'object'); |
| - assertSame(SIMD.constructor, Object); |
| - assertSame(Object.getPrototypeOf(SIMD), Object.prototype); |
| - assertSame(SIMD + "", "[object SIMD]"); |
| -} |
| -TestSIMDObject() |
| - |
| -// TestConstructor populates this with interesting values for the other tests. |
| -var values; |
| - |
| -// Test different forms of constructor calls. This test populates 'values' with |
| -// a variety of SIMD values as a side effect, which are used by other tests. |
| +// Test different forms of constructor calls. |
| function TestConstructor(type, lanes) { |
| var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| assertFalse(Object === simdFn.prototype.constructor) |
| assertFalse(simdFn === Object.prototype.constructor) |
| assertSame(simdFn, simdFn.prototype.constructor) |
| - values = [] |
| - |
| - // The constructor expects values for all lanes. |
| - switch (type) { |
| - case 'Float32x4': |
| - // The constructor expects values for all lanes. |
| - assertThrows(function () { simdFn() }, TypeError) |
| - assertThrows(function () { simdFn(0) }, TypeError) |
| - assertThrows(function () { simdFn(0, 1) }, TypeError) |
| - assertThrows(function () { simdFn(0, 1, 2) }, TypeError) |
| - |
| - values.push(simdFn(1, 2, 3, 4)) |
| - values.push(simdFn(1, 2, 3, 4)) // test structural equivalence |
| - values.push(simdFn(-0, NaN, 0, 0.5)) |
| - values.push(simdFn(-0, NaN, 0, 0.5)) // test structural equivalence |
| - values.push(simdFn(3, 2, 1, 0)) |
| - values.push(simdFn(0, 0, 0, 0)) |
| - break |
| - } |
| - for (var i in values) { |
| - assertSame(simdFn, values[i].__proto__.constructor) |
| - assertSame(simdFn, Object(values[i]).__proto__.constructor) |
| - assertSame(simdFn.prototype, values[i].__proto__) |
| - assertSame(simdFn.prototype, Object(values[i]).__proto__) |
| - } |
| + assertSame(simdFn, instance.__proto__.constructor) |
| + assertSame(simdFn, Object(instance).__proto__.constructor) |
| + assertSame(simdFn.prototype, instance.__proto__) |
| + assertSame(simdFn.prototype, Object(instance).__proto__) |
| } |
| - |
| function TestType(type, lanes) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| var typeofString = type.charAt(0).toLowerCase() + type.slice(1); |
| - for (var i in values) { |
| - assertEquals(typeofString, typeof values[i]) |
| - assertTrue(typeof values[i] === typeofString) |
| - assertTrue(typeof Object(values[i]) === 'object') |
| - assertEquals(null, %_ClassOf(values[i])) |
| - assertEquals(type, %_ClassOf(Object(values[i]))) |
| - } |
| + |
| + assertEquals(typeofString, typeof instance) |
| + assertTrue(typeof instance === typeofString) |
| + assertTrue(typeof Object(instance) === 'object') |
| + assertEquals(null, %_ClassOf(instance)) |
| + assertEquals(type, %_ClassOf(Object(instance))) |
| } |
| function TestPrototype(type, lanes) { |
| var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| assertSame(Object.prototype, simdFn.prototype.__proto__) |
| - for (var i in values) { |
| - assertSame(simdFn.prototype, values[i].__proto__) |
| - assertSame(simdFn.prototype, Object(values[i]).__proto__) |
| - } |
| + assertSame(simdFn.prototype, instance.__proto__) |
| + assertSame(simdFn.prototype, Object(instance).__proto__) |
| } |
| function TestValueOf(type, lanes) { |
| var simdFn = SIMD[type]; |
| - for (var i in values) { |
| - assertTrue(values[i] === Object(values[i]).valueOf()) |
| - assertTrue(values[i] === values[i].valueOf()) |
| - assertTrue(simdFn.prototype.valueOf.call(Object(values[i])) === values[i]) |
| - assertTrue(simdFn.prototype.valueOf.call(values[i]) === values[i]) |
| - } |
| + var instance = createInstance(type); |
| + |
| + assertTrue(instance === Object(instance).valueOf()) |
| + assertTrue(instance === instance.valueOf()) |
| + assertTrue(simdFn.prototype.valueOf.call(Object(instance)) === instance) |
| + assertTrue(simdFn.prototype.valueOf.call(instance) === instance) |
| } |
| function TestGet(type, lanes) { |
| var simdFn = SIMD[type]; |
| - for (var i in values) { |
| - assertEquals(undefined, values[i].a) |
| - assertEquals(undefined, values[i]["a" + "b"]) |
| - assertEquals(undefined, values[i]["" + "1"]) |
| - assertEquals(undefined, values[i][42]) |
| - } |
| + var instance = createInstance(type); |
| + |
| + assertEquals(undefined, instance.a) |
| + assertEquals(undefined, instance["a" + "b"]) |
| + assertEquals(undefined, instance["" + "1"]) |
| + assertEquals(undefined, instance[42]) |
| } |
| function TestToBoolean(type, lanes) { |
| - for (var i in values) { |
| - assertTrue(Boolean(Object(values[i]))) |
| - assertFalse(!Object(values[i])) |
| - assertTrue(Boolean(values[i]).valueOf()) |
| - assertFalse(!values[i]) |
| - assertTrue(!!values[i]) |
| - assertTrue(values[i] && true) |
| - assertFalse(!values[i] && false) |
| - assertTrue(!values[i] || true) |
| - assertEquals(1, values[i] ? 1 : 2) |
| - assertEquals(2, !values[i] ? 1 : 2) |
| - if (!values[i]) assertUnreachable(); |
| - if (values[i]) {} else assertUnreachable(); |
| - } |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| + assertTrue(Boolean(Object(instance))) |
| + assertFalse(!Object(instance)) |
| + assertTrue(Boolean(instance).valueOf()) |
| + assertFalse(!instance) |
| + assertTrue(!!instance) |
| + assertTrue(instance && true) |
| + assertFalse(!instance && false) |
| + assertTrue(!instance || true) |
| + assertEquals(1, instance ? 1 : 2) |
| + assertEquals(2, !instance ? 1 : 2) |
| + if (!instance) assertUnreachable(); |
| + if (instance) {} else assertUnreachable(); |
| } |
| function TestToString(type, lanes) { |
| var simdFn = SIMD[type]; |
| - for (var i in values) { |
| - assertEquals(values[i].toString(), String(values[i])) |
| - assertTrue(isValidSimdString(values[i].toString(), values[i], type, lanes)) |
| - assertTrue( |
| - isValidSimdString(Object(values[i]).toString(), values[i], type, lanes)) |
| - assertTrue(isValidSimdString( |
| - simdFn.prototype.toString.call(values[i]), values[i], type, lanes)) |
| - } |
| + var instance = createInstance(type); |
| + |
| + assertEquals(instance.toString(), String(instance)) |
| + assertTrue(isValidSimdString(instance.toString(), instance, type, lanes)) |
| + assertTrue( |
| + isValidSimdString(Object(instance).toString(), instance, type, lanes)) |
| + assertTrue(isValidSimdString( |
| + simdFn.prototype.toString.call(instance), instance, type, lanes)) |
| } |
| function TestToNumber(type, lanes) { |
| - for (var i in values) { |
| - assertThrows(function() { Number(Object(values[i])) }, TypeError) |
| - assertThrows(function() { +Object(values[i]) }, TypeError) |
| - assertThrows(function() { Number(values[i]) }, TypeError) |
| - assertThrows(function() { values[i] + 0 }, TypeError) |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| + assertThrows(function() { Number(Object(instance)) }, TypeError) |
| + assertThrows(function() { +Object(instance) }, TypeError) |
| + assertThrows(function() { Number(instance) }, TypeError) |
| + assertThrows(function() { instance + 0 }, TypeError) |
| +} |
| + |
| + |
| +function TestCoercions(type, lanes) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + // Test that setting a lane to value 'a' results in a lane with value 'b'. |
| + function test(a, b) { |
| + for (var i = 0; i < lanes; i++) { |
| + var ainstance = simdFn.replaceLane(instance, i, a); |
| + var lane_value = simdFn.extractLane(ainstance, i); |
| + assertSame(b, lane_value); |
| + } |
| + } |
| + |
| + switch (type) { |
| + case 'Float32x4': |
| + test(0, 0); |
| + test(-0, -0); |
| + test(NaN, NaN); |
| + test(null, 0); |
| + test(undefined, NaN); |
| + test("5.25", 5.25); |
| + test(Number.MAX_VALUE, Infinity); |
| + test(-Number.MAX_VALUE, -Infinity); |
| + test(Number.MIN_VALUE, 0); |
| + break; |
| + case 'Int32x4': |
| + test(Infinity, 0); |
| + test(-Infinity, 0); |
| + test(NaN, 0); |
| + test(0, 0); |
| + test(-0, 0); |
| + test(Number.MIN_VALUE, 0); |
| + test(-Number.MIN_VALUE, 0); |
| + test(0.1, 0); |
| + test(-0.1, 0); |
| + test(1, 1); |
| + test(1.1, 1); |
| + test(-1, -1); |
| + test(-1.6, -1); |
| + test(2147483647, 2147483647); |
| + test(2147483648, -2147483648); |
| + test(2147483649, -2147483647); |
| + test(4294967295, -1); |
| + test(4294967296, 0); |
| + test(4294967297, 1); |
| + break; |
| + case 'Int16x8': |
| + test(Infinity, 0); |
| + test(-Infinity, 0); |
| + test(NaN, 0); |
| + test(0, 0); |
| + test(-0, 0); |
| + test(Number.MIN_VALUE, 0); |
| + test(-Number.MIN_VALUE, 0); |
| + test(0.1, 0); |
| + test(-0.1, 0); |
| + test(1, 1); |
| + test(1.1, 1); |
| + test(-1, -1); |
| + test(-1.6, -1); |
| + test(32767, 32767); |
| + test(32768, -32768); |
| + test(32769, -32767); |
| + test(65535, -1); |
| + test(65536, 0); |
| + test(65537, 1); |
| + break; |
| + case 'Int8x16': |
| + test(Infinity, 0); |
| + test(-Infinity, 0); |
| + test(NaN, 0); |
| + test(0, 0); |
| + test(-0, 0); |
| + test(Number.MIN_VALUE, 0); |
| + test(-Number.MIN_VALUE, 0); |
| + test(0.1, 0); |
| + test(-0.1, 0); |
| + test(1, 1); |
| + test(1.1, 1); |
| + test(-1, -1); |
| + test(-1.6, -1); |
| + test(127, 127); |
| + test(128, -128); |
| + test(129, -127); |
| + test(255, -1); |
| + test(256, 0); |
| + test(257, 1); |
| + break; |
| + case 'Bool32x4': |
| + case 'Bool16x8': |
| + case 'Bool8x16': |
| + test(true, true); |
| + test(false, false); |
| + test(0, false); |
| + test(1, true); |
| + test(0.1, true); |
| + test(NaN, false); |
| + test(null, false); |
| + test("", false); |
| + test("false", true); |
| + break; |
| } |
| } |
| function TestEquality(type, lanes) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| // Every SIMD value should equal itself, and non-strictly equal its wrapper. |
| - for (var i in values) { |
| - assertSame(values[i], values[i]) |
| - assertEquals(values[i], values[i]) |
| - assertTrue(Object.is(values[i], values[i])) |
| - assertTrue(values[i] === values[i]) |
| - assertTrue(values[i] == values[i]) |
| - assertFalse(values[i] === Object(values[i])) |
| - assertFalse(Object(values[i]) === values[i]) |
| - assertFalse(values[i] == Object(values[i])) |
| - assertFalse(Object(values[i]) == values[i]) |
| - assertTrue(values[i] === values[i].valueOf()) |
| - assertTrue(values[i].valueOf() === values[i]) |
| - assertTrue(values[i] == values[i].valueOf()) |
| - assertTrue(values[i].valueOf() == values[i]) |
| - assertFalse(Object(values[i]) === Object(values[i])) |
| - assertEquals(Object(values[i]).valueOf(), Object(values[i]).valueOf()) |
| + assertSame(instance, instance) |
| + assertEquals(instance, instance) |
| + assertTrue(Object.is(instance, instance)) |
| + assertTrue(instance === instance) |
| + assertTrue(instance == instance) |
| + assertFalse(instance === Object(instance)) |
| + assertFalse(Object(instance) === instance) |
| + assertFalse(instance == Object(instance)) |
| + assertFalse(Object(instance) == instance) |
| + assertTrue(instance === instance.valueOf()) |
| + assertTrue(instance.valueOf() === instance) |
| + assertTrue(instance == instance.valueOf()) |
| + assertTrue(instance.valueOf() == instance) |
| + assertFalse(Object(instance) === Object(instance)) |
| + assertEquals(Object(instance).valueOf(), Object(instance).valueOf()) |
| + |
| + // SIMD values should not be equal to any other kind of object. |
|
rossberg
2015/07/29 14:37:56
Can you add tests involving two different SIMD typ
bbudge
2015/07/30 13:46:58
Good idea. Done.
|
| + var others = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] |
| + for (var j in others) { |
| + assertFalse(instance === others[j]) |
| + assertFalse(others[j] === instance) |
| + assertFalse(instance == others[j]) |
| + assertFalse(others[j] == instance) |
| } |
| - // Test structural equivalence. |
| - for (var i = 0; i < values.length; i++) { |
| - for (var j = i + 1; j < values.length; j++) { |
| - var a = values[i], b = values[j], |
| - equivalent = areEquivalent(type, lanes, a, b); |
| - assertSame(equivalent, a == b); |
| - assertSame(equivalent, a === b); |
| + // Test that f(a, b) is the same as f(SIMD(a), SIMD(b)) for equality and |
| + // strict equality, at every lane. |
| + function test(a, b) { |
| + for (var i = 0; i < lanes; i++) { |
| + var aval = simdFn.replaceLane(instance, i, a); |
| + var bval = simdFn.replaceLane(instance, i, b); |
| + assertSame(a == b, aval == bval); |
| + assertSame(a === b, aval === bval); |
| } |
| } |
| - // SIMD values should not be equal to any other kind of object. |
| - var others = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] |
| - for (var i in values) { |
| - for (var j in others) { |
| - assertFalse(values[i] === others[j]) |
| - assertFalse(others[j] === values[i]) |
| - assertFalse(values[i] == others[j]) |
| - assertFalse(others[j] == values[i]) |
| - } |
| + switch (type) { |
| + case 'Float32x4': |
| + test(1, 2.5); |
| + test(1, 1); |
| + test(0, 0); |
| + test(-0, +0); |
| + test(+0, -0); |
| + test(-0, -0); |
| + test(0, NaN); |
| + test(NaN, NaN); |
| + break; |
| + case 'Int32x4': |
| + case 'Int16x8': |
| + case 'Int8x16': |
| + test(1, 2); |
| + test(1, 1); |
| + test(1, -1); |
| + break; |
| + case 'Bool32x4': |
| + case 'Bool16x8': |
| + case 'Bool8x16': |
| + test(true, false); |
| + test(false, true); |
| + break; |
| } |
| } |
| - |
| function TestSameValue(type, lanes) { |
|
rossberg
2015/07/29 14:37:56
Same here.
bbudge
2015/07/30 13:46:58
Done.
|
| - // SIMD value types. |
| - // All lanes checked. |
| - // TODO(bbudge): use loops to test lanes when replaceLane is defined. |
| - assertTrue(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4), |
| - SIMD.Float32x4(1, 2, 3, 4))); |
| - assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4), |
| - SIMD.Float32x4(NaN, 2, 3, 4))); |
| - assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4), |
| - SIMD.Float32x4(1, NaN, 3, 4))); |
| - assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4), |
| - SIMD.Float32x4(1, 2, NaN, 4))); |
| - assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4), |
| - SIMD.Float32x4(1, 2, 3, NaN))); |
| - // Special values. |
| - // TODO(bbudge): use loops to test lanes when replaceLane is defined. |
| - assertTrue(sameValueBoth(SIMD.Float32x4(NaN, 2, 3, 4), |
| - SIMD.Float32x4(NaN, 2, 3, 4))); |
| - assertTrue(sameValueBoth(SIMD.Float32x4(+0, 2, 3, 4), |
| - SIMD.Float32x4(+0, 2, 3, 4))); |
| - assertTrue(sameValueBoth(SIMD.Float32x4(-0, 2, 3, 4), |
| - SIMD.Float32x4(-0, 2, 3, 4))); |
| - assertTrue(sameValueZeroOnly(SIMD.Float32x4(+0, 2, 3, 4), |
| - SIMD.Float32x4(-0, 2, 3, 4))); |
| - assertTrue(sameValueZeroOnly(SIMD.Float32x4(-0, 2, 3, 4), |
| - SIMD.Float32x4(+0, 2, 3, 4))); |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + var sameValue = natives.$sameValue; |
| + var sameValueZero = natives.$sameValueZero; |
| + |
| + // Test that f(a, b) is the same as f(SIMD(a), SIMD(b)) for sameValue and |
| + // sameValueZero, at every lane. |
| + function test(a, b) { |
| + for (var i = 0; i < lanes; i++) { |
| + var aval = simdFn.replaceLane(instance, i, a); |
| + var bval = simdFn.replaceLane(instance, i, b); |
| + assertSame(sameValue(a, b), sameValue(aval, bval)); |
| + assertSame(sameValueZero(a, b), sameValueZero(aval, bval)); |
| + } |
| + } |
| + |
| + switch (type) { |
| + case 'Float32x4': |
| + test(1, 2.5); |
| + test(1, 1); |
| + test(0, 0); |
| + test(-0, +0); |
| + test(+0, -0); |
| + test(-0, -0); |
| + test(0, NaN); |
| + test(NaN, NaN); |
| + break; |
| + case 'Int32x4': |
| + case 'Int16x8': |
| + case 'Int8x16': |
| + test(1, 2); |
| + test(1, 1); |
| + test(1, -1); |
| + break; |
| + case 'Bool32x4': |
| + case 'Bool16x8': |
| + case 'Bool8x16': |
| + test(true, false); |
| + test(false, true); |
| + break; |
| + } |
| } |
| function TestComparison(type, lanes) { |
| - var a = values[0], b = values[1]; |
| + var simdFn = SIMD[type]; |
| + var a = createInstance(type), b = createInstance(type); |
|
rossberg
2015/07/29 14:37:56
Again it would be good to check the matrix of SIMD
bbudge
2015/07/30 13:46:59
Done.
|
| function lt() { a < b; } |
| function gt() { a > b; } |
| @@ -284,7 +380,6 @@ function TestComparison(type, lanes) { |
| function ge_same() { a >= a; } |
| var throwFuncs = [lt, gt, le, ge, lt_same, gt_same, le_same, ge_same]; |
| - |
| for (var f of throwFuncs) { |
| assertThrows(f, TypeError); |
| %OptimizeFunctionOnNextCall(f); |
| @@ -297,16 +392,18 @@ function TestComparison(type, lanes) { |
| // Test SIMD value wrapping/boxing over non-builtins. |
| function TestCall(type, lanes) { |
| var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| simdFn.prototype.getThisProto = function () { |
| return Object.getPrototypeOf(this); |
| } |
| - for (var i in values) { |
| - assertTrue(values[i].getThisProto() === simdFn.prototype) |
| - } |
| + assertTrue(instance.getThisProto() === simdFn.prototype) |
| } |
| function TestAsSetKey(type, lanes, set) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| function test(set, key) { |
| assertFalse(set.has(key)); |
| assertFalse(set.delete(key)); |
| @@ -323,13 +420,14 @@ function TestAsSetKey(type, lanes, set) { |
| assertFalse(set.has(key)); |
| } |
| - for (var i in values) { |
| - test(set, values[i]); |
| - } |
| + test(set, instance); |
|
rossberg
2015/07/29 14:37:56
This now only tests for a zeroed value, which seem
bbudge
2015/07/30 13:46:58
I changed createInstance to create slightly more i
|
| } |
| function TestAsMapKey(type, lanes, map) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| function test(map, key, value) { |
| assertFalse(map.has(key)); |
| assertSame(undefined, map.get(key)); |
| @@ -350,40 +448,41 @@ function TestAsMapKey(type, lanes, map) { |
| assertSame(undefined, map.get(key)); |
| } |
| - for (var i in values) { |
| - test(map, values[i], {}); |
| - } |
| + test(map, instance, {}); |
|
rossberg
2015/07/29 14:37:56
Similarly here.
bbudge
2015/07/30 13:46:58
Done.
|
| } |
| // Test SIMD type with Harmony reflect-apply. |
| function TestReflectApply(type) { |
| + var simdFn = SIMD[type]; |
| + var instance = createInstance(type); |
| + |
| function returnThis() { return this; } |
| function returnThisStrict() { 'use strict'; return this; } |
| function noop() {} |
| function noopStrict() { 'use strict'; } |
| var R = void 0; |
| - for (var i in values) { |
| - assertSame(SIMD[type].prototype, |
| - Object.getPrototypeOf( |
| - Reflect.apply(returnThis, values[i], []))); |
| - assertSame(values[i], Reflect.apply(returnThisStrict, values[i], [])); |
| - |
| - assertThrows( |
| - function() { 'use strict'; Reflect.apply(values[i]); }, TypeError); |
| - assertThrows( |
| - function() { Reflect.apply(values[i]); }, TypeError); |
| - assertThrows( |
| - function() { Reflect.apply(noopStrict, R, values[i]); }, TypeError); |
| - assertThrows( |
| - function() { Reflect.apply(noop, R, values[i]); }, TypeError); |
| - } |
| + assertSame(SIMD[type].prototype, |
| + Object.getPrototypeOf( |
| + Reflect.apply(returnThis, instance, []))); |
| + assertSame(instance, Reflect.apply(returnThisStrict, instance, [])); |
| + |
| + assertThrows( |
| + function() { 'use strict'; Reflect.apply(instance); }, TypeError); |
| + assertThrows( |
| + function() { Reflect.apply(instance); }, TypeError); |
| + assertThrows( |
| + function() { Reflect.apply(noopStrict, R, instance); }, TypeError); |
| + assertThrows( |
| + function() { Reflect.apply(noop, R, instance); }, TypeError); |
| } |
| function TestSIMDTypes() { |
| - var types = [ 'Float32x4' ]; |
| + var types = ['Float32x4', 'Int32x4', 'Bool32x4', |
| + 'Int16x8', 'Bool16x8', |
| + 'Int8x16', 'Bool8x16']; |
| for (var i = 0; i < types.length; ++i) { |
| var type = types[i], |
| lanes = lanesForType(type); |
| @@ -395,6 +494,7 @@ function TestSIMDTypes() { |
| TestToBoolean(type, lanes); |
| TestToString(type, lanes); |
| TestToNumber(type, lanes); |
| + TestCoercions(type, lanes); |
| TestEquality(type, lanes); |
| TestSameValue(type, lanes); |
| TestComparison(type, lanes); |
| @@ -407,3 +507,18 @@ function TestSIMDTypes() { |
| } |
| } |
| TestSIMDTypes(); |
| + |
| +// Tests for the global SIMD object. |
| +function TestSIMDObject() { |
| + assertSame(typeof SIMD, 'object'); |
| + assertSame(SIMD.constructor, Object); |
| + assertSame(Object.getPrototypeOf(SIMD), Object.prototype); |
| + assertSame(SIMD + "", "[object SIMD]"); |
| + // The SIMD object is mutable. |
| + SIMD.foo = "foo"; |
| + assertSame(SIMD.foo, "foo"); |
| + delete SIMD.foo; |
| + delete SIMD.Bool8x16; |
| + assertSame(SIMD.Bool8x16, undefined); |
| +} |
| +TestSIMDObject() |