From 8a5f6d373cf260b36124309dcaa40a4f304585db Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Fri, 28 Oct 2022 08:34:39 +0900 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/45157 Reviewed-By: Antoine du Hamel Reviewed-By: Feng Yu Reviewed-By: James M Snell --- lib/internal/perf/resource_timing.js | 9 +++++---- lib/internal/perf/usertiming.js | 18 ++++++++++-------- .../parallel/test-perf-hooks-resourcetiming.js | 5 +++++ test/parallel/test-perf-hooks-usertiming.js | 13 +++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/internal/perf/resource_timing.js b/lib/internal/perf/resource_timing.js index 8c8dd699b440da..b98295b8426694 100644 --- a/lib/internal/perf/resource_timing.js +++ b/lib/internal/perf/resource_timing.js @@ -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]; @@ -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 = '') { diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index 4544c507752036..42c343a632be40 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -98,10 +98,6 @@ class PerformanceMark { return this[kDetail]; } - get [SymbolToStringTag]() { - return 'PerformanceMark'; - } - toJSON() { return { name: this.name, @@ -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 { @@ -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) { diff --git a/test/parallel/test-perf-hooks-resourcetiming.js b/test/parallel/test-perf-hooks-resourcetiming.js index 889e1ad02af5ce..f9574e90022f86 100644 --- a/test/parallel/test-perf-hooks-resourcetiming.js +++ b/test/parallel/test-perf-hooks-resourcetiming.js @@ -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, diff --git a/test/parallel/test-perf-hooks-usertiming.js b/test/parallel/test-perf-hooks-usertiming.js index c6fd664fdce902..b895476fa51cdc 100644 --- a/test/parallel/test-perf-hooks-usertiming.js +++ b/test/parallel/test-perf-hooks-usertiming.js @@ -6,6 +6,7 @@ const { PerformanceObserver, PerformanceEntry, PerformanceMark, + PerformanceMeasure, performance, performance: { nodeTiming, @@ -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.name, + } + ); +}); + [undefined, 'a', 'null', 1, true].forEach((i) => { const m = performance.mark(i); assert(m instanceof PerformanceEntry);