99const  kCode  =  Symbol ( 'code' ) ; 
1010const  messages  =  new  Map ( ) ; 
1111
12- var  util ; 
13- function  lazyUtil ( )  { 
14-   if  ( ! util ) 
15-     util  =  require ( 'util' ) ; 
16-   return  util ; 
17- } 
18- 
19- var  assert ; 
20- function  lazyAssert ( )  { 
21-   if  ( ! assert ) 
22-     assert  =  require ( 'assert' ) ; 
23-   return  assert ; 
24- } 
12+ // Lazily loaded 
13+ var  assert  =  null ; 
14+ var  util  =  null ; 
2515
2616function  makeNodeError ( Base )  { 
2717  return  class  NodeError  extends  Base  { 
@@ -45,13 +35,14 @@ class AssertionError extends Error {
4535    if  ( typeof  options  !==  'object'  ||  options  ===  null )  { 
4636      throw  new  exports . TypeError ( 'ERR_INVALID_ARG_TYPE' ,  'options' ,  'object' ) ; 
4737    } 
48-     const  util  =  lazyUtil ( ) ; 
49-     const  message  =  options . message  || 
50-                     `${ util . inspect ( options . actual ) . slice ( 0 ,  128 ) }   + 
51-                     `${ options . operator }   + 
52-                     util . inspect ( options . expected ) . slice ( 0 ,  128 ) ; 
38+     if  ( options . message )  { 
39+       super ( options . message ) ; 
40+     }  else  { 
41+       if  ( util  ===  null )  util  =  require ( 'util' ) ; 
42+       super ( `${ util . inspect ( options . actual ) . slice ( 0 ,  128 ) }   + 
43+         `${ options . operator } ${ util . inspect ( options . expected ) . slice ( 0 ,  128 ) }  ) ; 
44+     } 
5345
54-     super ( message ) ; 
5546    this . generatedMessage  =  ! options . message ; 
5647    this . name  =  'AssertionError [ERR_ASSERTION]' ; 
5748    this . code  =  'ERR_ASSERTION' ; 
@@ -63,15 +54,16 @@ class AssertionError extends Error {
6354} 
6455
6556function  message ( key ,  args )  { 
66-   const   assert  =   lazyAssert ( ) ; 
57+   if   ( assert  ===    null )   assert   =   require ( 'assert' ) ; 
6758  assert . strictEqual ( typeof  key ,  'string' ) ; 
68-   const  util  =  lazyUtil ( ) ; 
6959  const  msg  =  messages . get ( key ) ; 
7060  assert ( msg ,  `An invalid error message key was used: ${ key }  ) ; 
71-   let  fmt   =   util . format ; 
61+   let  fmt ; 
7262  if  ( typeof  msg  ===  'function' )  { 
7363    fmt  =  msg ; 
7464  }  else  { 
65+     if  ( util  ===  null )  util  =  require ( 'util' ) ; 
66+     fmt  =  util . format ; 
7567    if  ( args  ===  undefined  ||  args . length  ===  0 ) 
7668      return  msg ; 
7769    args . unshift ( msg ) ; 
@@ -240,7 +232,6 @@ E('ERR_VALID_PERFORMANCE_ENTRY_TYPE',
240232// Add new errors from here... 
241233
242234function  invalidArgType ( name ,  expected ,  actual )  { 
243-   const  assert  =  lazyAssert ( ) ; 
244235  assert ( name ,  'name is required' ) ; 
245236  var  msg  =  `The "${ name } ${ oneOf ( expected ,  'type' ) }  ; 
246237  if  ( arguments . length  >=  3 )  { 
0 commit comments