mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
vm: refactor to use validate function
Throwing error after checking type is repeated. So replace it with validate function. PR-URL: https://github.com/nodejs/node/pull/46176 Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -20,7 +20,6 @@ const {
|
||||
const { isContext } = internalBinding('contextify');
|
||||
const {
|
||||
isModuleNamespaceObject,
|
||||
isArrayBufferView,
|
||||
} = require('internal/util/types');
|
||||
const {
|
||||
customInspectSymbol,
|
||||
@@ -40,6 +39,7 @@ const {
|
||||
} = require('internal/errors').codes;
|
||||
const {
|
||||
validateBoolean,
|
||||
validateBuffer,
|
||||
validateFunction,
|
||||
validateInt32,
|
||||
validateObject,
|
||||
@@ -275,25 +275,16 @@ class SourceTextModule extends Module {
|
||||
validateInt32(lineOffset, 'options.lineOffset');
|
||||
validateInt32(columnOffset, 'options.columnOffset');
|
||||
|
||||
if (initializeImportMeta !== undefined &&
|
||||
typeof initializeImportMeta !== 'function') {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'options.initializeImportMeta', 'function', initializeImportMeta);
|
||||
if (initializeImportMeta !== undefined) {
|
||||
validateFunction(initializeImportMeta, 'options.initializeImportMeta');
|
||||
}
|
||||
|
||||
if (importModuleDynamically !== undefined &&
|
||||
typeof importModuleDynamically !== 'function') {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'options.importModuleDynamically', 'function',
|
||||
importModuleDynamically);
|
||||
if (importModuleDynamically !== undefined) {
|
||||
validateFunction(importModuleDynamically, 'options.importModuleDynamically');
|
||||
}
|
||||
|
||||
if (cachedData !== undefined && !isArrayBufferView(cachedData)) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'options.cachedData',
|
||||
['Buffer', 'TypedArray', 'DataView'],
|
||||
cachedData
|
||||
);
|
||||
if (cachedData !== undefined) {
|
||||
validateBuffer(cachedData, 'options.cachedData');
|
||||
}
|
||||
|
||||
super({
|
||||
|
||||
Reference in New Issue
Block a user