feat: add wasm_exec_node.js for Node.js support in WebAssembly execution
Some checks failed
Go Build Multi-Platform / build (amd64, darwin) (push) Successful in 36s
Bearer / scan (push) Failing after 38s
Go Build Multi-Platform / build (amd64, linux) (push) Successful in 32s
Go Build Multi-Platform / build (amd64, freebsd) (push) Successful in 34s
Go Build Multi-Platform / build (arm64, linux) (push) Successful in 52s
Go Build Multi-Platform / build (wasm, js) (push) Successful in 48s
Go Build Multi-Platform / build (arm64, windows) (push) Successful in 50s
TinyGo Build / tinygo-build (tinygo-build, tinygo-default, reticulum-go-tinygo, ) (pull_request) Failing after 46s
TinyGo Build / tinygo-build (tinygo-wasm, tinygo-wasm, reticulum-go.wasm, wasm) (pull_request) Failing after 59s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Successful in 59s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Failing after 1m33s
Run Gosec / tests (push) Successful in 1m45s
Go Revive Lint / lint (push) Successful in 52s
Go Build Multi-Platform / build (amd64, windows) (push) Successful in 9m23s
Go Build Multi-Platform / build (arm, freebsd) (push) Successful in 9m25s
Go Build Multi-Platform / build (arm, linux) (push) Successful in 9m23s
Go Build Multi-Platform / build (arm, windows) (push) Successful in 9m25s
Go Build Multi-Platform / build (arm64, darwin) (push) Successful in 9m23s
Go Build Multi-Platform / build (arm64, freebsd) (push) Successful in 9m25s
Go Build Multi-Platform / Create Release (push) Has been skipped

This commit is contained in:
2025-12-30 19:27:24 -06:00
parent 1ad1f3cfd2
commit 4ea1fd1f28

View File

@@ -0,0 +1,40 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
"use strict";
if (process.argv.length < 3) {
console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
process.exit(1);
}
globalThis.require = require;
globalThis.fs = require("fs");
globalThis.path = require("path");
globalThis.TextEncoder = require("util").TextEncoder;
globalThis.TextDecoder = require("util").TextDecoder;
globalThis.performance ??= require("performance");
globalThis.crypto ??= require("crypto");
require("./wasm_exec");
const go = new Go();
go.argv = process.argv.slice(2);
go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
go.exit = process.exit;
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
process.on("exit", (code) => { // Node.js exits if no event handler is pending
if (code === 0 && !go.exited) {
// deadlock, make Go print error and stack traces
go._pendingEvent = { id: 0 };
go._resume();
}
});
return go.run(result.instance);
}).catch((err) => {
console.error(err);
process.exit(1);
});