Skip to content

Accept a bare SharedArrayBuffer chunk in TS TextDecoderStream - #7643

Open
jasnell wants to merge 1 commit into
jasnell/ts-streams-identity-write-edgesfrom
jasnell/ts-streams-decoder-shared-buffer
Open

jasnell wants to merge 1 commit into
jasnell/ts-streams-identity-write-edgesfrom
jasnell/ts-streams-decoder-shared-buffer

Conversation

@jasnell

@jasnell jasnell commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

The Encoding Standard's TextDecoderStream writable accepts an
AllowSharedBufferSource, and Node decodes a bare SharedArrayBuffer
chunk. TS rejected it ("TextDecoderStream: chunk must be a
BufferSource") and errored the stream, though it already decoded views
over shared memory, and TextDecoder.decode() accepts a bare one. C++
rejects it too, as not a BufferSource.

The TS transform now accepts a SharedArrayBuffer, growable ones
included, and decodes it like an ArrayBuffer; a character split across
two of them decodes whole. C++ is unchanged, so this is a new
implementation divergence (encoding ledger #8).

Pins: encoding chunk-types.js decoderSharedArrayBufferChunks (parity
for shared-memory Uint8Array, subview and DataView chunks with a split
character; ledger #8 for bare, growable and split bare chunks: TS
decodes 'CD€', C++ rejects with its invalid-chunk TypeError). Without
the source change, it fails, in the TS cells only.

@jasnell
jasnell requested review from guybedford and npaun October 6, 2026 21:28
@jasnell
jasnell requested a review from a team as a code owner October 6, 2026 21:28
@jasnell
jasnell added this pull request to stack #7531 October 6, 2026 21:28
@jasnell
jasnell requested a review from a team as a code owner October 6, 2026 21:28
@ask-bonk

ask-bonk Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Since last review: 0 resolved, 0 still open, 0 new.
LGTM!

Not re-run: tests, api-compat, docs, compat-flags, design-simplicity (no author changes in their files since the last review)


Reviewed commit: bb41075d · github run

@guybedford guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified the change end to end: the Encoding Standard's writable chunk type is AllowSharedBufferSource, and the downstream TextDecoder::decode(kj::Array<const byte>) already unwraps a SharedArrayBuffer via jsg's tryUnwrap (value.h), so the cast-through is sound and growable SABs take the same path. All five encoding variants pass locally, and reverting only encoding.ts makes encoding-ts@ fail on decoderSharedArrayBufferChunks, so the pin is a real regression guard.

Two non-blocking nits:

  1. In the decode() helper in chunk-types.js, in the C++ branch the reader.read() loop throws before await writes is reached, so the Promise.all in writes is left as an unhandled rejection. The harness swallows it, but a writes.catch(() => {}) (or try { ... } finally { await writes.catch(() => {}) }) would keep it clean and make explicit that the read-side error is the one asserted.
  2. The TS message "chunk must be a BufferSource" and the AGENTS.md "Accepts BufferSource chunks only (...)" are now slightly imprecise, since a SAB isn't a BufferSource. The message is pinned under ledger #4 so I wouldn't change it here; AllowSharedBufferSource would be the exact term in the doc.

@jasnell
jasnell force-pushed the jasnell/ts-streams-decoder-shared-buffer branch 2 times, most recently from 7b0c1da to 6d064fd Compare October 8, 2026 01:26
@codecov-commenter

codecov-commenter commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.59%. Comparing base (ae4c08a) to head (bb41075).

Additional details and impacted files
@@                           Coverage Diff                            @@
##           jasnell/ts-streams-identity-write-edges    #7643   +/-   ##
========================================================================
  Coverage                                    38.59%   38.59%           
========================================================================
  Files                                          868      868           
  Lines                                       268548   268548           
  Branches                                     25414    25414           
========================================================================
  Hits                                        103635   103635           
  Misses                                      150701   150701           
  Partials                                     14212    14212           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell
jasnell force-pushed the jasnell/ts-streams-decoder-shared-buffer branch 3 times, most recently from 0dc54bc to a138a5d Compare October 8, 2026 19:49
The Encoding Standard's TextDecoderStream writable accepts an
AllowSharedBufferSource, and Node decodes a bare SharedArrayBuffer
chunk. TS rejected it ("TextDecoderStream: chunk must be a
BufferSource") and errored the stream, though it already decoded views
over shared memory, and TextDecoder.decode() accepts a bare one. C++
rejects it too, as not a BufferSource.

The TS transform now accepts a SharedArrayBuffer, growable ones
included, and decodes it like an ArrayBuffer; a character split across
two of them decodes whole. C++ is unchanged, so this is a new
implementation divergence (encoding ledger #8).

Pins: encoding chunk-types.js decoderSharedArrayBufferChunks (parity
for shared-memory Uint8Array, subview and DataView chunks with a split
character; ledger #8 for bare, growable and split bare chunks: TS
decodes 'CD€', C++ rejects with its invalid-chunk TypeError). Without
the source change, it fails, in the TS cells only.

Compatibility: the change is behind the experimental
typescript_implemented_streams flag. C++ is unchanged.
@jasnell
jasnell force-pushed the jasnell/ts-streams-decoder-shared-buffer branch from a138a5d to bb41075 Compare October 8, 2026 22:28
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.

3 participants