Skip to content

Commit 2c07ba0

Browse files
author
Mauro Bringolf
committed
Implement functional tests for i32 polyfills
1 parent c7b349d commit 2c07ba0

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

packages/proposal-sign-extension-ops/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@webassemblyjs/helper-test-framework": "1.5.6",
3030
"@webassemblyjs/wast-parser": "1.5.6",
3131
"@webassemblyjs/wasm-parser": "1.5.6",
32-
"@webassemblyjs/wast-printer": "1.5.6"
32+
"@webassemblyjs/wast-printer": "1.5.6",
33+
"wabt": "1.0.0"
3334
}
3435
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const path = require("path");
2+
const wabt = require("wabt");
3+
const assert = require("assert");
4+
5+
const { readFileSync } = require("fs");
6+
7+
const polyfills = [
8+
{
9+
name: "i32_extend8_s",
10+
fixtures: [
11+
[0, 0],
12+
[0x7f, 127],
13+
[0x80, -128],
14+
[0xff, -1],
15+
[0x01234500, 0],
16+
[0xfedcba80, -0x80],
17+
[-1, -1]
18+
]
19+
},
20+
{
21+
name: "i32_extend16_s",
22+
fixtures: [
23+
[0, 0],
24+
[0x7fff, 32767],
25+
[0x8000, -32768],
26+
[0xffff, -1],
27+
[0x01230000, 0],
28+
[0xfedc8000, -0x8000],
29+
[-1, -1]
30+
]
31+
}
32+
];
33+
34+
polyfills.forEach(p => {
35+
p.path = path.join(__dirname, `../lib/polyfills/${p.name}.wast`);
36+
});
37+
38+
polyfills.forEach(polyfill => {
39+
describe(polyfill.path, () => {
40+
const wast = readFileSync(polyfill.path, "utf8").trim();
41+
const wasm = wabt
42+
.parseWat(polyfill.path, wast)
43+
.toBinary({ write_debug_names: false });
44+
45+
it("should return correct values", () => {
46+
return WebAssembly.instantiate(wasm.buffer).then(result => {
47+
const polyfillFn = result.instance.exports[polyfill.name];
48+
polyfill.fixtures.forEach(([input, output]) => {
49+
assert.equal(output, polyfillFn(input));
50+
});
51+
});
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)