From 3d0fc13ba374d539cfb9a70e44310877cb6f7ceb Mon Sep 17 00:00:00 2001 From: Himself65 Date: Sun, 24 Apr 2022 17:33:00 -0500 Subject: [PATCH] perf_hooks: return different functions in timerify Fixes: https://github.com/nodejs/node/issues/42742 PR-URL: https://github.com/nodejs/node/pull/42854 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Co-authored-by: HE Shi-Jun --- lib/internal/perf/timerify.js | 18 ------------------ test/parallel/test-performance-function.js | 8 +++++--- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index dae0b06bf80c8a..6bfede7aa1fa20 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -6,7 +6,6 @@ const { MathCeil, ReflectApply, ReflectConstruct, - Symbol, } = primordials; const { InternalPerformanceEntry } = require('internal/perf/performance_entry'); @@ -35,8 +34,6 @@ const { enqueue, } = require('internal/perf/observe'); -const kTimerified = Symbol('kTimerified'); - function processComplete(name, start, args, histogram) { const duration = now() - start; if (histogram !== undefined) @@ -71,8 +68,6 @@ function timerify(fn, options = {}) { histogram); } - if (fn[kTimerified]) return fn[kTimerified]; - const constructor = isConstructor(fn); function timerified(...args) { @@ -95,11 +90,6 @@ function timerify(fn, options = {}) { } ObjectDefineProperties(timerified, { - [kTimerified]: { - configurable: false, - enumerable: false, - value: timerified, - }, length: { configurable: false, enumerable: true, @@ -112,14 +102,6 @@ function timerify(fn, options = {}) { } }); - ObjectDefineProperties(fn, { - [kTimerified]: { - configurable: false, - enumerable: false, - value: timerified, - } - }); - return timerified; } diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js index ea928028208e47..fcc3004d02884a 100644 --- a/test/parallel/test-performance-function.js +++ b/test/parallel/test-performance-function.js @@ -75,16 +75,18 @@ const { }); } -// Function can only be wrapped once, also check length and name +// Function can be wrapped many times, also check length and name { const m = (a, b = 1) => {}; const n = performance.timerify(m); const o = performance.timerify(m); const p = performance.timerify(n); - assert.strictEqual(n, o); - assert.strictEqual(n, p); + assert.notStrictEqual(n, o); + assert.notStrictEqual(n, p); + assert.notStrictEqual(o, p); assert.strictEqual(n.length, m.length); assert.strictEqual(n.name, 'timerified m'); + assert.strictEqual(p.name, 'timerified timerified m'); } (async () => {