mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
trace_events: use private fields instead of symbols for Tracing
PR-URL: https://github.com/nodejs/node/pull/51180 Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
This commit is contained in:
parent
9db4bf40d4
commit
9fe0424baa
@ -3,13 +3,9 @@
|
|||||||
const {
|
const {
|
||||||
ArrayPrototypeJoin,
|
ArrayPrototypeJoin,
|
||||||
SafeSet,
|
SafeSet,
|
||||||
Symbol,
|
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
const { hasTracing } = internalBinding('config');
|
const { hasTracing } = internalBinding('config');
|
||||||
const kHandle = Symbol('handle');
|
|
||||||
const kEnabled = Symbol('enabled');
|
|
||||||
const kCategories = Symbol('categories');
|
|
||||||
|
|
||||||
const kMaxTracingCount = 10;
|
const kMaxTracingCount = 10;
|
||||||
|
|
||||||
@ -33,16 +29,19 @@ const {
|
|||||||
const enabledTracingObjects = new SafeSet();
|
const enabledTracingObjects = new SafeSet();
|
||||||
|
|
||||||
class Tracing {
|
class Tracing {
|
||||||
|
#handle;
|
||||||
|
#categories;
|
||||||
|
#enabled = false;
|
||||||
|
|
||||||
constructor(categories) {
|
constructor(categories) {
|
||||||
this[kHandle] = new CategorySet(categories);
|
this.#handle = new CategorySet(categories);
|
||||||
this[kCategories] = categories;
|
this.#categories = categories;
|
||||||
this[kEnabled] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
if (!this[kEnabled]) {
|
if (!this.#enabled) {
|
||||||
this[kEnabled] = true;
|
this.#enabled = true;
|
||||||
this[kHandle].enable();
|
this.#handle.enable();
|
||||||
enabledTracingObjects.add(this);
|
enabledTracingObjects.add(this);
|
||||||
if (enabledTracingObjects.size > kMaxTracingCount) {
|
if (enabledTracingObjects.size > kMaxTracingCount) {
|
||||||
process.emitWarning(
|
process.emitWarning(
|
||||||
@ -54,19 +53,19 @@ class Tracing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
if (this[kEnabled]) {
|
if (this.#enabled) {
|
||||||
this[kEnabled] = false;
|
this.#enabled = false;
|
||||||
this[kHandle].disable();
|
this.#handle.disable();
|
||||||
enabledTracingObjects.delete(this);
|
enabledTracingObjects.delete(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get enabled() {
|
get enabled() {
|
||||||
return this[kEnabled];
|
return this.#enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
get categories() {
|
get categories() {
|
||||||
return ArrayPrototypeJoin(this[kCategories], ',');
|
return ArrayPrototypeJoin(this.#categories, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
[customInspectSymbol](depth, opts) {
|
[customInspectSymbol](depth, opts) {
|
||||||
|
@ -2920,7 +2920,7 @@ assert.strictEqual(
|
|||||||
try {
|
try {
|
||||||
const trace = require('trace_events').createTracing({ categories: ['fo'] });
|
const trace = require('trace_events').createTracing({ categories: ['fo'] });
|
||||||
const actualDepth0 = util.inspect({ trace }, { depth: 0 });
|
const actualDepth0 = util.inspect({ trace }, { depth: 0 });
|
||||||
assert.strictEqual(actualDepth0, '{ trace: [Tracing] }');
|
assert.strictEqual(actualDepth0, '{ trace: Tracing {} }');
|
||||||
const actualDepth1 = util.inspect({ trace }, { depth: 1 });
|
const actualDepth1 = util.inspect({ trace }, { depth: 1 });
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
actualDepth1,
|
actualDepth1,
|
||||||
|
Loading…
Reference in New Issue
Block a user