fix(lib/patcher): clean up unused references for instead hooks

This commit is contained in:
PalmDevs 2025-06-09 22:46:17 +07:00
parent fb41a53f6a
commit 74db4e3ce8
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 11 additions and 7 deletions

View file

@ -39,7 +39,7 @@ export interface HookNode<Hook extends UnknownFunction = UnknownFunction> {
export interface InsteadHookNode<T extends UnknownFunction = UnknownFunction>
extends HookNode<InsteadHook<T>>,
FunctionProxyState<T> {
readonly hook: InsteadHook<T>
hook: InsteadHook<T> | undefined
prev: InsteadHookNode<T> | undefined
next: InsteadHookNode<T> | undefined
}
@ -180,6 +180,9 @@ export function createPatchedFunctionProxy<
}
export function unproxy(state: PatchedFunctionProxyState) {
const { parent, key } = state
if (parent[key] === state.proxy) parent[key] = state.target
const { parent, key, proxy } = state
if (parent[key] === proxy) {
parent[key] = state.target
patchedFunctionProxyStates.delete(proxy)
}
}

View file

@ -24,8 +24,8 @@ const insteadHookProxyHandler = {
receiver: ThisParameterType<T>,
args: Parameters<T>,
) {
const { next } = hookNode
return Reflect.apply(hookNode.hook, receiver, [
const { next, hook } = hookNode
return Reflect.apply(hook!, receiver, [
args,
next === undefined ? hookNode.target : next.proxy,
])
@ -35,9 +35,9 @@ const insteadHookProxyHandler = {
args: ConstructorParameters<T>,
ctor: AbstractNewable,
) {
const { next } = hookNode
const { next, hook } = hookNode
return Reflect.construct(
hookNode.hook,
hook!,
[args, next === undefined ? hookNode.target : next.proxy],
ctor,
)
@ -51,6 +51,7 @@ function unpatchInstead<T extends UnknownFunction>(
if (hookNode.unpatched) return
hookNode.unpatched = true
hookNode.hook = undefined
const { prev, next } = hookNode
if (prev === undefined) {