@@ -42,6 +42,7 @@ const {
42
42
validateBoolean,
43
43
validateFunction,
44
44
validateInt32,
45
+ validateObject,
45
46
validateUint32,
46
47
validateString,
47
48
} = require ( 'internal/validators' ) ;
@@ -92,9 +93,7 @@ class Module {
92
93
} = options ;
93
94
94
95
if ( context !== undefined ) {
95
- if ( typeof context !== 'object' || context === null ) {
96
- throw new ERR_INVALID_ARG_TYPE ( 'options.context' , 'Object' , context ) ;
97
- }
96
+ validateObject ( context , 'context' ) ;
98
97
if ( ! isContext ( context ) ) {
99
98
throw new ERR_INVALID_ARG_TYPE ( 'options.context' , 'vm.Context' ,
100
99
context ) ;
@@ -204,9 +203,7 @@ class Module {
204
203
throw new ERR_VM_MODULE_NOT_MODULE ( ) ;
205
204
}
206
205
207
- if ( typeof options !== 'object' || options === null ) {
208
- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
209
- }
206
+ validateObject ( options , 'options' ) ;
210
207
211
208
let timeout = options . timeout ;
212
209
if ( timeout === undefined ) {
@@ -261,10 +258,7 @@ class SourceTextModule extends Module {
261
258
262
259
constructor ( sourceText , options = { } ) {
263
260
validateString ( sourceText , 'sourceText' ) ;
264
-
265
- if ( typeof options !== 'object' || options === null ) {
266
- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
267
- }
261
+ validateObject ( options , 'options' ) ;
268
262
269
263
const {
270
264
lineOffset = 0 ,
@@ -408,9 +402,7 @@ class SyntheticModule extends Module {
408
402
}
409
403
validateFunction ( evaluateCallback , 'evaluateCallback' ) ;
410
404
411
- if ( typeof options !== 'object' || options === null ) {
412
- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
413
- }
405
+ validateObject ( options , 'options' ) ;
414
406
415
407
const { context, identifier } = options ;
416
408
0 commit comments