quickjs-emscripten-sync 1.5.1 → 1.5.2

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.
@@ -1,4 +1,60 @@
1
- const F = [
1
+ var D = Object.defineProperty;
2
+ var A = (r, e, t) => e in r ? D(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var c = (r, e, t) => (A(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ const B = (r) => {
5
+ const e = new I(r);
6
+ return new Proxy(r, {
7
+ get(t, s, n) {
8
+ return s in e ? e[s] : Reflect.get(t, s, n);
9
+ }
10
+ });
11
+ };
12
+ class I {
13
+ constructor(e) {
14
+ c(this, "context");
15
+ c(this, "fn");
16
+ c(this, "fnGenerator");
17
+ c(this, "fnCounter", Number.MIN_SAFE_INTEGER);
18
+ c(this, "fnMap", /* @__PURE__ */ new Map());
19
+ /** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
20
+ c(this, "newFunction", (e, t) => {
21
+ this.fnCounter++;
22
+ const s = this.fnCounter;
23
+ return this.fnMap.set(s, t), this.context.unwrapResult(
24
+ this.context.callFunction(
25
+ this.fnGenerator,
26
+ this.context.undefined,
27
+ this.context.newString(e),
28
+ this.context.newNumber(t.length),
29
+ this.context.newNumber(s),
30
+ this.fn
31
+ )
32
+ );
33
+ });
34
+ this.context = e;
35
+ const t = this.fnMap;
36
+ this.fn = this.context.newFunction("", function(s, ...n) {
37
+ const o = e.getNumber(s), i = t.get(o);
38
+ if (!i)
39
+ throw new Error("function is not registered");
40
+ return i.call(this, ...n);
41
+ }), this.fnGenerator = e.unwrapResult(
42
+ e.evalCode(`((name, length, id, f) => {
43
+ const fn = function(...args) {
44
+ return f.call(this, id, ...args);
45
+ };
46
+ fn.name = name;
47
+ fn.length = length;
48
+ return fn;
49
+ })`)
50
+ );
51
+ }
52
+ disposeEx() {
53
+ this.fnGenerator.dispose(), this.fn.dispose();
54
+ }
55
+ }
56
+ const T = [
57
+ // basic objects
2
58
  [Symbol, "Symbol"],
3
59
  [Symbol.prototype, "Symbol.prototype"],
4
60
  [Object, "Object"],
@@ -9,6 +65,9 @@ const F = [
9
65
  [Boolean.prototype, "Boolean.prototype"],
10
66
  [Array, "Array"],
11
67
  [Array.prototype, "Array.prototype"],
68
+ // [BigInt, "BigInt"],
69
+ // [BigInt.prototype, "BigInt.prototype"],
70
+ // errors
12
71
  [Error, "Error"],
13
72
  [Error.prototype, "Error.prototype"],
14
73
  [EvalError, "EvalError"],
@@ -23,269 +82,273 @@ const F = [
23
82
  [TypeError.prototype, "TypeError.prototype"],
24
83
  [URIError, "URIError"],
25
84
  [URIError.prototype, "URIError.prototype"],
26
- ...Object.getOwnPropertyNames(Symbol).filter((t) => typeof Symbol[t] == "symbol").map((t) => [Symbol[t], `Symbol.${t}`])
85
+ // built-in symbols
86
+ ...Object.getOwnPropertyNames(Symbol).filter((r) => typeof Symbol[r] == "symbol").map((r) => [Symbol[r], `Symbol.${r}`])
27
87
  ];
28
- function A(t, e) {
29
- const r = t.unwrapResult(t.evalCode(e)), o = (n, ...s) => t.unwrapResult(t.callFunction(r, n != null ? n : t.undefined, ...s));
30
- return o.dispose = () => r.dispose(), o.alive = !0, Object.defineProperty(o, "alive", {
31
- get: () => r.alive
32
- }), o;
33
- }
34
- function d(t, e, r, ...o) {
35
- const n = A(t, e);
88
+ function G(r, e) {
89
+ const t = r.unwrapResult(r.evalCode(e)), s = (n, ...o) => r.unwrapResult(r.callFunction(t, n != null ? n : r.undefined, ...o));
90
+ return s.dispose = () => t.dispose(), s.alive = !0, Object.defineProperty(s, "alive", {
91
+ get: () => t.alive
92
+ }), s;
93
+ }
94
+ function y(r, e, t, ...s) {
95
+ const n = G(r, e);
36
96
  try {
37
- return n(r, ...o);
97
+ return n(t, ...s);
38
98
  } finally {
39
99
  n.dispose();
40
100
  }
41
101
  }
42
- function N(t, e, r) {
43
- return t.dump(d(t, "Object.is", void 0, e, r));
102
+ function J(r, e, t) {
103
+ return r.dump(y(r, "Object.is", void 0, e, t));
44
104
  }
45
- function B(t, e, r) {
46
- return t.dump(d(t, "(a, b) => a instanceof b", void 0, e, r));
105
+ function U(r, e, t) {
106
+ return r.dump(y(r, "(a, b) => a instanceof b", void 0, e, t));
47
107
  }
48
- function J(t, e) {
49
- return t.dump(
50
- d(t, 'a => typeof a === "object" && a !== null || typeof a === "function"', void 0, e)
108
+ function W(r, e) {
109
+ return r.dump(
110
+ y(r, 'a => typeof a === "object" && a !== null || typeof a === "function"', void 0, e)
51
111
  );
52
112
  }
53
- function I(t, e) {
54
- const r = JSON.stringify(e);
55
- return r ? d(t, "JSON.parse", void 0, t.newString(r)) : t.undefined;
113
+ function z(r, e) {
114
+ const t = JSON.stringify(e);
115
+ return t ? y(r, "JSON.parse", void 0, r.newString(t)) : r.undefined;
56
116
  }
57
- function T(t, e) {
117
+ function be(r, e) {
58
118
  try {
59
- return e(t);
119
+ return e(r);
60
120
  } finally {
61
- for (const r of t)
62
- r.alive && r.dispose();
121
+ for (const t of r)
122
+ t.alive && t.dispose();
63
123
  }
64
124
  }
65
- function U([t, e], r) {
125
+ function $([r, e], t) {
66
126
  try {
67
- return r(t);
127
+ return t(r);
68
128
  } finally {
69
- e && t.dispose();
129
+ e && r.dispose();
70
130
  }
71
131
  }
72
- function w(t, e) {
132
+ function g(r, e) {
73
133
  try {
74
- return e(...t.map((r) => r[0]));
134
+ return e(...r.map((t) => t[0]));
75
135
  } finally {
76
- for (const [r, o] of t)
77
- o && r.dispose();
136
+ for (const [t, s] of r)
137
+ s && t.dispose();
78
138
  }
79
139
  }
80
- function W(t) {
81
- return "handle" in t;
140
+ function q(r) {
141
+ return "handle" in r;
82
142
  }
83
- function z(t) {
84
- return W(t) ? t.handle : t;
143
+ function Q(r) {
144
+ return q(r) ? r.handle : r;
85
145
  }
86
- function $(t, e, r, o) {
87
- var s;
146
+ function V(r, e, t, s) {
147
+ var o;
88
148
  let n;
89
- for (const i of o)
90
- if (n = i(e, t), n)
149
+ for (const i of s)
150
+ if (n = i(e, r), n)
91
151
  break;
92
- return n ? (s = r(e, n)) != null ? s : n : void 0;
152
+ return n ? (o = t(e, n)) != null ? o : n : void 0;
93
153
  }
94
- function G(t, e) {
95
- return typeof t != "symbol" ? void 0 : d(
154
+ function L(r, e) {
155
+ return typeof r != "symbol" ? void 0 : y(
96
156
  e,
97
157
  "d => Symbol(d)",
98
158
  void 0,
99
- t.description ? e.newString(t.description) : e.undefined
159
+ r.description ? e.newString(r.description) : e.undefined
100
160
  );
101
161
  }
102
- function q(t, e) {
103
- return t instanceof Date ? d(e, "d => new Date(d)", void 0, e.newNumber(t.getTime())) : void 0;
162
+ function X(r, e) {
163
+ return r instanceof Date ? y(e, "d => new Date(d)", void 0, e.newNumber(r.getTime())) : void 0;
104
164
  }
105
- const Q = [G, q];
106
- function V(t) {
107
- return typeof t == "function" && /^class\s/.test(Function.prototype.toString.call(t));
165
+ const Y = [L, X];
166
+ function Z(r) {
167
+ return typeof r == "function" && /^class\s/.test(Function.prototype.toString.call(r));
108
168
  }
109
- function v(t) {
110
- return typeof t == "function" || typeof t == "object" && t !== null;
169
+ function v(r) {
170
+ return typeof r == "function" || typeof r == "object" && r !== null;
111
171
  }
112
- function S(t, e) {
113
- const r = /* @__PURE__ */ new Set(), o = (n) => {
114
- if (!(!v(n) || r.has(n) || (e == null ? void 0 : e(n, r)) === !1)) {
115
- if (r.add(n), Array.isArray(n)) {
116
- for (const s of n)
117
- o(s);
172
+ function E(r, e) {
173
+ const t = /* @__PURE__ */ new Set(), s = (n) => {
174
+ if (!(!v(n) || t.has(n) || (e == null ? void 0 : e(n, t)) === !1)) {
175
+ if (t.add(n), Array.isArray(n)) {
176
+ for (const o of n)
177
+ s(o);
118
178
  return;
119
179
  }
120
180
  if (typeof n == "object") {
121
- const s = Object.getPrototypeOf(n);
122
- s && s !== Object.prototype && o(s);
181
+ const o = Object.getPrototypeOf(n);
182
+ o && o !== Object.prototype && s(o);
123
183
  }
124
- for (const s of Object.values(Object.getOwnPropertyDescriptors(n)))
125
- "value" in s && o(s.value), "get" in s && o(s.get), "set" in s && o(s.set);
184
+ for (const o of Object.values(Object.getOwnPropertyDescriptors(n)))
185
+ "value" in o && s(o.value), "get" in o && s(o.get), "set" in o && s(o.set);
126
186
  }
127
187
  };
128
- return o(t), r;
188
+ return s(r), t;
129
189
  }
130
- function de(t, e) {
131
- return S(t, e ? (r, o) => o.size < e : void 0).size;
190
+ function ve(r, e) {
191
+ return E(r, e ? (t, s) => s.size < e : void 0).size;
132
192
  }
133
- function L() {
134
- let t = () => {
193
+ function K() {
194
+ let r = () => {
135
195
  }, e = () => {
136
196
  };
137
197
  return {
138
- promise: new Promise((o, n) => {
139
- t = o, e = n;
198
+ promise: new Promise((s, n) => {
199
+ r = s, e = n;
140
200
  }),
141
- resolve: t,
201
+ resolve: r,
142
202
  reject: e
143
203
  };
144
204
  }
145
- function E(t, e, r, o) {
146
- const n = t.newObject(), s = (u, a) => {
147
- const p = o(u), l = typeof a.value == "undefined" ? void 0 : o(a.value), f = typeof a.get == "undefined" ? void 0 : o(a.get), c = typeof a.set == "undefined" ? void 0 : o(a.set);
148
- t.newObject().consume((h) => {
149
- Object.entries(a).forEach(([m, y]) => {
150
- const _ = m === "value" ? l : m === "get" ? f : m === "set" ? c : y ? t.true : t.false;
151
- _ && t.setProp(h, m, _);
152
- }), t.setProp(n, p, h);
205
+ function R(r, e, t, s) {
206
+ const n = r.newObject(), o = (a, u) => {
207
+ const p = s(a), l = typeof u.value == "undefined" ? void 0 : s(u.value), f = typeof u.get == "undefined" ? void 0 : s(u.get), d = typeof u.set == "undefined" ? void 0 : s(u.set);
208
+ r.newObject().consume((m) => {
209
+ Object.entries(u).forEach(([h, _]) => {
210
+ const b = h === "value" ? l : h === "get" ? f : h === "set" ? d : _ ? r.true : r.false;
211
+ b && r.setProp(m, h, b);
212
+ }), r.setProp(n, p, m);
153
213
  });
154
214
  }, i = Object.getOwnPropertyDescriptors(e);
155
- Object.entries(i).forEach(([u, a]) => s(u, a)), Object.getOwnPropertySymbols(i).forEach((u) => s(u, i[u])), d(t, "Object.defineProperties", void 0, r, n).dispose(), n.dispose();
215
+ Object.entries(i).forEach(([a, u]) => o(a, u)), Object.getOwnPropertySymbols(i).forEach((a) => o(a, i[a])), y(r, "Object.defineProperties", void 0, t, n).dispose(), n.dispose();
156
216
  }
157
- function X(t, e, r, o, n, s) {
158
- var a;
217
+ function x(r, e, t, s, n, o) {
218
+ var u;
159
219
  if (typeof e != "function")
160
220
  return;
161
- const i = t.newFunction(e.name, function(...p) {
162
- const l = o(this), f = p.map((c) => o(c));
163
- if (V(e) && v(l)) {
164
- const c = new e(...f);
165
- return Object.entries(c).forEach(([h, m]) => {
166
- t.setProp(this, h, r(m));
221
+ const i = r.newFunction(e.name, function(...p) {
222
+ const l = s(this), f = p.map((d) => s(d));
223
+ if (Z(e) && v(l)) {
224
+ const d = new e(...f);
225
+ return Object.entries(d).forEach(([m, h]) => {
226
+ r.setProp(this, m, t(h));
167
227
  }), this;
168
228
  }
169
- return r(s ? s(e, l, f) : e.apply(l, f));
229
+ return t(o ? o(e, l, f) : e.apply(l, f));
170
230
  }).consume(
171
- (p) => d(
172
- t,
173
- `Cls => {
231
+ (p) => (
232
+ // fucntions created by vm.newFunction are not callable as a class constrcutor
233
+ y(
234
+ r,
235
+ `Cls => {
174
236
  const fn = function(...args) { return Cls.apply(this, args); };
175
237
  fn.name = Cls.name;
176
238
  fn.length = Cls.length;
177
239
  return fn;
178
240
  }`,
179
- void 0,
180
- p
241
+ void 0,
242
+ p
243
+ )
181
244
  )
182
- ), u = (a = n(e, i)) != null ? a : i;
183
- return E(t, e, i, r), u;
245
+ ), a = (u = n(e, i)) != null ? u : i;
246
+ return R(r, e, i, t), a;
184
247
  }
185
- function Y(t, e, r) {
186
- var s;
187
- const o = I(t, e);
188
- return (s = r(e, o)) != null ? s : o;
248
+ function ee(r, e, t) {
249
+ var o;
250
+ const s = z(r, e);
251
+ return (o = t(e, s)) != null ? o : s;
189
252
  }
190
- function Z(t, e, r, o) {
191
- var a;
253
+ function te(r, e, t, s) {
254
+ var u;
192
255
  if (typeof e != "object" || e === null)
193
256
  return;
194
- const n = Array.isArray(e) ? t.newArray() : t.newObject(), s = (a = o(e, n)) != null ? a : n, i = Object.getPrototypeOf(e), u = i && i !== Object.prototype && i !== Array.prototype ? r(i) : void 0;
195
- return u && d(t, "Object.setPrototypeOf", void 0, s, u).dispose(), E(t, e, n, r), s;
257
+ const n = Array.isArray(e) ? r.newArray() : r.newObject(), o = (u = s(e, n)) != null ? u : n, i = Object.getPrototypeOf(e), a = i && i !== Object.prototype && i !== Array.prototype ? t(i) : void 0;
258
+ return a && y(r, "Object.setPrototypeOf", void 0, o, a).dispose(), R(r, e, n, t), o;
196
259
  }
197
- function K(t, e) {
260
+ function re(r, e) {
198
261
  switch (typeof e) {
199
262
  case "undefined":
200
- return t.undefined;
263
+ return r.undefined;
201
264
  case "number":
202
- return t.newNumber(e);
265
+ return r.newNumber(e);
203
266
  case "string":
204
- return t.newString(e);
267
+ return r.newString(e);
205
268
  case "boolean":
206
- return e ? t.true : t.false;
269
+ return e ? r.true : r.false;
207
270
  case "object":
208
- return e === null ? t.null : void 0;
271
+ return e === null ? r.null : void 0;
209
272
  }
210
273
  }
211
- function x(t, e, r, o) {
212
- var s;
274
+ function ne(r, e, t, s) {
275
+ var o;
213
276
  if (!(e instanceof Promise))
214
277
  return;
215
- const n = t.newPromise();
278
+ const n = r.newPromise();
216
279
  return e.then(
217
- (i) => n.resolve(r(i)),
218
- (i) => n.reject(r(i))
219
- ), (s = o(e, n)) != null ? s : n.handle;
280
+ (i) => n.resolve(t(i)),
281
+ (i) => n.reject(t(i))
282
+ ), (o = s(e, n)) != null ? o : n.handle;
220
283
  }
221
- function R(t, e) {
222
- var l, f, c, h, m;
223
- const { ctx: r, unmarshal: o, isMarshalable: n, find: s, pre: i } = e;
284
+ function M(r, e) {
285
+ var l, f, d, m, h;
286
+ const { ctx: t, unmarshal: s, isMarshalable: n, find: o, pre: i } = e;
224
287
  {
225
- const y = K(r, t);
226
- if (y)
227
- return y;
288
+ const _ = re(t, r);
289
+ if (_)
290
+ return _;
228
291
  }
229
292
  {
230
- const y = s(t);
231
- if (y)
232
- return y;
233
- }
234
- const u = n == null ? void 0 : n(t);
235
- if (u === !1)
236
- return r.undefined;
237
- const a = (y, _) => i(y, _, u);
238
- if (u === "json")
239
- return Y(r, t, a);
240
- const p = (y) => R(y, e);
241
- return (m = (h = (c = (f = $(r, t, a, [...Q, ...(l = e.custom) != null ? l : []])) != null ? f : x(r, t, p, a)) != null ? c : X(r, t, p, o, a, e.preApply)) != null ? h : Z(r, t, p, a)) != null ? m : r.undefined;
242
- }
243
- function ee(t, e, r, o) {
244
- var s;
293
+ const _ = o(r);
294
+ if (_)
295
+ return _;
296
+ }
297
+ const a = n == null ? void 0 : n(r);
298
+ if (a === !1)
299
+ return t.undefined;
300
+ const u = (_, b) => i(_, b, a);
301
+ if (a === "json")
302
+ return ee(t, r, u);
303
+ const p = (_) => M(_, e);
304
+ return (h = (m = (d = (f = V(t, r, u, [...Y, ...(l = e.custom) != null ? l : []])) != null ? f : ne(t, r, p, u)) != null ? d : x(t, r, p, s, u, e.preApply)) != null ? m : te(t, r, p, u)) != null ? h : t.undefined;
305
+ }
306
+ function se(r, e, t, s) {
307
+ var o;
245
308
  let n;
246
- for (const i of o)
247
- if (n = i(e, t), n)
309
+ for (const i of s)
310
+ if (n = i(e, r), n)
248
311
  break;
249
- return n ? (s = r(n, e)) != null ? s : n : void 0;
312
+ return n ? (o = t(n, e)) != null ? o : n : void 0;
250
313
  }
251
- function te(t, e) {
252
- if (e.typeof(t) !== "symbol")
314
+ function oe(r, e) {
315
+ if (e.typeof(r) !== "symbol")
253
316
  return;
254
- const r = e.getString(e.getProp(t, "description"));
255
- return Symbol(r);
317
+ const t = e.getString(e.getProp(r, "description"));
318
+ return Symbol(t);
256
319
  }
257
- function re(t, e) {
258
- if (!e.dump(d(e, "a => a instanceof Date", void 0, t)))
320
+ function ie(r, e) {
321
+ if (!e.dump(y(e, "a => a instanceof Date", void 0, r)))
259
322
  return;
260
- const r = e.getNumber(d(e, "a => a.getTime()", void 0, t));
261
- return new Date(r);
323
+ const t = e.getNumber(y(e, "a => a.getTime()", void 0, r));
324
+ return new Date(t);
262
325
  }
263
- const ne = [te, re];
264
- function k(t, e, r, o) {
265
- t.newFunction("", (n, s) => {
266
- const [i] = o(n);
326
+ const ue = [oe, ie];
327
+ function k(r, e, t, s) {
328
+ r.newFunction("", (n, o) => {
329
+ const [i] = s(n);
267
330
  if (typeof i != "string" && typeof i != "number" && typeof i != "symbol")
268
331
  return;
269
- const u = [
332
+ const a = [
270
333
  ["value", !0],
271
334
  ["get", !0],
272
335
  ["set", !0],
273
336
  ["configurable", !1],
274
337
  ["enumerable", !1],
275
338
  ["writable", !1]
276
- ].reduce((a, [p, l]) => {
277
- const f = t.getProp(s, p), c = t.typeof(f);
278
- if (c === "undefined")
279
- return a;
280
- if (!l && c === "boolean")
281
- return a[p] = t.dump(t.getProp(s, p)), a;
282
- const [h, m] = o(f);
283
- return m && f.dispose(), a[p] = h, a;
339
+ ].reduce((u, [p, l]) => {
340
+ const f = r.getProp(o, p), d = r.typeof(f);
341
+ if (d === "undefined")
342
+ return u;
343
+ if (!l && d === "boolean")
344
+ return u[p] = r.dump(r.getProp(o, p)), u;
345
+ const [m, h] = s(f);
346
+ return h && f.dispose(), u[p] = m, u;
284
347
  }, {});
285
- Object.defineProperty(r, i, u);
348
+ Object.defineProperty(t, i, a);
286
349
  }).consume((n) => {
287
- d(
288
- t,
350
+ y(
351
+ r,
289
352
  `(o, fn) => {
290
353
  const descs = Object.getOwnPropertyDescriptors(o);
291
354
  Object.entries(descs).forEach(([k, v]) => fn(k, v));
@@ -297,85 +360,98 @@ function k(t, e, r, o) {
297
360
  ).dispose();
298
361
  });
299
362
  }
300
- function se(t, e, r, o, n) {
301
- var u;
302
- if (t.typeof(e) !== "function")
363
+ function ae(r, e, t, s, n) {
364
+ var a;
365
+ if (r.typeof(e) !== "function")
303
366
  return;
304
- const s = function(...a) {
305
- return w(
306
- [r(this), ...a.map((p) => r(p))],
367
+ const o = function(...u) {
368
+ return g(
369
+ [t(this), ...u.map((p) => t(p))],
307
370
  (p, ...l) => {
308
371
  if (new.target) {
309
- const [m] = o(
310
- d(t, "(Cls, ...args) => new Cls(...args)", p, e, ...l)
372
+ const [h] = s(
373
+ y(r, "(Cls, ...args) => new Cls(...args)", p, e, ...l)
311
374
  );
312
- return Object.defineProperties(this, Object.getOwnPropertyDescriptors(m)), this;
375
+ return Object.defineProperties(this, Object.getOwnPropertyDescriptors(h)), this;
313
376
  }
314
- const f = t.unwrapResult(t.callFunction(e, p, ...l)), [c, h] = o(f);
315
- return h && f.dispose(), c;
377
+ const f = r.unwrapResult(r.callFunction(e, p, ...l)), [d, m] = s(f);
378
+ return m && f.dispose(), d;
316
379
  }
317
380
  );
318
- }, i = (u = n(s, e)) != null ? u : s;
319
- return k(t, e, s, o), i;
381
+ }, i = (a = n(o, e)) != null ? a : o;
382
+ return k(r, e, o, s), i;
320
383
  }
321
- function oe(t, e, r, o) {
322
- var u;
323
- if (t.typeof(e) !== "object" || t.unwrapResult(t.evalCode("o => o === null")).consume((a) => t.dump(t.unwrapResult(t.callFunction(a, t.undefined, e)))))
384
+ function pe(r, e, t, s) {
385
+ var a;
386
+ if (r.typeof(e) !== "object" || // null check
387
+ r.unwrapResult(r.evalCode("o => o === null")).consume((u) => r.dump(r.unwrapResult(r.callFunction(u, r.undefined, e)))))
324
388
  return;
325
- const n = d(t, "Array.isArray", void 0, e).consume((a) => t.dump(a)) ? [] : {}, s = (u = o(n, e)) != null ? u : n, i = d(
326
- t,
389
+ const n = y(r, "Array.isArray", void 0, e).consume((u) => r.dump(u)) ? [] : {}, o = (a = s(n, e)) != null ? a : n, i = y(
390
+ r,
327
391
  `o => {
328
392
  const p = Object.getPrototypeOf(o);
329
393
  return !p || p === Object.prototype || p === Array.prototype ? undefined : p;
330
394
  }`,
331
395
  void 0,
332
396
  e
333
- ).consume((a) => {
334
- if (t.typeof(a) === "undefined")
397
+ ).consume((u) => {
398
+ if (r.typeof(u) === "undefined")
335
399
  return;
336
- const [p] = r(a);
400
+ const [p] = t(u);
337
401
  return p;
338
402
  });
339
- return typeof i == "object" && Object.setPrototypeOf(s, i), k(t, e, n, r), s;
403
+ return typeof i == "object" && Object.setPrototypeOf(o, i), k(r, e, n, t), o;
340
404
  }
341
- function ie(t, e) {
342
- const r = t.typeof(e);
343
- return r === "undefined" || r === "number" || r === "string" || r === "boolean" ? [t.dump(e), !0] : r === "object" && t.unwrapResult(t.evalCode("a => a === null")).consume((n) => t.dump(t.unwrapResult(t.callFunction(n, t.undefined, e)))) ? [null, !0] : [void 0, !1];
405
+ function fe(r, e) {
406
+ const t = r.typeof(e);
407
+ return t === "undefined" || t === "number" || t === "string" || t === "boolean" ? [r.dump(e), !0] : t === "object" && r.unwrapResult(r.evalCode("a => a === null")).consume((n) => r.dump(r.unwrapResult(r.callFunction(n, r.undefined, e)))) ? [null, !0] : [void 0, !1];
344
408
  }
345
- function ue(t, e, r, o) {
409
+ function ce(r, e, t, s) {
346
410
  var p;
347
- if (!ae(t, e))
411
+ if (!le(r, e))
348
412
  return;
349
- const n = L(), [s, i] = r(n.resolve), [u, a] = r(n.reject);
350
- return d(t, "(p, res, rej) => { p.then(res, rej); }", void 0, e, s, u), i && s.dispose(), a && u.dispose(), (p = o(n.promise, e)) != null ? p : n.promise;
413
+ const n = K(), [o, i] = t(n.resolve), [a, u] = t(n.reject);
414
+ return y(r, "(p, res, rej) => { p.then(res, rej); }", void 0, e, o, a), i && o.dispose(), u && a.dispose(), (p = s(n.promise, e)) != null ? p : n.promise;
351
415
  }
352
- function ae(t, e) {
353
- return e.owner ? t.unwrapResult(t.evalCode("Promise")).consume((r) => e.owner ? B(t, e, r) : !1) : !1;
416
+ function le(r, e) {
417
+ return e.owner ? r.unwrapResult(r.evalCode("Promise")).consume((t) => e.owner ? U(r, e, t) : !1) : !1;
354
418
  }
355
- function pe(t, e) {
356
- const [r] = M(t, e);
357
- return r;
419
+ function de(r, e) {
420
+ const [t] = C(r, e);
421
+ return t;
358
422
  }
359
- function M(t, e) {
360
- var a, p, l, f;
361
- const { ctx: r, marshal: o, find: n, pre: s } = e;
423
+ function C(r, e) {
424
+ var u, p, l, f;
425
+ const { ctx: t, marshal: s, find: n, pre: o } = e;
362
426
  {
363
- const [c, h] = ie(r, t);
364
- if (h)
365
- return [c, !1];
427
+ const [d, m] = fe(t, r);
428
+ if (m)
429
+ return [d, !1];
366
430
  }
367
431
  {
368
- const c = n(t);
369
- if (c)
370
- return [c, !0];
432
+ const d = n(r);
433
+ if (d)
434
+ return [d, !0];
371
435
  }
372
- const i = (c) => M(c, e);
373
- return [(f = (l = (p = ee(r, t, s, [...ne, ...(a = e.custom) != null ? a : []])) != null ? p : ue(r, t, o, s)) != null ? l : se(r, t, o, i, s)) != null ? f : oe(r, t, i, s), !1];
436
+ const i = (d) => C(d, e);
437
+ return [(f = (l = (p = se(t, r, o, [...ue, ...(u = e.custom) != null ? u : []])) != null ? p : ce(t, r, s, o)) != null ? l : ae(t, r, s, i, o)) != null ? f : pe(t, r, i, o), !1];
374
438
  }
375
- class O {
439
+ class S {
376
440
  constructor(e) {
377
- this._map1 = /* @__PURE__ */ new Map(), this._map2 = /* @__PURE__ */ new Map(), this._map3 = /* @__PURE__ */ new Map(), this._map4 = /* @__PURE__ */ new Map(), this._counterMap = /* @__PURE__ */ new Map(), this._disposables = /* @__PURE__ */ new Set(), this._counter = 0, this.ctx = e;
378
- const r = e.unwrapResult(
441
+ c(this, "ctx");
442
+ c(this, "_map1", /* @__PURE__ */ new Map());
443
+ c(this, "_map2", /* @__PURE__ */ new Map());
444
+ c(this, "_map3", /* @__PURE__ */ new Map());
445
+ c(this, "_map4", /* @__PURE__ */ new Map());
446
+ c(this, "_counterMap", /* @__PURE__ */ new Map());
447
+ c(this, "_disposables", /* @__PURE__ */ new Set());
448
+ c(this, "_mapGet");
449
+ c(this, "_mapSet");
450
+ c(this, "_mapDelete");
451
+ c(this, "_mapClear");
452
+ c(this, "_counter", Number.MIN_SAFE_INTEGER);
453
+ this.ctx = e;
454
+ const t = e.unwrapResult(
379
455
  e.evalCode(`() => {
380
456
  const mapSym = new Map();
381
457
  let map = new WeakMap();
@@ -400,39 +476,39 @@ class O {
400
476
  }
401
477
  };
402
478
  }`)
403
- ).consume((o) => this._call(o, void 0));
404
- this._mapGet = e.getProp(r, "get"), this._mapSet = e.getProp(r, "set"), this._mapDelete = e.getProp(r, "delete"), this._mapClear = e.getProp(r, "clear"), r.dispose(), this._disposables.add(this._mapGet), this._disposables.add(this._mapSet), this._disposables.add(this._mapDelete), this._disposables.add(this._mapClear);
479
+ ).consume((s) => this._call(s, void 0));
480
+ 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);
405
481
  }
406
- set(e, r, o, n) {
407
- var u;
408
- if (!r.alive || n && !n.alive)
482
+ set(e, t, s, n) {
483
+ var a;
484
+ if (!t.alive || n && !n.alive)
409
485
  return !1;
410
- const s = (u = this.get(e)) != null ? u : this.get(o);
411
- if (s)
412
- return s === r || s === n;
486
+ const o = (a = this.get(e)) != null ? a : this.get(s);
487
+ if (o)
488
+ return o === t || o === n;
413
489
  const i = this._counter++;
414
- return this._map1.set(e, i), this._map3.set(i, r), this._counterMap.set(i, e), o && (this._map2.set(o, i), n && this._map4.set(i, n)), this.ctx.newNumber(i).consume((a) => {
415
- this._call(this._mapSet, void 0, r, a, n != null ? n : this.ctx.undefined);
490
+ return this._map1.set(e, i), this._map3.set(i, t), this._counterMap.set(i, e), s && (this._map2.set(s, i), n && this._map4.set(i, n)), this.ctx.newNumber(i).consume((u) => {
491
+ this._call(this._mapSet, void 0, t, u, n != null ? n : this.ctx.undefined);
416
492
  }), !0;
417
493
  }
418
494
  merge(e) {
419
- if (!!e)
420
- for (const r of e)
421
- !r || r[1] && this.set(r[0], r[1], r[2], r[3]);
495
+ if (e)
496
+ for (const t of e)
497
+ t && t[1] && this.set(t[0], t[1], t[2], t[3]);
422
498
  }
423
499
  get(e) {
424
500
  var n;
425
- const r = (n = this._map1.get(e)) != null ? n : this._map2.get(e), o = typeof r == "number" ? this._map3.get(r) : void 0;
426
- if (!!o) {
427
- if (!o.alive) {
501
+ const t = (n = this._map1.get(e)) != null ? n : this._map2.get(e), s = typeof t == "number" ? this._map3.get(t) : void 0;
502
+ if (s) {
503
+ if (!s.alive) {
428
504
  this.delete(e);
429
505
  return;
430
506
  }
431
- return o;
507
+ return s;
432
508
  }
433
509
  }
434
510
  getByHandle(e) {
435
- if (!!e.alive)
511
+ if (e.alive)
436
512
  return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet, void 0, e)));
437
513
  }
438
514
  has(e) {
@@ -444,37 +520,37 @@ class O {
444
520
  keys() {
445
521
  return this._map1.keys();
446
522
  }
447
- delete(e, r) {
523
+ delete(e, t) {
448
524
  var i;
449
- const o = (i = this._map1.get(e)) != null ? i : this._map2.get(e);
450
- if (typeof o == "undefined")
525
+ const s = (i = this._map1.get(e)) != null ? i : this._map2.get(e);
526
+ if (typeof s == "undefined")
451
527
  return;
452
- const n = this._map3.get(o), s = this._map4.get(o);
528
+ const n = this._map3.get(s), o = this._map4.get(s);
453
529
  this._call(
454
530
  this._mapDelete,
455
531
  void 0,
456
- ...[n, s].filter((u) => !!(u != null && u.alive))
457
- ), this._map1.delete(e), this._map2.delete(e), this._map3.delete(o), this._map4.delete(o);
458
- for (const [u, a] of this._map1)
459
- if (a === o) {
460
- this._map1.delete(u);
532
+ ...[n, o].filter((a) => !!(a != null && a.alive))
533
+ ), this._map1.delete(e), this._map2.delete(e), this._map3.delete(s), this._map4.delete(s);
534
+ for (const [a, u] of this._map1)
535
+ if (u === s) {
536
+ this._map1.delete(a);
461
537
  break;
462
538
  }
463
- for (const [u, a] of this._map2)
464
- if (a === o) {
465
- this._map2.delete(u);
539
+ for (const [a, u] of this._map2)
540
+ if (u === s) {
541
+ this._map2.delete(a);
466
542
  break;
467
543
  }
468
- for (const [u, a] of this._counterMap)
469
- if (a === e) {
470
- this._counterMap.delete(u);
544
+ for (const [a, u] of this._counterMap)
545
+ if (u === e) {
546
+ this._counterMap.delete(a);
471
547
  break;
472
548
  }
473
- r && (n != null && n.alive && n.dispose(), s != null && s.alive && s.dispose());
549
+ t && (n != null && n.alive && n.dispose(), o != null && o.alive && o.dispose());
474
550
  }
475
- deleteByHandle(e, r) {
476
- const o = this.getByHandle(e);
477
- typeof o != "undefined" && this.delete(o, r);
551
+ deleteByHandle(e, t) {
552
+ const s = this.getByHandle(e);
553
+ typeof s != "undefined" && this.delete(s, t);
478
554
  }
479
555
  clear() {
480
556
  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);
@@ -496,101 +572,110 @@ class O {
496
572
  return {
497
573
  next: () => {
498
574
  for (; ; ) {
499
- const r = e.next();
500
- if (r.done)
575
+ const t = e.next();
576
+ if (t.done)
501
577
  return { value: void 0, done: !0 };
502
- const o = this._map1.get(r.value);
503
- if (typeof o == "undefined")
578
+ const s = this._map1.get(t.value);
579
+ if (typeof s == "undefined")
504
580
  continue;
505
- const n = this._map3.get(o), s = this._map4.get(o);
581
+ const n = this._map3.get(s), o = this._map4.get(s);
506
582
  if (!n)
507
583
  continue;
508
- const i = this._get2(o);
509
- return { value: [r.value, n, i, s], done: !1 };
584
+ const i = this._get2(s);
585
+ return { value: [t.value, n, i, o], done: !1 };
510
586
  }
511
587
  }
512
588
  };
513
589
  }
514
590
  _get2(e) {
515
- for (const [r, o] of this._map2)
516
- if (o === e)
517
- return r;
591
+ for (const [t, s] of this._map2)
592
+ if (s === e)
593
+ return t;
518
594
  }
519
- _call(e, r, ...o) {
595
+ _call(e, t, ...s) {
520
596
  return this.ctx.unwrapResult(
521
597
  this.ctx.callFunction(
522
598
  e,
523
- typeof r == "undefined" ? this.ctx.undefined : r,
524
- ...o
599
+ typeof t == "undefined" ? this.ctx.undefined : t,
600
+ ...s
525
601
  )
526
602
  );
527
603
  }
528
604
  }
529
- function fe(t, e, r, o, n, s, i) {
605
+ function me(r, e, t, s, n, o, i) {
530
606
  if (!v(e) || e instanceof Promise || e instanceof Date || i && !i(e))
531
607
  return;
532
- if (ce(e, r))
608
+ if (ye(e, t))
533
609
  return e;
534
- const u = new Proxy(e, {
535
- get(a, p) {
536
- return p === r ? a : Reflect.get(a, p);
610
+ const a = new Proxy(e, {
611
+ get(u, p) {
612
+ return p === t ? u : Reflect.get(u, p);
537
613
  },
538
- set(a, p, l, f) {
539
- var m;
540
- const c = b(l, r), h = (m = s == null ? void 0 : s(f)) != null ? m : "host";
541
- return h !== "vm" && !Reflect.set(a, p, c, f) || h === "host" || !t.alive || w(
542
- [n(f), n(p), n(c)],
543
- (y, _, j) => {
544
- const [P, C] = g(t, y, o);
545
- C ? P.consume((D) => t.setProp(D, _, j)) : t.setProp(P, _, j);
614
+ set(u, p, l, f) {
615
+ var h;
616
+ const d = w(l, t), m = (h = o == null ? void 0 : o(f)) != null ? h : "host";
617
+ return m !== "vm" && !Reflect.set(u, p, d, f) || m === "host" || !r.alive || g(
618
+ [n(f), n(p), n(d)],
619
+ (_, b, P) => {
620
+ const [O, H] = j(r, _, s);
621
+ H ? O.consume((N) => r.setProp(N, b, P)) : r.setProp(O, b, P);
546
622
  }
547
623
  ), !0;
548
624
  },
549
- deleteProperty(a, p) {
625
+ deleteProperty(u, p) {
550
626
  var f;
551
- const l = (f = s == null ? void 0 : s(u)) != null ? f : "host";
552
- return w([n(u), n(p)], (c, h) => {
553
- const [m, y] = g(t, c, o);
554
- if (l === "vm" || Reflect.deleteProperty(a, p)) {
555
- if (l === "host" || !t.alive)
627
+ const l = (f = o == null ? void 0 : o(a)) != null ? f : "host";
628
+ return g([n(a), n(p)], (d, m) => {
629
+ const [h, _] = j(r, d, s);
630
+ if (l === "vm" || Reflect.deleteProperty(u, p)) {
631
+ if (l === "host" || !r.alive)
556
632
  return !0;
557
- y ? m.consume((_) => d(t, "(a, b) => delete a[b]", void 0, _, h)) : d(t, "(a, b) => delete a[b]", void 0, m, h);
633
+ _ ? h.consume((b) => y(r, "(a, b) => delete a[b]", void 0, b, m)) : y(r, "(a, b) => delete a[b]", void 0, h, m);
558
634
  }
559
635
  return !0;
560
636
  });
561
637
  }
562
638
  });
563
- return u;
564
- }
565
- function le(t, e, r, o, n, s, i) {
566
- return !J(t, e) || i && !i(e, t) ? [void 0, !1] : H(t, e, o) ? [e, !1] : T(
567
- [
568
- t.newFunction("getSyncMode", (u) => {
569
- const a = s == null ? void 0 : s(n(u));
570
- return typeof a == "string" ? t.newString(a) : t.undefined;
571
- }),
572
- t.newFunction("setter", (u, a, p) => {
573
- const l = n(u);
574
- if (!l)
575
- return;
576
- const f = n(a);
577
- if (f === "__proto__")
578
- return;
579
- const c = n(p);
580
- b(l, r)[f] = c;
581
- }),
582
- t.newFunction("deleter", (u, a) => {
583
- const p = n(u);
584
- if (!p)
585
- return;
586
- const l = n(a);
587
- delete b(p, r)[l];
588
- })
589
- ],
590
- (u) => [
591
- d(
592
- t,
593
- `(target, sym, getSyncMode, setter, deleter) => {
639
+ return a;
640
+ }
641
+ function he(r, e, t, s, n, o, i) {
642
+ if (!W(r, e) || i && !i(e, r))
643
+ return [void 0, !1];
644
+ if (F(r, e, s))
645
+ return [e, !1];
646
+ const a = (l) => {
647
+ const f = o == null ? void 0 : o(n(l));
648
+ return typeof f == "string" ? r.newString(f) : r.undefined;
649
+ }, u = (l, f, d) => {
650
+ const m = n(l);
651
+ if (!m)
652
+ return;
653
+ const h = n(f);
654
+ if (h === "__proto__")
655
+ return;
656
+ const _ = n(d);
657
+ w(m, t)[h] = _;
658
+ }, p = (l, f) => {
659
+ const d = n(l);
660
+ if (!d)
661
+ return;
662
+ const m = n(f);
663
+ delete w(d, t)[m];
664
+ };
665
+ return r.newFunction("proxyFuncs", (l, ...f) => {
666
+ switch (r.getNumber(l)) {
667
+ case 1:
668
+ return a(f[0]);
669
+ case 2:
670
+ return u(f[0], f[1], f[2]);
671
+ case 3:
672
+ return p(f[0], f[1]);
673
+ }
674
+ return r.undefined;
675
+ }).consume((l) => [
676
+ y(
677
+ r,
678
+ `(target, sym, proxyFuncs) => {
594
679
  const rec = new Proxy(target, {
595
680
  get(obj, key, receiver) {
596
681
  return key === sym ? obj : Reflect.get(obj, key, receiver)
@@ -599,19 +684,19 @@ function le(t, e, r, o, n, s, i) {
599
684
  const v = typeof value === "object" && value !== null || typeof value === "function"
600
685
  ? value[sym] ?? value
601
686
  : value;
602
- const sync = getSyncMode(receiver) ?? "vm";
687
+ const sync = proxyFuncs(1, receiver) ?? "vm";
603
688
  if (sync === "host" || Reflect.set(obj, key, v, receiver)) {
604
689
  if (sync !== "vm") {
605
- setter(receiver, key, v);
690
+ proxyFuncs(2, receiver, key, v);
606
691
  }
607
692
  }
608
693
  return true;
609
694
  },
610
695
  deleteProperty(obj, key) {
611
- const sync = getSyncMode(rec) ?? "vm";
696
+ const sync = proxyFuncs(1, rec) ?? "vm";
612
697
  if (sync === "host" || Reflect.deleteProperty(obj, key)) {
613
698
  if (sync !== "vm") {
614
- deleter(rec, key);
699
+ proxyFuncs(3, rec, key);
615
700
  }
616
701
  }
617
702
  return true;
@@ -619,152 +704,207 @@ function le(t, e, r, o, n, s, i) {
619
704
  });
620
705
  return rec;
621
706
  }`,
622
- void 0,
623
- e,
624
- o,
625
- ...u
626
- ),
627
- !0
628
- ]
629
- );
630
- }
631
- function b(t, e) {
632
- var r;
633
- return v(t) && (r = t[e]) != null ? r : t;
634
- }
635
- function g(t, e, r) {
636
- return H(t, e, r) ? [t.getProp(e, r), !0] : [e, !1];
637
- }
638
- function ce(t, e) {
639
- return v(t) && !!t[e];
640
- }
641
- function H(t, e, r) {
642
- return !!t.dump(
643
- d(
644
- t,
707
+ void 0,
708
+ e,
709
+ s,
710
+ l
711
+ ),
712
+ !0
713
+ ]);
714
+ }
715
+ function w(r, e) {
716
+ var t;
717
+ return v(r) && (t = r[e]) != null ? t : r;
718
+ }
719
+ function j(r, e, t) {
720
+ return F(r, e, t) ? [r.getProp(e, t), !0] : [e, !1];
721
+ }
722
+ function ye(r, e) {
723
+ return v(r) && !!r[e];
724
+ }
725
+ function F(r, e, t) {
726
+ return !!r.dump(
727
+ y(
728
+ r,
729
+ // promise and date cannot be wrapped
645
730
  '(a, s) => (a instanceof Promise) || (a instanceof Date) || (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',
646
731
  void 0,
647
732
  e,
648
- r
733
+ t
649
734
  )
650
735
  );
651
736
  }
652
- class he {
653
- constructor(e, r) {
654
- var o;
655
- this._registeredMapDispose = /* @__PURE__ */ new Set(), this._sync = /* @__PURE__ */ new Set(), this._temporalSync = /* @__PURE__ */ new Set(), this._symbol = Symbol(), this._isMarshalable = (n) => {
656
- var i, u;
657
- const s = (i = this._options) == null ? void 0 : i.isMarshalable;
658
- return (u = typeof s == "function" ? s(this._unwrap(n)) : s) != null ? u : "json";
659
- }, this._marshalFind = (n) => {
660
- var u, a, p;
661
- const s = this._unwrap(n);
662
- return (p = (a = (u = this._registeredMap.get(n)) != null ? u : s !== n ? this._registeredMap.get(s) : void 0) != null ? a : this._map.get(n)) != null ? p : s !== n ? this._map.get(s) : void 0;
663
- }, this._marshalPre = (n, s, i) => {
664
- var u;
665
- if (i !== "json")
666
- return (u = this._register(n, z(s), this._map)) == null ? void 0 : u[1];
667
- }, this._marshalPreApply = (n, s, i) => {
668
- const u = v(s) ? this._unwrap(s) : void 0;
669
- u && this._temporalSync.add(u);
737
+ class we {
738
+ /** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
739
+ constructor(e, t) {
740
+ c(this, "context");
741
+ c(this, "_map");
742
+ c(this, "_registeredMap");
743
+ c(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
744
+ c(this, "_sync", /* @__PURE__ */ new Set());
745
+ c(this, "_temporalSync", /* @__PURE__ */ new Set());
746
+ c(this, "_symbol", Symbol());
747
+ c(this, "_symbolHandle");
748
+ c(this, "_options");
749
+ c(this, "_isMarshalable", (e) => {
750
+ var s, n;
751
+ const t = (s = this._options) == null ? void 0 : s.isMarshalable;
752
+ return (n = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? n : "json";
753
+ });
754
+ c(this, "_marshalFind", (e) => {
755
+ var n, o, i;
756
+ const t = this._unwrap(e);
757
+ return (i = (o = (n = this._registeredMap.get(e)) != null ? n : t !== e ? this._registeredMap.get(t) : void 0) != null ? o : this._map.get(e)) != null ? i : t !== e ? this._map.get(t) : void 0;
758
+ });
759
+ c(this, "_marshalPre", (e, t, s) => {
760
+ var n;
761
+ if (s !== "json")
762
+ return (n = this._register(e, Q(t), this._map)) == null ? void 0 : n[1];
763
+ });
764
+ c(this, "_marshalPreApply", (e, t, s) => {
765
+ const n = v(t) ? this._unwrap(t) : void 0;
766
+ n && this._temporalSync.add(n);
670
767
  try {
671
- return n.apply(s, i);
768
+ return e.apply(t, s);
672
769
  } finally {
673
- u && this._temporalSync.delete(u);
770
+ n && this._temporalSync.delete(n);
674
771
  }
675
- }, this._marshal = (n) => {
676
- var u, a;
677
- const s = this._registeredMap.get(n);
678
- if (s)
679
- return [s, !1];
680
- const i = R((u = this._wrap(n)) != null ? u : n, {
772
+ });
773
+ c(this, "_marshal", (e) => {
774
+ var n, o;
775
+ const t = this._registeredMap.get(e);
776
+ if (t)
777
+ return [t, !1];
778
+ const s = M((n = this._wrap(e)) != null ? n : e, {
681
779
  ctx: this.context,
682
780
  unmarshal: this._unmarshal,
683
781
  isMarshalable: this._isMarshalable,
684
782
  find: this._marshalFind,
685
783
  pre: this._marshalPre,
686
784
  preApply: this._marshalPreApply,
687
- custom: (a = this._options) == null ? void 0 : a.customMarshaller
785
+ custom: (o = this._options) == null ? void 0 : o.customMarshaller
688
786
  });
689
- return [i, !this._map.hasHandle(i)];
690
- }, this._preUnmarshal = (n, s) => {
691
- var i;
692
- return (i = this._register(n, s, void 0, !0)) == null ? void 0 : i[0];
693
- }, this._unmarshalFind = (n) => {
787
+ return [s, !this._map.hasHandle(s)];
788
+ });
789
+ c(this, "_preUnmarshal", (e, t) => {
694
790
  var s;
695
- return (s = this._registeredMap.getByHandle(n)) != null ? s : this._map.getByHandle(n);
696
- }, this._unmarshal = (n) => {
697
- var u;
698
- const s = this._registeredMap.getByHandle(n);
699
- if (typeof s != "undefined")
700
- return s;
701
- const [i] = this._wrapHandle(n);
702
- return pe(i != null ? i : n, {
791
+ return (s = this._register(e, t, void 0, !0)) == null ? void 0 : s[0];
792
+ });
793
+ c(this, "_unmarshalFind", (e) => {
794
+ var t;
795
+ return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
796
+ });
797
+ c(this, "_unmarshal", (e) => {
798
+ var n;
799
+ const t = this._registeredMap.getByHandle(e);
800
+ if (typeof t != "undefined")
801
+ return t;
802
+ const [s] = this._wrapHandle(e);
803
+ return de(s != null ? s : e, {
703
804
  ctx: this.context,
704
805
  marshal: this._marshal,
705
806
  find: this._unmarshalFind,
706
807
  pre: this._preUnmarshal,
707
- custom: (u = this._options) == null ? void 0 : u.customUnmarshaller
808
+ custom: (n = this._options) == null ? void 0 : n.customUnmarshaller
708
809
  });
709
- }, this._syncMode = (n) => {
710
- const s = this._unwrap(n);
711
- return this._sync.has(s) || this._temporalSync.has(s) ? "both" : void 0;
712
- }, this._unwrapIfNotSynced = (n) => {
713
- const s = this._unwrap(n);
714
- return s instanceof Promise || !this._sync.has(s) ? s : n;
715
- }, (r == null ? void 0 : r.compat) && !("runtime" in e) && (e.runtime = {
810
+ });
811
+ c(this, "_syncMode", (e) => {
812
+ const t = this._unwrap(e);
813
+ return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
814
+ });
815
+ c(this, "_unwrapIfNotSynced", (e) => {
816
+ const t = this._unwrap(e);
817
+ return t instanceof Promise || !this._sync.has(t) ? t : e;
818
+ });
819
+ var s;
820
+ t != null && t.compat && !("runtime" in e) && (e.runtime = {
716
821
  hasPendingJob: () => e.hasPendingJob(),
717
822
  executePendingJobs: (n) => e.executePendingJobs(n)
718
- }), this.context = e, this._options = r, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._map = new O(e), this._registeredMap = new O(e), this.registerAll((o = r == null ? void 0 : r.registeredObjects) != null ? o : F);
823
+ }), this.context = t != null && t.experimentalContextEx ? B(e) : e, this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._map = new S(e), this._registeredMap = new S(e), this.registerAll((s = t == null ? void 0 : t.registeredObjects) != null ? s : T);
719
824
  }
825
+ /**
826
+ * Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
827
+ */
720
828
  dispose() {
721
- this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose();
829
+ var e, t;
830
+ this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose(), (t = (e = this.context).disposeEx) == null || t.call(e);
722
831
  }
832
+ /**
833
+ * Evaluate JS code in the VM and get the result as an object on the host side. It also converts and re-throws error objects when an error is thrown during evaluation.
834
+ */
723
835
  evalCode(e) {
724
- const r = this.context.evalCode(e);
725
- return this._unwrapResultAndUnmarshal(r);
836
+ const t = this.context.evalCode(e);
837
+ return this._unwrapResultAndUnmarshal(t);
726
838
  }
839
+ /**
840
+ * Almost same as `vm.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.
841
+ */
727
842
  executePendingJobs(e) {
728
- const r = this.context.runtime.executePendingJobs(e);
729
- if ("value" in r)
730
- return r.value;
731
- throw this._unwrapIfNotSynced(r.error.consume(this._unmarshal));
732
- }
843
+ const t = this.context.runtime.executePendingJobs(e);
844
+ if ("value" in t)
845
+ return t.value;
846
+ throw this._unwrapIfNotSynced(t.error.consume(this._unmarshal));
847
+ }
848
+ /**
849
+ * Expose objects as global objects in the VM.
850
+ *
851
+ * By default, exposed objects are not synchronized between the host and the VM.
852
+ * If you want to sync an objects, first wrap the object with sync method, and then expose the wrapped object.
853
+ */
733
854
  expose(e) {
734
- for (const [r, o] of Object.entries(e))
735
- U(this._marshal(o), (n) => {
736
- this.context.setProp(this.context.global, r, n);
855
+ for (const [t, s] of Object.entries(e))
856
+ $(this._marshal(s), (n) => {
857
+ this.context.setProp(this.context.global, t, n);
737
858
  });
738
859
  }
860
+ /**
861
+ * Enables sync for the object between the host and the VM and returns objects wrapped with proxies.
862
+ *
863
+ * The return value is necessary in order to reflect changes to the object from the host to the VM. Please note that setting a value in the field or deleting a field in the original object will not synchronize it.
864
+ */
739
865
  sync(e) {
740
- const r = this._wrap(e);
741
- return typeof r == "undefined" ? e : (S(r, (o) => {
742
- const n = this._unwrap(o);
866
+ const t = this._wrap(e);
867
+ return typeof t == "undefined" ? e : (E(t, (s) => {
868
+ const n = this._unwrap(s);
743
869
  this._sync.add(n);
744
- }), r);
745
- }
746
- register(e, r) {
870
+ }), t);
871
+ }
872
+ /**
873
+ * Register a pair of objects that will be considered the same between the host and the QuickJS VM.
874
+ *
875
+ * Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, when you have to dispose them manually when destroying the VM.
876
+ */
877
+ register(e, t) {
747
878
  if (this._registeredMap.has(e))
748
879
  return;
749
- const o = typeof r == "string" ? this._unwrapResult(this.context.evalCode(r)) : r;
750
- N(this.context, o, this.context.undefined) || (typeof r == "string" && this._registeredMapDispose.add(e), this._registeredMap.set(e, o));
880
+ const s = typeof t == "string" ? this._unwrapResult(this.context.evalCode(t)) : t;
881
+ J(this.context, s, this.context.undefined) || (typeof t == "string" && this._registeredMapDispose.add(e), this._registeredMap.set(e, s));
751
882
  }
883
+ /**
884
+ * Execute `register` methods for each pair.
885
+ */
752
886
  registerAll(e) {
753
- for (const [r, o] of e)
754
- this.register(r, o);
755
- }
756
- unregister(e, r) {
757
- this._registeredMap.delete(e, this._registeredMapDispose.has(e) || r), this._registeredMapDispose.delete(e);
758
- }
759
- unregisterAll(e, r) {
760
- for (const o of e)
761
- this.unregister(o, r);
887
+ for (const [t, s] of e)
888
+ this.register(t, s);
889
+ }
890
+ /**
891
+ * Unregister a pair of objects that were registered with `registeredObjects` option and `register` method.
892
+ */
893
+ unregister(e, t) {
894
+ this._registeredMap.delete(e, this._registeredMapDispose.has(e) || t), this._registeredMapDispose.delete(e);
895
+ }
896
+ /**
897
+ * Execute `unregister` methods for each target.
898
+ */
899
+ unregisterAll(e, t) {
900
+ for (const s of e)
901
+ this.unregister(s, t);
762
902
  }
763
903
  startSync(e) {
764
904
  if (!v(e))
765
905
  return;
766
- const r = this._unwrap(e);
767
- this._sync.add(r);
906
+ const t = this._unwrap(e);
907
+ this._sync.add(t);
768
908
  }
769
909
  endSync(e) {
770
910
  this._sync.delete(this._unwrap(e));
@@ -775,68 +915,68 @@ class he {
775
915
  throw this._unwrapIfNotSynced(e.error.consume(this._unmarshal));
776
916
  }
777
917
  _unwrapResultAndUnmarshal(e) {
778
- if (!!e)
918
+ if (e)
779
919
  return this._unwrapIfNotSynced(this._unwrapResult(e).consume(this._unmarshal));
780
920
  }
781
- _register(e, r, o = this._map, n) {
782
- if (this._registeredMap.has(e) || this._registeredMap.hasHandle(r))
921
+ _register(e, t, s = this._map, n) {
922
+ if (this._registeredMap.has(e) || this._registeredMap.hasHandle(t))
783
923
  return;
784
- let s = this._wrap(e);
785
- const [i] = this._wrapHandle(r), u = e instanceof Promise;
786
- if (!i || !s && !u)
924
+ let o = this._wrap(e);
925
+ const [i] = this._wrapHandle(t), a = e instanceof Promise;
926
+ if (!i || !o && !a)
787
927
  return;
788
- u && (s = e);
789
- const a = this._unwrap(e), [p, l] = this._unwrapHandle(r);
790
- if (o.set(s, i, a, p))
791
- n && this._sync.add(a);
928
+ a && (o = e);
929
+ const u = this._unwrap(e), [p, l] = this._unwrapHandle(t);
930
+ if (s.set(o, i, u, p))
931
+ n && this._sync.add(u);
792
932
  else
793
933
  throw l && p.dispose(), new Error("already registered");
794
- return [s, i];
934
+ return [o, i];
795
935
  }
796
936
  _wrap(e) {
797
- var r;
798
- return fe(
937
+ var t;
938
+ return me(
799
939
  this.context,
800
940
  e,
801
941
  this._symbol,
802
942
  this._symbolHandle,
803
943
  this._marshal,
804
944
  this._syncMode,
805
- (r = this._options) == null ? void 0 : r.isWrappable
945
+ (t = this._options) == null ? void 0 : t.isWrappable
806
946
  );
807
947
  }
808
948
  _unwrap(e) {
809
- return b(e, this._symbol);
949
+ return w(e, this._symbol);
810
950
  }
811
951
  _wrapHandle(e) {
812
- var r;
813
- return le(
952
+ var t;
953
+ return he(
814
954
  this.context,
815
955
  e,
816
956
  this._symbol,
817
957
  this._symbolHandle,
818
958
  this._unmarshal,
819
959
  this._syncMode,
820
- (r = this._options) == null ? void 0 : r.isHandleWrappable
960
+ (t = this._options) == null ? void 0 : t.isHandleWrappable
821
961
  );
822
962
  }
823
963
  _unwrapHandle(e) {
824
- return g(this.context, e, this._symbolHandle);
964
+ return j(this.context, e, this._symbolHandle);
825
965
  }
826
966
  }
827
967
  export {
828
- he as Arena,
829
- O as VMMap,
830
- d as call,
831
- de as complexity,
832
- T as consumeAll,
833
- F as defaultRegisteredObjects,
834
- N as eq,
835
- V as isES2015Class,
836
- J as isHandleObject,
968
+ we as Arena,
969
+ S as VMMap,
970
+ y as call,
971
+ ve as complexity,
972
+ be as consumeAll,
973
+ T as defaultRegisteredObjects,
974
+ J as eq,
975
+ Z as isES2015Class,
976
+ W as isHandleObject,
837
977
  v as isObject,
838
- I as json,
839
- R as marshal,
840
- pe as unmarshal,
841
- S as walkObject
978
+ z as json,
979
+ M as marshal,
980
+ de as unmarshal,
981
+ E as walkObject
842
982
  };