From ed9f4dee4362afb2c274b81cda6755d62858f8c1 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 2 Aug 2026 17:03:57 +0700 Subject: [PATCH] fix(lib/utils/proxy)!: remove proxy patch and `isProxy` `getProxyTarget` --- lib/utils/src/patches/proxy.ts | 9 -------- lib/utils/src/proxy.ts | 40 ++++++++++------------------------ src/preinit.ts | 1 - 3 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 lib/utils/src/patches/proxy.ts diff --git a/lib/utils/src/patches/proxy.ts b/lib/utils/src/patches/proxy.ts deleted file mode 100644 index 29d51b7..0000000 --- a/lib/utils/src/patches/proxy.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const pTargets = new WeakMap() - -globalThis.Proxy = new Proxy(globalThis.Proxy, { - construct(target, args) { - const prox = Reflect.construct(target, args) - pTargets.set(prox, args[0]) - return prox - }, -}) diff --git a/lib/utils/src/proxy.ts b/lib/utils/src/proxy.ts index 3d26801..1e55e1a 100644 --- a/lib/utils/src/proxy.ts +++ b/lib/utils/src/proxy.ts @@ -5,16 +5,6 @@ import { asap } from './callback' import { getCurrentStack } from './error' -import { pTargets } from './patches/proxy' - -/** - * Returns whether the object is a proxy. - * - * @param obj The object to check - */ -export function isProxy(obj: object) { - return pTargets.has(obj) -} /** * Returns whether the object is a proxified value. @@ -25,16 +15,6 @@ export function isProxified(obj: object) { return pMetadata.has(obj) } -/** - * Returns the target of the proxy. - * - * @param obj The proxy - * @returns The target of the proxy - */ -export function getProxyTarget(obj: object) { - return pTargets.get(obj) -} - // Heavily inspired by Wintry's lazy utils, but more optimized and stripped down, with a few fixes. // https://github.com/pylixonly/wintry/blob/main/src/utils/lazy.ts @@ -42,6 +22,7 @@ const pMetadata = new WeakMap< object, { factory: () => unknown + hint: object bind: boolean cacheable: boolean cache?: unknown @@ -132,12 +113,6 @@ export function proxify(signal: () => T, options?: ProxifyOptions): T { // biome-ignore lint/complexity/useArrowFunction: We need a function with a constructor const hint = options?.hint ?? function () {} - pMetadata.set(hint, { - factory: signal, - bind: options?.bindMethods ?? false, - cacheable: options?.cache ?? false, - }) - if (__BUILD_FLAG_DEBUG_LAZY_VALUES__) // Prevent race conditions where proxified values with a self modifying signal gets called, // modifying the original value to a non-proxified value, causing subsequent destructure() calls to fail @@ -147,7 +122,16 @@ export function proxify(signal: () => T, options?: ProxifyOptions): T { DEBUG_warnNullishProxifiedValue() }) - return new Proxy(hint, _handler) as T + const prox = new Proxy(hint, _handler) as T + + pMetadata.set(hint, { + hint: hint, + factory: signal, + bind: options?.bindMethods ?? false, + cacheable: options?.cache ?? false, + }) + + return prox } /** @@ -178,7 +162,7 @@ export function proxify(signal: () => T, options?: ProxifyOptions): T { * ``` */ export function unproxify(proxified: T): T { - const hint = getProxyTarget(proxified) + const hint = pMetadata.get(proxified)?.hint if (!hint) return proxified return unproxifyFromHint(hint) } diff --git a/src/preinit.ts b/src/preinit.ts index b8471c9..ef09dc8 100644 --- a/src/preinit.ts +++ b/src/preinit.ts @@ -1,5 +1,4 @@ import '@revenge-mod/modules/metro/patches' -import '@revenge-mod/utils/patches/proxy' import { onModuleFirstRequired,