forked from devsnek/node-wasi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
executable file
·45 lines (34 loc) · 843 Bytes
/
run.js
File metadata and controls
executable file
·45 lines (34 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
'use strict';
/**
* A simple WASI runner which exposes the
* full environment and arguments to the
* WASI binary.
*
* :wasm:M::\x00\x61\x73\x6d::wasi:
*/
const fs = require('fs');
const WASI = require('.');
if (!process.argv[2]) {
process.stdout.write(`wasi runner
A simple WASI runner which exposes the full
environment, arguments, and cwd to the WASI
binary.
:wasm:M::\\x00\\x61\\x73\\x6d::wasi:
USAGE:
wasi <file> ...
`);
process.exit(1);
}
const bin = fs.readFileSync(process.argv[2]);
const mod = new WebAssembly.Module(bin);
const wasi = new WASI({
preopenDirectories: { '.': '.' },
env: process.env,
args: process.argv.slice(2),
});
const instance = new WebAssembly.Instance(mod, {
wasi_unstable: wasi.exports,
});
wasi.setMemory(instance.exports.memory);
instance.exports._start();