diff --git a/.changeset/honest-students-play.md b/.changeset/honest-students-play.md new file mode 100644 index 0000000..57cd0b8 --- /dev/null +++ b/.changeset/honest-students-play.md @@ -0,0 +1,5 @@ +--- +'async-call-rpc': patch +--- + +fix [[GetOwnPropertyDescriptor]] returns undefined diff --git a/__tests__/brand.ts b/__tests__/brand.ts index ab6311e..6af8e4f 100644 --- a/__tests__/brand.ts +++ b/__tests__/brand.ts @@ -17,6 +17,14 @@ it( // Method name check expect(server.add.name).toBe('add') + // [[GetOwnPropertyDescriptor]] check + { + const method = Object.getOwnPropertyDescriptor(server, 'missing-method') + expect(method).toBeTypeOf('object') + expect(Reflect.has(server, 'missing-method')).toBeTruthy() + expect((server as any)['missing-method']).toBe(method!.value!) + } + // Result check const q = server.add(0, 1) expect(q).toBeInstanceOf(Promise) @@ -40,6 +48,14 @@ it( // Method name check expect(server.echo.name).toBe('echo') + // [[GetOwnPropertyDescriptor]] check + { + const method = Object.getOwnPropertyDescriptor(server, 'missing-method') + expect(method).toBeTypeOf('object') + expect(Reflect.has(server, 'missing-method')).toBeTruthy() + expect((server as any)['missing-method']).toBe(method!.value!) + } + // Result check const iter = server.echo([]) async function* __() {} diff --git a/src/Async-Call-Generator.ts b/src/Async-Call-Generator.ts index 4d44052..45db345 100644 --- a/src/Async-Call-Generator.ts +++ b/src/Async-Call-Generator.ts @@ -176,6 +176,11 @@ export function AsyncGeneratorCall( return new Proxy(methodContainer, { getPrototypeOf: () => null, setPrototypeOf: (_, val) => val === null, + // some library will treat this object as a normal object and run algorithm steps in https://tc39.es/ecma262/#sec-ordinaryget + getOwnPropertyDescriptor(_, method) { + if (!(method in methodContainer)) (getTrap as any)[method] // trigger [[Get]] + return Object.getOwnPropertyDescriptor(methodContainer, method) + }, }) as AsyncGeneratorVersionOf } class _AsyncGenerator implements AsyncIterableIterator, AsyncIterator { diff --git a/src/Async-Call.ts b/src/Async-Call.ts index 09c0761..282d22e 100644 --- a/src/Async-Call.ts +++ b/src/Async-Call.ts @@ -381,6 +381,11 @@ export function AsyncCall( return new Proxy(methodContainer, { getPrototypeOf: () => null, setPrototypeOf: (_, value) => value === null, + // some library will treat this object as a normal object and run algorithm steps in https://tc39.es/ecma262/#sec-ordinaryget + getOwnPropertyDescriptor(_, method) { + if (!(method in methodContainer)) (getTrap as any)[method] // trigger [[Get]] + return Object.getOwnPropertyDescriptor(methodContainer, method) + }, }) as AsyncVersionOf } // Assume a console object in global if there is no custom logger provided