Skip to content

Commit aaac76a

Browse files
committed
feat: throw when Memory or Table import
1 parent 04eedb1 commit aaac76a

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

lib/BaseWasmMainTemplatePlugin.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,18 @@ function generateImportObject(module) {
5353
for (const pair of depsByRequest) {
5454
const properties = [];
5555
for (const data of pair[1]) {
56-
let params = "";
57-
let result = "void 0";
58-
59-
if (data.description.type === "FuncImportDescr") {
60-
params = data.description.params.map(
61-
(param, k) => "p" + k + param.valtype
62-
);
56+
const params = data.description.params.map(
57+
(param, k) => "p" + k + param.valtype
58+
);
6359

64-
result = `__webpack_require__(${JSON.stringify(
65-
data.module.id
66-
)})[${JSON.stringify(data.usedName)}](${params})`;
67-
}
60+
const result = `__webpack_require__(${JSON.stringify(
61+
data.module.id
62+
)})[${JSON.stringify(data.usedName)}](${params})`;
6863

6964
properties.push(
7065
`\n\t\t${JSON.stringify(data.exportName)}: function(${params}) {
71-
return ${result};
72-
}`
66+
return ${result};
67+
}`
7368
);
7469
}
7570

lib/WebAssemblyParser.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ const { decode } = require("@webassemblyjs/wasm-parser");
1010
const { Tapable } = require("tapable");
1111
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
1212

13+
const isMemoryImport = moduleImport => moduleImport.descr.type === "Memory";
14+
const isTableImport = moduleImport => moduleImport.descr.type === "Table";
15+
1316
const decoderOpts = {
1417
ignoreCodeSection: true,
1518
ignoreDataSection: true
1619
};
1720

21+
function nonSupportImportOfType(type) {
22+
const e = new Error("Unsupported import of type " + JSON.stringify(type));
23+
e.stack = "";
24+
25+
return e;
26+
}
27+
1828
class WebAssemblyParser extends Tapable {
1929
constructor(options) {
2030
super();
@@ -37,6 +47,16 @@ class WebAssemblyParser extends Tapable {
3747
},
3848

3949
ModuleImport({ node }) {
50+
// Prevent importing a Memory or Table for now
51+
// Depends on https://github.com/WebAssembly/esm-integration
52+
if (isMemoryImport(node) === true) {
53+
throw nonSupportImportOfType("Memory");
54+
}
55+
56+
if (isTableImport(node) === true) {
57+
throw nonSupportImportOfType("Table");
58+
}
59+
4060
const dep = new WebAssemblyImportDependency(
4161
node.module,
4262
node.name,

0 commit comments

Comments
 (0)