From a7b2e6e1e19f122a77713fbe4ce758843d24d7f9 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Tue, 21 May 2024 13:48:04 +1200 Subject: [PATCH] Avoid calling bind on instances of RpcProperty --- src/wrap.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wrap.ts b/src/wrap.ts index 5ecca7a..e564cb5 100644 --- a/src/wrap.ts +++ b/src/wrap.ts @@ -45,11 +45,14 @@ export function unwrap(item: T): T { } export function passthroughGet(target: any, prop: string | symbol, thisArg?: any) { - const value = Reflect.get(unwrap(target), prop) + const unwrappedTarget = unwrap(target) + const value = Reflect.get(unwrappedTarget, prop) if (typeof value === 'function') { - thisArg = thisArg || unwrap(target) - const bound = value.bind(thisArg) - return bound + if (value.constructor.name === 'RpcProperty') { + return (...args: unknown[]) => unwrappedTarget[prop](...args) + } + thisArg = thisArg || unwrappedTarget + return value.bind(thisArg) } else { return value }