quickjs-emscripten-sync 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -169,9 +169,7 @@ export declare class Arena {
169
169
  * By default, exposed objects are not synchronized between the host and the VM.
170
170
  * If you want to sync an objects, first wrap the object with sync method, and then expose the wrapped object.
171
171
  */
172
- expose(obj: {
173
- [k: string]: any;
174
- }): void;
172
+ expose(obj: Record<string, any>): void;
175
173
  /**
176
174
  * Enables sync for the object between the host and the VM and returns objects wrapped with proxies.
177
175
  *
@@ -203,7 +201,7 @@ export declare class Arena {
203
201
  _isMarshalable: (t: unknown) => boolean | "json";
204
202
  _marshalFind: (t: unknown) => QuickJSHandle | undefined;
205
203
  _marshalPre: (t: unknown, h: QuickJSHandle | QuickJSDeferredPromise, mode: true | "json" | undefined) => Wrapped<QuickJSHandle> | undefined;
206
- _marshalPreApply: (target: Function, that: unknown, args: unknown[]) => void;
204
+ _marshalPreApply: (target: (...args: any[]) => any, that: unknown, args: unknown[]) => void;
207
205
  _marshal: (target: any) => [QuickJSHandle, boolean];
208
206
  _preUnmarshal: (t: any, h: QuickJSHandle) => Wrapped<any>;
209
207
  _unmarshalFind: (h: QuickJSHandle) => unknown;
@@ -237,7 +235,7 @@ export declare function isES2015Class(cls: any): cls is new (...args: any[]) =>
237
235
 
238
236
  export declare function isHandleObject(ctx: QuickJSContext, h: QuickJSHandle): boolean;
239
237
 
240
- export declare function isObject(value: any): value is object | Function;
238
+ export declare function isObject(value: any): value is object | ((...args: any[]) => any);
241
239
 
242
240
  export declare function json(ctx: QuickJSContext, target: any): QuickJSHandle;
243
241
 
@@ -271,7 +269,7 @@ declare type Options_2 = {
271
269
  isMarshalable?: (target: unknown) => boolean | "json";
272
270
  find: (target: unknown) => QuickJSHandle | undefined;
273
271
  pre: (target: unknown, handle: QuickJSHandle | QuickJSDeferredPromise, mode: true | "json" | undefined) => QuickJSHandle | undefined;
274
- preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;
272
+ preApply?: (target: (...args: any[]) => any, thisArg: unknown, args: unknown[]) => any;
275
273
  custom?: Iterable<(obj: unknown, ctx: QuickJSContext) => QuickJSHandle | undefined>;
276
274
  };
277
275
 
@@ -631,7 +631,7 @@ function me(n, e, t, r, s, o, i) {
631
631
  const d = s(l);
632
632
  if (!d) return;
633
633
  const m = s(f);
634
- delete w(d, t)[m];
634
+ Reflect.deleteProperty(w(d, t), m);
635
635
  };
636
636
  return n.newFunction("proxyFuncs", (l, ...f) => {
637
637
  switch (n.getNumber(l)) {
@@ -714,7 +714,7 @@ class ve {
714
714
  c(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
715
715
  c(this, "_sync", /* @__PURE__ */ new Set());
716
716
  c(this, "_temporalSync", /* @__PURE__ */ new Set());
717
- c(this, "_symbol", Symbol());
717
+ c(this, "_symbol", /* @__PURE__ */ Symbol());
718
718
  c(this, "_symbolHandle");
719
719
  c(this, "_options");
720
720
  c(this, "_isMarshalable", (e) => {
@@ -40,7 +40,7 @@
40
40
  map2 = new WeakMap();
41
41
  }
42
42
  };
