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 <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-authored-by: HE Shi-Jun <hax@heshijun.net>
This commit is contained in:
Himself65
2022-04-24 17:33:00 -05:00
parent d268cf5a22
commit 3d0fc13ba3
2 changed files with 5 additions and 21 deletions

View File

@@ -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;
}

View File

@@ -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 () => {