Repository navigation
Keep a patched then out of TypeScript body consumption - #8060
Conversation
|
💬 Approved with comments — The code change is correct and well tested. The only finding is a documentation WARNING: the new AGENTS.md invariant covers more than the code guarantees. Findings: 1 warning The decision is advisory: this comment never approves, blocks or requests changes on the pull request. 🔧 Fix with your agentPaste the following into your coding agent to investigate and fix these issues. 📝 Documentation:
|
|
Since last review: 0 resolved, 0 still open, 0 new. Not re-run: tests, docs, api-compat, compat-flags, design-simplicity, jsg-gc, kj-style, memory-safety (no author changes in their files since the last review) Reviewed commit: a518a391 · github run |
8180d41 to
e90de05
Compare
Under typescript_implemented_streams, the C++ bridge consumed a body
by awaiting a TypeScript async function that resolved with the
result: an ArrayBuffer, a Uint8Array or a parsed JSON value.
Resolving a promise with an object looks up its then, so a patched
Object.prototype.then ran at that internal step. arrayBuffer() and
blob() then failed with an internal error (the bridge's ArrayBuffer
check), and bytes() resolved with an empty Uint8Array, because its
TypeScript side awaited the ArrayBuffer itself. The same paths serve
R2's GetResult and container stdout/stderr capture. With the C++
implementation the patch is consulted only when the caller's promise
resolves.
Every body consumption now goes through the one export text()
already uses, consumeReadableStreamAsArrayBufferRecord, which
resolves with a null-prototype { buffer } record. C++ builds each
result from it, as the legacy implementation builds them from its
own reads: bytes() wraps the buffer in a Uint8Array, blob() makes a
Blob of it, and json() parses text(), as Body::json() does. The
ArrayBuffer, Uint8Array and JSON consume functions are gone, and
with them the TypeScript-side text decoding that only json() used.
Tests: the readable suite checks that a self-removing patched then
intercepts only the result of each consumption method, for native
and queued bodies, under both implementations. A bridge unit test
installs a persistent patch and checks that arrayBuffer(), bytes(),
text(), json() and blob() still give C++ the stream's contents
without consulting it.
typescript_implemented_streams is still experimental, with no enable
date, so the change needs no compatibility flag.
Fixes: #8043
e90de05 to
a518a39
Compare
|
The generated output of |
Fixup patched then handling in consumer methods