@@ -13,6 +13,7 @@ const { |
13 | 13 | const { |
14 | 14 | validateAbortSignal, |
15 | 15 | validateInteger, |
| 16 | + validateObject, |
16 | 17 | } = require('internal/validators'); |
17 | 18 | const { kWeakHandler } = require('internal/event_target'); |
18 | 19 | const { finished } = require('internal/streams/end-of-stream'); |
@@ -36,8 +37,8 @@ function map(fn, options) { |
36 | 37 | throw new ERR_INVALID_ARG_TYPE( |
37 | 38 | 'fn', ['Function', 'AsyncFunction'], fn); |
38 | 39 | } |
39 | | - if (options != null && typeof options !== 'object') { |
40 | | - throw new ERR_INVALID_ARG_TYPE('options', ['Object']); |
| 40 | + if (options != null) { |
| 41 | + validateObject(options, 'options'); |
41 | 42 | } |
42 | 43 | if (options?.signal != null) { |
43 | 44 | validateAbortSignal(options.signal, 'options.signal'); |
@@ -167,8 +168,8 @@ function map(fn, options) { |
167 | 168 | } |
168 | 169 |
|
169 | 170 | function 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'); |
172 | 173 | } |
173 | 174 | if (options?.signal != null) { |
174 | 175 | validateAbortSignal(options.signal, 'options.signal'); |
@@ -252,8 +253,8 @@ async function reduce(reducer, initialValue, options) { |
252 | 253 | throw new ERR_INVALID_ARG_TYPE( |
253 | 254 | 'reducer', ['Function', 'AsyncFunction'], reducer); |
254 | 255 | } |
255 | | - if (options != null && typeof options !== 'object') { |
256 | | - throw new ERR_INVALID_ARG_TYPE('options', ['Object']); |
| 256 | + if (options != null) { |
| 257 | + validateObject(options, 'options'); |
257 | 258 | } |
258 | 259 | if (options?.signal != null) { |
259 | 260 | validateAbortSignal(options.signal, 'options.signal'); |
@@ -296,8 +297,8 @@ async function reduce(reducer, initialValue, options) { |
296 | 297 | } |
297 | 298 |
|
298 | 299 | async 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'); |
301 | 302 | } |
302 | 303 | if (options?.signal != null) { |
303 | 304 | validateAbortSignal(options.signal, 'options.signal'); |
@@ -336,8 +337,8 @@ function toIntegerOrInfinity(number) { |
336 | 337 | } |
337 | 338 |
|
338 | 339 | function 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'); |
341 | 342 | } |
342 | 343 | if (options?.signal != null) { |
343 | 344 | validateAbortSignal(options.signal, 'options.signal'); |
@@ -360,8 +361,8 @@ function drop(number, options = undefined) { |
360 | 361 | } |
361 | 362 |
|
362 | 363 | function 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'); |
365 | 366 | } |
366 | 367 | if (options?.signal != null) { |
367 | 368 | validateAbortSignal(options.signal, 'options.signal'); |
|