Skip to content

Commit

Permalink
fix(profiler): handle getters and setters in @Profile decorator (#6318
Browse files Browse the repository at this point in the history
)

The profiler has been broken since #5955
where we introduced properties with getters and setters in some classes.

The decorator implementation was crashing on getters and setters.
  • Loading branch information
vvagaytsev authored Jul 25, 2024
1 parent daea09f commit aa3ddcc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/src/util/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,20 @@ export function Profile(profiler?: Profiler) {
}

for (const propertyName of Object.getOwnPropertyNames(target.prototype)) {
const propertyValue = target.prototype[propertyName]
const isMethod = propertyValue instanceof Function
if (!isMethod) {
continue
const propertyDescriptor = Object.getOwnPropertyDescriptor(target.prototype, propertyName)
if (propertyDescriptor) {
const isGetter = propertyDescriptor.get
const isSetter = propertyDescriptor.set
if (!isGetter && !isSetter) {
const propertyValue = target.prototype[propertyName]
const isMethod = propertyValue instanceof Function
if (!isMethod) {
continue
}
}
}

const descriptor = Object.getOwnPropertyDescriptor(target.prototype, propertyName)!
const descriptor = propertyDescriptor!
const originalMethod = descriptor.get || descriptor.value

const timingKey = `${target.name}#${propertyName}`
Expand Down

0 comments on commit aa3ddcc

Please sign in to comment.