Skip to content

Commit

Permalink
fix: incorrect proxy caching
Browse files Browse the repository at this point in the history
  • Loading branch information
L2jLiga committed Oct 19, 2023
1 parent fd61774 commit b3246f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/simple-di/src/decorators/helpers/patch-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ function patchMethod<C>(constructor: Registrable<C>, methodName: string | symbol
};
}

const _PROXY_CACHE = new WeakMap<WeakKey, unknown>();
const _PROXY_CACHE = new WeakMap<WeakKey, WeakMap<WeakKey, unknown>>();

function createProxy<C>(target: Constructable<C>, request: unknown, reply: unknown): unknown {
if (_PROXY_CACHE.has(request as WeakKey)) return _PROXY_CACHE.get(request as WeakKey);
if (!_PROXY_CACHE.has(target)) _PROXY_CACHE.set(target, new WeakMap());
const targetProxyCache = _PROXY_CACHE.get(target) as WeakMap<WeakKey, unknown>;
if (targetProxyCache.has(request as WeakKey)) return targetProxyCache.get(request as WeakKey);

const proxy = new Proxy(target, {
get(target, p) {
Expand All @@ -70,5 +72,5 @@ function createProxy<C>(target: Constructable<C>, request: unknown, reply: unkno
},
});

return _PROXY_CACHE.set(request as WeakKey, proxy).get(request as WeakKey);
return targetProxyCache.set(request as WeakKey, proxy).get(request as WeakKey);
}

0 comments on commit b3246f2

Please sign in to comment.