mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
The upgrade to NodeJS 18 introduces various library updates that mean we can no longer override the global performance package. Instead, rely on the performance library provided by the NodeJS runtime. Fixes #57516 Change-Id: Ic8ed902c696ad154f676e0b74b42efb84f02f8db Reviewed-on: https://go-review.googlesource.com/c/go/+/463234 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Evan Phoenix <evan@phx.io> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
// 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.TextEncoder = require("util").TextEncoder;
|
|
globalThis.TextDecoder = require("util").TextDecoder;
|
|
|
|
globalThis.performance ??= require("performance");
|
|
|
|
const crypto = require("crypto");
|
|
globalThis.crypto = {
|
|
getRandomValues(b) {
|
|
crypto.randomFillSync(b);
|
|
},
|
|
};
|
|
|
|
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);
|
|
});
|