* @typedef {{ * start? : UnderlyingSourceStartCallback, * pull? : UnderlyingSourcePullCallback, * cancel? : UnderlyingSourceCancelCallback, * type? : "bytes", * autoAllocateChunkSize? : number * }} UnderlyingSource
| 244 | */ |
| 245 | |
| 246 | class ReadableStream { |
| 247 | [kType] = 'ReadableStream'; |
| 248 | |
| 249 | /** |
| 250 | * @param {UnderlyingSource} [source] |
| 251 | * @param {QueuingStrategy} [strategy] |
| 252 | */ |
| 253 | constructor(source = kEmptyObject, strategy = kEmptyObject) { |
| 254 | markTransferMode(this, false, true); |
| 255 | validateObject(source, 'source', kValidateObjectAllowObjects); |
| 256 | validateObject(strategy, 'strategy', kValidateObjectAllowObjectsAndNull); |
| 257 | this[kState] = createReadableStreamState(); |
| 258 | |
| 259 | // The spec requires handling of the strategy first |
| 260 | // here. Specifically, if getting the size and |
| 261 | // highWaterMark from the strategy fail, that has |
| 262 | // to trigger a throw before getting the details |
| 263 | // from the source. So be sure to keep these in |
| 264 | // this order. |
| 265 | const size = strategy?.size; |
| 266 | const highWaterMark = strategy?.highWaterMark; |
| 267 | const type = source.type; |
| 268 | |
| 269 | if (`${type}` === 'bytes') { |
| 270 | if (size !== undefined) |
| 271 | throw new ERR_INVALID_ARG_VALUE.RangeError('strategy.size', size); |
| 272 | setupReadableByteStreamControllerFromSource( |
| 273 | this, |
| 274 | source, |
| 275 | extractHighWaterMark(highWaterMark, 0)); |
| 276 | } else { |
| 277 | if (type !== undefined) |
| 278 | throw new ERR_INVALID_ARG_VALUE('source.type', type); |
| 279 | setupReadableStreamDefaultControllerFromSource( |
| 280 | this, |
| 281 | source, |
| 282 | extractHighWaterMark(highWaterMark, 1), |
| 283 | extractSizeAlgorithm(size)); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | get [kIsDisturbed]() { |
| 288 | return this[kState].disturbed; |
| 289 | } |
| 290 | |
| 291 | get [kIsErrored]() { |
| 292 | return this[kState].state === 'errored'; |
| 293 | } |
| 294 | |
| 295 | get [kIsReadable]() { |
| 296 | return this[kState].state === 'readable'; |
| 297 | } |
| 298 | |
| 299 | [kControllerErrorFunction](error) { |
| 300 | // Used by the internal stream interop (addAbortSignal). Historically |
| 301 | // only default controllers were wired here; byte stream controllers |
| 302 | // keep the previous no-op behavior. |
| 303 | const controller = this[kState].controller; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…