@@ -10,7 +10,10 @@ const {
1010 } ,
1111 AbortError,
1212} = require ( 'internal/errors' ) ;
13- const { validateInteger } = require ( 'internal/validators' ) ;
13+ const {
14+ validateAbortSignal,
15+ validateInteger,
16+ } = require ( 'internal/validators' ) ;
1417const { kWeakHandler } = require ( 'internal/event_target' ) ;
1518const { finished } = require ( 'internal/streams/end-of-stream' ) ;
1619
@@ -33,10 +36,12 @@ function map(fn, options) {
3336 throw new ERR_INVALID_ARG_TYPE (
3437 'fn' , [ 'Function' , 'AsyncFunction' ] , fn ) ;
3538 }
36-
3739 if ( options != null && typeof options !== 'object' ) {
3840 throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] ) ;
3941 }
42+ if ( options ?. signal != null ) {
43+ validateAbortSignal ( options . signal , 'options.signal' ) ;
44+ }
4045
4146 let concurrency = 1 ;
4247 if ( options ?. concurrency != null ) {
@@ -161,17 +166,33 @@ function map(fn, options) {
161166 } . call ( this ) ;
162167}
163168
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' ) ;
171175 }
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 ) ;
172186}
173187
174188async 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+
175196 // https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.some
176197 // Note that some does short circuit but also closes the iterator if it does
177198 const ac = new AbortController ( ) ;
@@ -246,6 +267,13 @@ async function reduce(reducer, initialValue, options) {
246267 throw new ERR_INVALID_ARG_TYPE (
247268 'reducer' , [ 'Function' , 'AsyncFunction' ] , reducer ) ;
248269 }
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+
249277 let hasInitialValue = arguments . length > 1 ;
250278 if ( options ?. signal ?. aborted ) {
251279 const err = new AbortError ( undefined , { cause : options . signal . reason } ) ;
@@ -283,6 +311,13 @@ async function reduce(reducer, initialValue, options) {
283311}
284312
285313async 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+
286321 const result = [ ] ;
287322 for await ( const val of this ) {
288323 if ( options ?. signal ?. aborted ) {
@@ -316,6 +351,13 @@ function toIntegerOrInfinity(number) {
316351}
317352
318353function 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+
319361 number = toIntegerOrInfinity ( number ) ;
320362 return async function * drop ( ) {
321363 if ( options ?. signal ?. aborted ) {
@@ -332,8 +374,14 @@ function drop(number, options) {
332374 } . call ( this ) ;
333375}
334376
335-
336377function 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+
337385 number = toIntegerOrInfinity ( number ) ;
338386 return async function * take ( ) {
339387 if ( options ?. signal ?. aborted ) {
0 commit comments