8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
validateObject
1 parent 37dda19 commit 486d51aCopy full SHA for 486d51a
lib/internal/encoding.js
@@ -39,7 +39,10 @@ const {
39
isUint8Array
40
} = require('internal/util/types');
41
42
-const { validateString } = require('internal/validators');
+const {
43
+ validateString,
44
+ validateObject,
45
+} = require('internal/validators');
46
47
const {
48
encodeInto,
@@ -63,12 +66,6 @@ function validateDecoder(obj) {
63
66
throw new ERR_INVALID_THIS('TextDecoder');
64
67
}
65
68
-function validateArgument(prop, expected, propName, expectedName) {
- // eslint-disable-next-line valid-typeof
- if (typeof prop !== expected)
69
- throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop);
70
-}
71
-
72
const CONVERTER_FLAGS_FLUSH = 0x1;
73
const CONVERTER_FLAGS_FATAL = 0x2;
74
const CONVERTER_FLAGS_IGNORE_BOM = 0x4;
@@ -381,7 +378,11 @@ function makeTextDecoderICU() {
381
378
class TextDecoder {
382
379
constructor(encoding = 'utf-8', options = {}) {
383
380
encoding = `${encoding}`;
384
- validateArgument(options, 'object', 'options', 'Object');
+ validateObject(options, 'options', {
+ nullable: true,
+ allowArray: true,
+ allowFunction: true,
385
+ });
386
387
const enc = getEncodingFromLabel(encoding);
388
if (enc === undefined)
@@ -413,7 +414,11 @@ function makeTextDecoderICU() {
413
414
['ArrayBuffer', 'ArrayBufferView'],
415
input);
416
417
418
419
420
421
422
423
let flags = 0;
424
if (options !== null)
@@ -447,7 +452,11 @@ function makeTextDecoderJS() {
447
452
448
453
449
454
450
455
456
457
458
459
451
460
461
462
if (enc === undefined || !hasConverter(enc))
@@ -481,7 +490,11 @@ function makeTextDecoderJS() {
481
490
482
491
483
492
484
493
494
495
496
497
485
498
486
499
if (this[kFlags] & CONVERTER_FLAGS_FLUSH) {
487
500
this[kBOMSeen] = false;