Skip to content

Commit

Permalink
fix: [[GetOwnPropertyDescriptor]] returns undefined
Browse files Browse the repository at this point in the history
compatibility with near-membrane
  • Loading branch information
Jack-Works committed Aug 31, 2022
1 parent 55f17be commit f4e2569
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-students-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'async-call-rpc': patch
---

fix [[GetOwnPropertyDescriptor]] returns undefined
16 changes: 16 additions & 0 deletions __tests__/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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* __() {}
Expand Down
5 changes: 5 additions & 0 deletions src/Async-Call-Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export function AsyncGeneratorCall<OtherSideImplementedFunctions = {}>(
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<OtherSideImplementedFunctions>
}
class _AsyncGenerator implements AsyncIterableIterator<unknown>, AsyncIterator<unknown, unknown, unknown> {
Expand Down
5 changes: 5 additions & 0 deletions src/Async-Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ export function AsyncCall<OtherSideImplementedFunctions = {}>(
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<OtherSideImplementedFunctions>
}
// Assume a console object in global if there is no custom logger provided
Expand Down

0 comments on commit f4e2569

Please sign in to comment.