]> git.lizzy.rs Git - rust.git/blob - src/etc/wasm32-shim.js
allow quick-edit convenience
[rust.git] / src / etc / wasm32-shim.js
1 // This is a small "shim" program which is used when wasm32 unit tests are run
2 // in this repository. This program is intended to be run in node.js and will
3 // load a wasm module into memory, instantiate it with a set of imports, and
4 // then run it.
5 //
6 // There's a bunch of helper functions defined here in `imports.env`, but note
7 // that most of them aren't actually needed to execute most programs. Many of
8 // these are just intended for completeness or debugging. Hopefully over time
9 // nothing here is needed for completeness.
10
11 const fs = require('fs');
12 const process = require('process');
13 const buffer = fs.readFileSync(process.argv[2]);
14
15 Error.stackTraceLimit = 20;
16
17 let m = new WebAssembly.Module(buffer);
18 let instance = new WebAssembly.Instance(m, {});
19 try {
20   instance.exports.main();
21 } catch (e) {
22   console.error(e);
23   process.exit(101);
24 }