1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 if (process.argv.length < 3) {
8 console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
12 globalThis.require = require;
13 globalThis.fs = require("fs");
14 globalThis.TextEncoder = require("util").TextEncoder;
15 globalThis.TextDecoder = require("util").TextDecoder;
17 globalThis.performance ??= require("performance");
19 const crypto = require("crypto");
22 crypto.randomFillSync(b);
26 require("./wasm_exec");
29 go.argv = process.argv.slice(2);
30 go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
31 go.exit = process.exit;
32 WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
33 process.on("exit", (code) => { // Node.js exits if no event handler is pending
34 if (code === 0 && !go.exited) {
35 // deadlock, make Go print error and stack traces
36 go._pendingEvent = { id: 0 };
40 return go.run(result.instance);