-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix: add performance.timerify method to perf_hooks #27887
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -139,6 +139,32 @@ export default { | |||||
| setResourceTimingBufferSize(_) { | ||||||
| return performance.setResourceTimingBufferSize(...arguments); | ||||||
| }, | ||||||
| timerify(fn) { | ||||||
| if (typeof fn !== 'function') { | ||||||
| throw new TypeError('The "fn" argument must be of type function'); | ||||||
| } | ||||||
|
Comment on lines
+143
to
+145
Contributor
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. 🧹 Nitpick | 🔵 Trivial Use Per coding guidelines, use JSC intrinsics like ♻️ Proposed fix timerify(fn) {
- if (typeof fn !== 'function') {
- throw new TypeError('The "fn" argument must be of type function');
+ if (!$isCallable(fn)) {
+ throw $ERR_INVALID_ARG_TYPE('fn', 'function', fn);
}🤖 Prompt for AI Agents |
||||||
| return function (...args) { | ||||||
| const start = performance.now(); | ||||||
| try { | ||||||
| const result = fn.apply(this, args); | ||||||
|
Contributor
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. 🛠️ Refactor suggestion | 🟠 Major Use As per coding guidelines, builtin modules should use ♻️ Proposed fix- const result = fn.apply(this, args);
+ const result = fn.$apply(this, args);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| // If result is a promise, measure when it resolves | ||||||
| if (result && typeof result.then === 'function') { | ||||||
| return result.then((value) => { | ||||||
| const duration = performance.now() - start; | ||||||
| performance.measure(fn.name || 'anonymous', { start, duration: start + duration }); | ||||||
|
Contributor
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. Bug: Incorrect The Use either 🐛 Proposed fix if (result && typeof result.then === 'function') {
return result.then((value) => {
const duration = performance.now() - start;
- performance.measure(fn.name || 'anonymous', { start, duration: start + duration });
+ performance.measure(fn.name || 'anonymous', { start, duration });
return value;
});
}
const duration = performance.now() - start;
- performance.measure(fn.name || 'anonymous', { start, duration: start + duration });
+ performance.measure(fn.name || 'anonymous', { start, duration });
return result;
} catch (error) {
const duration = performance.now() - start;
- performance.measure(fn.name || 'anonymous', { start, duration: start + duration });
+ performance.measure(fn.name || 'anonymous', { start, duration });
throw error;
}Also applies to: 159-159, 163-163 🤖 Prompt for AI Agents |
||||||
| return value; | ||||||
| }); | ||||||
|
Comment on lines
+151
to
+156
Contributor
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. Promise rejection not measured. When the wrapped function returns a promise that rejects, no measurement is recorded. The sync 🛡️ Proposed fix to handle promise rejection if (result && typeof result.then === 'function') {
- return result.then((value) => {
- const duration = performance.now() - start;
- performance.measure(fn.name || 'anonymous', { start, duration });
- return value;
- });
+ return result.then(
+ (value) => {
+ const duration = performance.now() - start;
+ performance.measure(fn.name || 'anonymous', { start, duration });
+ return value;
+ },
+ (error) => {
+ const duration = performance.now() - start;
+ performance.measure(fn.name || 'anonymous', { start, duration });
+ throw error;
+ }
+ );
}🤖 Prompt for AI Agents |
||||||
| } | ||||||
| const duration = performance.now() - start; | ||||||
| performance.measure(fn.name || 'anonymous', { start, duration: start + duration }); | ||||||
| return result; | ||||||
| } catch (error) { | ||||||
| const duration = performance.now() - start; | ||||||
| performance.measure(fn.name || 'anonymous', { start, duration: start + duration }); | ||||||
| throw error; | ||||||
| } | ||||||
| }; | ||||||
| }, | ||||||
| timeOrigin: performance.timeOrigin, | ||||||
| toJSON(_) { | ||||||
| return performance.toJSON(...arguments); | ||||||
|
|
||||||
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.
🧹 Nitpick | 🔵 Trivial
Add
thisparameter typing for TypeScript.Per coding guidelines, builtin functions must include
thisparameter typing in TypeScript to enable direct method binding in C++.♻️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents