Index: test/mjsunit/wasm/params.js |
diff --git a/test/mjsunit/wasm/params.js b/test/mjsunit/wasm/params.js |
index 82709ab95d2886c0cdaa6123158c6b1155ab9333..7c2b3d1794209522eacc626bf108550f5a72bda3 100644 |
--- a/test/mjsunit/wasm/params.js |
+++ b/test/mjsunit/wasm/params.js |
@@ -5,54 +5,39 @@ |
// Flags: --expose-wasm |
load("test/mjsunit/wasm/wasm-constants.js"); |
+load("test/mjsunit/wasm/wasm-module-builder.js"); |
-function runSelect2(module, which, a, b) { |
- assertEquals(which == 0 ? a : b, module.select(a, b)); |
+function runSelect2(select, which, a, b) { |
+ assertEquals(which == 0 ? a : b, select(a, b)); |
} |
function testSelect2(type) { |
- var kBodySize = 2; |
- var kNameOffset = kHeaderSize + 21 + kBodySize + 1; |
- |
for (var which = 0; which < 2; which++) { |
print("type = " + type + ", which = " + which); |
- var data = bytesWithHeader( |
- // -- memory |
- kDeclMemory, |
- 1, 1, 1, // memory |
- // -- signatures |
- kDeclSignatures, 1, |
- 2, type, type, type, // signature: (t,t)->t |
- // -- select |
- kDeclFunctions, 1, |
- kDeclFunctionName | kDeclFunctionExport, |
- 0, 0, |
- kNameOffset, 0, 0, 0, // name offset |
- kBodySize, 0, // body size |
- kExprGetLocal, which, // -- |
- kDeclEnd, |
- 's','e','l','e','c','t',0 // name |
- ); |
- |
- var module = _WASMEXP_.instantiateModule(data); |
- |
- assertEquals("function", typeof module.select); |
- runSelect2(module, which, 99, 97); |
- runSelect2(module, which, -99, -97); |
+ var builder = new WasmModuleBuilder(); |
+ |
+ builder.addFunction("select", [type, type, type]) |
+ .addBody([kExprGetLocal, which]) |
+ .exportFunc() |
+ |
+ var select = builder.instantiate().exports.select; |
+ |
+ runSelect2(select, which, 99, 97); |
+ runSelect2(select, which, -99, -97); |
if (type != kAstF32) { |
- runSelect2(module, which, 0x80000000 | 0, 0x7fffffff | 0); |
- runSelect2(module, which, 0x80000001 | 0, 0x7ffffffe | 0); |
- runSelect2(module, which, 0xffffffff | 0, 0xfffffffe | 0); |
- runSelect2(module, which, -2147483647, 2147483646); |
- runSelect2(module, which, -2147483646, 2147483645); |
- runSelect2(module, which, -2147483648, 2147483647); |
+ runSelect2(select, which, 0x80000000 | 0, 0x7fffffff | 0); |
+ runSelect2(select, which, 0x80000001 | 0, 0x7ffffffe | 0); |
+ runSelect2(select, which, 0xffffffff | 0, 0xfffffffe | 0); |
+ runSelect2(select, which, -2147483647, 2147483646); |
+ runSelect2(select, which, -2147483646, 2147483645); |
+ runSelect2(select, which, -2147483648, 2147483647); |
} |
if (type != kAstI32 && type != kAstI64) { |
- runSelect2(module, which, -1.25, 5.25); |
- runSelect2(module, which, Infinity, -Infinity); |
+ runSelect2(select, which, -1.25, 5.25); |
+ runSelect2(select, which, Infinity, -Infinity); |
} |
} |
} |
@@ -63,20 +48,20 @@ testSelect2(kAstF32); |
testSelect2(kAstF64); |
-function runSelect10(module, which, a, b) { |
+function runSelect10(select, which, a, b) { |
var x = -1; |
var result = [ |
- module.select(a, b, x, x, x, x, x, x, x, x), |
- module.select(x, a, b, x, x, x, x, x, x, x), |
- module.select(x, x, a, b, x, x, x, x, x, x), |
- module.select(x, x, x, a, b, x, x, x, x, x), |
- module.select(x, x, x, x, a, b, x, x, x, x), |
- module.select(x, x, x, x, x, a, b, x, x, x), |
- module.select(x, x, x, x, x, x, a, b, x, x), |
- module.select(x, x, x, x, x, x, x, a, b, x), |
- module.select(x, x, x, x, x, x, x, x, a, b), |
- module.select(x, x, x, x, x, x, x, x, x, a) |
+ select(a, b, x, x, x, x, x, x, x, x), |
+ select(x, a, b, x, x, x, x, x, x, x), |
+ select(x, x, a, b, x, x, x, x, x, x), |
+ select(x, x, x, a, b, x, x, x, x, x), |
+ select(x, x, x, x, a, b, x, x, x, x), |
+ select(x, x, x, x, x, a, b, x, x, x), |
+ select(x, x, x, x, x, x, a, b, x, x), |
+ select(x, x, x, x, x, x, x, a, b, x), |
+ select(x, x, x, x, x, x, x, x, a, b), |
+ select(x, x, x, x, x, x, x, x, x, a) |
]; |
for (var i = 0; i < 10; i++) { |
@@ -86,49 +71,36 @@ function runSelect10(module, which, a, b) { |
} |
} |
-function testSelect10(type) { |
+function testSelect10(t) { |
var kBodySize = 2; |
var kNameOffset = kHeaderSize + 29 + kBodySize + 1; |
for (var which = 0; which < 10; which++) { |
- print("type = " + type + ", which = " + which); |
- |
- var t = type; |
- var data = bytesWithHeader( |
- kDeclMemory, |
- 1, 1, 1, // memory |
- // signatures |
- kDeclSignatures, 1, |
- 10, t,t,t,t,t,t,t,t,t,t,t, // (tx10)->t |
- // main function |
- kDeclFunctions, 1, |
- kDeclFunctionName | kDeclFunctionExport, |
- 0, 0, |
- kNameOffset, 0, 0, 0, // name offset |
- kBodySize, 0, // body size |
- kExprGetLocal, which, // -- |
- kDeclEnd, |
- 's','e','l','e','c','t',0 // name |
- ); |
- |
- var module = _WASMEXP_.instantiateModule(data); |
- |
- assertEquals("function", typeof module.select); |
- runSelect10(module, which, 99, 97); |
- runSelect10(module, which, -99, -97); |
- |
- if (type != kAstF32) { |
- runSelect10(module, which, 0x80000000 | 0, 0x7fffffff | 0); |
- runSelect10(module, which, 0x80000001 | 0, 0x7ffffffe | 0); |
- runSelect10(module, which, 0xffffffff | 0, 0xfffffffe | 0); |
- runSelect10(module, which, -2147483647, 2147483646); |
- runSelect10(module, which, -2147483646, 2147483645); |
- runSelect10(module, which, -2147483648, 2147483647); |
+ print("type = " + t + ", which = " + which); |
+ |
+ var builder = new WasmModuleBuilder(); |
+ builder.addFunction("select", [t,t,t,t,t,t,t,t,t,t,t]) |
+ .addBody([kExprGetLocal, which]) |
+ .exportFunc(); |
+ |
+ var select = builder.instantiate().exports.select; |
+ |
+ assertEquals("function", typeof select); |
+ runSelect10(select, which, 99, 97); |
+ runSelect10(select, which, -99, -97); |
+ |
+ if (t != kAstF32) { |
+ runSelect10(select, which, 0x80000000 | 0, 0x7fffffff | 0); |
+ runSelect10(select, which, 0x80000001 | 0, 0x7ffffffe | 0); |
+ runSelect10(select, which, 0xffffffff | 0, 0xfffffffe | 0); |
+ runSelect10(select, which, -2147483647, 2147483646); |
+ runSelect10(select, which, -2147483646, 2147483645); |
+ runSelect10(select, which, -2147483648, 2147483647); |
} |
- if (type != kAstI32 && type != kAstI64) { |
- runSelect10(module, which, -1.25, 5.25); |
- runSelect10(module, which, Infinity, -Infinity); |
+ if (t != kAstI32 && t != kAstI64) { |
+ runSelect10(select, which, -1.25, 5.25); |
+ runSelect10(select, which, Infinity, -Infinity); |
} |
} |
} |