mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
bd61913973
* wasm: patch wasm_exec.js and wasm_exec_node.js from Go 1.18+ Port this commit https://github.com/golang/go/commit/680caf15355057ca84857a2a291b6f5c44e73329 removing polyfills from `wasm_exec.js`, now the environment is expected to provide all the required polyfills. `wasm_exec.js` now only provides stub fallbacks for globalThis.fs and globalThis.process. All NodeJS specific code is now in a separate file `wasm_exec_node.js` with its required polyfills. * feat: bump minimum node version to 22 Drops official support for NodeJS 18 for WASM by removing the provided polyfills in the `wasm_exec.js`. Now the environment is expected to provide the polyfill if it is running on older NodeJS versions The new minimum required version for WASM is NodeJS 22+. * chore: removed wrong comment `wasm_exec_node.js` no longer contains the polyfill for NodeJS 18
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
const fs = require('fs')
|
|
|
|
require('../targets/wasm_exec.js');
|
|
|
|
function runTests() {
|
|
let testCall = (name, params, expected) => {
|
|
let result = go._inst.exports[name].apply(null, params);
|
|
if (result !== expected) {
|
|
console.error(`${name}(...${params}): expected result ${expected}, got ${result}`);
|
|
}
|
|
}
|
|
|
|
// These are the same tests as in TestWasmExport.
|
|
testCall('hello', [], undefined);
|
|
testCall('add', [3, 5], 8);
|
|
testCall('add', [7, 9], 16);
|
|
testCall('add', [6, 1], 7);
|
|
testCall('reentrantCall', [2, 3], 5);
|
|
testCall('reentrantCall', [1, 8], 9);
|
|
}
|
|
|
|
let go = new Go();
|
|
go.importObject.tester = {
|
|
callOutside: (a, b) => {
|
|
return go._inst.exports.add(a, b);
|
|
},
|
|
callTestMain: () => {
|
|
runTests();
|
|
},
|
|
};
|
|
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then(async (result) => {
|
|
let value = await go.run(result.instance);
|
|
console.log('exit code:', value);
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|