mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
In JavaScript, a Response or Request body answered getReader, cancel and locked, and every other ReadableStream member was undefined: tee, pipeTo, pipeThrough, values and for await threw TypeErrors where Node's body is a ReadableStream. In programs that link the web stream classes, the body's handle now stands for a ReadableStream once any other member is used (sf_stream_web_view): a stream with a zero high-water mark whose native source reads the body (scr_webstream_readable_over). From then on every member goes to it, the class's method values and getters run on it through the alias's view (scr_dyn_handle_class_receiver), and text(), clone(), new Response(body) and fetch uploads read the body through it, so its lock and bodyUsed follow it as in Node. A body locked when the view is made keeps the view locked until the lock is released. Once only the view's source holds the body, the body lets the view go. The compiler links the classes into a program whose JavaScript reads a ReadableStream member that the fetch profile lists as unsupported by the native stream, or iterates a ReadableStream with for await, and that names none of the classes: %main calls webstream.install first. Programs without web streams build to the same binaries as before. Adds corpus programs fetch-body-web-stream-linked.mjs, fetch-body-web-stream-unlinked.mjs and fetch-body-web-stream-network.mjs, with their corpus costs and preflight/order baselines.