diff options
author | cjihrig <cjihrig@gmail.com> | 2019-06-02 22:33:23 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-06-05 15:39:44 -0400 |
commit | 81a9c7201f66855cdca534dae1a3f53f822a009b (patch) | |
tree | 30dfd011dff5b2c37d74a73dd878efcde8d7fa51 | |
parent | 39d6da81f992240aa87e403cb541e097d26cca26 (diff) | |
download | android-node-v8-81a9c7201f66855cdca534dae1a3f53f822a009b.tar.gz android-node-v8-81a9c7201f66855cdca534dae1a3f53f822a009b.tar.bz2 android-node-v8-81a9c7201f66855cdca534dae1a3f53f822a009b.zip |
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>
-rw-r--r-- | lib/trace_events.js | 3 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/trace_events.js b/lib/trace_events.js index 2b154946d8..0d533c76a7 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -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 diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 834b0c0236..f9566df48a 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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; + } +} |