@@ -39,7 +39,10 @@ const {
39
39
isUint8Array
40
40
} = require ( 'internal/util/types' ) ;
41
41
42
- const { validateString } = require ( 'internal/validators' ) ;
42
+ const {
43
+ validateString,
44
+ validateObject,
45
+ } = require ( 'internal/validators' ) ;
43
46
44
47
const {
45
48
encodeInto,
@@ -63,12 +66,6 @@ function validateDecoder(obj) {
63
66
throw new ERR_INVALID_THIS ( 'TextDecoder' ) ;
64
67
}
65
68
66
- function validateArgument ( prop , expected , propName , expectedName ) {
67
- // eslint-disable-next-line valid-typeof
68
- if ( typeof prop !== expected )
69
- throw new ERR_INVALID_ARG_TYPE ( propName , expectedName , prop ) ;
70
- }
71
-
72
69
const CONVERTER_FLAGS_FLUSH = 0x1 ;
73
70
const CONVERTER_FLAGS_FATAL = 0x2 ;
74
71
const CONVERTER_FLAGS_IGNORE_BOM = 0x4 ;
@@ -381,7 +378,10 @@ function makeTextDecoderICU() {
381
378
class TextDecoder {
382
379
constructor ( encoding = 'utf-8' , options = { } ) {
383
380
encoding = `${ encoding } ` ;
384
- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
381
+ validateObject ( options , 'options' , {
382
+ nullable : true ,
383
+ allowArray : true
384
+ } ) ;
385
385
386
386
const enc = getEncodingFromLabel ( encoding ) ;
387
387
if ( enc === undefined )
@@ -413,7 +413,10 @@ function makeTextDecoderICU() {
413
413
[ 'ArrayBuffer' , 'ArrayBufferView' ] ,
414
414
input ) ;
415
415
}
416
- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
416
+ validateObject ( options , 'options' , {
417
+ nullable : true ,
418
+ allowArray : true
419
+ } ) ;
417
420
418
421
let flags = 0 ;
419
422
if ( options !== null )
@@ -447,7 +450,10 @@ function makeTextDecoderJS() {
447
450
class TextDecoder {
448
451
constructor ( encoding = 'utf-8' , options = { } ) {
449
452
encoding = `${ encoding } ` ;
450
- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
453
+ validateObject ( options , 'options' , {
454
+ nullable : true ,
455
+ allowArray : true
456
+ } ) ;
451
457
452
458
const enc = getEncodingFromLabel ( encoding ) ;
453
459
if ( enc === undefined || ! hasConverter ( enc ) )
@@ -481,7 +487,10 @@ function makeTextDecoderJS() {
481
487
[ 'ArrayBuffer' , 'ArrayBufferView' ] ,
482
488
input ) ;
483
489
}
484
- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
490
+ validateObject ( options , 'options' , {
491
+ nullable : true ,
492
+ allowArray : true
493
+ } ) ;
485
494
486
495
if ( this [ kFlags ] & CONVERTER_FLAGS_FLUSH ) {
487
496
this [ kBOMSeen ] = false ;
0 commit comments