From 733eb6bc47318aff92e8853d7acebb1a5402ceb2 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 26 Jan 2014 09:37:36 -0800 Subject: [PATCH] log objects in events more consistently --- plugins/eventDumper.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/eventDumper.js b/plugins/eventDumper.js index 48cf4f64..901ed40b 100644 --- a/plugins/eventDumper.js +++ b/plugins/eventDumper.js @@ -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]; } });