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]; } });