Skip to content

Commit

Permalink
perf_hooks: return different functions in timerify
Browse files Browse the repository at this point in the history
Fixes: #42742

PR-URL: #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>
  • Loading branch information
himself65 and hax committed May 1, 2022
1 parent d268cf5 commit 3d0fc13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
18 changes: 0 additions & 18 deletions lib/internal/perf/timerify.js
Expand Up @@ -6,7 +6,6 @@ const {
MathCeil,
ReflectApply,
ReflectConstruct,
Symbol,
} = primordials;

const { InternalPerformanceEntry } = require('internal/perf/performance_entry');
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -71,8 +68,6 @@ function timerify(fn, options = {}) {
histogram);
}

if (fn[kTimerified]) return fn[kTimerified];

const constructor = isConstructor(fn);

function timerified(...args) {
Expand All @@ -95,11 +90,6 @@ function timerify(fn, options = {}) {
}

ObjectDefineProperties(timerified, {
[kTimerified]: {
configurable: false,
enumerable: false,
value: timerified,
},
length: {
configurable: false,
enumerable: true,
Expand All @@ -112,14 +102,6 @@ function timerify(fn, options = {}) {
}
});

ObjectDefineProperties(fn, {
[kTimerified]: {
configurable: false,
enumerable: false,
value: timerified,
}
});

return timerified;
}

Expand Down
8 changes: 5 additions & 3 deletions test/parallel/test-performance-function.js
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 3d0fc13

Please sign in to comment.