Skip to content

Commit 996463c

Browse files
committed
Refactor to ensure function name match exists.
Previously, the function would error for several examples, e.g. `constructorName( inheritedPropertyDescriptors( [] ) )`.
1 parent c4b123f commit 996463c

File tree

1 file changed

+5
-1
lines changed
  • lib/node_modules/@stdlib/utils/constructor-name/lib

1 file changed

+5
-1
lines changed

lib/node_modules/@stdlib/utils/constructor-name/lib/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var isBuffer = require( '@stdlib/assert/is-buffer' );
5454
* // returns 'Function'
5555
*/
5656
function constructorName( v ) {
57+
var match;
5758
var name;
5859
var ctor;
5960
name = nativeClass( v ).slice( 8, -1 );
@@ -62,7 +63,10 @@ function constructorName( v ) {
6263
if ( typeof ctor.name === 'string' ) {
6364
return ctor.name;
6465
}
65-
return RE.exec( ctor.toString() )[ 1 ];
66+
match = RE.exec( ctor.toString() );
67+
if ( match ) {
68+
return match[ 1 ];
69+
}
6670
}
6771
if ( isBuffer( v ) ) {
6872
return 'Buffer';

0 commit comments

Comments
 (0)