Skip to content

Commit

Permalink
make
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Sep 27, 2023
1 parent a141e57 commit 1a0f887
Showing 1 changed file with 68 additions and 41 deletions.
109 changes: 68 additions & 41 deletions chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -9251,6 +9251,7 @@ AssertionError.prototype.toJSON = function (stack) {
* MIT Licensed
*/

var getFunctionName = require('get-func-name');
/**
* ### .checkError
*
Expand Down Expand Up @@ -9330,34 +9331,6 @@ function compatibleMessage(thrown, errMatcher) {
return false;
}

/**
* ### .getFunctionName(constructorFn)
*
* Returns the name of a function.
* This also includes a polyfill function if `constructorFn.name` is not defined.
*
* @name getFunctionName
* @param {Function} constructorFn
* @namespace Utils
* @api private
*/

var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
function getFunctionName(constructorFn) {
var name = '';
if (typeof constructorFn.name === 'undefined') {
// Here we run a polyfill if constructorFn.name is not defined
var match = String(constructorFn).match(functionNameMatch);
if (match) {
name = match[1];
}
} else {
name = constructorFn.name;
}

return name;
}

/**
* ### .getConstructorName(errorLike)
*
Expand All @@ -9377,8 +9350,11 @@ function getConstructorName(errorLike) {
// If `err` is not an instance of Error it is an error constructor itself or another function.
// If we've got a common function we get its name, otherwise we may need to create a new instance
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
constructorName = getFunctionName(errorLike).trim() ||
getFunctionName(new errorLike()); // eslint-disable-line new-cap
constructorName = getFunctionName(errorLike);
if (constructorName === '') {
var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
constructorName = newConstructorName || constructorName;
}
}

return constructorName;
Expand Down Expand Up @@ -9416,7 +9392,7 @@ module.exports = {
getConstructorName: getConstructorName,
};

},{}],35:[function(require,module,exports){
},{"get-func-name":36}],35:[function(require,module,exports){
'use strict';
/* globals Symbol: false, Uint8Array: false, WeakMap: false */
/*!
Expand Down Expand Up @@ -9811,8 +9787,15 @@ function getEnumerableKeys(target) {
return keys;
}

function getNonEnumerableSymbols(target) {
var keys = Object.getOwnPropertySymbols(target);
function getEnumerableSymbols(target) {
var keys = [];
var allKeys = Object.getOwnPropertySymbols(target);
for (var i = 0; i < allKeys.length; i += 1) {
var key = allKeys[i];
if (Object.getOwnPropertyDescriptor(target, key).enumerable) {
keys.push(key);
}
}
return keys;
}

Expand Down Expand Up @@ -9851,8 +9834,8 @@ function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
function objectEqual(leftHandOperand, rightHandOperand, options) {
var leftHandKeys = getEnumerableKeys(leftHandOperand);
var rightHandKeys = getEnumerableKeys(rightHandOperand);
var leftHandSymbols = getNonEnumerableSymbols(leftHandOperand);
var rightHandSymbols = getNonEnumerableSymbols(rightHandOperand);
var leftHandSymbols = getEnumerableSymbols(leftHandOperand);
var rightHandSymbols = getEnumerableSymbols(rightHandOperand);
leftHandKeys = leftHandKeys.concat(leftHandSymbols);
rightHandKeys = rightHandKeys.concat(rightHandSymbols);

Expand Down Expand Up @@ -9928,15 +9911,23 @@ function mapSymbols(arr) {

var toString = Function.prototype.toString;
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
var maxFunctionSourceLength = 512;
function getFuncName(aFunc) {
if (typeof aFunc !== 'function') {
return null;
}

var name = '';
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
// eslint-disable-next-line prefer-reflect
var functionSource = toString.call(aFunc);
// To avoid unconstrained resource consumption due to pathalogically large function names,
// we limit the available return value to be less than 512 characters.
if (functionSource.indexOf('(') > maxFunctionSourceLength) {
return name;
}
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
var match = toString.call(aFunc).match(functionNameMatch);
var match = functionSource.match(functionNameMatch);
if (match) {
name = match[1];
}
Expand Down Expand Up @@ -10332,9 +10323,15 @@ module.exports = getFuncName;
}

function inspectDate(dateObject, options) {
// If we need to - truncate the time portion, but never the date
var split = dateObject.toJSON().split('T');
var date = split[0];
var stringRepresentation = dateObject.toJSON();

if (stringRepresentation === null) {
return 'Invalid Date';
}

var split = stringRepresentation.split('T');
var date = split[0]; // If we need to - truncate the time portion, but never the date

return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date');
}

Expand Down Expand Up @@ -10631,7 +10628,32 @@ module.exports = getFuncName;
nodeInspect = false;
}

var constructorMap = new WeakMap();
function FakeMap() {
// eslint-disable-next-line prefer-template
this.key = 'chai/loupe__' + Math.random() + Date.now();
}

FakeMap.prototype = {
// eslint-disable-next-line object-shorthand
get: function get(key) {
return key[this.key];
},
// eslint-disable-next-line object-shorthand
has: function has(key) {
return this.key in key;
},
// eslint-disable-next-line object-shorthand
set: function set(key, value) {
if (Object.isExtensible(key)) {
Object.defineProperty(key, this.key, {
// eslint-disable-next-line object-shorthand
value: value,
configurable: true
});
}
}
};
var constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)();
var stringTagMap = {};
var baseTypesMap = {
undefined: function undefined$1(value, options) {
Expand Down Expand Up @@ -10765,6 +10787,11 @@ module.exports = getFuncName;
} // If it is an object with an anonymous prototype, display it as an object.


return inspectObject(value, options);
} // last chance to check if it's an object


if (value === Object(value)) {
return inspectObject(value, options);
} // We have run out of options! Just stringify the value

Expand All @@ -10776,7 +10803,7 @@ module.exports = getFuncName;
return false;
}

constructorMap.add(constructor, inspector);
constructorMap.set(constructor, inspector);
return true;
}
function registerStringTag(stringTag, inspector) {
Expand Down

0 comments on commit 1a0f887

Please sign in to comment.