Skip to content

Commit e723e46

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

File tree

2 files changed

+61
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)