Verify that perf_hooks result actually contains the performance object (#59300)

This commit is contained in:
Jake Bailey 2024-07-16 10:03:02 -07:00 committed by GitHub
parent ec446b6f19
commit bd54a6bb2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,11 +31,14 @@ function tryGetPerformance() {
if (isNodeLikeSystem()) {
try {
// By default, only write native events when generating a cpu profile or using the v8 profiler.
const { performance } = require("perf_hooks") as typeof import("perf_hooks");
return {
shouldWriteNativeEvents: false,
performance,
};
// Some environments may polyfill this module with an empty object; verify the object has the expected shape.
const { performance } = require("perf_hooks") as Partial<typeof import("perf_hooks")>;
if (performance) {
return {
shouldWriteNativeEvents: false,
performance,
};
}
}
catch {
// ignore errors