Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: return different functions in timerify #42854

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions lib/internal/perf/timerify.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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