@@ -9251,6 +9251,7 @@ AssertionError.prototype.toJSON = function (stack) {
92519251 * MIT Licensed
92529252 */
92539253
9254+ var getFunctionName = require ( 'get-func-name' ) ;
92549255/**
92559256 * ### .checkError
92569257 *
@@ -9330,34 +9331,6 @@ function compatibleMessage(thrown, errMatcher) {
93309331 return false ;
93319332}
93329333
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-
93619334/**
93629335 * ### .getConstructorName(errorLike)
93639336 *
@@ -9377,8 +9350,11 @@ function getConstructorName(errorLike) {
93779350 // If `err` is not an instance of Error it is an error constructor itself or another function.
93789351 // If we've got a common function we get its name, otherwise we may need to create a new instance
93799352 // 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+ }
93829358 }
93839359
93849360 return constructorName ;
@@ -9416,7 +9392,7 @@ module.exports = {
94169392 getConstructorName : getConstructorName ,
94179393} ;
94189394
9419- } , { } ] , 35 :[ function ( require , module , exports ) {
9395+ } , { "get-func-name" : 36 } ] , 35 :[ function ( require , module , exports ) {
94209396'use strict' ;
94219397/* globals Symbol: false, Uint8Array: false, WeakMap: false */
94229398/*!
@@ -9811,8 +9787,15 @@ function getEnumerableKeys(target) {
98119787 return keys ;
98129788}
98139789
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+ }
98169799 return keys ;
98179800}
98189801
@@ -9851,8 +9834,8 @@ function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
98519834function objectEqual ( leftHandOperand , rightHandOperand , options ) {
98529835 var leftHandKeys = getEnumerableKeys ( leftHandOperand ) ;
98539836 var rightHandKeys = getEnumerableKeys ( rightHandOperand ) ;
9854- var leftHandSymbols = getNonEnumerableSymbols ( leftHandOperand ) ;
9855- var rightHandSymbols = getNonEnumerableSymbols ( rightHandOperand ) ;
9837+ var leftHandSymbols = getEnumerableSymbols ( leftHandOperand ) ;
9838+ var rightHandSymbols = getEnumerableSymbols ( rightHandOperand ) ;
98569839 leftHandKeys = leftHandKeys . concat ( leftHandSymbols ) ;
98579840 rightHandKeys = rightHandKeys . concat ( rightHandSymbols ) ;
98589841
@@ -9928,15 +9911,23 @@ function mapSymbols(arr) {
99289911
99299912var toString = Function . prototype . toString ;
99309913var functionNameMatch = / \s * f u n c t i o n (?: \s | \s * \/ \* [ ^ ( ? : * \/ ) ] + \* \/ \s * ) * ( [ ^ \s \( \/ ] + ) / ;
9914+ var maxFunctionSourceLength = 512 ;
99319915function getFuncName ( aFunc ) {
99329916 if ( typeof aFunc !== 'function' ) {
99339917 return null ;
99349918 }
99359919
99369920 var name = '' ;
99379921 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+ }
99389929 // 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 ) ;
99409931 if ( match ) {
99419932 name = match [ 1 ] ;
99429933 }
@@ -10332,9 +10323,15 @@ module.exports = getFuncName;
1033210323 }
1033310324
1033410325 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+
1033810335 return options . stylize ( "" . concat ( date , "T" ) . concat ( truncate ( split [ 1 ] , options . truncate - date . length - 1 ) ) , 'date' ) ;
1033910336 }
1034010337
@@ -10631,7 +10628,32 @@ module.exports = getFuncName;
1063110628 nodeInspect = false ;
1063210629 }
1063310630
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 ) ( ) ;
1063510657 var stringTagMap = { } ;
1063610658 var baseTypesMap = {
1063710659 undefined : function undefined$1 ( value , options ) {
@@ -10765,6 +10787,11 @@ module.exports = getFuncName;
1076510787 } // If it is an object with an anonymous prototype, display it as an object.
1076610788
1076710789
10790+ return inspectObject ( value , options ) ;
10791+ } // last chance to check if it's an object
10792+
10793+
10794+ if ( value === Object ( value ) ) {
1076810795 return inspectObject ( value , options ) ;
1076910796 } // We have run out of options! Just stringify the value
1077010797
@@ -10776,7 +10803,7 @@ module.exports = getFuncName;
1077610803 return false ;
1077710804 }
1077810805
10779- constructorMap . add ( constructor , inspector ) ;
10806+ constructorMap . set ( constructor , inspector ) ;
1078010807 return true ;
1078110808 }
1078210809 function registerStringTag ( stringTag , inspector ) {
0 commit comments