Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7447 from xtuc/fix-wasm-check-for-invalid-signatures
wasm: finalizer for checking exports
- Loading branch information
Showing
20 changed files
with
215 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
"use strict"; | ||
|
||
const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError"); | ||
|
||
class WasmFinalizeExportsPlugin { | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => { | ||
compilation.hooks.finishModules.tap( | ||
"WasmFinalizeExportsPlugin", | ||
modules => { | ||
for (const module of modules) { | ||
// 1. if a WebAssembly module | ||
if (module.type.startsWith("webassembly") === true) { | ||
const jsIncompatibleExports = | ||
module.buildMeta.jsIncompatibleExports; | ||
|
||
if (jsIncompatibleExports === undefined) { | ||
continue; | ||
} | ||
|
||
for (const reason of module.reasons) { | ||
// 2. is referenced by a non-WebAssembly module | ||
if (reason.module.type.startsWith("webassembly") === false) { | ||
const ref = reason.dependency.getReference(); | ||
|
||
const importedNames = ref.importedNames; | ||
|
||
if (Array.isArray(importedNames)) { | ||
importedNames.forEach(name => { | ||
// 3. and uses a func with an incompatible JS signature | ||
if ( | ||
Object.prototype.hasOwnProperty.call( | ||
jsIncompatibleExports, | ||
name | ||
) | ||
) { | ||
// 4. error | ||
/** @type {any} */ | ||
const error = new UnsupportedWebAssemblyFeatureError( | ||
`Export "${name}" with ${ | ||
jsIncompatibleExports[name] | ||
} can only be used for direct wasm to wasm dependencies` | ||
); | ||
error.module = module; | ||
error.origin = reason.module; | ||
error.originLoc = reason.dependency.loc; | ||
error.dependencies = [reason.dependency]; | ||
compilation.errors.push(error); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = WasmFinalizeExportsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const n = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = [ | ||
[ | ||
/export-i64-param\.wat/, | ||
/Export "a" with i64 as parameter can only be used for direct wasm to wasm dependencies/, | ||
/export-i64-param\.js/ | ||
], | ||
[ | ||
/export-i64-result\.wat/, | ||
/Export "a" with i64 as result can only be used for direct wasm to wasm dependencies/, | ||
/export-i64-result\.js/ | ||
], | ||
[ | ||
/import-i64\.wat/, | ||
/Import "n" from "\.\/env.js" with Non-JS-compatible Global Type \(i64\) can only be used for direct wasm to wasm dependencies/, | ||
/index\.js/ | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { a } from "./export-i64-param.wat"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(module | ||
(func (export "a") (param i64) (nop)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { a } from "./export-i64-result.wat"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(module | ||
(func (export "a") (result i64) | ||
(i64.const 1) | ||
) | ||
) |
Oops, something went wrong.