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: refactor to use validateBuffer #46489

Merged
Merged
Show file tree
Hide file tree
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
17 changes: 7 additions & 10 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ const {
} = require('internal/errors');
const {
isUint32,
validateAbortSignal,
validateBoolean,
validateBuffer,
validateFunction,
validateInt32,
validateInteger,
validateNumber,
validateString,
validateUint32,
validateAbortSignal,
validateBoolean,
} = require('internal/validators');
const fsPromisesInternal = require('internal/fs/promises');
const { utcDate } = require('internal/http');
Expand Down Expand Up @@ -1377,10 +1378,8 @@ class Http2Session extends EventEmitter {
callback = payload;
payload = undefined;
}
if (payload && !isArrayBufferView(payload)) {
throw new ERR_INVALID_ARG_TYPE('payload',
['Buffer', 'TypedArray', 'DataView'],
payload);
if (payload) {
validateBuffer(payload, 'payload');
}
if (payload && payload.length !== 8) {
throw new ERR_HTTP2_PING_LENGTH();
Expand Down Expand Up @@ -1506,10 +1505,8 @@ class Http2Session extends EventEmitter {
if (this.destroyed)
throw new ERR_HTTP2_INVALID_SESSION();

if (opaqueData !== undefined && !isArrayBufferView(opaqueData)) {
throw new ERR_INVALID_ARG_TYPE('opaqueData',
['Buffer', 'TypedArray', 'DataView'],
opaqueData);
if (opaqueData !== undefined) {
validateBuffer(opaqueData, 'opaqueData');
}
validateNumber(code, 'code');
validateNumber(lastStreamID, 'lastStreamID');
Expand Down
8 changes: 2 additions & 6 deletions lib/internal/tls/secure-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
} = require('internal/util/types');

const {
validateBuffer,
validateInt32,
validateObject,
validateString,
Expand Down Expand Up @@ -292,12 +293,7 @@ function configSecureContext(context, options = kEmptyObject, name = 'options')
}

if (ticketKeys !== undefined && ticketKeys !== null) {
if (!isArrayBufferView(ticketKeys)) {
throw new ERR_INVALID_ARG_TYPE(
`${name}.ticketKeys`,
['Buffer', 'TypedArray', 'DataView'],
ticketKeys);
}
validateBuffer(ticketKeys, `${name}.ticketKeys`);
if (ticketKeys.byteLength !== 48) {
throw new ERR_INVALID_ARG_VALUE(
`${name}.ticketKeys`,
Expand Down
12 changes: 3 additions & 9 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ const {
ERR_CONTEXT_NOT_INITIALIZED,
ERR_INVALID_ARG_TYPE,
} = require('internal/errors').codes;
const {
isArrayBufferView,
} = require('internal/util/types');
const {
validateBoolean,
validateBuffer,
validateFunction,
validateInt32,
validateObject,
Expand Down Expand Up @@ -84,12 +82,8 @@ class Script extends ContextifyScript {
validateString(filename, 'options.filename');
validateInt32(lineOffset, 'options.lineOffset');
validateInt32(columnOffset, 'options.columnOffset');
if (cachedData !== undefined && !isArrayBufferView(cachedData)) {
throw new ERR_INVALID_ARG_TYPE(
'options.cachedData',
['Buffer', 'TypedArray', 'DataView'],
cachedData
);
if (cachedData !== undefined) {
validateBuffer(cachedData, 'options.cachedData');
}
validateBoolean(produceCachedData, 'options.produceCachedData');

Expand Down