|
73 | 73 |
|
74 | 74 | global.Go = class {
|
75 | 75 | constructor() {
|
76 |
| - this.argv = ["js"]; |
77 |
| - this.env = {}; |
78 |
| - this.exit = (code) => { |
79 |
| - if (code !== 0) { |
80 |
| - console.warn("exit code:", code); |
81 |
| - } |
82 |
| - }; |
83 | 76 | this._callbackTimeouts = new Map();
|
84 | 77 | this._nextCallbackTimeoutID = 1;
|
85 | 78 |
|
|
342 | 335 |
|
343 | 336 | const mem = new DataView(this._inst.exports.memory.buffer)
|
344 | 337 |
|
345 |
| - // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory. |
346 |
| - let offset = 4096; |
347 |
| - |
348 |
| - const strPtr = (str) => { |
349 |
| - let ptr = offset; |
350 |
| - new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + "\0")); |
351 |
| - offset += str.length + (8 - (str.length % 8)); |
352 |
| - return ptr; |
353 |
| - }; |
354 |
| - |
355 |
| - const argc = this.argv.length; |
356 |
| - |
357 |
| - const argvPtrs = []; |
358 |
| - this.argv.forEach((arg) => { |
359 |
| - argvPtrs.push(strPtr(arg)); |
360 |
| - }); |
361 |
| - |
362 |
| - const keys = Object.keys(this.env).sort(); |
363 |
| - argvPtrs.push(keys.length); |
364 |
| - keys.forEach((key) => { |
365 |
| - argvPtrs.push(strPtr(`${key}=${this.env[key]}`)); |
366 |
| - }); |
367 |
| - |
368 |
| - const argv = offset; |
369 |
| - argvPtrs.forEach((ptr) => { |
370 |
| - mem.setUint32(offset, ptr, true); |
371 |
| - mem.setUint32(offset + 4, 0, true); |
372 |
| - offset += 8; |
373 |
| - }); |
374 |
| - |
375 | 338 | while (true) {
|
376 | 339 | const callbackPromise = new Promise((resolve) => {
|
377 | 340 | this._resolveCallbackPromise = () => {
|
|
381 | 344 | setTimeout(resolve, 0); // make sure it is asynchronous
|
382 | 345 | };
|
383 | 346 | });
|
384 |
| - this._inst.exports.cwa_main(argc, argv); |
| 347 | + this._inst.exports.cwa_main(); |
385 | 348 | if (this.exited) {
|
386 | 349 | break;
|
387 | 350 | }
|
|
413 | 376 | }
|
414 | 377 |
|
415 | 378 | if (isNodeJS) {
|
416 |
| - if (process.argv.length < 3) { |
| 379 | + if (process.argv.length != 3) { |
417 | 380 | process.stderr.write("usage: go_js_wasm_exec [wasm binary] [arguments]\n");
|
418 | 381 | process.exit(1);
|
419 | 382 | }
|
420 | 383 |
|
421 | 384 | const go = new Go();
|
422 |
| - go.argv = process.argv.slice(2); |
423 |
| - go.env = process.env; |
424 |
| - go.exit = process.exit; |
425 | 385 | WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
|
426 | 386 | process.on("exit", (code) => { // Node.js exits if no callback is pending
|
427 | 387 | if (code === 0 && !go.exited) {
|
|
0 commit comments