@@ -211,68 +211,73 @@ function expectedException(actual, expected) {
211211  return  expected . call ( { } ,  actual )  ===  true ; 
212212} 
213213
214- function  tryBlock ( block )  { 
214+ function  getActual ( block )  { 
215+   if  ( typeof  block  !==  'function' )  { 
216+     throw  new  errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,  'block' ,  'Function' , 
217+                                block ) ; 
218+   } 
215219  try  { 
216220    block ( ) ; 
217221  }  catch  ( e )  { 
218222    return  e ; 
219223  } 
220224} 
221225
222- function  innerThrows ( shouldThrow ,  block ,  expected ,  message )  { 
223-   var  details  =  '' ; 
226+ // Expected to throw an error. 
227+ assert . throws  =  function  throws ( block ,  error ,  message )  { 
228+   const  actual  =  getActual ( block ) ; 
224229
225-   if  ( typeof  block  !==  'function' )  { 
226-     throw  new  errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,  'block' ,  'Function' , 
227-                                block ) ; 
228-   } 
230+   if  ( typeof  error  ===  'string' )  { 
231+     if  ( arguments . length  ===  3 ) 
232+       throw  new  errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 
233+                                  'error' , 
234+                                  [ 'Function' ,  'RegExp' ] , 
235+                                  error ) ; 
229236
230-   if  ( typeof  expected  ===  'string' )  { 
231-     message  =  expected ; 
232-     expected  =  null ; 
237+     message  =  error ; 
238+     error  =  null ; 
233239  } 
234240
235-   const  actual  =  tryBlock ( block ) ; 
236- 
237-   if  ( shouldThrow  ===  true )  { 
238-     if  ( actual  ===  undefined )  { 
239-       if  ( expected  &&  expected . name )  { 
240-         details  +=  ` (${ expected . name }  ; 
241-       } 
242-       details  +=  message  ? `: ${ message }   : '.' ; 
243-       innerFail ( { 
244-         actual, 
245-         expected, 
246-         operator : 'throws' , 
247-         message : `Missing expected exception${ details }  , 
248-         stackStartFn : assert . throws 
249-       } ) ; 
250-     } 
251-     if  ( expected  &&  expectedException ( actual ,  expected )  ===  false )  { 
252-       throw  actual ; 
253-     } 
254-   }  else  if  ( actual  !==  undefined )  { 
255-     if  ( ! expected  ||  expectedException ( actual ,  expected ) )  { 
256-       details  =  message  ? `: ${ message }   : '.' ; 
257-       innerFail ( { 
258-         actual, 
259-         expected, 
260-         operator : 'doesNotThrow' , 
261-         message : `Got unwanted exception${ details } ${ actual . message }  , 
262-         stackStartFn : assert . doesNotThrow 
263-       } ) ; 
241+   if  ( actual  ===  undefined )  { 
242+     let  details  =  '' ; 
243+     if  ( error  &&  error . name )  { 
244+       details  +=  ` (${ error . name }  ; 
264245    } 
246+     details  +=  message  ? `: ${ message }   : '.' ; 
247+     innerFail ( { 
248+       actual, 
249+       expected : error , 
250+       operator : 'throws' , 
251+       message : `Missing expected exception${ details }  , 
252+       stackStartFn : throws 
253+     } ) ; 
254+   } 
255+   if  ( error  &&  expectedException ( actual ,  error )  ===  false )  { 
265256    throw  actual ; 
266257  } 
267- } 
268- 
269- // Expected to throw an error. 
270- assert . throws  =  function  throws ( block ,  error ,  message )  { 
271-   innerThrows ( true ,  block ,  error ,  message ) ; 
272258} ; 
273259
274260assert . doesNotThrow  =  function  doesNotThrow ( block ,  error ,  message )  { 
275-   innerThrows ( false ,  block ,  error ,  message ) ; 
261+   const  actual  =  getActual ( block ) ; 
262+   if  ( actual  ===  undefined ) 
263+     return ; 
264+ 
265+   if  ( typeof  error  ===  'string' )  { 
266+     message  =  error ; 
267+     error  =  null ; 
268+   } 
269+ 
270+   if  ( ! error  ||  expectedException ( actual ,  error ) )  { 
271+     const  details  =  message  ? `: ${ message }   : '.' ; 
272+     innerFail ( { 
273+       actual, 
274+       expected : error , 
275+       operator : 'doesNotThrow' , 
276+       message : `Got unwanted exception${ details } ${ actual . message }  , 
277+       stackStartFn : doesNotThrow 
278+     } ) ; 
279+   } 
280+   throw  actual ; 
276281} ; 
277282
278283assert . ifError  =  function  ifError ( err )  {  if  ( err )  throw  err ;  } ; 
0 commit comments