Skip to content

Commit

Permalink
fix(wasm-api): fix defType() property handling
Browse files Browse the repository at this point in the history
- inject `__base` and `__bytes` getters using `Object.defineProperties()`
  • Loading branch information
postspectacular committed Nov 10, 2024
1 parent ef89090 commit 37bebee
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/wasm-api/src/deftype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ export const defType =
instanceArray(base, num) {
return __instanceArray<T>(this, base, num);
},
instance: (base) =>
<T>{
get __base() {
return base;
instance: (base) => {
const inst = instance(mem, base);
Object.defineProperties(inst, {
__base: { value: base },
__bytes: {
get() {
return mem.u8.subarray(base, base + size);
},
},
get __bytes() {
return mem.u8.subarray(base, base + size);
},
...instance(mem, base),
},
});
return <T>inst;
},
});

0 comments on commit 37bebee

Please sign in to comment.