Skip to content

Commit 8cc4aed

Browse files
committed
vm: refactor to use validate function
Throwing error after checking type is repeated. So replace it with validate function.
1 parent a9bc3cf commit 8cc4aed

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lib/internal/vm/module.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const {
4545
validateObject,
4646
validateUint32,
4747
validateString,
48+
validateBuffer,
4849
} = require('internal/validators');
4950

5051
const binding = internalBinding('module_wrap');
@@ -275,25 +276,16 @@ class SourceTextModule extends Module {
275276
validateInt32(lineOffset, 'options.lineOffset');
276277
validateInt32(columnOffset, 'options.columnOffset');
277278

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

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

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

299291
super({

0 commit comments

Comments
 (0)