66 * MIT Licensed
77 */
88
9+ var getFunctionName = require ( 'get-func-name' ) ;
910/**
1011 * ### .checkError
1112 *
@@ -85,34 +86,6 @@ function compatibleMessage(thrown, errMatcher) {
8586 return false ;
8687}
8788
88- /**
89- * ### .getFunctionName(constructorFn)
90- *
91- * Returns the name of a function.
92- * This also includes a polyfill function if `constructorFn.name` is not defined.
93- *
94- * @name getFunctionName
95- * @param {Function } constructorFn
96- * @namespace Utils
97- * @api private
98- */
99-
100- var functionNameMatch = / \s * f u n c t i o n (?: \s | \s * \/ \* [ ^ ( ? : * \/ ) ] + \* \/ \s * ) * ( [ ^ \( \/ ] + ) / ;
101- function getFunctionName ( constructorFn ) {
102- var name = '' ;
103- if ( typeof constructorFn . name === 'undefined' ) {
104- // Here we run a polyfill if constructorFn.name is not defined
105- var match = String ( constructorFn ) . match ( functionNameMatch ) ;
106- if ( match ) {
107- name = match [ 1 ] ;
108- }
109- } else {
110- name = constructorFn . name ;
111- }
112-
113- return name ;
114- }
115-
11689/**
11790 * ### .getConstructorName(errorLike)
11891 *
@@ -132,8 +105,11 @@ function getConstructorName(errorLike) {
132105 // If `err` is not an instance of Error it is an error constructor itself or another function.
133106 // If we've got a common function we get its name, otherwise we may need to create a new instance
134107 // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
135- constructorName = getFunctionName ( errorLike ) . trim ( ) ||
136- getFunctionName ( new errorLike ( ) ) ; // eslint-disable-line new-cap
108+ constructorName = getFunctionName ( errorLike ) ;
109+ if ( constructorName === '' ) {
110+ var newConstructorName = getFunctionName ( new errorLike ( ) ) ; // eslint-disable-line new-cap
111+ constructorName = newConstructorName || constructorName ;
112+ }
137113 }
138114
139115 return constructorName ;
0 commit comments