Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: align @@toStringTag with other Web Performance implementations #45157

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/internal/perf/resource_timing.js
Expand Up @@ -29,10 +29,6 @@ class PerformanceResourceTiming extends PerformanceEntry {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

get [SymbolToStringTag]() {
return 'PerformanceResourceTiming';
}

get name() {
validateInternalField(this, kRequestedUrl, 'PerformanceResourceTiming');
return this[kRequestedUrl];
Expand Down Expand Up @@ -185,6 +181,11 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, {
encodedBodySize: kEnumerableProperty,
decodedBodySize: kEnumerableProperty,
toJSON: kEnumerableProperty,
[SymbolToStringTag]: {
__proto__: null,
configurable: true,
value: 'PerformanceResourceTiming',
},
});

function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') {
Expand Down
18 changes: 10 additions & 8 deletions lib/internal/perf/usertiming.js
Expand Up @@ -98,10 +98,6 @@ class PerformanceMark {
return this[kDetail];
}

get [SymbolToStringTag]() {
return 'PerformanceMark';
}

toJSON() {
return {
name: this.name,
Expand All @@ -116,6 +112,11 @@ ObjectSetPrototypeOf(PerformanceMark, PerformanceEntry);
ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype);
ObjectDefineProperties(PerformanceMark.prototype, {
detail: kEnumerableProperty,
[SymbolToStringTag]: {
__proto__: null,
configurable: true,
value: 'PerformanceMark',
},
});

class PerformanceMeasure extends PerformanceEntry {
Expand All @@ -127,13 +128,14 @@ class PerformanceMeasure extends PerformanceEntry {
validateInternalField(this, kDetail, 'PerformanceMeasure');
return this[kDetail];
}

get [SymbolToStringTag]() {
return 'PerformanceMeasure';
}
}
ObjectDefineProperties(PerformanceMeasure.prototype, {
detail: kEnumerableProperty,
[SymbolToStringTag]: {
__proto__: null,
configurable: true,
value: 'PerformanceMeasure',
},
});

function createPerformanceMeasure(name, start, duration, detail) {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-perf-hooks-resourcetiming.js
Expand Up @@ -17,6 +17,11 @@ assert(PerformanceResourceTiming);
assert(performance.clearResourceTimings);
assert(performance.markResourceTiming);

assert.deepStrictEqual(
Object.getOwnPropertyDescriptor(PerformanceResourceTiming.prototype, Symbol.toStringTag),
{ configurable: true, enumerable: false, value: 'PerformanceResourceTiming', writable: false },
);

function createTimingInfo({
startTime = 0,
redirectStartTime = 0,
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-perf-hooks-usertiming.js
Expand Up @@ -6,6 +6,7 @@ const {
PerformanceObserver,
PerformanceEntry,
PerformanceMark,
PerformanceMeasure,
performance,
performance: {
nodeTiming,
Expand All @@ -18,6 +19,18 @@ assert(PerformanceMark);
assert(performance.mark);
assert(performance.measure);

[PerformanceMark, PerformanceMeasure].forEach((c) => {
assert.deepStrictEqual(
Object.getOwnPropertyDescriptor(c.prototype, Symbol.toStringTag),
{
configurable: true,
enumerable: false,
writable: false,
value: c.prototype.constructor.name,
daeyeon marked this conversation as resolved.
Show resolved Hide resolved
}
);
});

[undefined, 'a', 'null', 1, true].forEach((i) => {
const m = performance.mark(i);
assert(m instanceof PerformanceEntry);
Expand Down