43
- }`)).consume(r=>this._call(r,void 0));this._mapGet=e.getProp(t,"get"),this._mapSet=e.getProp(t,"set"),this._mapDelete=e.getProp(t,"delete"),this._mapClear=e.getProp(t,"clear"),t.dispose(),this._disposables.add(this._mapGet),this._disposables.add(this._mapSet),this._disposables.add(this._mapDelete),this._disposables.add(this._mapClear)}set(e,t,r,s){var a;if(!t.alive||s&&!s.alive)return!1;const o=(a=this.get(e))!=null?a:this.get(r);if(o)return o===t||o===s;const i=this._counter++;return this._map1.set(e,i),this._map3.set(i,t),this._counterMap.set(i,e),r&&(this._map2.set(r,i),s&&this._map4.set(i,s)),this.ctx.newNumber(i).consume(u=>{this._call(this._mapSet,void 0,t,u,s!=null?s:this.ctx.undefined)}),!0}merge(e){if(e)for(const t of e)t&&t[1]&&this.set(t[0],t[1],t[2],t[3])}get(e){var s;const t=(s=this._map1.get(e))!=null?s:this._map2.get(e),r=typeof t=="number"?this._map3.get(t):void 0;if(r){if(!r.alive){this.delete(e);return}return r}}getByHandle(e){if(e.alive)return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet,void 0,e)))}has(e){return!!this.get(e)}hasHandle(e){return typeof this.getByHandle(e)!="undefined"}keys(){return this._map1.keys()}delete(e,t){var i;const r=(i=this._map1.get(e))!=null?i:this._map2.get(e);if(typeof r=="undefined")return;const s=this._map3.get(r),o=this._map4.get(r);this._call(this._mapDelete,void 0,...[s,o].filter(a=>!!(a!=null&&a.alive))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(r),this._map4.delete(r);for(const[a,u]of this._map1)if(u===r){this._map1.delete(a);break}for(const[a,u]of this._map2)if(u===r){this._map2.delete(a);break}for(const[a,u]of this._counterMap)if(u===e){this._counterMap.delete(a);break}t&&(s!=null&&s.alive&&s.dispose(),o!=null&&o.alive&&o.dispose())}deleteByHandle(e,t){const r=this.getByHandle(e);typeof r!="undefined"&&this.delete(r,t)}clear(){this._counter=0,this._map1.clear(),this._map2.clear(),this._map3.clear(),this._map4.clear(),this._counterMap.clear(),this._mapClear.alive&&this._call(this._mapClear,void 0)}dispose(){for(const e of this._disposables.values())e.alive&&e.dispose();for(const e of this._map3.values())e.alive&&e.dispose();for(const e of this._map4.values())e.alive&&e.dispose();this._disposables.clear(),this.clear()}get size(){return this._map1.size}[Symbol.iterator](){const e=this._map1.keys();return{next:()=>{for(;;){const t=e.next();if(t.done)return{value:void 0,done:!0};const r=this._map1.get(t.value);if(typeof r=="undefined")continue;const s=this._map3.get(r),o=this._map4.get(r);if(!s)continue;const i=this._get2(r);return{value:[t.value,s,i,o],done:!1}}}}}_get2(e){for(const[t,r]of this._map2)if(r===e)return t}_call(e,t,...r){return this.ctx.unwrapResult(this.ctx.callFunction(e,typeof t=="undefined"?this.ctx.undefined:t,...r))}}function le(n,e,t,r,s,o,i){if(!g(e)||e instanceof Promise||e instanceof Date||i&&!i(e))return;if(me(e,t))return e;const a=new Proxy(e,{get(u,p){return p===t?u:Reflect.get(u,p)},set(u,p,l,f){var y;const d=P(l,t),h=(y=o==null?void 0:o(f))!=null?y:"host";return h!=="vm"&&!Reflect.set(u,p,d,f)||h==="host"||!n.alive||S([s(f),s(p),s(d)],(b,w,U)=>{const[I,ye]=R(n,b,r);ye?I.consume(_e=>n.setProp(_e,w,U)):n.setProp(I,w,U)}),!0},deleteProperty(u,p){var f;const l=(f=o==null?void 0:o(a))!=null?f:"host";return S([s(a),s(p)],(d,h)=>{const[y,b]=R(n,d,r);if(l==="vm"||Reflect.deleteProperty(u,p)){if(l==="host"||!n.alive)return!0;b?y.consume(w=>_(n,"(a, b) => delete a[b]",void 0,w,h)):_(n,"(a, b) => delete a[b]",void 0,y,h)}return!0})}});return a}function de(n,e,t,r,s,o,i){if(!C(n,e)||i&&!i(e,n))return[void 0,!1];if(T(n,e,r))return[e,!1];const a=l=>{const f=o==null?void 0:o(s(l));return typeof f=="string"?n.newString(f):n.undefined},u=(l,f,d)=>{const h=s(l);if(!h)return;const y=s(f);if(y==="__proto__")return;const b=s(d);P(h,t)[y]=b},p=(l,f)=>{const d=s(l);if(!d)return;const h=s(f);delete P(d,t)[h]};return n.newFunction("proxyFuncs",(l,...f)=>{switch(n.getNumber(l)){case 1:return a(f[0]);case 2:return u(f[0],f[1],f[2]);case 3:return p(f[0],f[1])}return n.undefined}).consume(l=>[_(n,`(target, sym, proxyFuncs) => {
43
+ }`)).consume(r=>this._call(r,void 0));this._mapGet=e.getProp(t,"get"),this._mapSet=e.getProp(t,"set"),this._mapDelete=e.getProp(t,"delete"),this._mapClear=e.getProp(t,"clear"),t.dispose(),this._disposables.add(this._mapGet),this._disposables.add(this._mapSet),this._disposables.add(this._mapDelete),this._disposables.add(this._mapClear)}set(e,t,r,s){var a;if(!t.alive||s&&!s.alive)return!1;const o=(a=this.get(e))!=null?a:this.get(r);if(o)return o===t||o===s;const i=this._counter++;return this._map1.set(e,i),this._map3.set(i,t),this._counterMap.set(i,e),r&&(this._map2.set(r,i),s&&this._map4.set(i,s)),this.ctx.newNumber(i).consume(u=>{this._call(this._mapSet,void 0,t,u,s!=null?s:this.ctx.undefined)}),!0}merge(e){if(e)for(const t of e)t&&t[1]&&this.set(t[0],t[1],t[2],t[3])}get(e){var s;const t=(s=this._map1.get(e))!=null?s:this._map2.get(e),r=typeof t=="number"?this._map3.get(t):void 0;if(r){if(!r.alive){this.delete(e);return}return r}}getByHandle(e){if(e.alive)return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet,void 0,e)))}has(e){return!!this.get(e)}hasHandle(e){return typeof this.getByHandle(e)!="undefined"}keys(){return this._map1.keys()}delete(e,t){var i;const r=(i=this._map1.get(e))!=null?i:this._map2.get(e);if(typeof r=="undefined")return;const s=this._map3.get(r),o=this._map4.get(r);this._call(this._mapDelete,void 0,...[s,o].filter(a=>!!(a!=null&&a.alive))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(r),this._map4.delete(r);for(const[a,u]of this._map1)if(u===r){this._map1.delete(a);break}for(const[a,u]of this._map2)if(u===r){this._map2.delete(a);break}for(const[a,u]of this._counterMap)if(u===e){this._counterMap.delete(a);break}t&&(s!=null&&s.alive&&s.dispose(),o!=null&&o.alive&&o.dispose())}deleteByHandle(e,t){const r=this.getByHandle(e);typeof r!="undefined"&&this.delete(r,t)}clear(){this._counter=0,this._map1.clear(),this._map2.clear(),this._map3.clear(),this._map4.clear(),this._counterMap.clear(),this._mapClear.alive&&this._call(this._mapClear,void 0)}dispose(){for(const e of this._disposables.values())e.alive&&e.dispose();for(const e of this._map3.values())e.alive&&e.dispose();for(const e of this._map4.values())e.alive&&e.dispose();this._disposables.clear(),this.clear()}get size(){return this._map1.size}[Symbol.iterator](){const e=this._map1.keys();return{next:()=>{for(;;){const t=e.next();if(t.done)return{value:void 0,done:!0};const r=this._map1.get(t.value);if(typeof r=="undefined")continue;const s=this._map3.get(r),o=this._map4.get(r);if(!s)continue;const i=this._get2(r);return{value:[t.value,s,i,o],done:!1}}}}}_get2(e){for(const[t,r]of this._map2)if(r===e)return t}_call(e,t,...r){return this.ctx.unwrapResult(this.ctx.callFunction(e,typeof t=="undefined"?this.ctx.undefined:t,...r))}}function le(n,e,t,r,s,o,i){if(!g(e)||e instanceof Promise||e instanceof Date||i&&!i(e))return;if(me(e,t))return e;const a=new Proxy(e,{get(u,p){return p===t?u:Reflect.get(u,p)},set(u,p,l,f){var y;const d=P(l,t),h=(y=o==null?void 0:o(f))!=null?y:"host";return h!=="vm"&&!Reflect.set(u,p,d,f)||h==="host"||!n.alive||S([s(f),s(p),s(d)],(b,w,U)=>{const[I,ye]=R(n,b,r);ye?I.consume(_e=>n.setProp(_e,w,U)):n.setProp(I,w,U)}),!0},deleteProperty(u,p){var f;const l=(f=o==null?void 0:o(a))!=null?f:"host";return S([s(a),s(p)],(d,h)=>{const[y,b]=R(n,d,r);if(l==="vm"||Reflect.deleteProperty(u,p)){if(l==="host"||!n.alive)return!0;b?y.consume(w=>_(n,"(a, b) => delete a[b]",void 0,w,h)):_(n,"(a, b) => delete a[b]",void 0,y,h)}return!0})}});return a}function de(n,e,t,r,s,o,i){if(!C(n,e)||i&&!i(e,n))return[void 0,!1];if(T(n,e,r))return[e,!1];const a=l=>{const f=o==null?void 0:o(s(l));return typeof f=="string"?n.newString(f):n.undefined},u=(l,f,d)=>{const h=s(l);if(!h)return;const y=s(f);if(y==="__proto__")return;const b=s(d);P(h,t)[y]=b},p=(l,f)=>{const d=s(l);if(!d)return;const h=s(f);Reflect.deleteProperty(P(d,t),h)};return n.newFunction("proxyFuncs",(l,...f)=>{switch(n.getNumber(l)){case 1:return a(f[0]);case 2:return u(f[0],f[1],f[2]);case 3:return p(f[0],f[1])}return n.undefined}).consume(l=>[_(n,`(target, sym, proxyFuncs) => {
44
44
  const rec = new Proxy(target, {
45
45
  get(obj, key, receiver) {
46
46
  return key === sym ? obj : Reflect.get(obj, key, receiver)
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "quickjs-emscripten-sync",
3
3
  "author": "rot1024",
4
- "version": "1.8.0",
4
+ "version": "1.8.1",
5
5
  "license": "MIT",
6
+ "type": "module",
6
7
  "source": "./src/index.ts",
7
8
  "main": "./dist/quickjs-emscripten-sync.umd.js",
8
9
  "module": "./dist/quickjs-emscripten-sync.mjs",
@@ -31,14 +32,14 @@
31
32
  "quickjs-emscripten": "*"
32
33
  },
33
34
  "devDependencies": {
34
- "@vitest/coverage-c8": "^0.28.5",
35
- "eslint": "^8.57.1",
36
- "eslint-config-reearth": "^0.2.1",
37
- "prettier": "^2.8.8",
35
+ "@vitest/coverage-v8": "^4.0.18",
36
+ "eslint": "^9.39.2",
37
+ "eslint-config-reearth": "^0.3.8",
38
+ "prettier": "^3.8.1",
38
39
  "quickjs-emscripten": "^0.31.0",
39
- "typescript": "^5.7.2",
40
- "vite": "^6.0.3",
40
+ "typescript": "^5.9.3",
41
+ "vite": "^7.3.1",
41
42
  "vite-plugin-dts": "^4.3.0",
42
- "vitest": "^0.28.5"
43
+ "vitest": "^4.0.18"
43
44
  }
44
45
  }
package/src/edge.test.ts CHANGED
@@ -44,27 +44,31 @@ describe("edge cases", () => {
44
44
  // ctx.dispose(); // reports an error
45
45
  });
46
46
 
47
- test("many newFunction", async () => {
48
- const rt = (await getQuickJS()).newRuntime();
49
- const ctx = rt.newContext();
50
- const arena = new Arena(ctx, {
51
- isMarshalable: true,
52
- // enable this option to solve this problem
53
- experimentalContextEx: true,
54
- });
47
+ test(
48
+ "many newFunction",
49
+ async () => {
50
+ const rt = (await getQuickJS()).newRuntime();
51
+ const ctx = rt.newContext();
52
+ const arena = new Arena(ctx, {
53
+ isMarshalable: true,
54
+ // enable this option to solve this problem
55
+ experimentalContextEx: true,
56
+ });
55
57
 
56
- arena.expose({
57
- hoge: () => {},
58
- });
59
- // should have an object as an arg
60
- const fn = arena.evalCode(`() => { hoge([]); }`);
61
- // error happens from 3926 times
62
- for (let i = 0; i < 10000; i++) {
63
- fn();
64
- }
58
+ arena.expose({
59
+ hoge: () => {},
60
+ });
61
+ // should have an object as an arg
62
+ const fn = arena.evalCode(`() => { hoge([]); }`);
63
+ // error happens from 3926 times
64
+ for (let i = 0; i < 10000; i++) {
65
+ fn();
66
+ }
65
67
 
66
- arena.dispose();
67
- ctx.dispose();
68
- rt.dispose();
69
- });
68
+ arena.dispose();
69
+ ctx.dispose();
70
+ rt.dispose();
71
+ },
72
+ 90000,
73
+ );
70
74
  });
