Skip to content

Commit 67fa81f

Browse files
authored
Merge pull request webpack#7419 from webpack/bugfix/wasm-multi-direct
fix a code generation bug and add test cases
2 parents 1f2584e + e367b93 commit 67fa81f

File tree

10 files changed

+65
-1
lines changed

10 files changed

+65
-1
lines changed

lib/wasm/WasmMainTemplatePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function generateImportObject(module) {
9696
).join(", ");
9797
const variables = Array.from(
9898
waitForInstances.keys(),
99-
(name, i) => `${name} = array[${i}];`
99+
(name, i) => `${name} = array[${i}]`
100100
).join(", ");
101101
return Template.asString([
102102
`${JSON.stringify(module.id)}: function() {`,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should allow to run a WebAssembly module with many direct wasm dependencies", function() {
2+
return import("./wasm.wat").then(function(wasm) {
3+
const result = wasm.testI64();
4+
expect(result).toEqual(42);
5+
});
6+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(module
2+
(type $t0 (func (param i64) (result i64)))
3+
(func $getI64 (type $t0) (param $p0 i64) (result i64)
4+
get_local $p0
5+
i64.const 20
6+
i64.add)
7+
(export "getI64" (func $getI64)))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(module
2+
(type $t0 (func (param i64) (result i64)))
3+
(func $getI64 (type $t0) (param $p0 i64) (result i64)
4+
get_local $p0
5+
i64.const 22
6+
i64.add)
7+
(export "getI64" (func $getI64)))
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+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(module
2+
(type $t0 (func (param i64) (result i64)))
3+
(type $t1 (func (result i32)))
4+
(import "./other1.wat" "getI64" (func $getI641 (type $t0)))
5+
(import "./other2.wat" "getI64" (func $getI642 (type $t0)))
6+
(func $testI64 (type $t1) (result i32)
7+
i64.const 1152921504606846976
8+
call $getI641
9+
call $getI642
10+
i64.const 1152921504606846976
11+
i64.sub
12+
i32.wrap/i64)
13+
(export "testI64" (func $testI64)))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should allow wasm with unused exports", function() {
2+
return import("./module").then(function(module) {
3+
const result = module.run();
4+
expect(result).toEqual(42);
5+
});
6+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { getNumber } from "./wasm.wat";
2+
3+
export function run() {
4+
return getNumber();
5+
}
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+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(module
2+
(type $t0 (func (param i32 i32) (result i32)))
3+
(type $t1 (func (result i32)))
4+
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
5+
(i32.add
6+
(get_local $p0)
7+
(get_local $p1)))
8+
(func $getNumber (export "getNumber") (type $t1) (result i32)
9+
(i32.const 42)))
10+

0 commit comments

Comments
 (0)