* @returns {Promise<{ * value : any, * done : boolean * }>}
()
| 907 | * }>} |
| 908 | */ |
| 909 | read() { |
| 910 | if (!isReadableStreamDefaultReader(this)) |
| 911 | return PromiseReject(new ERR_INVALID_THIS('ReadableStreamDefaultReader')); |
| 912 | if (this[kState].stream === undefined) { |
| 913 | return PromiseReject( |
| 914 | new ERR_INVALID_STATE.TypeError( |
| 915 | 'The reader is not attached to a stream')); |
| 916 | } |
| 917 | |
| 918 | const stream = this[kState].stream; |
| 919 | const controller = stream[kState].controller; |
| 920 | |
| 921 | // Fast path: if data is already buffered in a default controller, |
| 922 | // return a resolved promise immediately without creating a read request. |
| 923 | // This is spec-compliant because read() returns a Promise, and |
| 924 | // Promise.resolve() callbacks still run in the microtask queue. |
| 925 | if (stream[kState].state === 'readable' && |
| 926 | isReadableStreamDefaultController(controller) && |
| 927 | controller[kState].queue.length > 0) { |
| 928 | stream[kState].disturbed = true; |
| 929 | const chunk = dequeueValue(controller); |
| 930 | |
| 931 | if (controller[kState].closeRequested && !controller[kState].queue.length) { |
| 932 | readableStreamDefaultControllerClearAlgorithms(controller); |
| 933 | readableStreamClose(stream); |
| 934 | } else { |
| 935 | readableStreamDefaultControllerCallPullIfNeeded(controller); |
| 936 | } |
| 937 | |
| 938 | return PromiseResolve({ done: false, value: chunk }); |
| 939 | } |
| 940 | |
| 941 | // Slow path: create request and go through normal flow |
| 942 | const readRequest = new DefaultReadRequest(); |
| 943 | readableStreamDefaultReaderRead(this, readRequest); |
| 944 | return readRequest.promise; |
| 945 | } |
| 946 | |
| 947 | releaseLock() { |
| 948 | if (!isReadableStreamDefaultReader(this)) |
nothing calls this directly
no test coverage detected