| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ const { | |||
| 11 | 11 | FunctionPrototypeCall, | |
| 12 | 12 | MathMin, | |
| 13 | 13 | NumberIsInteger, | |
| 14 | - ObjectCreate, | ||
| 15 | 14 | ObjectDefineProperties, | |
| 16 | 15 | ObjectSetPrototypeOf, | |
| 17 | 16 | Promise, | |
@@ -96,9 +95,9 @@ const { | |||
| 96 | 95 | AsyncIterator, | |
| 97 | 96 | cloneAsUint8Array, | |
| 98 | 97 | copyArrayBuffer, | |
| 98 | + createPromiseCallback, | ||
| 99 | 99 | customInspect, | |
| 100 | 100 | dequeueValue, | |
| 101 | - ensureIsPromise, | ||
| 102 | 101 | enqueueValueWithSize, | |
| 103 | 102 | extractHighWaterMark, | |
| 104 | 103 | extractSizeAlgorithm, | |
@@ -251,19 +250,7 @@ class ReadableStream { | |||
| 251 | 250 | constructor(source = {}, strategy = kEmptyObject) { | |
| 252 | 251 | if (source === null) | |
| 253 | 252 | throw new ERR_INVALID_ARG_VALUE('source', 'Object', source); | |
| 254 | - this[kState] = { | ||
| 255 | - disturbed: false, | ||
| 256 | - reader: undefined, | ||
| 257 | - state: 'readable', | ||
| 258 | - storedError: undefined, | ||
| 259 | - stream: undefined, | ||
| 260 | - transfer: { | ||
| 261 | - writable: undefined, | ||
| 262 | - port1: undefined, | ||
| 263 | - port2: undefined, | ||
| 264 | - promise: undefined, | ||
| 265 | - }, | ||
| 266 | - }; | ||
| 253 | + this[kState] = createReadableStreamState(); | ||
| 267 | 254 | ||
| 268 | 255 | this[kIsClosedPromise] = createDeferredPromise(); | |
| 269 | 256 | this[kControllerErrorFunction] = () => {}; | |
@@ -655,17 +642,7 @@ function TransferredReadableStream() { | |||
| 655 | 642 | return makeTransferable(ReflectConstruct( | |
| 656 | 643 | function() { | |
| 657 | 644 | this[kType] = 'ReadableStream'; | |
| 658 | - this[kState] = { | ||
| 659 | - disturbed: false, | ||
| 660 | - state: 'readable', | ||
| 661 | - storedError: undefined, | ||
| 662 | - stream: undefined, | ||
| 663 | - transfer: { | ||
| 664 | - writable: undefined, | ||
| 665 | - port: undefined, | ||
| 666 | - promise: undefined, | ||
| 667 | - }, | ||
| 668 | - }; | ||
| 645 | + this[kState] = createReadableStreamState(); | ||
| 669 | 646 | this[kIsClosedPromise] = createDeferredPromise(); | |
| 670 | 647 | }, | |
| 671 | 648 | [], ReadableStream)); | |
@@ -1223,43 +1200,58 @@ ObjectDefineProperties(ReadableByteStreamController.prototype, { | |||
| 1223 | 1200 | [SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableByteStreamController.name), | |
| 1224 | 1201 | }); | |
| 1225 | 1202 | ||
| 1226 | - function TeeReadableStream(start, pull, cancel) { | ||
| 1203 | + function InternalReadableStream(start, pull, cancel, highWaterMark, size) { | ||
| 1227 | 1204 | this[kType] = 'ReadableStream'; | |
| 1228 | - this[kState] = { | ||
| 1229 | - disturbed: false, | ||
| 1230 | - state: 'readable', | ||
| 1231 | - storedError: undefined, | ||
| 1232 | - stream: undefined, | ||
| 1233 | - transfer: { | ||
| 1234 | - writable: undefined, | ||
| 1235 | - port: undefined, | ||
| 1236 | - promise: undefined, | ||
| 1237 | - }, | ||
| 1238 | - }; | ||
| 1205 | + this[kState] = createReadableStreamState(); | ||
| 1239 | 1206 | this[kIsClosedPromise] = createDeferredPromise(); | |
| 1240 | - setupReadableStreamDefaultControllerFromSource( | ||
| 1207 | + const controller = new ReadableStreamDefaultController(kSkipThrow); | ||
| 1208 | + setupReadableStreamDefaultController( | ||
| 1241 | 1209 | this, | |
| 1242 | - ObjectCreate(null, { | ||
| 1243 | - start: { __proto__: null, value: start }, | ||
| 1244 | - pull: { __proto__: null, value: pull }, | ||
| 1245 | - cancel: { __proto__: null, value: cancel }, | ||
| 1246 | - }), | ||
| 1247 | - 1, | ||
| 1248 | - () => 1); | ||
| 1210 | + controller, | ||
| 1211 | + start, | ||
| 1212 | + pull, | ||
| 1213 | + cancel, | ||
| 1214 | + highWaterMark, | ||
| 1215 | + size); | ||
| 1216 | + return makeTransferable(this); | ||
| 1217 | + } | ||
| 1249 | 1218 | ||
| 1219 | + ObjectSetPrototypeOf(InternalReadableStream.prototype, ReadableStream.prototype); | ||
| 1220 | + ObjectSetPrototypeOf(InternalReadableStream, ReadableStream); | ||
| 1221 | + | ||
| 1222 | + function createReadableStream(start, pull, cancel, highWaterMark = 1, size = () => 1) { | ||
| 1223 | + const stream = new InternalReadableStream(start, pull, cancel, highWaterMark, size); | ||
| 1224 | + | ||
| 1225 | + // For spec compliance the InternalReadableStream must be a ReadableStream | ||
| 1226 | + stream.constructor = ReadableStream; | ||
| 1227 | + return stream; | ||
| 1228 | + } | ||
| 1250 | 1229 | ||
| 1230 | + function InternalReadableByteStream(start, pull, cancel) { | ||
| 1231 | + this[kType] = 'ReadableStream'; | ||
| 1232 | + this[kState] = createReadableStreamState(); | ||
| 1233 | + this[kIsClosedPromise] = createDeferredPromise(); | ||
| 1234 | + const controller = new ReadableByteStreamController(kSkipThrow); | ||
| 1235 | + setupReadableByteStreamController( | ||
| 1236 | + this, | ||
| 1237 | + controller, | ||
| 1238 | + start, | ||
| 1239 | + pull, | ||
| 1240 | + cancel, | ||
| 1241 | + 0, | ||
| 1242 | + undefined); | ||
| 1251 | 1243 | return makeTransferable(this); | |
| 1252 | 1244 | } | |
| 1253 | 1245 | ||
| 1254 | - ObjectSetPrototypeOf(TeeReadableStream.prototype, ReadableStream.prototype); | ||
| 1255 | - ObjectSetPrototypeOf(TeeReadableStream, ReadableStream); | ||
| 1246 | + ObjectSetPrototypeOf(InternalReadableByteStream.prototype, ReadableStream.prototype); | ||
| 1247 | + ObjectSetPrototypeOf(InternalReadableByteStream, ReadableStream); | ||
| 1256 | 1248 | ||
| 1257 | - function createTeeReadableStream(start, pull, cancel) { | ||
| 1258 | - const tee = new TeeReadableStream(start, pull, cancel); | ||
| 1249 | + function createReadableByteStream(start, pull, cancel) { | ||
| 1250 | + const stream = new InternalReadableByteStream(start, pull, cancel); | ||
| 1259 | 1251 | ||
| 1260 | - // For spec compliance the Tee must be a ReadableStream | ||
| 1261 | - tee.constructor = ReadableStream; | ||
| 1262 | - return tee; | ||
| 1252 | + // For spec compliance the InternalReadableByteStream must be a ReadableStream | ||
| 1253 | + stream.constructor = ReadableStream; | ||
| 1254 | + return stream; | ||
| 1263 | 1255 | } | |
| 1264 | 1256 | ||
| 1265 | 1257 | const isReadableStream = | |
@@ -1275,6 +1267,23 @@ const isReadableStreamBYOBReader = | |||
| 1275 | 1267 | ||
| 1276 | 1268 | // ---- ReadableStream Implementation | |
| 1277 | 1269 | ||
| 1270 | + function createReadableStreamState() { | ||
| 1271 | + return { | ||
| 1272 | + __proto__: null, | ||
| 1273 | + disturbed: false, | ||
| 1274 | + reader: undefined, | ||
| 1275 | + state: 'readable', | ||
| 1276 | + storedError: undefined, | ||
| 1277 | + transfer: { | ||
| 1278 | + __proto__: null, | ||
| 1279 | + writable: undefined, | ||
| 1280 | + port1: undefined, | ||
| 1281 | + port2: undefined, | ||
| 1282 | + promise: undefined, | ||
| 1283 | + }, | ||
| 1284 | + }; | ||
| 1285 | + } | ||
| 1286 | + | ||
| 1278 | 1287 | function readableStreamFromIterable(iterable) { | |
| 1279 | 1288 | let stream; | |
| 1280 | 1289 | const iteratorRecord = getIterator(iterable, 'async'); | |
@@ -1314,16 +1323,12 @@ function readableStreamFromIterable(iterable) { | |||
| 1314 | 1323 | }); | |
| 1315 | 1324 | } | |
| 1316 | 1325 | ||
| 1317 | - stream = new ReadableStream({ | ||
| 1318 | - start: startAlgorithm, | ||
| 1319 | - pull: pullAlgorithm, | ||
| 1320 | - cancel: cancelAlgorithm, | ||
| 1321 | - }, { | ||
| 1322 | - size() { | ||
| 1323 | - return 1; | ||
| 1324 | - }, | ||
| 1325 | - highWaterMark: 0, | ||
| 1326 | - }); | ||
| 1326 | + stream = createReadableStream( | ||
| 1327 | + startAlgorithm, | ||
| 1328 | + pullAlgorithm, | ||
| 1329 | + cancelAlgorithm, | ||
| 1330 | + 0, | ||
| 1331 | + ); | ||
| 1327 | 1332 | ||
| 1328 | 1333 | return stream; | |
| 1329 | 1334 | } | |
@@ -1649,9 +1654,9 @@ function readableStreamDefaultTee(stream, cloneForBranch2) { | |||
| 1649 | 1654 | } | |
| 1650 | 1655 | ||
| 1651 | 1656 | branch1 = | |
| 1652 | - createTeeReadableStream(nonOpStart, pullAlgorithm, cancel1Algorithm); | ||
| 1657 | + createReadableStream(nonOpStart, pullAlgorithm, cancel1Algorithm); | ||
| 1653 | 1658 | branch2 = | |
| 1654 | - createTeeReadableStream(nonOpStart, pullAlgorithm, cancel2Algorithm); | ||
| 1659 | + createReadableStream(nonOpStart, pullAlgorithm, cancel2Algorithm); | ||
| 1655 | 1660 | ||
| 1656 | 1661 | PromisePrototypeThen( | |
| 1657 | 1662 | reader[kState].close.promise, | |
@@ -1928,16 +1933,10 @@ function readableByteStreamTee(stream) { | |||
| 1928 | 1933 | return cancelDeferred.promise; | |
| 1929 | 1934 | } | |
| 1930 | 1935 | ||
| 1931 | - branch1 = new ReadableStream({ | ||
| 1932 | - type: 'bytes', | ||
| 1933 | - pull: pull1Algorithm, | ||
| 1934 | - cancel: cancel1Algorithm, | ||
| 1935 | - }); | ||
| 1936 | - branch2 = new ReadableStream({ | ||
| 1937 | - type: 'bytes', | ||
| 1938 | - pull: pull2Algorithm, | ||
| 1939 | - cancel: cancel2Algorithm, | ||
| 1940 | - }); | ||
| 1936 | + branch1 = | ||
| 1937 | + createReadableByteStream(nonOpStart, pull1Algorithm, cancel1Algorithm); | ||
| 1938 | + branch2 = | ||
| 1939 | + createReadableByteStream(nonOpStart, pull2Algorithm, cancel2Algorithm); | ||
| 1941 | 1940 | ||
| 1942 | 1941 | forwardReaderError(reader); | |
| 1943 | 1942 | ||
@@ -1988,10 +1987,7 @@ function readableStreamCancel(stream, reason) { | |||
| 1988 | 1987 | } | |
| 1989 | 1988 | ||
| 1990 | 1989 | return PromisePrototypeThen( | |
| 1991 | - ensureIsPromise( | ||
| 1992 | - stream[kState].controller[kCancel], | ||
| 1993 | - stream[kState].controller, | ||
| 1994 | - reason), | ||
| 1990 | + stream[kState].controller[kCancel](reason), | ||
| 1995 | 1991 | () => {}); | |
| 1996 | 1992 | } | |
| 1997 | 1993 | ||
@@ -2356,7 +2352,7 @@ function readableStreamDefaultControllerCallPullIfNeeded(controller) { | |||
| 2356 | 2352 | assert(!controller[kState].pullAgain); | |
| 2357 | 2353 | controller[kState].pulling = true; | |
| 2358 | 2354 | PromisePrototypeThen( | |
| 2359 | - ensureIsPromise(controller[kState].pullAlgorithm, controller), | ||
| 2355 | + controller[kState].pullAlgorithm(controller), | ||
| 2360 | 2356 | () => { | |
| 2361 | 2357 | controller[kState].pulling = false; | |
| 2362 | 2358 | if (controller[kState].pullAgain) { | |
@@ -2386,12 +2382,9 @@ function readableStreamDefaultControllerError(controller, error) { | |||
| 2386 | 2382 | ||
| 2387 | 2383 | function readableStreamDefaultControllerCancelSteps(controller, reason) { | |
| 2388 | 2384 | resetQueue(controller); | |
| 2389 | - try { | ||
| 2390 | - const result = controller[kState].cancelAlgorithm(reason); | ||
| 2391 | - return result; | ||
| 2392 | - } finally { | ||
| 2393 | - readableStreamDefaultControllerClearAlgorithms(controller); | ||
| 2394 | - } | ||
| 2385 | + const result = controller[kState].cancelAlgorithm(reason); | ||
| 2386 | + readableStreamDefaultControllerClearAlgorithms(controller); | ||
| 2387 | + return result; | ||
| 2395 | 2388 | } | |
| 2396 | 2389 | ||
| 2397 | 2390 | function readableStreamDefaultControllerPullSteps(controller, readRequest) { | |
@@ -2465,11 +2458,10 @@ function setupReadableStreamDefaultControllerFromSource( | |||
| 2465 | 2458 | FunctionPrototypeBind(start, source, controller) : | |
| 2466 | 2459 | nonOpStart; | |
| 2467 | 2460 | const pullAlgorithm = pull ? | |
| 2468 | - FunctionPrototypeBind(pull, source, controller) : | ||
| 2461 | + createPromiseCallback('source.pull', pull, source) : | ||
| 2469 | 2462 | nonOpPull; | |
| 2470 | - | ||
| 2471 | 2463 | const cancelAlgorithm = cancel ? | |
| 2472 | - FunctionPrototypeBind(cancel, source) : | ||
| 2464 | + createPromiseCallback('source.cancel', cancel, source) : | ||
| 2473 | 2465 | nonOpCancel; | |
| 2474 | 2466 | ||
| 2475 | 2467 | setupReadableStreamDefaultController( | |
@@ -3097,7 +3089,7 @@ function readableByteStreamControllerCallPullIfNeeded(controller) { | |||
| 3097 | 3089 | assert(!controller[kState].pullAgain); | |
| 3098 | 3090 | controller[kState].pulling = true; | |
| 3099 | 3091 | PromisePrototypeThen( | |
| 3100 | - ensureIsPromise(controller[kState].pullAlgorithm, controller), | ||
| 3092 | + controller[kState].pullAlgorithm(controller), | ||
| 3101 | 3093 | () => { | |
| 3102 | 3094 | controller[kState].pulling = false; | |
| 3103 | 3095 | if (controller[kState].pullAgain) { | |
@@ -3264,10 +3256,10 @@ function setupReadableByteStreamControllerFromSource( | |||
| 3264 | 3256 | FunctionPrototypeBind(start, source, controller) : | |
| 3265 | 3257 | nonOpStart; | |
| 3266 | 3258 | const pullAlgorithm = pull ? | |
| 3267 | - FunctionPrototypeBind(pull, source, controller) : | ||
| 3259 | + createPromiseCallback('source.pull', pull, source, controller) : | ||
| 3268 | 3260 | nonOpPull; | |
| 3269 | 3261 | const cancelAlgorithm = cancel ? | |
| 3270 | - FunctionPrototypeBind(cancel, source) : | ||
| 3262 | + createPromiseCallback('source.cancel', cancel, source) : | ||
| 3271 | 3263 | nonOpCancel; | |
| 3272 | 3264 | ||
| 3273 | 3265 | if (autoAllocateChunkSize === 0) { | |
@@ -3364,4 +3356,6 @@ module.exports = { | |||
| 3364 | 3356 | readableByteStreamControllerPullSteps, | |
| 3365 | 3357 | setupReadableByteStreamController, | |
| 3366 | 3358 | setupReadableByteStreamControllerFromSource, | |
| 3359 | + createReadableStream, | ||
| 3360 | + createReadableByteStream, | ||
| 3367 | 3361 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments