mirror of
https://github.com/syumai/workers.git
synced 2025-03-11 01:39:11 +00:00
update wasm_exec_tinygo.js
This commit is contained in:
parent
31604756b7
commit
d3a0b9f41e
@ -24,17 +24,13 @@
|
|||||||
throw new Error("cannot export Go (neither global, window nor self is defined)");
|
throw new Error("cannot export Go (neither global, window nor self is defined)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (!global.require && typeof require !== "undefined") {
|
if (!global.require && typeof require !== "undefined") {
|
||||||
global.require = require;
|
global.require = require;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!global.fs && global.require) {
|
if (!global.fs && global.require) {
|
||||||
global.fs = require("fs");
|
global.fs = require("node:fs");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
const enosys = () => {
|
const enosys = () => {
|
||||||
const err = new Error("not implemented");
|
const err = new Error("not implemented");
|
||||||
@ -104,16 +100,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (!global.crypto) {
|
if (!global.crypto) {
|
||||||
const nodeCrypto = require("crypto");
|
const nodeCrypto = require("node:crypto");
|
||||||
global.crypto = {
|
global.crypto = {
|
||||||
getRandomValues(b) {
|
getRandomValues(b) {
|
||||||
nodeCrypto.randomFillSync(b);
|
nodeCrypto.randomFillSync(b);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if (!global.performance) {
|
if (!global.performance) {
|
||||||
global.performance = {
|
global.performance = {
|
||||||
@ -124,15 +118,13 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (!global.TextEncoder) {
|
if (!global.TextEncoder) {
|
||||||
global.TextEncoder = require("util").TextEncoder;
|
global.TextEncoder = require("node:util").TextEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.TextDecoder) {
|
if (!global.TextDecoder) {
|
||||||
global.TextDecoder = require("util").TextDecoder;
|
global.TextDecoder = require("node:util").TextDecoder;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// End of polyfills for common API.
|
// End of polyfills for common API.
|
||||||
|
|
||||||
@ -412,7 +404,7 @@
|
|||||||
|
|
||||||
// func valueInstanceOf(v ref, t ref) bool
|
// func valueInstanceOf(v ref, t ref) bool
|
||||||
"syscall/js.valueInstanceOf": (v_ref, t_ref) => {
|
"syscall/js.valueInstanceOf": (v_ref, t_ref) => {
|
||||||
return unboxValue(v_ref) instanceof unboxValue(t_ref);
|
return unboxValue(v_ref) instanceof unboxValue(t_ref);
|
||||||
},
|
},
|
||||||
|
|
||||||
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
||||||
@ -467,7 +459,7 @@
|
|||||||
}
|
}
|
||||||
return Reflect.get(...arguments);
|
return Reflect.get(...arguments);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
this._values = [ // JS values that Go currently has references to, indexed by reference id
|
this._values = [ // JS values that Go currently has references to, indexed by reference id
|
||||||
NaN,
|
NaN,
|
||||||
0,
|
0,
|
||||||
@ -482,22 +474,13 @@
|
|||||||
this._idPool = []; // unused ids that have been garbage collected
|
this._idPool = []; // unused ids that have been garbage collected
|
||||||
this.exited = false; // whether the Go program has exited
|
this.exited = false; // whether the Go program has exited
|
||||||
|
|
||||||
const mem = new DataView(this._inst.exports.memory.buffer)
|
if (this._inst.exports._start) {
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
});
|
|
||||||
this._inst.exports._start();
|
this._inst.exports._start();
|
||||||
if (this.exited) {
|
|
||||||
break;
|
// TODO: wait until the program exists.
|
||||||
}
|
await new Promise(() => {});
|
||||||
await callbackPromise;
|
} else {
|
||||||
|
this._inst.exports._initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user