@@ -10,7 +10,10 @@ const {
10
10
} ,
11
11
AbortError,
12
12
} = require ( 'internal/errors' ) ;
13
- const { validateInteger } = require ( 'internal/validators' ) ;
13
+ const {
14
+ validateAbortSignal,
15
+ validateInteger,
16
+ } = require ( 'internal/validators' ) ;
14
17
const { kWeakHandler } = require ( 'internal/event_target' ) ;
15
18
const { finished } = require ( 'internal/streams/end-of-stream' ) ;
16
19
@@ -33,10 +36,12 @@ function map(fn, options) {
33
36
throw new ERR_INVALID_ARG_TYPE (
34
37
'fn' , [ 'Function' , 'AsyncFunction' ] , fn ) ;
35
38
}
36
-
37
39
if ( options != null && typeof options !== 'object' ) {
38
40
throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
39
41
}
42
+ if ( options ?. signal != null ) {
43
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
44
+ }
40
45
41
46
let concurrency = 1 ;
42
47
if ( options ?. concurrency != null ) {
@@ -161,17 +166,33 @@ function map(fn, options) {
161
166
} . call ( this ) ;
162
167
}
163
168
164
- async function * asIndexedPairs ( options ) {
165
- let index = 0 ;
166
- for await ( const val of this ) {
167
- if ( options ?. signal ?. aborted ) {
168
- throw new AbortError ( { cause : options . signal . reason } ) ;
169
- }
170
- yield [ index ++ , val ] ;
169
+ function asIndexedPairs ( options ) {
170
+ if ( options != null && typeof options !== 'object' ) {
171
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
172
+ }
173
+ if ( options ?. signal != null ) {
174
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
171
175
}
176
+
177
+ return async function * asIndexedPairs ( ) {
178
+ let index = 0 ;
179
+ for await ( const val of this ) {
180
+ if ( options ?. signal ?. aborted ) {
181
+ throw new AbortError ( { cause : options . signal . reason } ) ;
182
+ }
183
+ yield [ index ++ , val ] ;
184
+ }
185
+ } . call ( this ) ;
172
186
}
173
187
174
188
async function some ( fn , options ) {
189
+ if ( options != null && typeof options !== 'object' ) {
190
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
191
+ }
192
+ if ( options ?. signal != null ) {
193
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
194
+ }
195
+
175
196
// https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.some
176
197
// Note that some does short circuit but also closes the iterator if it does
177
198
const ac = new AbortController ( ) ;
@@ -246,6 +267,13 @@ async function reduce(reducer, initialValue, options) {
246
267
throw new ERR_INVALID_ARG_TYPE (
247
268
'reducer' , [ 'Function' , 'AsyncFunction' ] , reducer ) ;
248
269
}
270
+ if ( options != null && typeof options !== 'object' ) {
271
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
272
+ }
273
+ if ( options ?. signal != null ) {
274
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
275
+ }
276
+
249
277
let hasInitialValue = arguments . length > 1 ;
250
278
if ( options ?. signal ?. aborted ) {
251
279
const err = new AbortError ( undefined , { cause : options . signal . reason } ) ;
@@ -283,6 +311,13 @@ async function reduce(reducer, initialValue, options) {
283
311
}
284
312
285
313
async function toArray ( options ) {
314
+ if ( options != null && typeof options !== 'object' ) {
315
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
316
+ }
317
+ if ( options ?. signal != null ) {
318
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
319
+ }
320
+
286
321
const result = [ ] ;
287
322
for await ( const val of this ) {
288
323
if ( options ?. signal ?. aborted ) {
@@ -316,6 +351,13 @@ function toIntegerOrInfinity(number) {
316
351
}
317
352
318
353
function drop ( number , options ) {
354
+ if ( options != null && typeof options !== 'object' ) {
355
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
356
+ }
357
+ if ( options ?. signal != null ) {
358
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
359
+ }
360
+
319
361
number = toIntegerOrInfinity ( number ) ;
320
362
return async function * drop ( ) {
321
363
if ( options ?. signal ?. aborted ) {
@@ -332,8 +374,14 @@ function drop(number, options) {
332
374
} . call ( this ) ;
333
375
}
334
376
335
-
336
377
function take ( number , options ) {
378
+ if ( options != null && typeof options !== 'object' ) {
379
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
380
+ }
381
+ if ( options ?. signal != null ) {
382
+ validateAbortSignal ( options . signal , 'options.signal' ) ;
383
+ }
384
+
337
385
number = toIntegerOrInfinity ( number ) ;
338
386
return async function * take ( ) {
339
387
if ( options ?. signal ?. aborted ) {
0 commit comments