mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user