[DEBUG] More descriptive event reporting

This patch improves DEBUG reporting so that circular event
arguments are shown with some information.
This commit is contained in:
Andrey Lushnikov 2017-07-29 13:02:56 -07:00
parent 0f3a0dcbfc
commit adf35952fc

View File

@ -158,19 +158,24 @@ class Helper {
* @return {string}
*/
function stringifyArgument(arg) {
if (typeof arg !== 'function') {
try {
if (Helper.isString(arg) || Helper.isNumber(arg) || !arg)
return JSON.stringify(arg);
} catch (e) {
// The object was recursive
return arg.toString();
}
}
if (typeof arg === 'function') {
let text = arg.toString().split('\n').map(line => line.trim()).join('');
if (text.length > 20)
text = text.substring(0, 20) + '…';
return `"${text}"`;
}
const state = {};
const keys = Object.keys(arg);
for (let key of keys) {
const value = arg[key];
if (Helper.isString(value) || Helper.isNumber(value))
state[key] = JSON.stringify(value);
}
const name = arg.constructor.name === 'Object' ? '' : arg.constructor.name;
return name + JSON.stringify(state);
}
}
/**