Skip to content

print doesn't work in any event handler #11

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

Closed
MaxDesiatov opened this issue Jun 17, 2020 · 3 comments · Fixed by #17
Closed

print doesn't work in any event handler #11

MaxDesiatov opened this issue Jun 17, 2020 · 3 comments · Fixed by #17

Comments

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jun 17, 2020

While using print as a top-level invocation works, if you call print in any closure handler, such as onclick, addEventListener etc, print output is not redirected to console.log. Apparently, there isn't anything that reads from stdout and redirects to console.log at that point.

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Jun 19, 2020

Hmm, I couldn't reproduce. How do you redirect stdout? Could you try that way used in IntegratedTests?

const wasmFs = new WasmFs();
// Output stdout and stderr to console
const originalWriteSync = wasmFs.fs.writeSync;
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
  const text = new TextDecoder("utf-8").decode(buffer);
  switch (fd) {
  case 1:
    console.log(text);
    break;
  case 2:
    console.error(text);
    break;
  }
  return originalWriteSync(fd, buffer, offset, length, position);
};

@MaxDesiatov
Copy link
Contributor Author

This is great, thanks! Would you mind if I create a PR that adds this to index.js in the example?

@kateinoigakukun
Copy link
Member

Thanks. It would be helpful 🙏

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

Successfully merging a pull request may close this issue.

2 participants