@@ -13,6 +13,7 @@ const {
1313const {
1414 validateAbortSignal,
1515 validateInteger,
16+ validateObject,
1617} = require ( 'internal/validators' ) ;
1718const { kWeakHandler } = require ( 'internal/event_target' ) ;
1819const { finished } = require ( 'internal/streams/end-of-stream' ) ;
@@ -36,8 +37,8 @@ function map(fn, options) {
3637 throw new ERR_INVALID_ARG_TYPE (
3738 'fn' , [ 'Function' , 'AsyncFunction' ] , fn ) ;
3839 }
39- if ( options != null && typeof options !== 'object' ) {
40- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
40+ if ( options != null ) {
41+ validateObject ( options , 'options' ) ;
4142 }
4243 if ( options ?. signal != null ) {
4344 validateAbortSignal ( options . signal , 'options.signal' ) ;
@@ -167,8 +168,8 @@ function map(fn, options) {
167168}
168169
169170function asIndexedPairs ( options = undefined ) {
170- if ( options != null && typeof options !== 'object' ) {
171- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
171+ if ( options != null ) {
172+ validateObject ( options , 'options' ) ;
172173 }
173174 if ( options ?. signal != null ) {
174175 validateAbortSignal ( options . signal , 'options.signal' ) ;
@@ -252,8 +253,8 @@ async function reduce(reducer, initialValue, options) {
252253 throw new ERR_INVALID_ARG_TYPE (
253254 'reducer' , [ 'Function' , 'AsyncFunction' ] , reducer ) ;
254255 }
255- if ( options != null && typeof options !== 'object' ) {
256- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
256+ if ( options != null ) {
257+ validateObject ( options , 'options' ) ;
257258 }
258259 if ( options ?. signal != null ) {
259260 validateAbortSignal ( options . signal , 'options.signal' ) ;
@@ -296,8 +297,8 @@ async function reduce(reducer, initialValue, options) {
296297}
297298
298299async function toArray ( options ) {
299- if ( options != null && typeof options !== 'object' ) {
300- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
300+ if ( options != null ) {
301+ validateObject ( options , 'options' ) ;
301302 }
302303 if ( options ?. signal != null ) {
303304 validateAbortSignal ( options . signal , 'options.signal' ) ;
@@ -336,8 +337,8 @@ function toIntegerOrInfinity(number) {
336337}
337338
338339function drop ( number , options = undefined ) {
339- if ( options != null && typeof options !== 'object' ) {
340- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
340+ if ( options != null ) {
341+ validateObject ( options , 'options' ) ;
341342 }
342343 if ( options ?. signal != null ) {
343344 validateAbortSignal ( options . signal , 'options.signal' ) ;
@@ -360,8 +361,8 @@ function drop(number, options = undefined) {
360361}
361362
362363function take ( number , options = undefined ) {
363- if ( options != null && typeof options !== 'object' ) {
364- throw new ERR_INVALID_ARG_TYPE ( ' options' , [ 'Object' ] ) ;
364+ if ( options != null ) {
365+ validateObject ( options , 'options' ) ;
365366 }
366367 if ( options ?. signal != null ) {
367368 validateAbortSignal ( options . signal , 'options.signal' ) ;
0 commit comments