From f2cb00894c260c3eec22bd3b17271a8765072d30 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Mon, 24 Oct 2022 12:13:36 +0900 Subject: [PATCH 1/3] 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 --- 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 | 11 +++++++++++ 4 files changed, 31 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..5e96cc4b195bf7 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,16 @@ assert(PerformanceMark); assert(performance.mark); assert(performance.measure); +assert.deepStrictEqual( + Object.getOwnPropertyDescriptor(PerformanceMark.prototype, Symbol.toStringTag), + { configurable: true, enumerable: false, value: 'PerformanceMark', writable: false }, +); + +assert.deepStrictEqual( + Object.getOwnPropertyDescriptor(PerformanceMeasure.prototype, Symbol.toStringTag), + { configurable: true, enumerable: false, value: 'PerformanceMeasure', writable: false }, +); + [undefined, 'a', 'null', 1, true].forEach((i) => { const m = performance.mark(i); assert(m instanceof PerformanceEntry); From a2cd0ae6cf35065c61fdba02d05272dea9c88a6f Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Tue, 25 Oct 2022 23:01:02 +0900 Subject: [PATCH 2/3] fixup: apply the review Signed-off-by: Daeyeon Jeong --- test/parallel/test-perf-hooks-usertiming.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-perf-hooks-usertiming.js b/test/parallel/test-perf-hooks-usertiming.js index 5e96cc4b195bf7..fad256f02b9369 100644 --- a/test/parallel/test-perf-hooks-usertiming.js +++ b/test/parallel/test-perf-hooks-usertiming.js @@ -19,15 +19,17 @@ assert(PerformanceMark); assert(performance.mark); assert(performance.measure); -assert.deepStrictEqual( - Object.getOwnPropertyDescriptor(PerformanceMark.prototype, Symbol.toStringTag), - { configurable: true, enumerable: false, value: 'PerformanceMark', writable: false }, -); - -assert.deepStrictEqual( - Object.getOwnPropertyDescriptor(PerformanceMeasure.prototype, Symbol.toStringTag), - { configurable: true, enumerable: false, value: 'PerformanceMeasure', writable: false }, -); +[PerformanceMark, PerformanceMeasure].forEach((c) => { + assert.deepStrictEqual( + Object.getOwnPropertyDescriptor(c.prototype, Symbol.toStringTag), + { + configurable: true, + enumerable: false, + writable: false, + value: c.prototype.constructor.name, + } + ); +}); [undefined, 'a', 'null', 1, true].forEach((i) => { const m = performance.mark(i); From 07b8444eaea0dc223cf445389e4031c6fd2d7085 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Tue, 25 Oct 2022 23:36:49 +0900 Subject: [PATCH 3/3] fixup: apply the review Signed-off-by: Daeyeon Jeong --- test/parallel/test-perf-hooks-usertiming.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-perf-hooks-usertiming.js b/test/parallel/test-perf-hooks-usertiming.js index fad256f02b9369..b895476fa51cdc 100644 --- a/test/parallel/test-perf-hooks-usertiming.js +++ b/test/parallel/test-perf-hooks-usertiming.js @@ -26,7 +26,7 @@ assert(performance.measure); configurable: true, enumerable: false, writable: false, - value: c.prototype.constructor.name, + value: c.name, } ); });