|
4 | 4 | */ |
5 | 5 | "use strict"; |
6 | 6 |
|
7 | | -const Queue = require("../util/Queue"); |
8 | | -const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); |
9 | 7 | const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError"); |
10 | 8 |
|
| 9 | +const error = new UnsupportedWebAssemblyFeatureError( |
| 10 | + "JavaScript modules can not use a WebAssembly export with an incompatible type signature" |
| 11 | +); |
| 12 | + |
11 | 13 | class WasmFinalizeExportsPlugin { |
12 | 14 | apply(compiler) { |
13 | 15 | compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => { |
14 | 16 | compilation.hooks.finishModules.tap( |
15 | 17 | "WasmFinalizeExportsPlugin", |
16 | 18 | modules => { |
17 | | - const queue = new Queue(); |
18 | | - |
19 | | - let module; |
20 | | - let jsIncompatibleExports = []; |
21 | | - |
22 | 19 | 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; |
27 | 28 | } |
28 | 29 |
|
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 = []; |
31 | 40 |
|
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 | + }); |
47 | 48 | } |
48 | 49 | } |
49 | 50 | } |
|
0 commit comments