@@ -9251,6 +9251,7 @@ AssertionError.prototype.toJSON = function (stack) {
9251
9251
* MIT Licensed
9252
9252
*/
9253
9253
9254
+ var getFunctionName = require ( 'get-func-name' ) ;
9254
9255
/**
9255
9256
* ### .checkError
9256
9257
*
@@ -9330,34 +9331,6 @@ function compatibleMessage(thrown, errMatcher) {
9330
9331
return false ;
9331
9332
}
9332
9333
9333
- /**
9334
- * ### .getFunctionName(constructorFn)
9335
- *
9336
- * Returns the name of a function.
9337
- * This also includes a polyfill function if `constructorFn.name` is not defined.
9338
- *
9339
- * @name getFunctionName
9340
- * @param {Function } constructorFn
9341
- * @namespace Utils
9342
- * @api private
9343
- */
9344
-
9345
- var functionNameMatch = / \s * f u n c t i o n (?: \s | \s * \/ \* [ ^ ( ? : * \/ ) ] + \* \/ \s * ) * ( [ ^ \( \/ ] + ) / ;
9346
- function getFunctionName ( constructorFn ) {
9347
- var name = '' ;
9348
- if ( typeof constructorFn . name === 'undefined' ) {
9349
- // Here we run a polyfill if constructorFn.name is not defined
9350
- var match = String ( constructorFn ) . match ( functionNameMatch ) ;
9351
- if ( match ) {
9352
- name = match [ 1 ] ;
9353
- }
9354
- } else {
9355
- name = constructorFn . name ;
9356
- }
9357
-
9358
- return name ;
9359
- }
9360
-
9361
9334
/**
9362
9335
* ### .getConstructorName(errorLike)
9363
9336
*
@@ -9377,8 +9350,11 @@ function getConstructorName(errorLike) {
9377
9350
// If `err` is not an instance of Error it is an error constructor itself or another function.
9378
9351
// If we've got a common function we get its name, otherwise we may need to create a new instance
9379
9352
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
9380
- constructorName = getFunctionName ( errorLike ) . trim ( ) ||
9381
- getFunctionName ( new errorLike ( ) ) ; // eslint-disable-line new-cap
9353
+ constructorName = getFunctionName ( errorLike ) ;
9354
+ if ( constructorName === '' ) {
9355
+ var newConstructorName = getFunctionName ( new errorLike ( ) ) ; // eslint-disable-line new-cap
9356
+ constructorName = newConstructorName || constructorName ;
9357
+ }
9382
9358
}
9383
9359
9384
9360
return constructorName ;
@@ -9416,7 +9392,7 @@ module.exports = {
9416
9392
getConstructorName : getConstructorName ,
9417
9393
} ;
9418
9394
9419
- } , { } ] , 35 :[ function ( require , module , exports ) {
9395
+ } , { "get-func-name" : 36 } ] , 35 :[ function ( require , module , exports ) {
9420
9396
'use strict' ;
9421
9397
/* globals Symbol: false, Uint8Array: false, WeakMap: false */
9422
9398
/*!
@@ -9811,8 +9787,15 @@ function getEnumerableKeys(target) {
9811
9787
return keys ;
9812
9788
}
9813
9789
9814
- function getNonEnumerableSymbols ( target ) {
9815
- var keys = Object . getOwnPropertySymbols ( target ) ;
9790
+ function getEnumerableSymbols ( target ) {
9791
+ var keys = [ ] ;
9792
+ var allKeys = Object . getOwnPropertySymbols ( target ) ;
9793
+ for ( var i = 0 ; i < allKeys . length ; i += 1 ) {
9794
+ var key = allKeys [ i ] ;
9795
+ if ( Object . getOwnPropertyDescriptor ( target , key ) . enumerable ) {
9796
+ keys . push ( key ) ;
9797
+ }
9798
+ }
9816
9799
return keys ;
9817
9800
}
9818
9801
@@ -9851,8 +9834,8 @@ function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
9851
9834
function objectEqual ( leftHandOperand , rightHandOperand , options ) {
9852
9835
var leftHandKeys = getEnumerableKeys ( leftHandOperand ) ;
9853
9836
var rightHandKeys = getEnumerableKeys ( rightHandOperand ) ;
9854
- var leftHandSymbols = getNonEnumerableSymbols ( leftHandOperand ) ;
9855
- var rightHandSymbols = getNonEnumerableSymbols ( rightHandOperand ) ;
9837
+ var leftHandSymbols = getEnumerableSymbols ( leftHandOperand ) ;
9838
+ var rightHandSymbols = getEnumerableSymbols ( rightHandOperand ) ;
9856
9839
leftHandKeys = leftHandKeys . concat ( leftHandSymbols ) ;
9857
9840
rightHandKeys = rightHandKeys . concat ( rightHandSymbols ) ;
9858
9841
@@ -9928,15 +9911,23 @@ function mapSymbols(arr) {
9928
9911
9929
9912
var toString = Function . prototype . toString ;
9930
9913
var functionNameMatch = / \s * f u n c t i o n (?: \s | \s * \/ \* [ ^ ( ? : * \/ ) ] + \* \/ \s * ) * ( [ ^ \s \( \/ ] + ) / ;
9914
+ var maxFunctionSourceLength = 512 ;
9931
9915
function getFuncName ( aFunc ) {
9932
9916
if ( typeof aFunc !== 'function' ) {
9933
9917
return null ;
9934
9918
}
9935
9919
9936
9920
var name = '' ;
9937
9921
if ( typeof Function . prototype . name === 'undefined' && typeof aFunc . name === 'undefined' ) {
9922
+ // eslint-disable-next-line prefer-reflect
9923
+ var functionSource = toString . call ( aFunc ) ;
9924
+ // To avoid unconstrained resource consumption due to pathalogically large function names,
9925
+ // we limit the available return value to be less than 512 characters.
9926
+ if ( functionSource . indexOf ( '(' ) > maxFunctionSourceLength ) {
9927
+ return name ;
9928
+ }
9938
9929
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
9939
- var match = toString . call ( aFunc ) . match ( functionNameMatch ) ;
9930
+ var match = functionSource . match ( functionNameMatch ) ;
9940
9931
if ( match ) {
9941
9932
name = match [ 1 ] ;
9942
9933
}
@@ -10332,9 +10323,15 @@ module.exports = getFuncName;
10332
10323
}
10333
10324
10334
10325
function inspectDate ( dateObject , options ) {
10335
- // If we need to - truncate the time portion, but never the date
10336
- var split = dateObject . toJSON ( ) . split ( 'T' ) ;
10337
- var date = split [ 0 ] ;
10326
+ var stringRepresentation = dateObject . toJSON ( ) ;
10327
+
10328
+ if ( stringRepresentation === null ) {
10329
+ return 'Invalid Date' ;
10330
+ }
10331
+
10332
+ var split = stringRepresentation . split ( 'T' ) ;
10333
+ var date = split [ 0 ] ; // If we need to - truncate the time portion, but never the date
10334
+
10338
10335
return options . stylize ( "" . concat ( date , "T" ) . concat ( truncate ( split [ 1 ] , options . truncate - date . length - 1 ) ) , 'date' ) ;
10339
10336
}
10340
10337
@@ -10631,7 +10628,32 @@ module.exports = getFuncName;
10631
10628
nodeInspect = false ;
10632
10629
}
10633
10630
10634
- var constructorMap = new WeakMap ( ) ;
10631
+ function FakeMap ( ) {
10632
+ // eslint-disable-next-line prefer-template
10633
+ this . key = 'chai/loupe__' + Math . random ( ) + Date . now ( ) ;
10634
+ }
10635
+
10636
+ FakeMap . prototype = {
10637
+ // eslint-disable-next-line object-shorthand
10638
+ get : function get ( key ) {
10639
+ return key [ this . key ] ;
10640
+ } ,
10641
+ // eslint-disable-next-line object-shorthand
10642
+ has : function has ( key ) {
10643
+ return this . key in key ;
10644
+ } ,
10645
+ // eslint-disable-next-line object-shorthand
10646
+ set : function set ( key , value ) {
10647
+ if ( Object . isExtensible ( key ) ) {
10648
+ Object . defineProperty ( key , this . key , {
10649
+ // eslint-disable-next-line object-shorthand
10650
+ value : value ,
10651
+ configurable : true
10652
+ } ) ;
10653
+ }
10654
+ }
10655
+ } ;
10656
+ var constructorMap = new ( typeof WeakMap === 'function' ? WeakMap : FakeMap ) ( ) ;
10635
10657
var stringTagMap = { } ;
10636
10658
var baseTypesMap = {
10637
10659
undefined : function undefined$1 ( value , options ) {
@@ -10765,6 +10787,11 @@ module.exports = getFuncName;
10765
10787
} // If it is an object with an anonymous prototype, display it as an object.
10766
10788
10767
10789
10790
+ return inspectObject ( value , options ) ;
10791
+ } // last chance to check if it's an object
10792
+
10793
+
10794
+ if ( value === Object ( value ) ) {
10768
10795
return inspectObject ( value , options ) ;
10769
10796
} // We have run out of options! Just stringify the value
10770
10797
@@ -10776,7 +10803,7 @@ module.exports = getFuncName;
10776
10803
return false ;
10777
10804
}
10778
10805
10779
- constructorMap . add ( constructor , inspector ) ;
10806
+ constructorMap . set ( constructor , inspector ) ;
10780
10807
return true ;
10781
10808
}
10782
10809
function registerStringTag ( stringTag , inspector ) {
0 commit comments