Skip to content

Commit bd54a6b

Browse files
authored
Verify that perf_hooks result actually contains the performance object (#59300)
1 parent ec446b6 commit bd54a6b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/compiler/performanceCore.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ function tryGetPerformance() {
3131
if (isNodeLikeSystem()) {
3232
try {
3333
// By default, only write native events when generating a cpu profile or using the v8 profiler.
34-
const { performance } = require("perf_hooks") as typeof import("perf_hooks");
35-
return {
36-
shouldWriteNativeEvents: false,
37-
performance,
38-
};
34+
// Some environments may polyfill this module with an empty object; verify the object has the expected shape.
35+
const { performance } = require("perf_hooks") as Partial<typeof import("perf_hooks")>;
36+
if (performance) {
37+
return {
38+
shouldWriteNativeEvents: false,
39+
performance,
40+
};
41+
}
3942
}
4043
catch {
4144
// ignore errors

0 commit comments

Comments
 (0)