Merge pull request #7419 from webpack/bugfix/wasm-multi-direct

fix a code generation bug and add test cases
This commit is contained in:
Tobias Koppers 2018-05-29 00:55:31 +02:00 committed by GitHub
commit 67fa81f5c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 1 deletions

View File

@ -96,7 +96,7 @@ function generateImportObject(module) {
).join(", ");
const variables = Array.from(
waitForInstances.keys(),
(name, i) => `${name} = array[${i}];`
(name, i) => `${name} = array[${i}]`
).join(", ");
return Template.asString([
`${JSON.stringify(module.id)}: function() {`,

View File

@ -0,0 +1,6 @@
it("should allow to run a WebAssembly module with many direct wasm dependencies", function() {
return import("./wasm.wat").then(function(wasm) {
const result = wasm.testI64();
expect(result).toEqual(42);
});
});

View File

@ -0,0 +1,7 @@
(module
(type $t0 (func (param i64) (result i64)))
(func $getI64 (type $t0) (param $p0 i64) (result i64)
get_local $p0
i64.const 20
i64.add)
(export "getI64" (func $getI64)))

View File

@ -0,0 +1,7 @@
(module
(type $t0 (func (param i64) (result i64)))
(func $getI64 (type $t0) (param $p0 i64) (result i64)
get_local $p0
i64.const 22
i64.add)
(export "getI64" (func $getI64)))

View File

@ -0,0 +1,5 @@
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
module.exports = function(config) {
return supportsWebAssembly();
};

View File

@ -0,0 +1,13 @@
(module
(type $t0 (func (param i64) (result i64)))
(type $t1 (func (result i32)))
(import "./other1.wat" "getI64" (func $getI641 (type $t0)))
(import "./other2.wat" "getI64" (func $getI642 (type $t0)))
(func $testI64 (type $t1) (result i32)
i64.const 1152921504606846976
call $getI641
call $getI642
i64.const 1152921504606846976
i64.sub
i32.wrap/i64)
(export "testI64" (func $testI64)))

View File

@ -0,0 +1,6 @@
it("should allow wasm with unused exports", function() {
return import("./module").then(function(module) {
const result = module.run();
expect(result).toEqual(42);
});
});

View File

@ -0,0 +1,5 @@
import { getNumber } from "./wasm.wat";
export function run() {
return getNumber();
}

View File

@ -0,0 +1,5 @@
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
module.exports = function(config) {
return supportsWebAssembly();
};

View File

@ -0,0 +1,10 @@
(module
(type $t0 (func (param i32 i32) (result i32)))
(type $t1 (func (result i32)))
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
(i32.add
(get_local $p0)
(get_local $p1)))
(func $getNumber (export "getNumber") (type $t1) (result i32)
(i32.const 42)))