mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib: refactor to use validateBuffer
Use validateBuffer to remove duplicate implementation. PR-URL: https://github.com/nodejs/node/pull/46489 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
f234bd43ce
commit
d43b532789
@ -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');
|
||||
@ -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();
|
||||
@ -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');
|
||||
|
@ -26,6 +26,7 @@ const {
|
||||
} = require('internal/util/types');
|
||||
|
||||
const {
|
||||
validateBuffer,
|
||||
validateInt32,
|
||||
validateObject,
|
||||
validateString,
|
||||
@ -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`,
|
||||
|
12
lib/vm.js
12
lib/vm.js
@ -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,
|
||||
@ -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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user