Skip to content

Commit b34ed23

Browse files
committed
fix: address some comments
1 parent 24a9574 commit b34ed23

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

lib/wasm/WasmFinalizeExportsPlugin.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,47 @@
44
*/
55
"use strict";
66

7-
const Queue = require("../util/Queue");
8-
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
97
const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError");
108

9+
const error = new UnsupportedWebAssemblyFeatureError(
10+
"JavaScript modules can not use a WebAssembly export with an incompatible type signature"
11+
);
12+
1113
class WasmFinalizeExportsPlugin {
1214
apply(compiler) {
1315
compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => {
1416
compilation.hooks.finishModules.tap(
1517
"WasmFinalizeExportsPlugin",
1618
modules => {
17-
const queue = new Queue();
18-
19-
let module;
20-
let jsIncompatibleExports = [];
21-
2219
for (const module of modules) {
23-
if (module.buildMeta.jsIncompatibleExports) {
24-
jsIncompatibleExports.push(
25-
...module.buildMeta.jsIncompatibleExports
26-
);
20+
const jsIncompatibleExports =
21+
module.buildMeta.jsIncompatibleExports;
22+
23+
if (
24+
typeof jsIncompatibleExports === "undefined" ||
25+
jsIncompatibleExports.length === 0
26+
) {
27+
continue;
2728
}
2829

29-
queue.enqueue(module);
30-
}
30+
// 1. if a WebAssembly module
31+
if (module.type.startsWith("webassembly") === true) {
32+
for (const reason of module.reasons) {
33+
// 2. is referenced by a non-WebAssembly module
34+
if (reason.module.type.startsWith("webassembly") === false) {
35+
// const ref = reason.dependency.getReference();
36+
37+
// ref.importedNames // returns true?
38+
39+
const names = [];
3140

32-
while (queue.length > 0) {
33-
module = queue.dequeue();
34-
35-
// 1. if a non WebAssembly module
36-
if (module.type.startsWith("webassembly") === false) {
37-
for (const dep of module.dependencies) {
38-
// 2. imports a WebAssembly module
39-
// FIXME(sven): pseudo code from here
40-
if (dep.type === "webassembly") {
41-
// 3. if the used import is flaged as invalid
42-
if (jsIncompatibleExports.indexOf(dep.usedName)) {
43-
throw new UnsupportedWebAssemblyFeatureError(
44-
"JavaScript modules can not use WebAssembly export with an incompatible type signature"
45-
);
46-
}
41+
names.forEach(name => {
42+
// 3. and uses a func with an incompatible JS signature
43+
if (jsIncompatibleExports.indexOf(name) !== -1) {
44+
// 4. error
45+
compilation.errors.push(error);
46+
}
47+
});
4748
}
4849
}
4950
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
it("should disallow exporting a func signature with result i64", function() {
2-
return expect(import("./export-i64-result.wat")).rejects.toThrow(/invalid type/);
2+
return import("./export-i64-result.wat").then(({a}) => {
3+
expect(a).toThrow(/invalid type/);
4+
});
35
});
46

57
it("should disallow exporting a func signature with param i64", function() {
6-
return expect(import("./export-i64-param.wat")).rejects.toThrow(/invalid type/);
8+
return import("./export-i64-param.wat").then(({a}) => {
9+
expect(a).toThrow(/invalid type/);
10+
});
711
});
812

913
it("should disallow importing a value type of i64", function() {
10-
return expect(import("./import-i64.wat")).rejects.toThrow(/invalid type/);
14+
return expect(import("./import-i64.wat")).rejects.toThrow(/invalid type/);
1115
});

0 commit comments

Comments
 (0)