Skip to content

wasm host: stdio writes keep the program's bytes - #830

Merged
ASDAlexander77 merged 1 commit into
mainfrom
wasm-host-binary-stdout
Nov 12, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
wasm-host-binary-stdout

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

The wasm host (tslang/test/wasm/host.mjs) decoded every stdio_write and stdio_write_bytes buffer as UTF-8 before writing it. Any byte that isn't valid UTF-8, such as 0x80 and up in a length prefix or binary data, became U+FFFD (3 bytes). A Native Messaging host built for wasm wrote corrupt frames (discussion 364).

Change

  • The host takes an optional writeBytes(fd, bytes) and sends both stdio writes through it, with the bytes unchanged.
  • bufferedOutput buffers text and bytes together and writes them as bytes. run.mjs and thread.mjs pass its writeBytes.
  • A host made with only a write of its own, such as the browser page, still gets UTF-8 text.
  • The README says so.

Testing

  • A wasm32 program that writes bytes 0 to 255 and then echoes 70,000 bytes of stdin:
    • Fixed host: 70,256 bytes out, byte-for-byte equal to the input.
    • Old host: 140,512 bytes, corrupted.
  • run_tests.mjs, tester and defaultlib suites, on wasm32 and wasm64 under none, rc and own: all pass (tester 652/652/486 per triple, defaultlib 206/207/206), the same as before

🤖 Generated with Claude Code

stdio_write and stdio_write_bytes decoded the buffer as UTF-8, so binary output (a
Native Messaging length prefix, any byte 0x80 and up that is not UTF-8) was corrupted.
They now go through writeBytes, which bufferedOutput writes unchanged; a host given
only a text write (the browser page) still gets UTF-8 text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 882b2e0 into main Nov 12, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the wasm-host-binary-stdout branch November 12, 2026 20:39
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.

1 participant