wasm: add //go:wasmexport support to js/wasm

This adds support for //go:wasmexport with `-target=wasm` (in the
browser). This follows the //go:wasmexport proposal, meaning that
blocking functions are not allowed.

Both `-buildmode=default` and `-buildmode=c-shared` are supported. The
latter allows calling exported functions after `go.run()` has returned.
This commit is contained in:
Ayke van Laethem
2024-10-03 17:58:48 +02:00
committed by Ron Evans
parent 6016d0c739
commit 4ef5109a07
5 changed files with 94 additions and 28 deletions
+6 -13
View File
@@ -466,20 +466,13 @@
this._idPool = []; // unused ids that have been garbage collected
this.exited = false; // whether the Go program has exited
while (true) {
const callbackPromise = new Promise((resolve) => {
this._resolveCallbackPromise = () => {
if (this.exited) {
throw new Error("bad callback: Go program has already exited");
}
setTimeout(resolve, 0); // make sure it is asynchronous
};
});
if (this._inst.exports._start) {
this._inst.exports._start();
if (this.exited) {
break;
}
await callbackPromise;
// TODO: wait until the program exists.
await new Promise(() => {});
} else {
this._inst.exports._initialize();
}
}