summaryrefslogtreecommitdiff
path: root/src/tools/js-wrapper.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-12-27 15:24:57 -0800
committerGitHub <noreply@github.com>2018-12-27 15:24:57 -0800
commit3f3fc857ff6204517281ed5caa3209cc8f02d4fc (patch)
treeb64969a33874f29d5f35ea546c69eda90f89edf4 /src/tools/js-wrapper.h
parentfdd4cb7b11d43c6ff200c9541f8567000a8d4bcd (diff)
downloadbinaryen-3f3fc857ff6204517281ed5caa3209cc8f02d4fc.tar.gz
binaryen-3f3fc857ff6204517281ed5caa3209cc8f02d4fc.tar.bz2
binaryen-3f3fc857ff6204517281ed5caa3209cc8f02d4fc.zip
Fix fuzzing JS glue code (#1843)
After we added logging to the fuzzer, we forgot to add to the JS glue code the necessary imports so it can be run there too. Also adds legalization for the JS glue code imports and exports. Also adds a missing validator check on imports having a function type (the fuzzing code was missing one). Fixes #1842
Diffstat (limited to 'src/tools/js-wrapper.h')
-rw-r--r--src/tools/js-wrapper.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/tools/js-wrapper.h b/src/tools/js-wrapper.h
index cb5c0bd5b..7cf2ffc53 100644
--- a/src/tools/js-wrapper.h
+++ b/src/tools/js-wrapper.h
@@ -22,10 +22,15 @@
namespace wasm {
static std::string generateJSWrapper(Module& wasm) {
+ PassRunner runner(&wasm);
+ runner.add("legalize-js-interface");
+ runner.run();
+
std::string ret;
ret += "if (typeof console === 'undefined') {\n"
" console = { log: print };\n"
"}\n"
+ "var tempRet0;\n"
"var binary;\n"
"if (typeof process === 'object' && typeof require === 'function' /* node.js detection */) {\n"
" var args = process.argv.slice(2);\n"
@@ -44,7 +49,18 @@ static std::string generateJSWrapper(Module& wasm) {
" binary = read(args[0], 'binary');\n"
" }\n"
"}\n"
- "var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), {});\n";
+ "var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), {\n"
+ " 'fuzzing-support': {\n"
+ " 'log-i32': function(x) { console.log('i32: ' + x) },\n"
+ " 'log-i64': function(x, y) { console.log('i64: ' + x + ', ' + y) },\n"
+ " 'log-f32': function(x) { console.log('f32: ' + x) },\n"
+ " 'log-f64': function(x) { console.log('f64: ' + x) }\n"
+ " },\n"
+ " 'env': {\n"
+ " 'setTempRet0': function(x) { tempRet0 = x },\n"
+ " 'getTempRet0': function() { return tempRet0 },\n"
+ " },\n"
+ "});\n";
for (auto& exp : wasm.exports) {
auto* func = wasm.getFunctionOrNull(exp->value);
if (!func) continue; // something exported other than a function