Skip to content

Commit 277d9da

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

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
@@ -21,7 +21,6 @@ const {
2121
const { isContext } = internalBinding('contextify');
2222
const {
2323
isModuleNamespaceObject,
24-
isArrayBufferView,
2524
} = require('internal/util/types');
2625
const {
2726
customInspectSymbol,
@@ -41,6 +40,7 @@ const {
4140
} = require('internal/errors').codes;
4241
const {
4342
validateBoolean,
43+
validateBuffer,
4444
validateFunction,
4545
validateInt32,
4646
validateObject,
@@ -276,25 +276,16 @@ class SourceTextModule extends Module {
276276
validateInt32(lineOffset, 'options.lineOffset');
277277
validateInt32(columnOffset, 'options.columnOffset');
278278

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

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

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

300291
super({

0 commit comments

Comments
 (0)