Skip to content

Commit edddefb

Browse files
committed
add test cases for decoding wasm
1 parent 2df9630 commit edddefb

File tree

10 files changed

+53
-0
lines changed

10 files changed

+53
-0
lines changed

test/cases/wasm/decoding/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
it("should support wasm compiled from c++", function() {
2+
return import("./memory3.wasm").then(function(wasm) {
3+
expect(wasm._Z3getv()).toBe(0);
4+
wasm._Z3seti(42);
5+
expect(wasm._Z3getv()).toBe(42);
6+
});
7+
});
8+
9+
it("should raw memory export without data", function() {
10+
return import("./memory2.wasm").then(function(wasm) {
11+
expect(wasm.memory).toBeInstanceOf(WebAssembly.Memory);
12+
expect(wasm.memory.buffer).toBeInstanceOf(ArrayBuffer);
13+
expect(wasm.memory.buffer.byLength).toBe(1 << 16);
14+
});
15+
});
35 Bytes
Binary file not shown.
143 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};

test/cases/wasm/table/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
it("should support tables", function() {
2+
return import("./wasm-table.wasm").then(function(wasm) {
3+
expect(wasm.callByIndex(0)).toEqual(42);
4+
expect(wasm.callByIndex(1)).toEqual(13);
5+
expect(() => wasm.callByIndex(2)).toThrow("fefef");
6+
});
7+
});
8+
9+
it("should support exported tables", function() {
10+
return import("./wasm-table-export.wasm").then(function(wasm) {
11+
expect(wasm.table).toBeInstanceOf(WebAssembly.Table);
12+
expect(wasm.table.length).toBe(2);
13+
const e0 = wasm.table.get(0);
14+
const e1 = wasm.table.get(1);
15+
expect(e0).toBeInstanceOf(Function);
16+
expect(e1).toBeInstanceOf(Function);
17+
expect(e0()).toEqual(42);
18+
expect(e1()).toEqual(13);
19+
});
20+
});
21+
22+
it("should support imported tables", function() {
23+
return import("./wasm-table-imported.wasm").then(function(wasm) {
24+
expect(wasm.callByIndex(0)).toEqual(42);
25+
expect(wasm.callByIndex(1)).toEqual(13);
26+
expect(() => wasm.callByIndex(2)).toThrow("fefef");
27+
});
28+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};
85 Bytes
Binary file not shown.
56 Bytes
Binary file not shown.
105 Bytes
Binary file not shown.
84 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)