| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ const { | |||
| 24 | 24 | Symbol, | |
| 25 | 25 | SymbolAsyncIterator, | |
| 26 | 26 | SymbolDispose, | |
| 27 | + SymbolIterator, | ||
| 27 | 28 | SymbolToStringTag, | |
| 28 | 29 | TypedArrayPrototypeGetLength, | |
| 29 | 30 | Uint8Array, | |
@@ -32,6 +33,7 @@ const { | |||
| 32 | 33 | const { | |
| 33 | 34 | AbortError, | |
| 34 | 35 | codes: { | |
| 36 | + ERR_ARG_NOT_ITERABLE, | ||
| 35 | 37 | ERR_ILLEGAL_CONSTRUCTOR, | |
| 36 | 38 | ERR_INVALID_ARG_TYPE, | |
| 37 | 39 | ERR_INVALID_ARG_VALUE, | |
@@ -111,8 +113,6 @@ const { | |||
| 111 | 113 | nonOpCancel, | |
| 112 | 114 | nonOpPull, | |
| 113 | 115 | nonOpStart, | |
| 114 | - getIterator, | ||
| 115 | - iteratorNext, | ||
| 116 | 116 | kType, | |
| 117 | 117 | kState, | |
| 118 | 118 | } = require('internal/webstreams/util'); | |
@@ -1360,41 +1360,36 @@ function createReadableStreamState() { | |||
| 1360 | 1360 | ||
| 1361 | 1361 | function readableStreamFromIterable(iterable) { | |
| 1362 | 1362 | let stream; | |
| 1363 | - const iteratorRecord = getIterator(iterable, 'async'); | ||
| 1364 | - | ||
| 1363 | + const iteratorGetter = iterable[SymbolAsyncIterator] ?? iterable[SymbolIterator]; | ||
| 1364 | + if (iteratorGetter == null || typeof iteratorGetter !== 'function') { | ||
| 1365 | + throw new ERR_ARG_NOT_ITERABLE(iterable); | ||
| 1366 | + } | ||
| 1367 | + const iterator = FunctionPrototypeCall(iteratorGetter, iterable); | ||
| 1365 | 1368 | const startAlgorithm = nonOpStart; | |
| 1366 | 1369 | ||
| 1367 | 1370 | async function pullAlgorithm() { | |
| 1368 | - const nextResult = iteratorNext(iteratorRecord); | ||
| 1369 | - const nextPromise = PromiseResolve(nextResult); | ||
| 1370 | - return PromisePrototypeThen(nextPromise, (iterResult) => { | ||
| 1371 | - if (typeof iterResult !== 'object' || iterResult === null) { | ||
| 1372 | - throw new ERR_INVALID_STATE.TypeError( | ||
| 1373 | - 'The promise returned by the iterator.next() method must fulfill with an object'); | ||
| 1374 | - } | ||
| 1375 | - if (iterResult.done) { | ||
| 1376 | - readableStreamDefaultControllerClose(stream[kState].controller); | ||
| 1377 | - } else { | ||
| 1378 | - readableStreamDefaultControllerEnqueue(stream[kState].controller, iterResult.value); | ||
| 1379 | - } | ||
| 1380 | - }); | ||
| 1371 | + const iterResult = await iterator.next(); | ||
| 1372 | + if (typeof iterResult !== 'object' || iterResult === null) { | ||
| 1373 | + throw new ERR_INVALID_STATE.TypeError( | ||
| 1374 | + 'The promise returned by the iterator.next() method must fulfill with an object'); | ||
| 1375 | + } | ||
| 1376 | + if (iterResult.done) { | ||
| 1377 | + readableStreamDefaultControllerClose(stream[kState].controller); | ||
| 1378 | + } else { | ||
| 1379 | + readableStreamDefaultControllerEnqueue(stream[kState].controller, await iterResult.value); | ||
| 1380 | + } | ||
| 1381 | 1381 | } | |
| 1382 | 1382 | ||
| 1383 | 1383 | async function cancelAlgorithm(reason) { | |
| 1384 | - const iterator = iteratorRecord.iterator; | ||
| 1385 | 1384 | const returnMethod = iterator.return; | |
| 1386 | 1385 | if (returnMethod === undefined) { | |
| 1387 | - return PromiseResolve(); | ||
| 1386 | + return; | ||
| 1387 | + } | ||
| 1388 | + const iterResult = await FunctionPrototypeCall(returnMethod, iterator, reason); | ||
| 1389 | + if (typeof iterResult !== 'object' || iterResult === null) { | ||
| 1390 | + throw new ERR_INVALID_STATE.TypeError( | ||
| 1391 | + 'The promise returned by the iterator.return() method must fulfill with an object'); | ||
| 1388 | 1392 | } | |
| 1389 | - const returnResult = FunctionPrototypeCall(returnMethod, iterator, reason); | ||
| 1390 | - const returnPromise = PromiseResolve(returnResult); | ||
| 1391 | - return PromisePrototypeThen(returnPromise, (iterResult) => { | ||
| 1392 | - if (typeof iterResult !== 'object' || iterResult === null) { | ||
| 1393 | - throw new ERR_INVALID_STATE.TypeError( | ||
| 1394 | - 'The promise returned by the iterator.return() method must fulfill with an object'); | ||
| 1395 | - } | ||
| 1396 | - return undefined; | ||
| 1397 | - }); | ||
| 1398 | 1393 | } | |
| 1399 | 1394 | ||
| 1400 | 1395 | stream = createReadableStream( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,16 +14,12 @@ const { | |||
| 14 | 14 | ReflectApply, | |
| 15 | 15 | ReflectGet, | |
| 16 | 16 | Symbol, | |
| 17 | - SymbolAsyncIterator, | ||
| 18 | - SymbolIterator, | ||
| 19 | 17 | Uint8Array, | |
| 20 | 18 | } = primordials; | |
| 21 | 19 | ||
| 22 | 20 | const { | |
| 23 | 21 | codes: { | |
| 24 | - ERR_ARG_NOT_ITERABLE, | ||
| 25 | 22 | ERR_INVALID_ARG_VALUE, | |
| 26 | - ERR_INVALID_STATE, | ||
| 27 | 23 | }, | |
| 28 | 24 | } = require('internal/errors'); | |
| 29 | 25 | ||
@@ -203,64 +199,6 @@ function lazyTransfer() { | |||
| 203 | 199 | return transfer; | |
| 204 | 200 | } | |
| 205 | 201 | ||
| 206 | - function createAsyncFromSyncIterator(syncIteratorRecord) { | ||
| 207 | - const syncIterable = { | ||
| 208 | - [SymbolIterator]: () => syncIteratorRecord.iterator, | ||
| 209 | - }; | ||
| 210 | - | ||
| 211 | - const asyncIterator = (async function* () { | ||
| 212 | - return yield* syncIterable; | ||
| 213 | - }()); | ||
| 214 | - | ||
| 215 | - const nextMethod = asyncIterator.next; | ||
| 216 | - return { iterator: asyncIterator, nextMethod, done: false }; | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - // Refs: https://tc39.es/ecma262/#sec-getiterator | ||
| 220 | - function getIterator(obj, kind = 'sync', method) { | ||
| 221 | - if (method === undefined) { | ||
| 222 | - if (kind === 'async') { | ||
| 223 | - method = obj[SymbolAsyncIterator]; | ||
| 224 | - if (method == null) { | ||
| 225 | - const syncMethod = obj[SymbolIterator]; | ||
| 226 | - | ||
| 227 | - if (syncMethod === undefined) { | ||
| 228 | - throw new ERR_ARG_NOT_ITERABLE(obj); | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | - const syncIteratorRecord = getIterator(obj, 'sync', syncMethod); | ||
| 232 | - return createAsyncFromSyncIterator(syncIteratorRecord); | ||
| 233 | - } | ||
| 234 | - } else { | ||
| 235 | - method = obj[SymbolIterator]; | ||
| 236 | - } | ||
| 237 | - } | ||
| 238 | - | ||
| 239 | - if (method === undefined) { | ||
| 240 | - throw new ERR_ARG_NOT_ITERABLE(obj); | ||
| 241 | - } | ||
| 242 | - | ||
| 243 | - const iterator = FunctionPrototypeCall(method, obj); | ||
| 244 | - if (typeof iterator !== 'object' || iterator === null) { | ||
| 245 | - throw new ERR_INVALID_STATE.TypeError('The iterator method must return an object'); | ||
| 246 | - } | ||
| 247 | - const nextMethod = iterator.next; | ||
| 248 | - return { iterator, nextMethod, done: false }; | ||
| 249 | - } | ||
| 250 | - | ||
| 251 | - function iteratorNext(iteratorRecord, value) { | ||
| 252 | - let result; | ||
| 253 | - if (value === undefined) { | ||
| 254 | - result = FunctionPrototypeCall(iteratorRecord.nextMethod, iteratorRecord.iterator); | ||
| 255 | - } else { | ||
| 256 | - result = FunctionPrototypeCall(iteratorRecord.nextMethod, iteratorRecord.iterator, [value]); | ||
| 257 | - } | ||
| 258 | - if (typeof result !== 'object' || result === null) { | ||
| 259 | - throw new ERR_INVALID_STATE.TypeError('The iterator.next() method must return an object'); | ||
| 260 | - } | ||
| 261 | - return result; | ||
| 262 | - } | ||
| 263 | - | ||
| 264 | 202 | module.exports = { | |
| 265 | 203 | ArrayBufferViewGetBuffer, | |
| 266 | 204 | ArrayBufferViewGetByteLength, | |
@@ -286,8 +224,6 @@ module.exports = { | |||
| 286 | 224 | nonOpPull, | |
| 287 | 225 | nonOpStart, | |
| 288 | 226 | nonOpWrite, | |
| 289 | - getIterator, | ||
| 290 | - iteratorNext, | ||
| 291 | 227 | kType, | |
| 292 | 228 | kState, | |
| 293 | 229 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments