Skip to content

Commit 631bdb4

Browse files
authored
perf_hooks: align toStringTag with other Web Performance implementations
This gets `Symbol.toStringTag` on Web Performance APIs to be aligned with the other runtime implementations. Signed-off-by: Daeyeon Jeong <[email protected]> PR-URL: #45157 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b6eba6b commit 631bdb4

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

lib/internal/perf/resource_timing.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class PerformanceResourceTiming extends PerformanceEntry {
2929
throw new ERR_ILLEGAL_CONSTRUCTOR();
3030
}
3131

32-
get [SymbolToStringTag]() {
33-
return 'PerformanceResourceTiming';
34-
}
35-
3632
get name() {
3733
validateInternalField(this, kRequestedUrl, 'PerformanceResourceTiming');
3834
return this[kRequestedUrl];
@@ -185,6 +181,11 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, {
185181
encodedBodySize: kEnumerableProperty,
186182
decodedBodySize: kEnumerableProperty,
187183
toJSON: kEnumerableProperty,
184+
[SymbolToStringTag]: {
185+
__proto__: null,
186+
configurable: true,
187+
value: 'PerformanceResourceTiming',
188+
},
188189
});
189190

190191
function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') {

lib/internal/perf/usertiming.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ class PerformanceMark {
9898
return this[kDetail];
9999
}
100100

101-
get [SymbolToStringTag]() {
102-
return 'PerformanceMark';
103-
}
104-
105101
toJSON() {
106102
return {
107103
name: this.name,
@@ -116,6 +112,11 @@ ObjectSetPrototypeOf(PerformanceMark, PerformanceEntry);
116112
ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype);
117113
ObjectDefineProperties(PerformanceMark.prototype, {
118114
detail: kEnumerableProperty,
115+
[SymbolToStringTag]: {
116+
__proto__: null,
117+
configurable: true,
118+
value: 'PerformanceMark',
119+
},
119120
});
120121

121122
class PerformanceMeasure extends PerformanceEntry {
@@ -127,13 +128,14 @@ class PerformanceMeasure extends PerformanceEntry {
127128
validateInternalField(this, kDetail, 'PerformanceMeasure');
128129
return this[kDetail];
129130
}
130-
131-
get [SymbolToStringTag]() {
132-
return 'PerformanceMeasure';
133-
}
134131
}
135132
ObjectDefineProperties(PerformanceMeasure.prototype, {
136133
detail: kEnumerableProperty,
134+
[SymbolToStringTag]: {
135+
__proto__: null,
136+
configurable: true,
137+
value: 'PerformanceMeasure',
138+
},
137139
});
138140

139141
function createPerformanceMeasure(name, start, duration, detail) {

test/parallel/test-perf-hooks-resourcetiming.js

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ assert(PerformanceResourceTiming);
1717
assert(performance.clearResourceTimings);
1818
assert(performance.markResourceTiming);
1919

20+
assert.deepStrictEqual(
21+
Object.getOwnPropertyDescriptor(PerformanceResourceTiming.prototype, Symbol.toStringTag),
22+
{ configurable: true, enumerable: false, value: 'PerformanceResourceTiming', writable: false },
23+
);
24+
2025
function createTimingInfo({
2126
startTime = 0,
2227
redirectStartTime = 0,

test/parallel/test-perf-hooks-usertiming.js

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
PerformanceObserver,
77
PerformanceEntry,
88
PerformanceMark,
9+
PerformanceMeasure,
910
performance,
1011
performance: {
1112
nodeTiming,
@@ -18,6 +19,18 @@ assert(PerformanceMark);
1819
assert(performance.mark);
1920
assert(performance.measure);
2021

22+
[PerformanceMark, PerformanceMeasure].forEach((c) => {
23+
assert.deepStrictEqual(
24+
Object.getOwnPropertyDescriptor(c.prototype, Symbol.toStringTag),
25+
{
26+
configurable: true,
27+
enumerable: false,
28+
writable: false,
29+
value: c.name,
30+
}
31+
);
32+
});
33+
2134
[undefined, 'a', 'null', 1, true].forEach((i) => {
2235
const m = performance.mark(i);
2336
assert(m instanceof PerformanceEntry);

0 commit comments

Comments
 (0)