package/src/index.ts CHANGED
@@ -62,9 +62,9 @@ export class Arena {
62
62
  context: QuickJSContextEx;
63
63
  _map: VMMap;
64
64
  _registeredMap: VMMap;
65
- _registeredMapDispose: Set<any> = new Set();
66
- _sync: Set<any> = new Set();
67
- _temporalSync: Set<any> = new Set();
65
+ _registeredMapDispose = new Set<any>();
66
+ _sync = new Set<any>();
67
+ _temporalSync = new Set<any>();
68
68
  _symbol = Symbol();
69
69
  _symbolHandle: QuickJSHandle;
70
70
  _options?: Options;
@@ -74,7 +74,7 @@ export class Arena {
74
74
  if (options?.compat && !("runtime" in ctx)) {
75
75
  (ctx as any).runtime = {
76
76
  hasPendingJob: () => (ctx as any).hasPendingJob(),
77
- executePendingJobs: (maxJobsToExecute?: number | void) =>
77
+ executePendingJobs: (maxJobsToExecute?: number | undefined) =>
78
78
  (ctx as any).executePendingJobs(maxJobsToExecute),
79
79
  };
80
80
  }
@@ -274,7 +274,7 @@ export class Arena {
274
274
  * By default, exposed objects are not synchronized between the host and the VM.
275
275
  * If you want to sync an objects, first wrap the object with sync method, and then expose the wrapped object.
276
276
  */
277
- expose(obj: { [k: string]: any }) {
277
+ expose(obj: Record<string, any>) {
278
278
  for (const [key, value] of Object.entries(obj)) {
279
279
  mayConsume(this._marshal(value), handle => {
280
280
  this.context.setProp(this.context.global, key, handle);
@@ -387,7 +387,7 @@ export class Arena {
387
387
  return this._register(t, handleFrom(h), this._map)?.[1];
388
388
  };
389
389
 
390
- _marshalPreApply = (target: Function, that: unknown, args: unknown[]): void => {
390
+ _marshalPreApply = (target: (...args: any[]) => any, that: unknown, args: unknown[]): void => {
391
391
  const unwrapped = isObject(that) ? this._unwrap(that) : undefined;
392
392
  // override sync mode of this object while calling the function
393
393
  if (unwrapped) this._temporalSync.add(unwrapped);
@@ -116,7 +116,7 @@ test("preApply", async () => {
116
116
  return ctx.null;
117
117
  };
118
118
  const unmarshal = (v: QuickJSHandle) => (ctx.typeof(v) === "object" ? that : ctx.dump(v));
119
- const preApply = vi.fn((a: Function, b: any, c: any[]) => a.apply(b, c) + "!");
119
+ const preApply = vi.fn((a: (...args: any[]) => any, b: any, c: any[]) => a.apply(b, c) + "!");
120
120
  const that = {};
121
121
  const thatHandle = ctx.newObject();
122
122
 
@@ -11,7 +11,7 @@ export default function marshalFunction(
11
11
  marshal: (target: unknown) => QuickJSHandle,
12
12
  unmarshal: (handle: QuickJSHandle) => unknown,
13
13
  preMarshal: (target: unknown, handle: QuickJSHandle) => QuickJSHandle | undefined,
14
- preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any,
14
+ preApply?: (target: (...args: any[]) => any, thisArg: unknown, args: unknown[]) => any,
15
15
  ): QuickJSHandle | undefined {
16
16
  if (typeof target !== "function") return;
17
17
 
@@ -29,7 +29,7 @@ export default function marshalFunction(
29
29
  return this;
30
30
  }
31
31
 
32
- return marshal(preApply ? preApply(target, that, args) : target.apply(that, args));
32
+ return marshal(preApply ? preApply(target as (...args: any[]) => any, that, args) : (target as (...args: any[]) => any).apply(that, args));
33
33
  })
34
34
  .consume(handle2 =>
35
35
  // fucntions created by vm.newFunction are not callable as a class constrcutor
@@ -17,7 +17,7 @@ export type Options = {
17
17
  handle: QuickJSHandle | QuickJSDeferredPromise,
18
18
  mode: true | "json" | undefined,
19
19
  ) => QuickJSHandle | undefined;
20
- preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;
20
+ preApply?: (target: (...args: any[]) => any, thisArg: unknown, args: unknown[]) => any;
21
21
  custom?: Iterable<(obj: unknown, ctx: QuickJSContext) => QuickJSHandle | undefined>;
22
22
  };
23
23
 
@@ -4,7 +4,7 @@ import { call } from "../vmutil";
4
4
 
5
5
  export default function marshalProperties(
6
6
  ctx: QuickJSContext,
7
- target: object | Function,
7
+ target: object | ((...args: any[]) => any),
8
8
  handle: QuickJSHandle,
9
9
  marshal: (target: unknown) => QuickJSHandle,
10
10
  ): void {
@@ -11,7 +11,7 @@ export default function unmarshalFunction(
11
11
  marshal: (value: unknown) => [QuickJSHandle, boolean],
12
12
  unmarshal: (handle: QuickJSHandle) => [unknown, boolean],
13
13
  preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined,
14
- ): Function | undefined {
14
+ ): ((...args: any[]) => any) | undefined {
15
15
  if (ctx.typeof(handle) !== "function") return;
16
16
 
17
17
  const raw = function (this: any, ...args: any[]) {
@@ -31,9 +31,9 @@ const testPromise = (reject: boolean) => async () => {
31
31
  expect(ctx.runtime.hasPendingJob()).toBe(true);
32
32
  expect(ctx.unwrapResult(ctx.runtime.executePendingJobs())).toBe(1);
33
33
  if (reject) {
34
- expect(promise).rejects.toThrow("hoge");
34
+ await expect(promise).rejects.toThrow("hoge");
35
35
  } else {
36
- expect(promise).resolves.toBe("hoge");
36
+ await expect(promise).resolves.toBe("hoge");
37
37
  }
38
38
 
39
39
  disposables.forEach(d => d.dispose());
@@ -5,7 +5,7 @@ import { call } from "../vmutil";
5
5
  export default function unmarshalProperties(
6
6
  ctx: QuickJSContext,
7
7
  handle: QuickJSHandle,
8
- target: object | Function,
8
+ target: object | ((...args: any[]) => any),
9
9
  unmarshal: (handle: QuickJSHandle) => [unknown, boolean],
10
10
  ) {
11
11
  ctx
package/src/util.test.ts CHANGED
@@ -55,12 +55,12 @@ test("complexity", () => {
55
55
  expect(complexity({ a: {} }, 1)).toBe(1);
56
56
  });
57
57
 
58
- test("newDeferred", () => {
58
+ test("newDeferred", async () => {
59
59
  const deferred = newDeferred();
60
60
  deferred.resolve("foo");
61
- expect(deferred.promise).resolves.toBe("foo");
61
+ await expect(deferred.promise).resolves.toBe("foo");
62
62
 
63
63
  const deferred2 = newDeferred();
64
64
  deferred2.reject("bar");
65
- expect(deferred2.promise).rejects.toBe("bar");
65
+ await expect(deferred2.promise).rejects.toBe("bar");
66
66
  });
package/src/util.ts CHANGED
@@ -2,12 +2,13 @@ export function isES2015Class(cls: any): cls is new (...args: any[]) => any {
2
2
  return typeof cls === "function" && /^class\s/.test(Function.prototype.toString.call(cls));
3
3
  }
4
4
 
5
- export function isObject(value: any): value is object | Function {
5
+ export function isObject(value: any): value is object | ((...args: any[]) => any) {
6
6
  return typeof value === "function" || (typeof value === "object" && value !== null);
7
7
  }
8
8
 
9
9
  export function walkObject(
10
10
  value: any,
11
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
11
12
  callback?: (target: any, set: Set<any>) => boolean | void,
12
13
  ): Set<any> {
13
14
  const set = new Set<any>();
package/src/vmmap.ts CHANGED
@@ -2,12 +2,12 @@ import type { QuickJSContext, QuickJSHandle } from "quickjs-emscripten";
2
2
 
3
3
  export default class VMMap {
4
4
  ctx: QuickJSContext;
5
- _map1: Map<any, number> = new Map();
6
- _map2: Map<any, number> = new Map();
7
- _map3: Map<number, QuickJSHandle> = new Map();
8
- _map4: Map<number, QuickJSHandle> = new Map();
9
- _counterMap: Map<number, any> = new Map();
10
- _disposables: Set<QuickJSHandle> = new Set();
5
+ _map1 = new Map<any, number>();
6
+ _map2 = new Map<any, number>();
7
+ _map3 = new Map<number, QuickJSHandle>();
8
+ _map4 = new Map<number, QuickJSHandle>();
9
+ _counterMap = new Map<number, any>();
10
+ _disposables = new Set<QuickJSHandle>();
11
11
  _mapGet: QuickJSHandle;
12
12
  _mapSet: QuickJSHandle;
13
13
  _mapDelete: QuickJSHandle;
@@ -226,7 +226,7 @@ export default class VMMap {
226
226
  const keys = this._map1.keys();
227
227
  return {
228
228
  next: () => {
229
- // eslint-disable-next-line no-constant-condition
229
+
230
230
  while (true) {
231
231
  const k1 = keys.next();
232
232
  if (k1.done) return { value: undefined, done: true };
package/src/wrapper.ts CHANGED
@@ -105,7 +105,7 @@ export function wrapHandle(
105
105
  const target = unmarshal(h);
106
106
  if (!target) return;
107
107
  const key = unmarshal(keyHandle);
108
- delete unwrap(target, proxyKeySymbol)[key];
108
+ Reflect.deleteProperty(unwrap(target, proxyKeySymbol), key);
109
109
  };
110
110
 
111
111
  return ctx