second-state / wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
Apache License 2.0
477 stars 59 forks source link

process.argv undefined #119

Open anuraaga opened 8 months ago

anuraaga commented 8 months ago

I am trying to run a very simple program using argv.

argv.js:

import { argv } from 'process';
console.log(argv);

But it seems to be undefined

 wasmedge --dir=. wasmedge_quickjs.wasm argv.js foo bar baz
undefined

Tried wasmedge --dir=. wasmedge_quickjs.wasm argv.js -- foo bar baz as well just in case but with same result.

I see argv should be set to globalThis.argv, which I assume should be initialized by quickjs itself, calling the WASI function to fetch arguments, but it seems to not be happening.

https://github.com/second-state/wasmedge-quickjs/blob/main/modules/process.js#L9C28-L9C28

env, initialized in the same pattern, seems to work fine

env.js:

import { env } from 'process';
console.log(env["ANIMAL"]);
❯ wasmedge --env ANIMAL=bear --dir=. wasmedge_quickjs.wasm env.js
bear

I have tried both the latest release wasmedge_quickjs.wasm and one I built myself from commit ebad9e74 (before TLS addition).

alabulei1 commented 8 months ago

@L-jasmine Please take a look. Thanks.

L-jasmine commented 8 months ago

@anuraaga I apologize for the confusion, and thank you for bringing up the question. I'm not very familiar with JavaScript myself, so I initially thought that arguments were obtained using 'args'.

https://github.com/second-state/wasmedge-quickjs/blob/602159f403a0e13eeb5680d6a8ccd219c5b71422/src/quickjs_sys/mod.rs#L426