feat(lib/utils/proxy): store targets

This commit is contained in:
PalmDevs 2025-03-30 23:28:03 +07:00
parent db52252c68
commit 400026daec
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 6 additions and 6 deletions

View file

@ -4,7 +4,7 @@
*/
export const _instances = new WeakSet<object>()
// export const _targets = new WeakMap<object, object>()
export const _targets = new WeakMap<object, object>()
const OriginalProxy = globalThis.Proxy
globalThis.Proxy = new Proxy(OriginalProxy, {
@ -12,7 +12,7 @@ globalThis.Proxy = new Proxy(OriginalProxy, {
// @ts-expect-error
const prox = new OriginalProxy(...args)
_instances.add(prox)
// _targets.set(prox, args[0])
_targets.set(prox, args[0])
return prox
},
})

View file

@ -1,4 +1,4 @@
import { _instances /* _targets */ } from '../../init/src/patches/proxy'
import { _instances, _targets } from '../../init/src/patches/proxy'
/**
* Returns whether the object is a proxy
@ -8,6 +8,6 @@ export function isProxy(obj: object) {
return _instances.has(obj)
}
// export function getProxyTarget(obj: object) {
// return _targets.get(obj)
// }
export function getProxyTarget(obj: object) {
return _targets.get(obj)
}