@@ -39,7 +39,10 @@ const {
3939 isUint8Array
4040} = require ( 'internal/util/types' ) ;
4141
42- const { validateString } = require ( 'internal/validators' ) ;
42+ const {
43+ validateString,
44+ validateObject,
45+ } = require ( 'internal/validators' ) ;
4346
4447const {
4548 encodeInto,
@@ -63,12 +66,6 @@ function validateDecoder(obj) {
6366 throw new ERR_INVALID_THIS ( 'TextDecoder' ) ;
6467}
6568
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-
7269const CONVERTER_FLAGS_FLUSH = 0x1 ;
7370const CONVERTER_FLAGS_FATAL = 0x2 ;
7471const CONVERTER_FLAGS_IGNORE_BOM = 0x4 ;
@@ -381,7 +378,11 @@ function makeTextDecoderICU() {
381378 class TextDecoder {
382379 constructor ( encoding = 'utf-8' , options = { } ) {
383380 encoding = `${ encoding } ` ;
384- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
381+ validateObject ( options , 'options' , {
382+ nullable : true ,
383+ allowArray : true ,
384+ allowFunction : true ,
385+ } ) ;
385386
386387 const enc = getEncodingFromLabel ( encoding ) ;
387388 if ( enc === undefined )
@@ -413,7 +414,11 @@ function makeTextDecoderICU() {
413414 [ 'ArrayBuffer' , 'ArrayBufferView' ] ,
414415 input ) ;
415416 }
416- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
417+ validateObject ( options , 'options' , {
418+ nullable : true ,
419+ allowArray : true ,
420+ allowFunction : true ,
421+ } ) ;
417422
418423 let flags = 0 ;
419424 if ( options !== null )
@@ -447,7 +452,11 @@ function makeTextDecoderJS() {
447452 class TextDecoder {
448453 constructor ( encoding = 'utf-8' , options = { } ) {
449454 encoding = `${ encoding } ` ;
450- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
455+ validateObject ( options , 'options' , {
456+ nullable : true ,
457+ allowArray : true ,
458+ allowFunction : true ,
459+ } ) ;
451460
452461 const enc = getEncodingFromLabel ( encoding ) ;
453462 if ( enc === undefined || ! hasConverter ( enc ) )
@@ -481,7 +490,11 @@ function makeTextDecoderJS() {
481490 [ 'ArrayBuffer' , 'ArrayBufferView' ] ,
482491 input ) ;
483492 }
484- validateArgument ( options , 'object' , 'options' , 'Object' ) ;
493+ validateObject ( options , 'options' , {
494+ nullable : true ,
495+ allowArray : true ,
496+ allowFunction : true ,
497+ } ) ;
485498
486499 if ( this [ kFlags ] & CONVERTER_FLAGS_FLUSH ) {
487500 this [ kBOMSeen ] = false ;
0 commit comments