summaryrefslogtreecommitdiffstats
path: root/src/etc/wasm32-shim.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/etc/wasm32-shim.js
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/etc/wasm32-shim.js')
-rw-r--r--src/etc/wasm32-shim.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/etc/wasm32-shim.js b/src/etc/wasm32-shim.js
new file mode 100644
index 000000000..262a53eab
--- /dev/null
+++ b/src/etc/wasm32-shim.js
@@ -0,0 +1,24 @@
+// This is a small "shim" program which is used when wasm32 unit tests are run
+// in this repository. This program is intended to be run in node.js and will
+// load a wasm module into memory, instantiate it with a set of imports, and
+// then run it.
+//
+// There's a bunch of helper functions defined here in `imports.env`, but note
+// that most of them aren't actually needed to execute most programs. Many of
+// these are just intended for completeness or debugging. Hopefully over time
+// nothing here is needed for completeness.
+
+const fs = require('fs');
+const process = require('process');
+const buffer = fs.readFileSync(process.argv[2]);
+
+Error.stackTraceLimit = 20;
+
+let m = new WebAssembly.Module(buffer);
+let instance = new WebAssembly.Instance(m, {});
+try {
+ instance.exports.main();
+} catch (e) {
+ console.error(e);
+ process.exit(101);
+}