Skip to content

Commit 9fe0424

Browse files
author
Jungku Lee
authored
trace_events: use private fields instead of symbols for Tracing
PR-URL: #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>
1 parent 9db4bf4 commit 9fe0424

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

lib/trace_events.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
const {
44
ArrayPrototypeJoin,
55
SafeSet,
6-
Symbol,
76
} = primordials;
87

98
const { hasTracing } = internalBinding('config');
10-
const kHandle = Symbol('handle');
11-
const kEnabled = Symbol('enabled');
12-
const kCategories = Symbol('categories');
139

1410
const kMaxTracingCount = 10;
1511

@@ -33,16 +29,19 @@ const {
3329
const enabledTracingObjects = new SafeSet();
3430

3531
class Tracing {
32+
#handle;
33+
#categories;
34+
#enabled = false;
35+
3636
constructor(categories) {
37-
this[kHandle] = new CategorySet(categories);
38-
this[kCategories] = categories;
39-
this[kEnabled] = false;
37+
this.#handle = new CategorySet(categories);
38+
this.#categories = categories;
4039
}
4140

4241
enable() {
43-
if (!this[kEnabled]) {
44-
this[kEnabled] = true;
45-
this[kHandle].enable();
42+
if (!this.#enabled) {
43+
this.#enabled = true;
44+
this.#handle.enable();
4645
enabledTracingObjects.add(this);
4746
if (enabledTracingObjects.size > kMaxTracingCount) {
4847
process.emitWarning(
@@ -54,19 +53,19 @@ class Tracing {
5453
}
5554

5655
disable() {
57-
if (this[kEnabled]) {
58-
this[kEnabled] = false;
59-
this[kHandle].disable();
56+
if (this.#enabled) {
57+
this.#enabled = false;
58+
this.#handle.disable();
6059
enabledTracingObjects.delete(this);
6160
}
6261
}
6362

6463
get enabled() {
65-
return this[kEnabled];
64+
return this.#enabled;
6665
}
6766

6867
get categories() {
69-
return ArrayPrototypeJoin(this[kCategories], ',');
68+
return ArrayPrototypeJoin(this.#categories, ',');
7069
}
7170

7271
[customInspectSymbol](depth, opts) {

test/parallel/test-util-inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,7 @@ assert.strictEqual(
29202920
try {
29212921
const trace = require('trace_events').createTracing({ categories: ['fo'] });
29222922
const actualDepth0 = util.inspect({ trace }, { depth: 0 });
2923-
assert.strictEqual(actualDepth0, '{ trace: [Tracing] }');
2923+
assert.strictEqual(actualDepth0, '{ trace: Tracing {} }');
29242924
const actualDepth1 = util.inspect({ trace }, { depth: 1 });
29252925
assert.strictEqual(
29262926
actualDepth1,

0 commit comments

Comments
 (0)