(cls: {prototype: T}, prop: P, overrides: Record<string, OverrideFactory<T, P>>)
| 31 | documentEventListener('__darkreader__disableConflictingPlugins', disableConflictingPlugins); |
| 32 | |
| 33 | function overrideProperty<T, P extends keyof T>(cls: {prototype: T}, prop: P, overrides: Record<string, OverrideFactory<T, P>>) { |
| 34 | const proto = cls.prototype; |
| 35 | const oldDescriptor = Object.getOwnPropertyDescriptor(proto, prop); |
| 36 | if (!oldDescriptor) { |
| 37 | return; |
| 38 | } |
| 39 | const newDescriptor: PropertyDescriptor = {...oldDescriptor}; |
| 40 | (Object.keys(overrides) as Array<keyof PropertyDescriptor>).forEach((key) => { |
| 41 | const factory = overrides[key]; |
| 42 | newDescriptor[key] = factory(oldDescriptor[key]); |
| 43 | }); |
| 44 | Object.defineProperty(proto, prop, newDescriptor); |
| 45 | cleaners.push(() => Object.defineProperty(proto, prop, oldDescriptor)); |
| 46 | } |
| 47 | |
| 48 | function override<T, P extends keyof T>(cls: {prototype: T}, prop: P, factory: OverrideFactory<T, P>) { |
| 49 | overrideProperty(cls, prop, {value: factory}); |
no outgoing calls
no test coverage detected
searching dependent graphs…