@@ -4,29 +4,24 @@ const ModuleJob = require('internal/modules/esm/module_job');
4
4
const { SafeMap } = require ( 'internal/safe_globals' ) ;
5
5
const debug = require ( 'util' ) . debuglog ( 'esm' ) ;
6
6
const { ERR_INVALID_ARG_TYPE } = require ( 'internal/errors' ) . codes ;
7
+ const { validateString } = require ( 'internal/validators' ) ;
7
8
8
9
// Tracks the state of the loader-level module cache
9
10
class ModuleMap extends SafeMap {
10
11
get ( url ) {
11
- if ( typeof url !== 'string' ) {
12
- throw new ERR_INVALID_ARG_TYPE ( 'url' , 'string' , url ) ;
13
- }
12
+ validateString ( url , 'url' ) ;
14
13
return super . get ( url ) ;
15
14
}
16
15
set ( url , job ) {
17
- if ( typeof url !== 'string' ) {
18
- throw new ERR_INVALID_ARG_TYPE ( 'url' , 'string' , url ) ;
19
- }
16
+ validateString ( url , 'url' ) ;
20
17
if ( job instanceof ModuleJob !== true ) {
21
18
throw new ERR_INVALID_ARG_TYPE ( 'job' , 'ModuleJob' , job ) ;
22
19
}
23
20
debug ( `Storing ${ url } in ModuleMap` ) ;
24
21
return super . set ( url , job ) ;
25
22
}
26
23
has ( url ) {
27
- if ( typeof url !== 'string' ) {
28
- throw new ERR_INVALID_ARG_TYPE ( 'url' , 'string' , url ) ;
29
- }
24
+ validateString ( url , 'url' ) ;
30
25
return super . has ( url ) ;
31
26
}
32
27
}
0 commit comments