Repository navigation
wasm host: stdio writes keep the program's bytes - #830
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The wasm host (
tslang/test/wasm/host.mjs) decoded everystdio_writeandstdio_write_bytesbuffer 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
writeBytes(fd, bytes)and sends both stdio writes through it, with the bytes unchanged.bufferedOutputbuffers text and bytes together and writes them as bytes.run.mjsandthread.mjspass itswriteBytes.writeof its own, such as the browser page, still gets UTF-8 text.Testing
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