log objects in events more consistently

This commit is contained in:
Jeff Williams 2014-01-26 09:37:36 -08:00
parent 28b467f3a8
commit 733eb6bc47

View File

@ -10,6 +10,7 @@ var _ = require('underscore');
var util = require('util');
var conf = env.conf.eventDumper || {};
var isRhino = require('jsdoc/util/runtime').isRhino();
// Dump the included parser events (defaults to all events)
var events = conf.include || [
@ -28,6 +29,20 @@ if (conf.exclude) {
events = _.difference(events, conf.exclude);
}
/**
* Check whether a variable appears to be a Java native object.
*
* @param {*} o - The variable to check.
* @return {boolean} Set to `true` for Java native objects and `false` in all other cases.
*/
function isJavaNativeObject(o) {
if (!isRhino) {
return false;
}
return o && typeof o === 'object' && typeof o.getClass === 'function';
}
/**
* Get rid of native Java crud in an event object so that JSON.stringify() works.
* @param {object} e The event object.
@ -46,12 +61,8 @@ function cleanse(e) {
else if (typeof e[prop] === 'function') {
// do nothing
}
// go down an extra level for these
else if (['code', 'doclet', 'meta'].indexOf(prop) !== -1) {
result[prop] = cleanse(e[prop]);
}
else {
result[prop] = String(e[prop]);
result[prop] = isJavaNativeObject(e[prop]) ? String(e[prop]) : e[prop];
}
});