@@ -239,47 +239,50 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
239239 }
240240} ;
241241
242- function _throws ( shouldThrow , block , err , message ) {
243- var exception = null ,
244- threw = false ,
245- typematters = true ;
246-
247- message = message || "" ;
248-
249- //handle optional arguments
250- if ( arguments . length == 3 ) {
251- if ( typeof ( err ) == "string" ) {
252- message = err ;
253- typematters = false ;
242+ function expectedException ( actual , expected ) {
243+ if ( ! actual || ! expected ) {
244+ return false ;
245+ }
246+
247+ if ( expected instanceof RegExp ) {
248+ if ( expected . test ( actual ) ) {
249+ return true ;
254250 }
255- } else if ( arguments . length == 2 ) {
256- typematters = false ;
251+ } else if ( actual instanceof expected || expected . call ( { } , actual ) !== false ) {
252+ return true ;
253+ }
254+ }
255+
256+ function _throws ( shouldThrow , block , expected , message ) {
257+ var actual ;
258+
259+ if ( typeof expected === "string" ) {
260+ message = expected ;
261+ expected = null ;
257262 }
258263
259264 try {
260265 block ( ) ;
261266 } catch ( e ) {
262- threw = true ;
263- exception = e ;
267+ actual = e ;
264268 }
265269
266- if ( shouldThrow && ! threw ) {
267- fail ( "Missing expected exception"
268- + ( err && err . name ? " (" + err . name + ")." : '.' )
269- + ( message ? " " + message : "" )
270- ) ;
270+ message = ( expected && expected . name ? " (" + expected . name + ")." : "." )
271+ + ( message ? " " + message : "." ) ;
272+
273+ if ( shouldThrow && ! actual ) {
274+ fail ( "Missing expected exception" + message ) ;
271275 }
272- if ( ! shouldThrow && threw && typematters && exception instanceof err ) {
273- fail ( "Got unwanted exception"
274- + ( err && err . name ? " (" + err . name + ")." : '.' )
275- + ( message ? " " + message : "" )
276- ) ;
276+
277+ if ( ! shouldThrow && expectedException ( actual , expected ) ) {
278+ fail ( "Got unwanted exception" + message ) ;
277279 }
278- if ( ( shouldThrow && threw && typematters && ! ( exception instanceof err ) ) ||
279- ( ! shouldThrow && threw ) ) {
280- throw exception ;
280+
281+ if ( ( shouldThrow && actual && expected && ! expectedException ( actual , expected ) ) ||
282+ ( ! shouldThrow && actual ) ) {
283+ throw actual ;
281284 }
282- } ;
285+ }
283286
284287// 11. Expected to throw an error:
285288// assert.throws(block, Error_opt, message_opt);
0 commit comments