wasm: add browser stderr builtins#27452
Conversation
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Fixes #27450.
The native wasm browser target could emit calls to
eprintln, but the browser-specific wasm builtin only providedprintlnandpanic. That madev -b wasm -os browserpanic while finalizing the wasm module, even for an emptymain.This adds browser wasm definitions for
print,eprint, andeprintln, routing them through the existing__writelnbrowser 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/