Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use validateObject #39595

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const {
isUint8Array
} = require('internal/util/types');

const { validateString } = require('internal/validators');
const {
validateString,
validateObject,
} = require('internal/validators');

const {
encodeInto,
Expand All @@ -63,12 +66,6 @@ function validateDecoder(obj) {
throw new ERR_INVALID_THIS('TextDecoder');
}

function validateArgument(prop, expected, propName, expectedName) {
// eslint-disable-next-line valid-typeof
if (typeof prop !== expected)
throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop);
}

const CONVERTER_FLAGS_FLUSH = 0x1;
const CONVERTER_FLAGS_FATAL = 0x2;
const CONVERTER_FLAGS_IGNORE_BOM = 0x4;
Expand Down Expand Up @@ -381,7 +378,14 @@ function makeTextDecoderICU() {
class TextDecoder {
constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`;
validateArgument(options, 'object', 'options', 'Object');
<<<<<<< HEAD
validateObject(options, 'options');
=======
validateObject(options, 'options', {
nullable: true,
allowArray: true
});
>>>>>>> 7da680863e... lib: use `validateObject`

const enc = getEncodingFromLabel(encoding);
if (enc === undefined)
Expand Down Expand Up @@ -413,7 +417,14 @@ function makeTextDecoderICU() {
['ArrayBuffer', 'ArrayBufferView'],
input);
}
validateArgument(options, 'object', 'options', 'Object');
<<<<<<< HEAD
validateObject(options, 'options');
=======
validateObject(options, 'options', {
nullable: true,
allowArray: true
});
>>>>>>> 7da680863e... lib: use `validateObject`

let flags = 0;
if (options !== null)
Expand Down Expand Up @@ -447,7 +458,14 @@ function makeTextDecoderJS() {
class TextDecoder {
constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`;
validateArgument(options, 'object', 'options', 'Object');
<<<<<<< HEAD
validateObject(options, 'options');
=======
validateObject(options, 'options', {
nullable: true,
allowArray: true
});
>>>>>>> 7da680863e... lib: use `validateObject`

const enc = getEncodingFromLabel(encoding);
if (enc === undefined || !hasConverter(enc))
Expand Down Expand Up @@ -481,7 +499,14 @@ function makeTextDecoderJS() {
['ArrayBuffer', 'ArrayBufferView'],
input);
}
validateArgument(options, 'object', 'options', 'Object');
<<<<<<< HEAD
validateObject(options, 'options');
=======
validateObject(options, 'options', {
nullable: true,
allowArray: true
});
>>>>>>> 7da680863e... lib: use `validateObject`

if (this[kFlags] & CONVERTER_FLAGS_FLUSH) {
this[kBOMSeen] = false;
Expand Down