Files
scriptc/tests/corpus/web-stream-pull-after-script.mjs
T
Chris Tate 9ca9c7af9d Run JavaScript web streams on a native ReadableStream
In JavaScript sources, ReadableStream, ReadableStreamDefaultReader,
ReadableStreamDefaultController, CountQueuingStrategy and
ByteLengthQueuingStrategy (globals and node:stream/web exports) are class
values over a new runtime unit, scr_webstreams.c, which follows Node 24's
webstreams step by step: underlying sources, queuing strategies, default
readers, tee, ReadableStream.from and async iteration settle their promises
in Node's order. scr_dyn_handle_class.c gives a dyn handle tag a
constructor value with a prototype, brand checks and Node's constructor
errors. Stream state carries cycle headers, so the collector reclaims
streams whose callbacks close over their controllers.

Promise steps run as native promise reactions, a variant of scr_async.c
that only programs with web streams link; every other program links the
default object. TypeScript sources keep their static web stream lowerings.
Byte streams, BYOB readers, pipeTo and pipeThrough throw SC2020.

node24-web-stream-readers and node24-web-stream-readable-lifecycle now
match Node.
2026-10-27 06:53:26 -05:00

15 lines
448 B
JavaScript

// A stream's start step runs during construction and its first pull as a
// promise job after the script, in a program with no other asynchronous
// work.
const stream = new ReadableStream({
start() {
console.log("start");
},
pull(controller) {
console.log("pull", controller.desiredSize, stream.locked);
controller.enqueue("chunk");
console.log("queued", controller.desiredSize);
},
});
console.log("end", stream.locked);