Skip to content

Commit 8a29296

Browse files
himself65hax
authored andcommitted
perf_hooks: return different functions in timerify
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>
1 parent fb8a23a commit 8a29296

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

lib/internal/perf/timerify.js

-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const {
66
MathCeil,
77
ReflectApply,
88
ReflectConstruct,
9-
Symbol,
109
} = primordials;
1110

1211
const { InternalPerformanceEntry } = require('internal/perf/performance_entry');
@@ -35,8 +34,6 @@ const {
3534
enqueue,
3635
} = require('internal/perf/observe');
3736

38-
const kTimerified = Symbol('kTimerified');
39-
4037
function processComplete(name, start, args, histogram) {
4138
const duration = now() - start;
4239
if (histogram !== undefined)
@@ -71,8 +68,6 @@ function timerify(fn, options = {}) {
7168
histogram);
7269
}
7370

74-
if (fn[kTimerified]) return fn[kTimerified];
75-
7671
const constructor = isConstructor(fn);
7772

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

9792
ObjectDefineProperties(timerified, {
98-
[kTimerified]: {
99-
configurable: false,
100-
enumerable: false,
101-
value: timerified,
102-
},
10393
length: {
10494
configurable: false,
10595
enumerable: true,
@@ -112,14 +102,6 @@ function timerify(fn, options = {}) {
112102
}
113103
});
114104

115-
ObjectDefineProperties(fn, {
116-
[kTimerified]: {
117-
configurable: false,
118-
enumerable: false,
119-
value: timerified,
120-
}
121-
});
122-
123105
return timerified;
124106
}
125107

test/parallel/test-performance-function.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ const {
7575
});
7676
}
7777

78-
// Function can only be wrapped once, also check length and name
78+
// Function can be wrapped many times, also check length and name
7979
{
8080
const m = (a, b = 1) => {};
8181
const n = performance.timerify(m);
8282
const o = performance.timerify(m);
8383
const p = performance.timerify(n);
84-
assert.strictEqual(n, o);
85-
assert.strictEqual(n, p);
84+
assert.notStrictEqual(n, o);
85+
assert.notStrictEqual(n, p);
86+
assert.notStrictEqual(o, p);
8687
assert.strictEqual(n.length, m.length);
8788
assert.strictEqual(n.name, 'timerified m');
89+
assert.strictEqual(p.name, 'timerified timerified m');
8890
}
8991

9092
(async () => {

0 commit comments

Comments
 (0)