trace_events: respect inspect() depth

This commit causes the Tracing class to account for
util.inspect() depth.

PR-URL: https://github.com/nodejs/node/pull/28037
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
cjihrig 2019-06-02 22:33:23 -04:00
parent 39d6da81f9
commit 81a9c7201f
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 15 additions and 0 deletions

View File

@ -61,6 +61,9 @@ class Tracing {
}
[customInspectSymbol](depth, opts) {
if (typeof depth === 'number' && depth < 0)
return this;
const obj = {
enabled: this.enabled,
categories: this.categories

View File

@ -2519,3 +2519,15 @@ assert.strictEqual(
assert(i < 2 || line.startsWith('\u001b[90m'));
});
}
{
// Tracing class respects inspect depth.
try {
const trace = require('trace_events').createTracing({ categories: ['fo'] });
const actual = util.inspect({ trace }, { depth: 0 });
assert.strictEqual(actual, '{ trace: [Tracing] }');
} catch (err) {
if (err.code !== 'ERR_TRACE_EVENTS_UNAVAILABLE')
throw err;
}
}