File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 234234 }
235235
236236 function createErrorClass ( className ) {
237- var ExtendedError = function ( message ) {
238- Error . call ( this , message ) ;
239- this . name = className ;
237+ function ExtendedError ( message ) {
238+ var instance = new Error ( message ) ;
239+ instance . name = className ;
240+ Object . setPrototypeOf ( instance , Object . getPrototypeOf ( this ) ) ;
241+ if ( Error . captureStackTrace ) {
242+ Error . captureStackTrace ( instance , ExtendedError )
243+ }
244+ return instance ;
240245 } ;
241- ExtendedError . prototype = Object . create ( Error . prototype ) ;
242- ExtendedError . prototype . constructor = ExtendedError ;
246+ ExtendedError . prototype = Object . create ( Error . prototype , {
247+ constructor : {
248+ value : Error ,
249+ enumerable : false ,
250+ writeable : true ,
251+ configurable : true ,
252+ } ,
253+ } ) ;
243254
244255 return ExtendedError ;
245256 }
Original file line number Diff line number Diff line change @@ -227,6 +227,7 @@ describe('search', function() {
227227 assert ( e . message . search (
228228 'expected argument 1 to be type string,array,object'
229229 ) , e . message ) ;
230+ assert . strictEqual ( e . name , 'TypeMismatchError' ) ;
230231 assert ( e . message . search ( 'received type null' ) , e . message ) ;
231232 }
232233 }
You can’t perform that action at this time.
0 commit comments