Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running in Chrome/Node.js - am I doing something wrong? #163

Open
drogus opened this issue Nov 10, 2024 · 0 comments
Open

Running in Chrome/Node.js - am I doing something wrong? #163

drogus opened this issue Nov 10, 2024 · 0 comments

Comments

@drogus
Copy link

drogus commented Nov 10, 2024

Hi, it's a very cool project! I'm trying to run an example code:

function init() {
  let message: string = 'Hello, World!';

  function test() {
    console.log(message);
  }

  test()
}

export { init };
export default init;

I compiled it with:

node cli/ts2wasm.js --opt=3 example.ts -o out.wasm --debug --sourceMap

I'm trying to run in Chrome or in Node.js according to instructions and in both cases the result is simply a null value printed in console.log. I also tried just console.log("a string literal"); and there is still no output, so I'm guessing it's something with the environment? This is the command I'm using to run it:

node --experimental-wasm-gc --experimental-wasm-stringref run_module.js -f init out.wasm

I've tried on Node v23 and also a build from Git.

The generated WASM is:

    call $global|init|func
    i32.const 1144
    i32.const 13
    string.new_utf8
    drop
    ref.null none
    ref.null none
    global.get $dyntype_context
    i32.const 1160
    i32.const 4
    string.new_utf8
    call $dyntype_new_string
    array.new_fixed $array0 1
    i32.const 1
    struct.new $array-struct0
    call $builtin|Console|log

Now I don't know much about libdyntype, but it looks correct. The call to test() got optimized, so it's just creating a new string, pushing it to an arguments array and calling Console.log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant