Skip to content

Commit 2c639c0

Browse files
deokjinkimRafaelGSS
authored andcommitted
vm: refactor to use validate function
Throwing error after checking type is repeated. So replace it with validate function. PR-URL: nodejs#46176 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9da26db commit 2c639c0

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

lib/internal/vm/module.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const {
2020
const { isContext } = internalBinding('contextify');
2121
const {
2222
isModuleNamespaceObject,
23-
isArrayBufferView,
2423
} = require('internal/util/types');
2524
const {
2625
customInspectSymbol,
@@ -40,6 +39,7 @@ const {
4039
} = require('internal/errors').codes;
4140
const {
4241
validateBoolean,
42+
validateBuffer,
4343
validateFunction,
4444
validateInt32,
4545
validateObject,
@@ -275,25 +275,16 @@ class SourceTextModule extends Module {
275275
validateInt32(lineOffset, 'options.lineOffset');
276276
validateInt32(columnOffset, 'options.columnOffset');
277277

278-
if (initializeImportMeta !== undefined &&
279-
typeof initializeImportMeta !== 'function') {
280-
throw new ERR_INVALID_ARG_TYPE(
281-
'options.initializeImportMeta', 'function', initializeImportMeta);
278+
if (initializeImportMeta !== undefined) {
279+
validateFunction(initializeImportMeta, 'options.initializeImportMeta');
282280
}
283281

284-
if (importModuleDynamically !== undefined &&
285-
typeof importModuleDynamically !== 'function') {
286-
throw new ERR_INVALID_ARG_TYPE(
287-
'options.importModuleDynamically', 'function',
288-
importModuleDynamically);
282+
if (importModuleDynamically !== undefined) {
283+
validateFunction(importModuleDynamically, 'options.importModuleDynamically');
289284
}
290285

291-
if (cachedData !== undefined && !isArrayBufferView(cachedData)) {
292-
throw new ERR_INVALID_ARG_TYPE(
293-
'options.cachedData',
294-
['Buffer', 'TypedArray', 'DataView'],
295-
cachedData
296-
);
286+
if (cachedData !== undefined) {
287+
validateBuffer(cachedData, 'options.cachedData');
297288
}
298289

299290
super({

0 commit comments

Comments
 (0)