Skip to content

wasm: add browser stderr builtins#27452

Merged
medvednikov merged 2 commits into
masterfrom
codex/fix-wasm-browser-eprintln
Jun 14, 2026
Merged

wasm: add browser stderr builtins#27452
medvednikov merged 2 commits into
masterfrom
codex/fix-wasm-browser-eprintln

Conversation

@medvednikov

Copy link
Copy Markdown
Member

Summary

Fixes #27450.

The native wasm browser target could emit calls to eprintln, but the browser-specific wasm builtin only provided println and panic. That made v -b wasm -os browser panic while finalizing the wasm module, even for an empty main.

This adds browser wasm definitions for print, eprint, and eprintln, routing them through the existing __writeln browser host hook, and updates the empty-main regression test so it no longer masks the issue with -no-bounds-checking.

Validation

  • ./v -g -keepc -o ./vnew cmd/v
  • ./vnew -b wasm -os browser -o "$tmpdir/m.wasm" "$tmpdir/m.v"
  • ./vnew -b wasm -os browser -o /tmp/change_color_by_id.wasm examples/wasm/change_color_by_id/change_color_by_id.wasm.v
  • ./vnew test vlib/v/gen/wasm/tests/browser_empty_main_test.v
  • ./vnew -silent test vlib/v/gen/wasm/tests/

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66c1d2e3c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


// print prints a message to the browser output host.
pub fn print(s string) {
JS.__writeln(s.str, s.len)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve non-newline print semantics

When the browser host uses the documented/sample __writeln hook as a line-oriented sink (the wasm browser examples implement it with console.log), routing print through the same hook makes print behave like println. Browser wasm code such as print('a'); println('b') will no longer match V's normal output semantics or the existing wasm expectation that the two writes stay on one line, so the non-newline variants should either remain unsupported or use a separate non-line-writing host import.

Useful? React with 👍 / 👎.

@medvednikov medvednikov merged commit acd0803 into master Jun 14, 2026
90 of 92 checks passed
dy-tea pushed a commit to wenxuanjun/v that referenced this pull request Jun 19, 2026
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 this pull request may close these issues.

wasm: -os browser panics 'called function eprintln does not exist' for any program (even empty main)

1 participant