-
Notifications
You must be signed in to change notification settings - Fork 30k
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: fix timerify bug #42883
base: main
Are you sure you want to change the base?
perf_hooks: fix timerify bug #42883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict'; | ||
|
||
const { | ||
FunctionPrototypeBind, | ||
ObjectDefineProperties, | ||
MathCeil, | ||
ReflectApply, | ||
|
@@ -75,18 +74,17 @@ function timerify(fn, options = {}) { | |
const result = constructor ? | ||
ReflectConstruct(fn, args, fn) : | ||
ReflectApply(fn, this, args); | ||
if (!constructor && typeof result?.finally === 'function') { | ||
return result.finally( | ||
FunctionPrototypeBind( | ||
processComplete, | ||
result, | ||
fn.name, | ||
start, | ||
args, | ||
histogram)); | ||
if (!constructor && typeof result?.then === 'function') { | ||
return result.then( | ||
function wrappedTimerifiedPromise(value) { | ||
processComplete(fn.name, start, args, histogram); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One idea which is not relate to the bug directly, but: currently, const t = now()
processComplete(fn.name, start - t, args, histogram) (also need to modify other related places, omit here) This could rule out the invoking time of |
||
return value; | ||
} | ||
); | ||
} | ||
processComplete(fn.name, start, args, histogram); | ||
return result; | ||
|
||
} | ||
|
||
ObjectDefineProperties(timerified, { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we retrieve
result.then
twice which theoretically not work like JS spec strictly. We'd better write a helper to ensure such subtle semantic. (Not sure whether Node.js already have such internal thenable helpers).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean like this?
node/lib/assert.js
Lines 763 to 771 in 1e76165
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if follow JS spec strictly, the code should be:
Because theoretically
result.then
could be a getter, and two retrieve could give u different result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't understand why
checkIsPromise
"do not accept thenables that use a function asobj
and that have nocatch
handler" intentionally, this limitation seems wrong to me.