|
| 1 | +require('../targets/wasm_exec.js'); |
| 2 | + |
| 3 | +function runTests() { |
| 4 | + let testCall = (name, params, expected) => { |
| 5 | + let result = go._inst.exports[name].apply(null, params); |
| 6 | + if (result !== expected) { |
| 7 | + console.error(`${name}(...${params}): expected result ${expected}, got ${result}`); |
| 8 | + } |
| 9 | + } |
| 10 | + |
| 11 | + // These are the same tests as in TestWasmExport. |
| 12 | + testCall('hello', [], undefined); |
| 13 | + testCall('add', [3, 5], 8); |
| 14 | + testCall('add', [7, 9], 16); |
| 15 | + testCall('add', [6, 1], 7); |
| 16 | + testCall('reentrantCall', [2, 3], 5); |
| 17 | + testCall('reentrantCall', [1, 8], 9); |
| 18 | +} |
| 19 | + |
| 20 | +let go = new Go(); |
| 21 | +go.importObject.tester = { |
| 22 | + callOutside: (a, b) => { |
| 23 | + return go._inst.exports.add(a, b); |
| 24 | + }, |
| 25 | + callTestMain: () => { |
| 26 | + runTests(); |
| 27 | + }, |
| 28 | +}; |
| 29 | +WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => { |
| 30 | + let buildMode = process.argv[3]; |
| 31 | + if (buildMode === 'default') { |
| 32 | + go.run(result.instance); |
| 33 | + } else if (buildMode === 'c-shared') { |
| 34 | + go.run(result.instance); |
| 35 | + runTests(); |
| 36 | + } |
| 37 | +}).catch((err) => { |
| 38 | + console.error(err); |
| 39 | + process.exit(1); |
| 40 | +}); |
0 commit comments