summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/wasm')
-rw-r--r--deps/v8/test/mjsunit/wasm/asm-wasm-math-intrinsic.js1
-rw-r--r--deps/v8/test/mjsunit/wasm/bigint.js75
-rw-r--r--deps/v8/test/mjsunit/wasm/exceptions-global.js6
-rw-r--r--deps/v8/test/mjsunit/wasm/multi-value.js31
-rw-r--r--deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js261
-rw-r--r--deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js12
-rw-r--r--deps/v8/test/mjsunit/wasm/type-reflection-with-exnref.js21
-rw-r--r--deps/v8/test/mjsunit/wasm/type-reflection.js268
-rw-r--r--deps/v8/test/mjsunit/wasm/wasm-module-builder.js29
9 files changed, 540 insertions, 164 deletions
diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-math-intrinsic.js b/deps/v8/test/mjsunit/wasm/asm-wasm-math-intrinsic.js
index f683436246..59fcc66d7e 100644
--- a/deps/v8/test/mjsunit/wasm/asm-wasm-math-intrinsic.js
+++ b/deps/v8/test/mjsunit/wasm/asm-wasm-math-intrinsic.js
@@ -246,7 +246,6 @@ function assertBinop(name, math_func, asm_func) {
];
for (name of f64_intrinsics) {
- if (name == 'pow') continue; // TODO(8505): asm.js correctness
let math_func = Math[name];
let f32 = false;
print('Testing (f64) Math.' + name);
diff --git a/deps/v8/test/mjsunit/wasm/bigint.js b/deps/v8/test/mjsunit/wasm/bigint.js
index d64c0e0623..ff9046e9dc 100644
--- a/deps/v8/test/mjsunit/wasm/bigint.js
+++ b/deps/v8/test/mjsunit/wasm/bigint.js
@@ -7,7 +7,7 @@
load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestWasmI64ToJSBigInt() {
- var builder = new WasmModuleBuilder();
+ let builder = new WasmModuleBuilder();
builder
.addFunction("fn", kSig_l_v) // () -> i64
@@ -16,22 +16,22 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
])
.exportFunc();
- var module = builder.instantiate();
+ let module = builder.instantiate();
assertEquals(typeof module.exports.fn(), "bigint");
assertEquals(module.exports.fn(), 3n);
})();
(function TestJSBigIntToWasmI64Global() {
- var builder = new WasmModuleBuilder();
+ let builder = new WasmModuleBuilder();
- var a_global_index = builder
+ let a_global_index = builder
.addImportedGlobal("mod", "a", kWasmI64)
- var b_global_index = builder
+ let b_global_index = builder
.addImportedGlobal("mod", "b", kWasmI64);
- var c_global_index = builder
+ let c_global_index = builder
.addImportedGlobal("mod", "c", kWasmI64);
builder
@@ -39,7 +39,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
.addExportOfKind('b', kExternalGlobal, b_global_index)
.addExportOfKind('c', kExternalGlobal, c_global_index);
- var module = builder.instantiate({
+ let module = builder.instantiate({
mod: {
a: 1n,
b: 2n ** 63n,
@@ -53,16 +53,16 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})();
(function TestJSBigIntToWasmI64MutableGlobal() {
- var builder = new WasmModuleBuilder();
+ let builder = new WasmModuleBuilder();
- var a_global_index = builder
+ let a_global_index = builder
.addImportedGlobal("mod", "a", kWasmI64, /* mutable = */ true)
builder
.addExportOfKind('a', kExternalGlobal, a_global_index);
// as non object
- var fn = () => builder.instantiate({
+ let fn = () => builder.instantiate({
mod: {
a: 1n,
}
@@ -71,7 +71,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertThrows(fn, WebAssembly.LinkError);
// as WebAssembly.Global object
- var module = builder.instantiate({
+ let module = builder.instantiate({
mod: {
a: new WebAssembly.Global({ value: "i64", mutable: true }, 1n),
}
@@ -81,20 +81,19 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})();
(function TestJSBigIntToWasmI64Identity() {
- var builder = new WasmModuleBuilder();
+ let builder = new WasmModuleBuilder();
builder
.addFunction("f", kSig_l_l) // i64 -> i64
.addBody([
- kExprGetLocal, 0x0,
+ kExprGetLocal, 0,
])
.exportFunc();
- var module = builder.instantiate();
- var f = module.exports.f;
+ let module = builder.instantiate();
+ let f = module.exports.f;
assertEquals(f(0n), 0n);
- assertEquals(f(-0n), -0n);
assertEquals(f(123n), 123n);
assertEquals(f(-123n), -123n);
@@ -103,9 +102,31 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertThrows(() => f(5), TypeError);
})();
+(function TestJSBigIntToWasmI64Projection() {
+ let builder = new WasmModuleBuilder();
+
+ builder
+ .addFunction("f", kSig_l_ll) // i64 -> i64
+ .addBody([
+ kExprGetLocal, 1,
+ ])
+ .exportFunc();
+
+ let module = builder.instantiate();
+ let f = module.exports.f;
+
+ assertEquals(f(1n, 0n), 0n);
+ assertEquals(f(1n, 123n), 123n);
+ assertEquals(f(1n, -123n), -123n);
+
+ assertEquals(f(1n, "5"), 5n);
+
+ assertThrows(() => f(1n, 5), TypeError);
+})();
+
(function TestI64Global() {
- var argument = { "value": "i64", "mutable": true };
- var global = new WebAssembly.Global(argument);
+ let argument = { "value": "i64", "mutable": true };
+ let global = new WebAssembly.Global(argument);
assertEquals(global.value, 0n); // initial value
@@ -117,10 +138,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})();
(function TestI64GlobalValueOf() {
- var argument = { "value": "i64" };
+ let argument = { "value": "i64" };
// as literal
- var global = new WebAssembly.Global(argument, {
+ let global = new WebAssembly.Global(argument, {
valueOf() {
return 123n;
}
@@ -128,7 +149,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(global.value, 123n);
// as string
- var global2 = new WebAssembly.Global(argument, {
+ let global2 = new WebAssembly.Global(argument, {
valueOf() {
return "321";
}
@@ -137,7 +158,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})();
(function TestInvalidValtypeGlobalErrorMessage() {
- var argument = { "value": "some string" };
+ let argument = { "value": "some string" };
assertThrows(() => new WebAssembly.Global(argument), TypeError);
try {
@@ -149,26 +170,26 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})();
(function TestGlobalI64ValueWrongType() {
- var argument = { "value": "i64" };
+ let argument = { "value": "i64" };
assertThrows(() => new WebAssembly.Global(argument, 666), TypeError);
})();
(function TestGlobalI64SetWrongType() {
- var argument = { "value": "i64", "mutable": true };
- var global = new WebAssembly.Global(argument);
+ let argument = { "value": "i64", "mutable": true };
+ let global = new WebAssembly.Global(argument);
assertThrows(() => global.value = 1, TypeError);
})();
(function TestFuncParamF64PassingBigInt() {
- var builder = new WasmModuleBuilder();
+ let builder = new WasmModuleBuilder();
builder
.addFunction("f", kSig_v_d) // f64 -> ()
.addBody([])
.exportFunc();
- var module = builder.instantiate();
+ let module = builder.instantiate();
assertThrows(() => module.exports.f(123n), TypeError);
})();
diff --git a/deps/v8/test/mjsunit/wasm/exceptions-global.js b/deps/v8/test/mjsunit/wasm/exceptions-global.js
index c3f208ca16..4a74dfb010 100644
--- a/deps/v8/test/mjsunit/wasm/exceptions-global.js
+++ b/deps/v8/test/mjsunit/wasm/exceptions-global.js
@@ -115,10 +115,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertThrowsEquals(() => instance.exports.rethrow_exnref(), exception2);
})();
-// TODO(mstarzinger): Add the following test once proposal makes it clear how
-// far interaction with the mutable globals proposal is intended to go.
// Test loading an imported mutable "exnref" being changed from the outside.
-/*(function TestGlobalExnRefGetImportedMutableAndRethrow() {
+(function TestGlobalExnRefGetImportedMutableAndRethrow() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let g_index = builder.addImportedGlobal("m", "exn", kWasmExnRef, true);
@@ -135,7 +133,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertThrowsEquals(() => instance.exports.rethrow_exnref(), exception1);
let exception2 = mutable_global.value = "an even fancier exception";
assertThrowsEquals(() => instance.exports.rethrow_exnref(), exception2);
-})();*/
+})();
// Test custom initialization index for a global "exnref" variable.
(function TestGlobalExnRefInitIndex() {
diff --git a/deps/v8/test/mjsunit/wasm/multi-value.js b/deps/v8/test/mjsunit/wasm/multi-value.js
index 1948801958..31f9e8149b 100644
--- a/deps/v8/test/mjsunit/wasm/multi-value.js
+++ b/deps/v8/test/mjsunit/wasm/multi-value.js
@@ -319,3 +319,34 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(instance.exports.main(2), 8);
assertEquals(instance.exports.main(10), 200);
})();
+
+(function MultiJSReturnTest() {
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ let sig_fi_if = makeSig([kWasmI32, kWasmF32], [kWasmF32, kWasmI32]);
+
+ builder.addFunction("swap", sig_fi_if)
+ .addBody([
+ kExprGetLocal, 1,
+ kExprGetLocal, 0])
+ .exportAs("swap");
+ builder.addFunction("addsubmul", kSig_iii_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprGetLocal, 0,
+ kExprI32Add,
+ kExprGetLocal, 0,
+ kExprGetLocal, 0,
+ kExprI32Sub,
+ kExprGetLocal, 0,
+ kExprGetLocal, 0,
+ kExprI32Mul])
+ .exportAs("addsubmul");
+
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let instance = new WebAssembly.Instance(module);
+ assertEquals(instance.exports.swap(0, 1.5), [1.5, 0]);
+ assertEquals(instance.exports.swap(2, 3.75), [3.75, 2]);
+ assertEquals(instance.exports.addsubmul(4), [8, 0, 16]);
+ assertEquals(instance.exports.addsubmul(5), [10, 0, 25]);
+})();
diff --git a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
index eb0a95384c..96d3a0bac5 100644
--- a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
+++ b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
@@ -13,153 +13,174 @@ function instantiate(buffer, ffi) {
}
(function BasicTest() {
- print("BasicTest");
- let builder = new WasmModuleBuilder();
- builder.addMemory(1, 2, false);
- builder.addFunction("foo", kSig_i_v)
- .addBody([kExprI32Const, 11])
- .exportAs("blarg");
-
- var buffer = builder.toBuffer(debug);
- var instance = instantiate(buffer);
- assertEquals(11, instance.exports.blarg());
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 2, false);
+ builder.addFunction('foo', kSig_i_v)
+ .addBody([kExprI32Const, 11])
+ .exportAs('blarg');
+
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
+ assertEquals(11, instance.exports.blarg());
})();
(function ImportTest() {
- print("ImportTest");
- let builder = new WasmModuleBuilder();
- var index = builder.addImport("", "print", makeSig_v_x(kWasmI32));
- builder.addFunction("foo", kSig_v_v)
- .addBody([kExprI32Const, 13, kExprCallFunction, index])
- .exportAs("main");
-
- var buffer = builder.toBuffer(debug);
- var instance = instantiate(buffer, {"": {print: print}});
- print("should print 13! ");
- instance.exports.main();
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ var index = builder.addImport('', 'print', makeSig_v_x(kWasmI32));
+ builder.addFunction('foo', kSig_v_v)
+ .addBody([kExprI32Const, 13, kExprCallFunction, index])
+ .exportAs('main');
+
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer, {'': {print: print}});
+ print('should print 13! ');
+ instance.exports.main();
})();
(function LocalsTest() {
- print("LocalsTest");
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addFunction(undefined, kSig_i_i)
+ .addLocals({i32_count: 1})
+ .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
+ .exportAs('main');
+
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
+ assertEquals(19, instance.exports.main(19));
+ assertEquals(27777, instance.exports.main(27777));
+})();
+
+(function LocalsTest2() {
+ print(arguments.callee.name);
+ // TODO(titzer): i64 only works on 64-bit platforms.
+ var types = [
+ {locals: {i32_count: 1}, type: kWasmI32},
+ // {locals: {i64_count: 1}, type: kWasmI64},
+ {locals: {f32_count: 1}, type: kWasmF32},
+ {locals: {f64_count: 1}, type: kWasmF64},
+ ];
+
+ for (p of types) {
let builder = new WasmModuleBuilder();
- builder.addFunction(undefined, kSig_i_i)
- .addLocals({i32_count: 1})
+ builder.addFunction(undefined, makeSig_r_x(p.type, p.type))
+ .addLocals(p.locals)
.addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
- .exportAs("main");
+ .exportAs('main');
var buffer = builder.toBuffer(debug);
var instance = instantiate(buffer);
assertEquals(19, instance.exports.main(19));
assertEquals(27777, instance.exports.main(27777));
-})();
-
-(function LocalsTest2() {
- print("LocalsTest2");
- // TODO(titzer): i64 only works on 64-bit platforms.
- var types = [
- {locals: {i32_count: 1}, type: kWasmI32},
-// {locals: {i64_count: 1}, type: kWasmI64},
- {locals: {f32_count: 1}, type: kWasmF32},
- {locals: {f64_count: 1}, type: kWasmF64},
- ];
-
- for (p of types) {
- let builder = new WasmModuleBuilder();
- builder.addFunction(undefined, makeSig_r_x(p.type, p.type))
- .addLocals(p.locals)
- .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
- .exportAs("main");
-
- var buffer = builder.toBuffer(debug);
- var instance = instantiate(buffer);
- assertEquals(19, instance.exports.main(19));
- assertEquals(27777, instance.exports.main(27777));
- }
+ }
})();
(function CallTest() {
- print("CallTest");
- let builder = new WasmModuleBuilder();
- builder.addFunction("add", kSig_i_ii)
- .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
- builder.addFunction("main", kSig_i_ii)
- .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
- .exportAs("main");
-
- var instance = builder.instantiate();
- assertEquals(44, instance.exports.main(11, 33));
- assertEquals(7777, instance.exports.main(2222, 5555));
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addFunction('add', kSig_i_ii).addBody([
+ kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add
+ ]);
+ builder.addFunction('main', kSig_i_ii)
+ .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
+ .exportAs('main');
+
+ var instance = builder.instantiate();
+ assertEquals(44, instance.exports.main(11, 33));
+ assertEquals(7777, instance.exports.main(2222, 5555));
})();
(function IndirectCallTest() {
- print("IndirectCallTest");
- let builder = new WasmModuleBuilder();
- builder.addFunction("add", kSig_i_ii)
- .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
- builder.addFunction("main", kSig_i_iii)
- .addBody([kExprGetLocal,
- 1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0, kTableZero])
- .exportAs("main");
- builder.appendToTable([0]);
-
- var instance = builder.instantiate();
- assertEquals(44, instance.exports.main(0, 11, 33));
- assertEquals(7777, instance.exports.main(0, 2222, 5555));
- assertThrows(function() { instance.exports.main(1, 1, 1); });
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addFunction('add', kSig_i_ii).addBody([
+ kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add
+ ]);
+ builder.addFunction('main', kSig_i_iii)
+ .addBody([
+ kExprGetLocal, 1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect,
+ 0, kTableZero
+ ])
+ .exportAs('main');
+ builder.appendToTable([0]);
+
+ var instance = builder.instantiate();
+ assertEquals(44, instance.exports.main(0, 11, 33));
+ assertEquals(7777, instance.exports.main(0, 2222, 5555));
+ assertThrows(() => instance.exports.main(1, 1, 1));
})();
(function DataSegmentTest() {
- print("DataSegmentTest");
- let builder = new WasmModuleBuilder();
- builder.addMemory(1, 1, false);
- builder.addFunction("load", kSig_i_i)
- .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
- .exportAs("load");
- builder.addDataSegment(0, [9, 9, 9, 9]);
-
- var buffer = builder.toBuffer(debug);
- var instance = instantiate(buffer);
- assertEquals(151587081, instance.exports.load(0));
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 1, false);
+ builder.addFunction('load', kSig_i_i)
+ .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
+ .exportAs('load');
+ builder.addDataSegment(0, [9, 9, 9, 9]);
+
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
+ assertEquals(151587081, instance.exports.load(0));
})();
-
(function BasicTestWithUint8Array() {
- print("BasicTestWithUint8Array");
- let builder = new WasmModuleBuilder();
- builder.addMemory(1, 2, false);
- builder.addFunction("foo", kSig_i_v)
- .addBody([kExprI32Const, 17])
- .exportAs("blarg");
-
- var buffer = builder.toBuffer(debug);
- var array = new Uint8Array(buffer);
- var instance = instantiate(array);
- assertEquals(17, instance.exports.blarg());
-
- var kPad = 5;
- var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad);
- var whole = new Uint8Array(buffer2);
- for (var i = 0; i < whole.byteLength; i++) {
- whole[i] = 0xff;
- }
- var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength);
- for (var i = 0; i < array2.byteLength; i++) {
- array2[i] = array[i];
- }
- var instance = instantiate(array2);
- assertEquals(17, instance.exports.blarg());
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 2, false);
+ builder.addFunction('foo', kSig_i_v)
+ .addBody([kExprI32Const, 17])
+ .exportAs('blarg');
+
+ var buffer = builder.toBuffer(debug);
+ var array = new Uint8Array(buffer);
+ var instance = instantiate(array);
+ assertEquals(17, instance.exports.blarg());
+
+ var kPad = 5;
+ var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad);
+ var whole = new Uint8Array(buffer2);
+ for (var i = 0; i < whole.byteLength; i++) {
+ whole[i] = 0xff;
+ }
+ var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength);
+ for (var i = 0; i < array2.byteLength; i++) {
+ array2[i] = array[i];
+ }
+ var instance = instantiate(array2);
+ assertEquals(17, instance.exports.blarg());
})();
(function ImportTestTwoLevel() {
- print("ImportTestTwoLevel");
- let builder = new WasmModuleBuilder();
- var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32));
- builder.addFunction("foo", kSig_v_v)
- .addBody([kExprI32Const, 19, kExprCallFunction, index])
- .exportAs("main");
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ var index = builder.addImport('mod', 'print', makeSig_v_x(kWasmI32));
+ builder.addFunction('foo', kSig_v_v)
+ .addBody([kExprI32Const, 19, kExprCallFunction, index])
+ .exportAs('main');
+
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer, {mod: {print: print}});
+ print('should print 19! ');
+ instance.exports.main();
+})();
- var buffer = builder.toBuffer(debug);
- var instance = instantiate(buffer, {mod: {print: print}});
- print("should print 19! ");
- instance.exports.main();
+(function TestI32Const() {
+ print(arguments.callee.name);
+ let ints = [
+ // A few negative number of different length.
+ -3 << 28, -20000, -400, -200, -100, -50, -10, -1,
+ // And a few positive number of different length.
+ 0, 1, 2, 20, 120, 130, 260, 500, 5000000, 3 << 28
+ ];
+ for (let i of ints) {
+ let builder = new WasmModuleBuilder();
+ builder.addFunction('main', kSig_i_v)
+ .addBody([...wasmI32Const(i)])
+ .exportAs('main');
+ let instance = builder.instantiate();
+ assertEquals(i, instance.exports.main());
+ }
})();
diff --git a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js b/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
index 0b857fb42f..b7a7ee7969 100644
--- a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
+++ b/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
@@ -33,6 +33,12 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals("anyref", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
+
+ global = new WebAssembly.Global({value: "anyfunc"});
+ type = WebAssembly.Global.type(global);
+ assertEquals("anyfunc", type.value);
+ assertEquals(false, type.mutable);
+ assertEquals(2, Object.getOwnPropertyNames(type).length);
})();
// This is an extension of "type-reflection.js/TestFunctionTableSetAndCall" to
@@ -65,17 +71,23 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
// Test table #0 first.
assertEquals(v1, instance.exports.call0(0));
+ assertSame(f1, table.get(0));
table.set(1, f2);
assertEquals(v2, instance.exports.call0(1));
+ assertSame(f2, table.get(1));
table.set(1, f3);
assertTraps(kTrapFuncSigMismatch, () => instance.exports.call0(1));
+ assertSame(f3, table.get(1));
// Test table #1 next.
assertTraps(kTrapFuncSigMismatch, () => instance.exports.call1(0));
instance.exports.tbl.set(0, f1);
assertEquals(v1, instance.exports.call1(0));
+ assertSame(f1, instance.exports.tbl.get(0));
instance.exports.tbl.set(0, f2);
assertEquals(v2, instance.exports.call1(0));
+ assertSame(f2, instance.exports.tbl.get(0));
instance.exports.tbl.set(0, f3);
assertTraps(kTrapFuncSigMismatch, () => instance.exports.call1(0));
+ assertSame(f3, instance.exports.tbl.get(0));
})();
diff --git a/deps/v8/test/mjsunit/wasm/type-reflection-with-exnref.js b/deps/v8/test/mjsunit/wasm/type-reflection-with-exnref.js
new file mode 100644
index 0000000000..df655f6ce7
--- /dev/null
+++ b/deps/v8/test/mjsunit/wasm/type-reflection-with-exnref.js
@@ -0,0 +1,21 @@
+// Copyright 2019 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --experimental-wasm-type-reflection --experimental-wasm-eh
+
+load('test/mjsunit/wasm/wasm-module-builder.js');
+
+(function TestGlobalType() {
+ let global = new WebAssembly.Global({value: "exnref", mutable: true});
+ let type = WebAssembly.Global.type(global);
+ assertEquals("exnref", type.value);
+ assertEquals(true, type.mutable);
+ assertEquals(2, Object.getOwnPropertyNames(type).length);
+
+ global = new WebAssembly.Global({value: "exnref"});
+ type = WebAssembly.Global.type(global);
+ assertEquals("exnref", type.value);
+ assertEquals(false, type.mutable);
+ assertEquals(2, Object.getOwnPropertyNames(type).length);
+})();
diff --git a/deps/v8/test/mjsunit/wasm/type-reflection.js b/deps/v8/test/mjsunit/wasm/type-reflection.js
index da9ef83fda..a9a0b87143 100644
--- a/deps/v8/test/mjsunit/wasm/type-reflection.js
+++ b/deps/v8/test/mjsunit/wasm/type-reflection.js
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --experimental-wasm-type-reflection
+// Flags: --experimental-wasm-type-reflection --expose-gc
load('test/mjsunit/wasm/wasm-module-builder.js');
@@ -57,6 +57,52 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(2, Object.getOwnPropertyNames(type).length);
})();
+(function TestMemoryExports() {
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1).exportMemoryAs("a")
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let exports = WebAssembly.Module.exports(module);
+
+ assertEquals("a", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals(1, exports[0].type.minimum);
+ assertFalse("maximum" in exports[0].type);
+
+ builder = new WasmModuleBuilder();
+ builder.addMemory(2, 16).exportMemoryAs("b")
+ module = new WebAssembly.Module(builder.toBuffer());
+ exports = WebAssembly.Module.exports(module);
+
+ assertEquals("b", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals(2, exports[0].type.minimum);
+ assertEquals(16, exports[0].type.maximum);
+})();
+
+(function TestMemoryImports() {
+ let builder = new WasmModuleBuilder();
+ builder.addImportedMemory("m", "a", 1);
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let imports = WebAssembly.Module.imports(module);
+
+ assertEquals("a", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals(1, imports[0].type.minimum);
+ assertFalse("maximum" in imports[0].type);
+
+ builder = new WasmModuleBuilder();
+ builder.addImportedMemory("m", "b", 2, 16);
+ module = new WebAssembly.Module(builder.toBuffer());
+ imports = WebAssembly.Module.imports(module);
+
+ assertEquals("b", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals(2, imports[0].type.minimum);
+ assertEquals(16, imports[0].type.maximum);
+})();
+
(function TestTableType() {
let table = new WebAssembly.Table({initial: 1, element: "anyfunc"});
let type = WebAssembly.Table.type(table);
@@ -73,6 +119,56 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(3, Object.getOwnPropertyNames(type).length);
})();
+(function TestTableExports() {
+ let builder = new WasmModuleBuilder();
+ builder.addTable(kWasmAnyFunc, 20).exportAs("a");
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let exports = WebAssembly.Module.exports(module);
+
+ assertEquals("a", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals("anyfunc", exports[0].type.element);
+ assertEquals(20, exports[0].type.minimum);
+ assertFalse("maximum" in exports[0].type);
+
+ builder = new WasmModuleBuilder();
+ builder.addTable(kWasmAnyFunc, 15, 25).exportAs("b");
+ module = new WebAssembly.Module(builder.toBuffer());
+ exports = WebAssembly.Module.exports(module);
+
+ assertEquals("b", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals("anyfunc", exports[0].type.element);
+ assertEquals(15, exports[0].type.minimum);
+ assertEquals(25, exports[0].type.maximum);
+})();
+
+(function TestTableImports() {
+ let builder = new WasmModuleBuilder();
+ builder.addImportedTable("m", "a", 20, undefined, kWasmAnyFunc);
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let imports = WebAssembly.Module.imports(module);
+
+ assertEquals("a", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals("anyfunc", imports[0].type.element);
+ assertEquals(20, imports[0].type.minimum);
+ assertFalse("maximum" in imports[0].type);
+
+ builder = new WasmModuleBuilder();
+ builder.addImportedTable("m", "b", 15, 25, kWasmAnyFunc);
+ module = new WebAssembly.Module(builder.toBuffer());
+ imports = WebAssembly.Module.imports(module);
+
+ assertEquals("b", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals("anyfunc", imports[0].type.element);
+ assertEquals(15, imports[0].type.minimum);
+ assertEquals(25, imports[0].type.maximum);
+})();
+
(function TestGlobalType() {
let global = new WebAssembly.Global({value: "i32", mutable: true});
let type = WebAssembly.Global.type(global);
@@ -105,6 +201,44 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(2, Object.getOwnPropertyNames(type).length);
})();
+(function TestGlobalExports() {
+ let builder = new WasmModuleBuilder();
+ builder.addGlobal(kWasmI32).exportAs("a");
+ builder.addGlobal(kWasmF64, true).exportAs("b");
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let exports = WebAssembly.Module.exports(module);
+
+ assertEquals("a", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals("i32", exports[0].type.value);
+ assertEquals(false, exports[0].type.mutable);
+
+ assertEquals("b", exports[1].name);
+ assertTrue("type" in exports[1]);
+ assertEquals("f64", exports[1].type.value);
+ assertEquals(true, exports[1].type.mutable);
+})();
+
+(function TestGlobalImports() {
+ let builder = new WasmModuleBuilder();
+ builder.addImportedGlobal("m", "a", kWasmI32);
+ builder.addImportedGlobal("m", "b", kWasmF64, true);
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let imports = WebAssembly.Module.imports(module);
+
+ assertEquals("a", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals("i32", imports[0].type.value);
+ assertEquals(false, imports[0].type.mutable);
+
+ assertEquals("b", imports[1].name);
+ assertEquals("m", imports[1].module);
+ assertTrue("type" in imports[1]);
+ assertEquals("f64", imports[1].type.value);
+ assertEquals(true, imports[1].type.mutable);
+})();
+
(function TestMemoryConstructorWithMinimum() {
let mem = new WebAssembly.Memory({minimum: 1});
assertTrue(mem instanceof WebAssembly.Memory);
@@ -209,6 +343,42 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
() => new WebAssembly.Function({parameters:[], results:[]}, _ => 0));
})();
+(function TestFunctionConstructorNonArray1() {
+ let log = []; // Populated with a log of accesses.
+ let two = { toString: () => "2" }; // Just a fancy "2".
+ let logger = new Proxy({ length: two, "0": "i32", "1": "f32"}, {
+ get: function(obj, prop) { log.push(prop); return Reflect.get(obj, prop); },
+ set: function(obj, prop, val) { assertUnreachable(); }
+ });
+ let fun = new WebAssembly.Function({parameters:logger, results:[]}, _ => 0);
+ assertArrayEquals(["i32", "f32"], WebAssembly.Function.type(fun).parameters);
+ assertArrayEquals(["length", "0", "1"], log);
+})();
+
+(function TestFunctionConstructorNonArray2() {
+ let throw1 = { get length() { throw new Error("cannot see length"); }};
+ let throw2 = { length: { toString: _ => { throw new Error("no length") } } };
+ let throw3 = { length: "not a length value, this also throws" };
+ assertThrows(
+ () => new WebAssembly.Function({parameters:throw1, results:[]}), Error,
+ /cannot see length/);
+ assertThrows(
+ () => new WebAssembly.Function({parameters:throw2, results:[]}), Error,
+ /no length/);
+ assertThrows(
+ () => new WebAssembly.Function({parameters:throw3, results:[]}), TypeError,
+ /Argument 0 contains parameters without 'length'/);
+ assertThrows(
+ () => new WebAssembly.Function({parameters:[], results:throw1}), Error,
+ /cannot see length/);
+ assertThrows(
+ () => new WebAssembly.Function({parameters:[], results:throw2}), Error,
+ /no length/);
+ assertThrows(
+ () => new WebAssembly.Function({parameters:[], results:throw3}), TypeError,
+ /Argument 0 contains results without 'length'/);
+})();
+
(function TestFunctionConstructedFunction() {
let fun = new WebAssembly.Function({parameters:[], results:[]}, _ => 0);
assertTrue(fun instanceof WebAssembly.Function);
@@ -219,8 +389,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertSame(fun.__proto__.__proto__.__proto__, Object.prototype);
assertSame(fun.constructor, WebAssembly.Function);
assertEquals(typeof fun, 'function');
- // TODO(7742): Enable once it is callable.
- // assertDoesNotThrow(() => fun());
+ assertDoesNotThrow(() => fun());
})();
(function TestFunctionExportedFunction() {
@@ -271,6 +440,88 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
});
})();
+(function TestFunctionExports() {
+ let testcases = [
+ [kSig_v_v, {parameters:[], results:[]}],
+ [kSig_v_i, {parameters:["i32"], results:[]}],
+ [kSig_i_l, {parameters:["i64"], results:["i32"]}],
+ [kSig_v_ddi, {parameters:["f64", "f64", "i32"], results:[]}],
+ [kSig_f_f, {parameters:["f32"], results:["f32"]}],
+ ];
+ testcases.forEach(function([sig, expected]) {
+ let builder = new WasmModuleBuilder();
+ builder.addFunction("fun", sig).addBody([kExprUnreachable]).exportFunc();
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let exports = WebAssembly.Module.exports(module);
+ assertEquals("fun", exports[0].name);
+ assertTrue("type" in exports[0]);
+ assertEquals(expected, exports[0].type);
+ });
+})();
+
+(function TestFunctionImports() {
+ let testcases = [
+ [kSig_v_v, {parameters:[], results:[]}],
+ [kSig_v_i, {parameters:["i32"], results:[]}],
+ [kSig_i_l, {parameters:["i64"], results:["i32"]}],
+ [kSig_v_ddi, {parameters:["f64", "f64", "i32"], results:[]}],
+ [kSig_f_f, {parameters:["f32"], results:["f32"]}],
+ ];
+ testcases.forEach(function([sig, expected]) {
+ let builder = new WasmModuleBuilder();
+ builder.addImport("m", "fun", sig);
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let imports = WebAssembly.Module.imports(module);
+ assertEquals("fun", imports[0].name);
+ assertEquals("m", imports[0].module);
+ assertTrue("type" in imports[0]);
+ assertEquals(expected, imports[0].type);
+ });
+})();
+
+(function TestFunctionConstructedCoercions() {
+ let obj1 = { valueOf: _ => 123.45 };
+ let obj2 = { toString: _ => "456" };
+ let gcer = { valueOf: _ => gc() };
+ let testcases = [
+ { params: { sig: ["i32"],
+ val: [23.5],
+ exp: [23], },
+ result: { sig: ["i32"],
+ val: 42.7,
+ exp: 42, },
+ },
+ { params: { sig: ["i32", "f32", "f64"],
+ val: [obj1, obj2, "789"],
+ exp: [123, 456, 789], },
+ result: { sig: [],
+ val: undefined,
+ exp: undefined, },
+ },
+ { params: { sig: ["i32", "f32", "f64"],
+ val: [gcer, {}, "xyz"],
+ exp: [0, NaN, NaN], },
+ result: { sig: ["f64"],
+ val: gcer,
+ exp: NaN, },
+ },
+ ];
+ testcases.forEach(function({params, result}) {
+ let p = params.sig; let r = result.sig; var params_after;
+ function testFun() { params_after = arguments; return result.val; }
+ let fun = new WebAssembly.Function({parameters:p, results:r}, testFun);
+ let result_after = fun.apply(undefined, params.val);
+ assertArrayEquals(params.exp, params_after);
+ assertEquals(result.exp, result_after);
+ });
+})();
+
+(function TestFunctionConstructedIncompatibleSig() {
+ let fun = new WebAssembly.Function({parameters:["i64"], results:[]}, _ => 0);
+ assertThrows(() => fun(), TypeError,
+ /wasm function signature contains illegal type/);
+})();
+
(function TestFunctionTableSetAndCall() {
let builder = new WasmModuleBuilder();
let fun1 = new WebAssembly.Function({parameters:[], results:["i32"]}, _ => 7);
@@ -353,3 +604,14 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
() => builder.instantiate({ m: { fun: fun3 }}), WebAssembly.LinkError,
/imported function does not match the expected type/);
})();
+
+(function TestFunctionModuleImportReExport () {
+ let builder = new WasmModuleBuilder();
+ let fun = new WebAssembly.Function({parameters:[], results:["i32"]}, _ => 7);
+ let fun_index = builder.addImport("m", "fun", kSig_i_v)
+ builder.addExport("fun1", fun_index);
+ builder.addExport("fun2", fun_index);
+ let instance = builder.instantiate({ m: { fun: fun }});
+ assertSame(instance.exports.fun1, instance.exports.fun2);
+ assertSame(fun, instance.exports.fun1);
+})();
diff --git a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js
index 8e423bd24f..45af969d09 100644
--- a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js
+++ b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js
@@ -552,7 +552,7 @@ class Binary {
this.buffer[this.length++] = val >> 24;
}
- emit_leb(val, max_len) {
+ emit_leb_u(val, max_len) {
this.ensure_space(max_len);
for (let i = 0; i < max_len; ++i) {
let v = val & 0xff;
@@ -567,11 +567,11 @@ class Binary {
}
emit_u32v(val) {
- this.emit_leb(val, kMaxVarInt32Size);
+ this.emit_leb_u(val, kMaxVarInt32Size);
}
emit_u64v(val) {
- this.emit_leb(val, kMaxVarInt64Size);
+ this.emit_leb_u(val, kMaxVarInt64Size);
}
emit_bytes(data) {
@@ -1384,13 +1384,24 @@ class WasmModuleBuilder {
}
}
-function wasmI32Const(val) {
- let bytes = [kExprI32Const];
- for (let i = 0; i < 4; ++i) {
- bytes.push(0x80 | ((val >> (7 * i)) & 0x7f));
+function wasmSignedLeb(val, max_len = 5) {
+ let res = [];
+ for (let i = 0; i < max_len; ++i) {
+ let v = val & 0x7f;
+ // If {v} sign-extended from 7 to 32 bits is equal to val, we are done.
+ if (((v << 25) >> 25) == val) {
+ res.push(v);
+ return res;
+ }
+ res.push(v | 0x80);
+ val = val >> 7;
}
- bytes.push((val >> (7 * 4)) & 0x7f);
- return bytes;
+ throw new Error(
+ 'Leb value <' + val + '> exceeds maximum length of ' + max_len);
+}
+
+function wasmI32Const(val) {
+ return [kExprI32Const, ...wasmSignedLeb(val, 5)];
}
function wasmF32Const(f) {