quickjs-emscripten-sync 1.10.0 → 1.11.0

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,114 +1,32 @@
1
- var z = Object.defineProperty;
1
+ var Q = Object.defineProperty, X = Object.defineProperties;
2
+ var Y = Object.getOwnPropertyDescriptors;
2
3
  var B = Object.getOwnPropertySymbols;
3
- var $ = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
4
- var M = (n, e, t) => e in n ? z(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, F = (n, e) => {
4
+ var Z = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
5
+ var M = (n, e, t) => e in n ? Q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, I = (n, e) => {
5
6
  for (var t in e || (e = {}))
6
- $.call(e, t) && M(n, t, e[t]);
7
+ Z.call(e, t) && M(n, t, e[t]);
7
8
  if (B)
8
9
  for (var t of B(e))
9
- L.call(e, t) && M(n, t, e[t]);
10
+ x.call(e, t) && M(n, t, e[t]);
10
11
  return n;
11
- };
12
- var p = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
13
- var A = (n, e, t) => new Promise((r, s) => {
12
+ }, N = (n, e) => X(n, Y(e));
13
+ var d = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
14
+ var F = (n, e, t) => new Promise((r, s) => {
14
15
  var i = (u) => {
15
16
  try {
16
- f(t.next(u));
17
- } catch (a) {
18
- s(a);
17
+ a(t.next(u));
18
+ } catch (f) {
19
+ s(f);
19
20
  }
20
21
  }, o = (u) => {
21
22
  try {
22
- f(t.throw(u));
23
- } catch (a) {
24
- s(a);
23
+ a(t.throw(u));
24
+ } catch (f) {
25
+ s(f);
25
26
  }
26
- }, f = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(i, o);
27
- f((t = t.apply(n, e)).next());
27
+ }, a = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(i, o);
28
+ a((t = t.apply(n, e)).next());
28
29
  });
29
- const K = (n) => {
30
- const e = new q(n);
31
- return new Proxy(n, {
32
- get(t, r, s) {
33
- return r in e ? e[r] : Reflect.get(t, r, s);
34
- }
35
- });
36
- };
37
- class q {
38
- constructor(e) {
39
- p(this, "context");
40
- p(this, "fn");
41
- p(this, "fnGenerator");
42
- p(this, "fnCounter", Number.MIN_SAFE_INTEGER);
43
- p(this, "fnMap", /* @__PURE__ */ new Map());
44
- /** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
45
- p(this, "newFunction", (e, t) => {
46
- this.fnCounter++;
47
- const r = this.fnCounter;
48
- return this.fnMap.set(r, t), this.context.unwrapResult(
49
- this.context.callFunction(
50
- this.fnGenerator,
51
- this.context.undefined,
52
- this.context.newString(e),
53
- this.context.newNumber(t.length),
54
- this.context.newNumber(r),
55
- this.fn
56
- )
57
- );
58
- });
59
- this.context = e;
60
- const t = this.fnMap;
61
- this.fn = this.context.newFunction("", function(r, ...s) {
62
- const i = e.getNumber(r), o = t.get(i);
63
- if (!o) throw new Error("function is not registered");
64
- return o.call(this, ...s);
65
- }), this.fnGenerator = e.unwrapResult(
66
- e.evalCode(`((name, length, id, f) => {
67
- const fn = function(...args) {
68
- return f.call(this, id, ...args);
69
- };
70
- fn.name = name;
71
- fn.length = length;
72
- return fn;
73
- })`)
74
- );
75
- }
76
- disposeEx() {
77
- this.fnGenerator.dispose(), this.fn.dispose();
78
- }
79
- }
80
- const Q = [
81
- // basic objects
82
- [Symbol, "Symbol"],
83
- [Symbol.prototype, "Symbol.prototype"],
84
- [Object, "Object"],
85
- [Object.prototype, "Object.prototype"],
86
- [Function, "Function"],
87
- [Function.prototype, "Function.prototype"],
88
- [Boolean, "Boolean"],
89
- [Boolean.prototype, "Boolean.prototype"],
90
- [Array, "Array"],
91
- [Array.prototype, "Array.prototype"],
92
- // [BigInt, "BigInt"],
93
- // [BigInt.prototype, "BigInt.prototype"],
94
- // errors
95
- [Error, "Error"],
96
- [Error.prototype, "Error.prototype"],
97
- [EvalError, "EvalError"],
98
- [EvalError.prototype, "EvalError.prototype"],
99
- [RangeError, "RangeError"],
100
- [RangeError.prototype, "RangeError.prototype"],
101
- [ReferenceError, "ReferenceError"],
102
- [ReferenceError.prototype, "ReferenceError.prototype"],
103
- [SyntaxError, "SyntaxError"],
104
- [SyntaxError.prototype, "SyntaxError.prototype"],
105
- [TypeError, "TypeError"],
106
- [TypeError.prototype, "TypeError.prototype"],
107
- [URIError, "URIError"],
108
- [URIError.prototype, "URIError.prototype"],
109
- // built-in symbols
110
- ...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
111
- ];
112
30
  function R(n, e) {
113
31
  if ("error" in e && e.error) {
114
32
  const { error: t } = e;
@@ -126,28 +44,28 @@ function R(n, e) {
126
44
  }
127
45
  return e.value;
128
46
  }
129
- function X(n, e) {
47
+ function ee(n, e) {
130
48
  const t = R(n, n.evalCode(e)), r = (i, ...o) => R(n, n.callFunction(t, i != null ? i : n.undefined, ...o)), s = () => t.dispose();
131
49
  return r.dispose = s, r[Symbol.dispose] = s, Object.defineProperty(r, "alive", {
132
50
  get: () => t.alive
133
51
  }), r;
134
52
  }
135
- const T = /* @__PURE__ */ new WeakMap();
136
- function Y(n) {
137
- T.has(n) || T.set(n, /* @__PURE__ */ new Map());
53
+ const E = /* @__PURE__ */ new WeakMap();
54
+ function te(n) {
55
+ E.has(n) || E.set(n, /* @__PURE__ */ new Map());
138
56
  }
139
- function Z(n) {
140
- const e = T.get(n);
57
+ function ne(n) {
58
+ const e = E.get(n);
141
59
  if (e) {
142
60
  for (const t of e.values())
143
61
  t.alive && t.dispose();
144
- T.delete(n);
62
+ E.delete(n);
145
63
  }
146
64
  }
147
- function m(n, e, t, ...r) {
148
- const s = T.get(n);
65
+ function b(n, e, t, ...r) {
66
+ const s = E.get(n);
149
67
  if (!s) {
150
- const o = X(n, e);
68
+ const o = ee(n, e);
151
69
  try {
152
70
  return o(t, ...r);
153
71
  } finally {
@@ -157,25 +75,25 @@ function m(n, e, t, ...r) {
157
75
  let i = s.get(e);
158
76
  return (!i || !i.alive) && (i = R(n, n.evalCode(e)), s.set(e, i)), R(n, n.callFunction(i, t != null ? t : n.undefined, ...r));
159
77
  }
160
- function x(n, e, t) {
161
- return n.dump(m(n, "(a, b) => a instanceof b", void 0, e, t));
78
+ function re(n, e, t) {
79
+ return n.dump(b(n, "(a, b) => a instanceof b", void 0, e, t));
162
80
  }
163
- function ee(n, e) {
81
+ function U(n, e) {
164
82
  const t = n.typeof(e);
165
83
  return t === "function" || t === "object" && !n.sameValue(e, n.null);
166
84
  }
167
- function te(n, e) {
85
+ function se(n, e) {
168
86
  const t = JSON.stringify(e);
169
- return t ? n.newString(t).consume((r) => m(n, "JSON.parse", void 0, r)) : n.undefined;
87
+ return t ? n.newString(t).consume((r) => b(n, "JSON.parse", void 0, r)) : n.undefined;
170
88
  }
171
- function g(n, e) {
89
+ function j(n, e) {
172
90
  try {
173
91
  return e(n);
174
92
  } finally {
175
93
  n.alive && n.dispose();
176
94
  }
177
95
  }
178
- function ne(n, e) {
96
+ function V(n, e) {
179
97
  try {
180
98
  return e(n);
181
99
  } finally {
@@ -183,14 +101,14 @@ function ne(n, e) {
183
101
  t.alive && t.dispose();
184
102
  }
185
103
  }
186
- function re([n, e], t) {
104
+ function ie([n, e], t) {
187
105
  try {
188
106
  return t(n);
189
107
  } finally {
190
108
  e && n.dispose();
191
109
  }
192
110
  }
193
- function H(n, e) {
111
+ function O(n, e) {
194
112
  try {
195
113
  return e(...n.map((t) => t[0]));
196
114
  } finally {
@@ -198,51 +116,145 @@ function H(n, e) {
198
116
  r && t.dispose();
199
117
  }
200
118
  }
201
- function se(n) {
119
+ function oe(n) {
202
120
  return "handle" in n;
203
121
  }
204
122
  function C(n) {
205
- return se(n) ? n.handle : n;
123
+ return oe(n) ? n.handle : n;
206
124
  }
207
- function ie(n, e, t, r) {
208
- var i;
125
+ const ae = (n) => {
126
+ const e = new ue(n);
127
+ return new Proxy(n, {
128
+ get(t, r, s) {
129
+ return r in e ? e[r] : Reflect.get(t, r, s);
130
+ }
131
+ });
132
+ };
133
+ class ue {
134
+ constructor(e) {
135
+ d(this, "context");
136
+ d(this, "fn");
137
+ d(this, "fnGenerator");
138
+ d(this, "fnCounter", Number.MIN_SAFE_INTEGER);
139
+ d(this, "fnMap", /* @__PURE__ */ new Map());
140
+ /** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
141
+ d(this, "newFunction", (e, t) => {
142
+ this.fnCounter++;
143
+ const r = this.fnCounter;
144
+ return this.fnMap.set(r, t), V(
145
+ [
146
+ this.context.newString(e),
147
+ this.context.newNumber(t.length),
148
+ this.context.newNumber(r)
149
+ ],
150
+ ([s, i, o]) => this.context.unwrapResult(
151
+ this.context.callFunction(
152
+ this.fnGenerator,
153
+ this.context.undefined,
154
+ s,
155
+ i,
156
+ o,
157
+ this.fn
158
+ )
159
+ )
160
+ );
161
+ });
162
+ this.context = e;
163
+ const t = this.fnMap;
164
+ this.fn = this.context.newFunction("", function(r, ...s) {
165
+ const i = e.getNumber(r), o = t.get(i);
166
+ if (!o) throw new Error("function is not registered");
167
+ return o.call(this, ...s);
168
+ }), this.fnGenerator = e.unwrapResult(
169
+ e.evalCode(`((name, length, id, f) => {
170
+ const fn = function(...args) {
171
+ return f.call(this, id, ...args);
172
+ };
173
+ fn.name = name;
174
+ fn.length = length;
175
+ return fn;
176
+ })`)
177
+ );
178
+ }
179
+ disposeEx() {
180
+ this.fnGenerator.dispose(), this.fn.dispose();
181
+ }
182
+ }
183
+ const fe = [
184
+ // basic objects
185
+ [Symbol, "Symbol"],
186
+ [Symbol.prototype, "Symbol.prototype"],
187
+ [Object, "Object"],
188
+ [Object.prototype, "Object.prototype"],
189
+ [Function, "Function"],
190
+ [Function.prototype, "Function.prototype"],
191
+ [Boolean, "Boolean"],
192
+ [Boolean.prototype, "Boolean.prototype"],
193
+ [Array, "Array"],
194
+ [Array.prototype, "Array.prototype"],
195
+ // [BigInt, "BigInt"],
196
+ // [BigInt.prototype, "BigInt.prototype"],
197
+ // errors
198
+ [Error, "Error"],
199
+ [Error.prototype, "Error.prototype"],
200
+ [EvalError, "EvalError"],
201
+ [EvalError.prototype, "EvalError.prototype"],
202
+ [RangeError, "RangeError"],
203
+ [RangeError.prototype, "RangeError.prototype"],
204
+ [ReferenceError, "ReferenceError"],
205
+ [ReferenceError.prototype, "ReferenceError.prototype"],
206
+ [SyntaxError, "SyntaxError"],
207
+ [SyntaxError.prototype, "SyntaxError.prototype"],
208
+ [TypeError, "TypeError"],
209
+ [TypeError.prototype, "TypeError.prototype"],
210
+ [URIError, "URIError"],
211
+ [URIError.prototype, "URIError.prototype"],
212
+ // built-in symbols
213
+ ...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
214
+ ];
215
+ function le(n, e, t, r) {
216
+ var o;
209
217
  let s;
210
- for (const o of r)
211
- if (s = o(e, n), s) break;
212
- return s ? (i = t(e, s)) != null ? i : s : void 0;
218
+ for (const a of r)
219
+ if (s = a(e, n), s) break;
220
+ if (!s) return;
221
+ let i = !0;
222
+ try {
223
+ const a = (o = t(e, s)) != null ? o : s;
224
+ return i = !1, a;
225
+ } finally {
226
+ i && s.alive && s.dispose();
227
+ }
213
228
  }
214
- function oe(n, e) {
215
- return typeof n != "symbol" ? void 0 : m(
216
- e,
217
- "d => Symbol(d)",
218
- void 0,
219
- n.description ? e.newString(n.description) : e.undefined
220
- );
229
+ function ce(n, e) {
230
+ if (typeof n == "symbol")
231
+ return n.description ? j(e.newString(n.description), (t) => b(e, "d => Symbol(d)", void 0, t)) : b(e, "d => Symbol(d)", void 0, e.undefined);
221
232
  }
222
- function ue(n, e) {
223
- return n instanceof Date ? m(e, "d => new Date(d)", void 0, e.newNumber(n.getTime())) : void 0;
233
+ function pe(n, e) {
234
+ if (n instanceof Date)
235
+ return j(e.newNumber(n.getTime()), (t) => b(e, "d => new Date(d)", void 0, t));
224
236
  }
225
- function ae(n, e) {
237
+ function de(n, e) {
226
238
  if (n instanceof ArrayBuffer)
227
239
  return e.newArrayBuffer(n.slice(0));
228
240
  if (ArrayBuffer.isView(n)) {
229
241
  const t = new Uint8Array(n.buffer, n.byteOffset, n.byteLength).slice();
230
- return ne(
242
+ return V(
231
243
  [e.newArrayBuffer(t.buffer), e.newString(n.constructor.name)],
232
- ([r, s]) => m(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
244
+ ([r, s]) => b(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
233
245
  );
234
246
  }
235
247
  }
236
- const fe = [oe, ue, ae];
237
- function ce(n) {
248
+ const ye = [ce, pe, de];
249
+ function he(n) {
238
250
  return typeof n == "function" && /^class\s/.test(Function.prototype.toString.call(n));
239
251
  }
240
- function S(n) {
252
+ function P(n) {
241
253
  return typeof n == "function" || typeof n == "object" && n !== null;
242
254
  }
243
- function N(n, e) {
255
+ function G(n, e) {
244
256
  const t = /* @__PURE__ */ new Set(), r = (s) => {
245
- if (!(!S(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
257
+ if (!(!P(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
246
258
  if (t.add(s), Array.isArray(s)) {
247
259
  for (const i of s)
248
260
  r(i);
@@ -258,10 +270,10 @@ function N(n, e) {
258
270
  };
259
271
  return r(n), t;
260
272
  }
261
- function Ie(n, e) {
262
- return N(n, e ? (t, r) => r.size < e : void 0).size;
273
+ function Ge(n, e) {
274
+ return G(n, e ? (t, r) => r.size < e : void 0).size;
263
275
  }
264
- function pe() {
276
+ function me() {
265
277
  let n = () => {
266
278
  }, e = () => {
267
279
  };
@@ -273,98 +285,148 @@ function pe() {
273
285
  reject: e
274
286
  };
275
287
  }
276
- function D(n, e, t, r, s = () => {
288
+ function J(n, e, t, r, s = () => {
277
289
  }) {
278
- const i = n.newObject(), o = [], f = (u, a) => {
279
- const d = r(u), y = typeof a.value == "undefined" ? void 0 : r(a.value), h = typeof a.get == "undefined" ? void 0 : r(a.get), c = typeof a.set == "undefined" ? void 0 : r(a.set);
280
- y && o.push(y), h && o.push(h), c && o.push(c), n.newObject().consume((l) => {
281
- Object.entries(a).forEach(([_, b]) => {
282
- const v = _ === "value" ? y : _ === "get" ? h : _ === "set" ? c : b ? n.true : n.false;
283
- v && n.setProp(l, _, v);
284
- }), n.setProp(i, d, l);
290
+ let i;
291
+ const o = [], a = Object.getPrototypeOf(e), u = a === Object.prototype || a === Array.prototype, f = (l, c) => {
292
+ if (u && typeof l == "string" && l !== "__proto__" && c.writable === !0 && c.enumerable === !0 && c.configurable === !0 && c.get === void 0 && c.set === void 0) {
293
+ const _ = r(l), w = r(c.value);
294
+ n.setProp(t, _, w), s(w);
295
+ return;
296
+ }
297
+ const m = r(l), p = typeof c.value == "undefined" ? void 0 : r(c.value), y = typeof c.get == "undefined" ? void 0 : r(c.get), h = typeof c.set == "undefined" ? void 0 : r(c.set);
298
+ p && o.push(p), y && o.push(y), h && o.push(h);
299
+ const g = i != null ? i : i = n.newObject();
300
+ j(n.newObject(), (_) => {
301
+ Object.entries(c).forEach(([w, v]) => {
302
+ const H = w === "value" ? p : w === "get" ? y : w === "set" ? h : v ? n.true : n.false;
303
+ H && n.setProp(_, w, H);
304
+ }), n.setProp(g, m, _);
285
305
  });
286
306
  };
287
307
  try {
288
- const u = Object.getOwnPropertyDescriptors(e);
289
- Object.entries(u).forEach(([a, d]) => f(a, d)), Object.getOwnPropertySymbols(u).forEach((a) => f(a, u[a])), m(n, "Object.defineProperties", void 0, t, i).dispose();
290
- for (const a of o) s(a);
308
+ const l = Object.getOwnPropertyDescriptors(e);
309
+ if (Object.entries(l).forEach(([c, m]) => f(c, m)), Object.getOwnPropertySymbols(l).forEach((c) => f(c, l[c])), i) {
310
+ b(n, "Object.defineProperties", void 0, t, i).dispose();
311
+ for (const c of o) s(c);
312
+ }
291
313
  } finally {
292
- i.dispose();
314
+ i == null || i.dispose();
293
315
  }
294
316
  }
295
- function le(n, e, t, r, s, i, o = () => {
296
- }, f = (u) => u) {
297
- var d;
317
+ function _e(n, e, t, r, s, i, o = () => {
318
+ }, a = (l) => l, u = (l) => l, f) {
319
+ var g;
298
320
  if (typeof e != "function") return;
299
- const u = n.newFunction(e.name, function(...y) {
300
- const h = n.sameValue(this, n.global) ? void 0 : r(this), c = y.map((l) => r(l));
301
- if (ce(e) && S(h)) {
302
- const l = new e(...c);
303
- return Object.entries(l).forEach(([_, b]) => {
304
- const v = t(b);
305
- n.setProp(this, _, v), o(v);
321
+ const l = u(e), c = he(l), p = !!f && f(l) && "newAsyncifiedFunction" in n ? (
322
+ // Asyncify: the VM stack is suspended until the host promise settles, so
323
+ // the guest receives the resolved value synchronously. Async functions
324
+ // can never be class constructors, so the class-constructor path is
325
+ // skipped here.
326
+ n.newAsyncifiedFunction(e.name, function(..._) {
327
+ return F(this, null, function* () {
328
+ const w = n.sameValue(this, n.global) ? void 0 : r(this), v = _.map((k) => r(k)), H = yield i ? i(e, w, v) : e.apply(w, v);
329
+ return a(t(H));
330
+ });
331
+ })
332
+ ) : n.newFunction(e.name, function(..._) {
333
+ const w = n.sameValue(this, n.global) ? void 0 : r(this), v = _.map((H) => r(H));
334
+ if (c && P(w)) {
335
+ const H = new e(...v);
336
+ return Object.entries(H).forEach(([k, q]) => {
337
+ const A = t(q);
338
+ n.setProp(this, k, A), o(A);
306
339
  }), this;
307
340
  }
308
- return f(
341
+ return a(
309
342
  t(
310
- i ? i(e, h, c) : e.apply(h, c)
343
+ i ? i(e, w, v) : e.apply(w, v)
311
344
  )
312
345
  );
313
- }).consume(
314
- (y) => (
315
- // fucntions created by vm.newFunction are not callable as a class constrcutor
316
- m(
346
+ }), y = j(
347
+ p,
348
+ (_) => (
349
+ // functions created by vm.newFunction are not callable as a class constructor
350
+ b(
317
351
  n,
318
352
  `Cls => {
319
- const fn = function(...args) { return Cls.apply(this, args); };
320
- fn.name = Cls.name;
321
- fn.length = Cls.length;
322
- return fn;
323
- }`,
353
+ const fn = function(...args) { return Cls.apply(this, args); };
354
+ fn.name = Cls.name;
355
+ fn.length = Cls.length;
356
+ return fn;
357
+ }`,
324
358
  void 0,
325
- y
359
+ _
326
360
  )
327
361
  )
328
- ), a = (d = s(e, u)) != null ? d : u;
329
- return D(n, e, u, t, o), a;
362
+ );
363
+ let h = !0;
364
+ try {
365
+ const _ = (g = s(e, y)) != null ? g : y;
366
+ return h = !1, J(n, e, y, t, o), _;
367
+ } finally {
368
+ h && y.alive && y.dispose();
369
+ }
330
370
  }
331
- function de(n, e, t) {
371
+ function ve(n, e, t) {
332
372
  if (!(typeof e != "object" && typeof e != "function") && e !== null)
333
373
  return t(e, n.newHostRef(e).handle);
334
374
  }
335
- function ye(n, e, t) {
375
+ function be(n, e, t) {
336
376
  var i;
337
- const r = te(n, e);
377
+ const r = se(n, e);
338
378
  return (i = t(e, r)) != null ? i : r;
339
379
  }
340
- function he(n, e, t, r, s = () => {
380
+ function we(n, e, t, r, s = () => {
341
381
  }) {
342
382
  var i, o;
343
383
  if (e instanceof Map) {
344
- const f = m(n, "() => new Map()"), u = (i = r(e, f)) != null ? i : f;
345
- for (const [a, d] of e) {
346
- const y = t(a), h = t(d);
347
- m(n, "(m, k, v) => m.set(k, v)", void 0, f, y, h).dispose(), s(y), s(h);
384
+ const a = b(n, "() => new Map()");
385
+ let u = !0;
386
+ try {
387
+ const f = (i = r(e, a)) != null ? i : a;
388
+ u = !1;
389
+ for (const [l, c] of e) {
390
+ const m = t(l), p = t(c);
391
+ b(n, "(m, k, v) => m.set(k, v)", void 0, a, m, p).dispose(), s(m), s(p);
392
+ }
393
+ return f;
394
+ } finally {
395
+ u && a.alive && a.dispose();
348
396
  }
349
- return u;
350
397
  }
351
398
  if (e instanceof Set) {
352
- const f = m(n, "() => new Set()"), u = (o = r(e, f)) != null ? o : f;
353
- for (const a of e) {
354
- const d = t(a);
355
- m(n, "(s, v) => s.add(v)", void 0, f, d).dispose(), s(d);
399
+ const a = b(n, "() => new Set()");
400
+ let u = !0;
401
+ try {
402
+ const f = (o = r(e, a)) != null ? o : a;
403
+ u = !1;
404
+ for (const l of e) {
405
+ const c = t(l);
406
+ b(n, "(s, v) => s.add(v)", void 0, a, c).dispose(), s(c);
407
+ }
408
+ return f;
409
+ } finally {
410
+ u && a.alive && a.dispose();
356
411
  }
357
- return u;
358
412
  }
359
413
  }
360
- function me(n, e, t, r, s = () => {
414
+ function ge(n, e, t, r, s = () => {
361
415
  }) {
362
416
  var a;
363
417
  if (typeof e != "object" || e === null) return;
364
- const i = Array.isArray(e) ? n.newArray() : n.newObject(), o = (a = r(e, i)) != null ? a : i, f = Object.getPrototypeOf(e), u = f && f !== Object.prototype && f !== Array.prototype ? t(f) : void 0;
365
- return u && (m(n, "Object.setPrototypeOf", void 0, o, u).dispose(), s(u)), D(n, e, i, t, s), o;
418
+ const i = Array.isArray(e) ? n.newArray() : n.newObject();
419
+ let o = !0;
420
+ try {
421
+ const u = (a = r(e, i)) != null ? a : i;
422
+ o = !1;
423
+ const f = Object.getPrototypeOf(e), l = f && f !== Object.prototype && f !== Array.prototype ? t(f) : void 0;
424
+ return l && (b(n, "Object.setPrototypeOf", void 0, u, l).dispose(), s(l)), J(n, e, i, t, s), u;
425
+ } finally {
426
+ o && i.alive && i.dispose();
427
+ }
366
428
  }
367
- function _e(n, e) {
429
+ function je(n, e) {
368
430
  switch (typeof e) {
369
431
  case "undefined":
370
432
  return n.undefined;
@@ -380,78 +442,87 @@ function _e(n, e) {
380
442
  return e === null ? n.null : void 0;
381
443
  }
382
444
  }
383
- function ve(n, e, t, r) {
384
- var i;
445
+ function He(n, e, t, r) {
446
+ var o;
385
447
  if (!(e instanceof Promise)) return;
386
448
  const s = n.newPromise();
387
- return e.then(
388
- (o) => s.resolve(t(o)),
389
- (o) => s.reject(t(o))
390
- ), (i = r(e, s)) != null ? i : s.handle;
449
+ let i = !0;
450
+ try {
451
+ e.then(
452
+ (u) => s.resolve(t(u)),
453
+ (u) => s.reject(t(u))
454
+ );
455
+ const a = (o = r(e, s)) != null ? o : s.handle;
456
+ return i = !1, a;
457
+ } finally {
458
+ i && s.alive && s.dispose();
459
+ }
391
460
  }
392
- function U(n, e) {
393
- var y, h, c, l, _, b, v, j;
461
+ function W(n, e) {
462
+ var c, m, p, y, h, g, _, w;
394
463
  const { ctx: t, unmarshal: r, isMarshalable: s, find: i, pre: o } = e;
395
464
  {
396
- const w = _e(t, n);
397
- if (w)
398
- return typeof n == "bigint" && ((y = e.registerTransient) == null || y.call(e, w)), w;
465
+ const v = je(t, n);
466
+ if (v)
467
+ return typeof n == "bigint" && ((c = e.registerTransient) == null || c.call(e, v)), v;
399
468
  }
400
469
  {
401
- const w = i(n);
402
- if (w) return w;
470
+ const v = i(n);
471
+ if (v) return v;
403
472
  }
404
- if ((h = e.marshalByReference) != null && h.call(e, n) && e.registerHostRef) {
405
- const w = de(t, n, e.registerHostRef);
406
- if (w) return w;
473
+ if ((m = e.marshalByReference) != null && m.call(e, n) && e.registerHostRef) {
474
+ const v = ve(t, n, e.registerHostRef);
475
+ if (v) return v;
407
476
  }
408
- const f = s == null ? void 0 : s(n);
409
- if (f === !1)
477
+ const a = s == null ? void 0 : s(n);
478
+ if (a === !1)
410
479
  return t.undefined;
411
- const u = (w, k) => o(w, k, f);
412
- if (f === "json")
413
- return ye(t, n, u);
414
- const a = (w) => U(w, e), d = e.disposeTransient;
415
- return (j = (v = (b = (_ = (l = ie(t, n, u, [...fe, ...(c = e.custom) != null ? c : []])) != null ? l : ve(t, n, a, u)) != null ? _ : le(
480
+ const u = (v, H) => o(v, H, a);
481
+ if (a === "json")
482
+ return be(t, n, u);
483
+ const f = (v) => W(v, e), l = e.disposeTransient;
484
+ return (w = (_ = (g = (h = (y = le(t, n, u, [...ye, ...(p = e.custom) != null ? p : []])) != null ? y : He(t, n, f, u)) != null ? h : _e(
416
485
  t,
417
486
  n,
418
- a,
487
+ f,
419
488
  r,
420
489
  u,
421
490
  e.preApply,
422
- d,
423
- e.prepareReturn
424
- )) != null ? b : he(t, n, a, u, d)) != null ? v : me(t, n, a, u, d)) != null ? j : t.undefined;
491
+ l,
492
+ e.prepareReturn,
493
+ e.unwrap,
494
+ e.asyncify
495
+ )) != null ? g : we(t, n, f, u, l)) != null ? _ : ge(t, n, f, u, l)) != null ? w : t.undefined;
425
496
  }
426
- function be(n, e, t, r) {
497
+ function Se(n, e, t, r) {
427
498
  var i;
428
499
  let s;
429
500
  for (const o of r)
430
501
  if (s = o(e, n), s) break;
431
502
  return s ? (i = t(s, e)) != null ? i : s : void 0;
432
503
  }
433
- function we(n, e) {
504
+ function Pe(n, e) {
434
505
  if (e.typeof(n) !== "symbol") return;
435
506
  const t = e.getString(e.getProp(n, "description"));
436
507
  return Symbol(t);
437
508
  }
438
- function ge(n, e) {
439
- if (!g(m(e, "a => a instanceof Date", void 0, n), (r) => e.dump(r))) return;
440
- const t = g(m(e, "a => a.getTime()", void 0, n), (r) => e.getNumber(r));
509
+ function ke(n, e) {
510
+ if (!j(b(e, "a => a instanceof Date", void 0, n), (r) => e.dump(r))) return;
511
+ const t = j(b(e, "a => a.getTime()", void 0, n), (r) => e.getNumber(r));
441
512
  return new Date(t);
442
513
  }
443
- function je(n, e) {
444
- if (g(m(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
514
+ function Re(n, e) {
515
+ if (j(b(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
445
516
  const t = e.getArrayBuffer(n), r = t.value.slice();
446
517
  return t.dispose(), r.buffer;
447
518
  }
448
- if (g(m(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
449
- const t = g(
450
- m(e, "a => a.constructor.name", void 0, n),
451
- (f) => e.getString(f)
519
+ if (j(b(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
520
+ const t = j(
521
+ b(e, "a => a.constructor.name", void 0, n),
522
+ (a) => e.getString(a)
452
523
  ), r = globalThis[t];
453
524
  if (typeof r != "function") return;
454
- const s = m(
525
+ const s = b(
455
526
  e,
456
527
  "a => a.buffer.slice(a.byteOffset, a.byteOffset + a.byteLength)",
457
528
  void 0,
@@ -460,66 +531,65 @@ function je(n, e) {
460
531
  return i.dispose(), s.dispose(), new r(o.buffer);
461
532
  }
462
533
  }
463
- const Pe = [we, ge, je];
464
- function V(n, e, t, r) {
465
- g(
466
- n.newFunction("", (s, i) => {
467
- const [o] = r(s);
468
- if (typeof o != "string" && typeof o != "number" && typeof o != "symbol")
534
+ const Ee = [Pe, ke, Re], Oe = `(o, fn) => {
535
+ const descs = Object.getOwnPropertyDescriptors(o);
536
+ const emit = (k, d) => {
537
+ let f = 0;
538
+ if (typeof d.value !== "undefined") f |= 1;
539
+ if (typeof d.get !== "undefined") f |= 2;
540
+ if (typeof d.set !== "undefined") f |= 4;
541
+ if (typeof d.configurable === "boolean") { f |= 8; if (d.configurable) f |= 16; }
542
+ if (typeof d.enumerable === "boolean") { f |= 32; if (d.enumerable) f |= 64; }
543
+ if (typeof d.writable === "boolean") { f |= 128; if (d.writable) f |= 256; }
544
+ fn(k, d, f);
545
+ };
546
+ Object.entries(descs).forEach(([k, v]) => emit(k, v));
547
+ Object.getOwnPropertySymbols(descs).forEach(k => emit(k, descs[k]));
548
+ }`;
549
+ function z(n, e, t, r) {
550
+ j(
551
+ n.newFunction("", (s, i, o) => {
552
+ const [a] = r(s);
553
+ if (typeof a != "string" && typeof a != "number" && typeof a != "symbol")
469
554
  return;
470
- const f = [
471
- ["value", !0],
472
- ["get", !0],
473
- ["set", !0],
474
- ["configurable", !1],
475
- ["enumerable", !1],
476
- ["writable", !1]
477
- ].reduce((u, [a, d]) => {
478
- const y = n.getProp(i, a), h = n.typeof(y);
479
- if (h === "undefined") return u;
480
- if (!d && h === "boolean")
481
- return u[a] = n.dump(n.getProp(i, a)), u;
482
- const [c, l] = r(y);
483
- return l && y.dispose(), u[a] = c, u;
484
- }, {});
485
- Object.defineProperty(t, o, f);
555
+ const u = n.getNumber(o), f = {}, l = (c) => {
556
+ const m = n.getProp(i, c);
557
+ let p = !1;
558
+ try {
559
+ const [y, h] = r(m);
560
+ return p = !h, y;
561
+ } finally {
562
+ !p && m.alive && m.dispose();
563
+ }
564
+ };
565
+ u & 1 && (f.value = l("value")), u & 2 && (f.get = l("get")), u & 4 && (f.set = l("set")), u & 8 && (f.configurable = !!(u & 16)), u & 32 && (f.enumerable = !!(u & 64)), u & 128 && (f.writable = !!(u & 256)), Object.defineProperty(t, a, f);
486
566
  }),
487
567
  (s) => {
488
- m(
489
- n,
490
- `(o, fn) => {
491
- const descs = Object.getOwnPropertyDescriptors(o);
492
- Object.entries(descs).forEach(([k, v]) => fn(k, v));
493
- Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));
494
- }`,
495
- void 0,
496
- e,
497
- s
498
- ).dispose();
568
+ b(n, Oe, void 0, e, s).dispose();
499
569
  }
500
570
  );
501
571
  }
502
- function Se(n, e, t, r, s) {
503
- var f;
572
+ function Te(n, e, t, r, s) {
573
+ var a;
504
574
  if (n.typeof(e) !== "function") return;
505
575
  const i = function(...u) {
506
- return H(
507
- [t(this), ...u.map((a) => t(a))],
508
- (a, ...d) => {
576
+ return O(
577
+ [t(this), ...u.map((f) => t(f))],
578
+ (f, ...l) => {
509
579
  if (new.target) {
510
- const [l] = r(
511
- m(n, "(Cls, ...args) => new Cls(...args)", a, e, ...d)
580
+ const [y] = r(
581
+ b(n, "(Cls, ...args) => new Cls(...args)", f, e, ...l)
512
582
  );
513
- return Object.defineProperties(this, Object.getOwnPropertyDescriptors(l)), this;
583
+ return Object.defineProperties(this, Object.getOwnPropertyDescriptors(y)), this;
514
584
  }
515
- const y = R(n, n.callFunction(e, a, ...d)), [h, c] = r(y);
516
- return c && y.dispose(), h;
585
+ const c = R(n, n.callFunction(e, f, ...l)), [m, p] = r(c);
586
+ return p && c.dispose(), m;
517
587
  }
518
588
  );
519
- }, o = (f = s(i, e)) != null ? f : i;
520
- return V(n, e, i, r), o;
589
+ }, o = (a = s(i, e)) != null ? a : i;
590
+ return z(n, e, i, r), o;
521
591
  }
522
- function G(n, e) {
592
+ function $(n, e) {
523
593
  const t = n.toHostRef(e);
524
594
  if (t)
525
595
  try {
@@ -528,33 +598,46 @@ function G(n, e) {
528
598
  t.dispose();
529
599
  }
530
600
  }
531
- function ke(n, e, t, r) {
532
- const s = g(m(n, "a => a instanceof Map", void 0, e), (u) => n.dump(u)), i = !s && g(m(n, "a => a instanceof Set", void 0, e), (u) => n.dump(u));
601
+ function Me(n, e, t, r) {
602
+ const s = j(b(n, "a => a instanceof Map", void 0, e), (u) => n.dump(u)), i = !s && j(b(n, "a => a instanceof Set", void 0, e), (u) => n.dump(u));
533
603
  if (!s && !i) return;
534
604
  const o = s ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
535
605
  r(o, e);
536
- const f = n.unwrapResult(n.getIterator(e));
606
+ const a = n.unwrapResult(n.getIterator(e));
537
607
  try {
538
- for (const u of f) {
539
- const a = n.unwrapResult(u);
608
+ for (const u of a) {
609
+ const f = n.unwrapResult(u);
540
610
  if (s) {
541
- const d = n.getProp(a, 0), y = n.getProp(a, 1), [h, c] = t(d), [l, _] = t(y);
542
- c && d.dispose(), _ && y.dispose(), o.set(h, l), a.dispose();
611
+ const l = n.getProp(f, 0), c = n.getProp(f, 1);
612
+ let m = !0, p = !0;
613
+ try {
614
+ const [y, h] = t(l);
615
+ m = h;
616
+ const [g, _] = t(c);
617
+ p = _, o.set(y, g);
618
+ } finally {
619
+ m && l.alive && l.dispose(), p && c.alive && c.dispose(), f.alive && f.dispose();
620
+ }
543
621
  } else {
544
- const [d, y] = t(a);
545
- y && a.dispose(), o.add(d);
622
+ let l = !0;
623
+ try {
624
+ const [c, m] = t(f);
625
+ l = m, o.add(c);
626
+ } finally {
627
+ l && f.alive && f.dispose();
628
+ }
546
629
  }
547
630
  }
548
631
  } finally {
549
- f.alive && f.dispose();
632
+ a.alive && a.dispose();
550
633
  }
551
634
  return o;
552
635
  }
553
- function Re(n, e, t, r) {
554
- var f;
636
+ function Ie(n, e, t, r) {
637
+ var a;
555
638
  if (n.typeof(e) !== "object" || n.sameValue(e, n.null)) return;
556
- const s = g(m(n, "Array.isArray", void 0, e), (u) => n.dump(u)) ? [] : {}, i = (f = r(s, e)) != null ? f : s, o = g(
557
- m(
639
+ const s = j(b(n, "Array.isArray", void 0, e), (u) => n.dump(u)) ? [] : {}, i = (a = r(s, e)) != null ? a : s, o = j(
640
+ b(
558
641
  n,
559
642
  `o => {
560
643
  const p = Object.getPrototypeOf(o);
@@ -565,66 +648,66 @@ function Re(n, e, t, r) {
565
648
  ),
566
649
  (u) => {
567
650
  if (n.typeof(u) === "undefined") return;
568
- const [a] = t(u);
569
- return a;
651
+ const [f] = t(u);
652
+ return f;
570
653
  }
571
654
  );
572
- return typeof o == "object" && Object.setPrototypeOf(i, o), V(n, e, s, t), i;
655
+ return typeof o == "object" && Object.setPrototypeOf(i, o), z(n, e, s, t), i;
573
656
  }
574
- function Te(n, e) {
657
+ function K(n, e) {
575
658
  const t = n.typeof(e);
576
659
  return t === "undefined" || t === "number" || t === "string" || t === "boolean" ? [n.dump(e), !0] : t === "bigint" ? [n.getBigInt(e), !0] : t === "object" && n.sameValue(e, n.null) ? [null, !0] : [void 0, !1];
577
660
  }
578
- function He(n, e, t, r) {
579
- var a;
580
- if (!Ee(n, e)) return;
581
- const s = pe(), [i, o] = t(s.resolve), [f, u] = t(s.reject);
582
- return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, f), o && i.dispose(), u && f.dispose(), (a = r(s.promise, e)) != null ? a : s.promise;
661
+ function Fe(n, e, t, r) {
662
+ var f;
663
+ if (!Ce(n, e)) return;
664
+ const s = me(), [i, o] = t(s.resolve), [a, u] = t(s.reject);
665
+ return b(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, a), o && i.dispose(), u && a.dispose(), (f = r(s.promise, e)) != null ? f : s.promise;
583
666
  }
584
- function Ee(n, e) {
585
- return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? x(n, e, t) : !1) : !1;
667
+ function Ce(n, e) {
668
+ return e.owner ? j(n.unwrapResult(n.evalCode("Promise")), (t) => e.owner ? re(n, e, t) : !1) : !1;
586
669
  }
587
- function Oe(n, e) {
588
- const [t] = J(n, e);
670
+ function Ae(n, e) {
671
+ const [t] = L(n, e);
589
672
  return t;
590
673
  }
591
- function J(n, e) {
592
- var d, y, h;
674
+ function L(n, e) {
675
+ var l, c, m;
593
676
  const { ctx: t, marshal: r, find: s, pre: i } = e;
594
677
  {
595
- const [c, l] = Te(t, n);
596
- if (l) return [c, !1];
678
+ const [p, y] = K(t, n);
679
+ if (y) return [p, !1];
597
680
  }
598
681
  {
599
- const c = s(n);
600
- if (c)
601
- return [c, !0];
682
+ const p = s(n);
683
+ if (p)
684
+ return [p, !0];
602
685
  }
603
- const o = (c) => J(c, e);
686
+ const o = (p) => L(p, e);
604
687
  if (e.hostRef) {
605
- const c = G(t, n);
606
- if (c) return [c.value, !0];
688
+ const p = $(t, n);
689
+ if (p) return [p.value, !0];
607
690
  }
608
- const f = be(t, n, i, [...Pe, ...(d = e.custom) != null ? d : []]);
609
- if (f) return [f, !0];
610
- const u = ke(t, n, o, i);
611
- return u ? [u, !0] : [(h = (y = He(t, n, r, i)) != null ? y : Se(t, n, r, o, i)) != null ? h : Re(t, n, o, i), !1];
691
+ const a = Se(t, n, i, [...Ee, ...(l = e.custom) != null ? l : []]);
692
+ if (a) return [a, !0];
693
+ const u = Me(t, n, o, i);
694
+ return u ? [u, !0] : [(m = (c = Fe(t, n, r, i)) != null ? c : Te(t, n, r, o, i)) != null ? m : Ie(t, n, o, i), !1];
612
695
  }
613
- class I {
696
+ class D {
614
697
  constructor(e) {
615
- p(this, "ctx");
616
- p(this, "_keyToId", /* @__PURE__ */ new Map());
617
- p(this, "_key2ToId", /* @__PURE__ */ new Map());
618
- p(this, "_idToHandle", /* @__PURE__ */ new Map());
619
- p(this, "_idToHandle2", /* @__PURE__ */ new Map());
620
- p(this, "_idToKey", /* @__PURE__ */ new Map());
621
- p(this, "_idToKey2", /* @__PURE__ */ new Map());
622
- p(this, "_disposables", /* @__PURE__ */ new Set());
623
- p(this, "_mapGet");
624
- p(this, "_mapSet");
625
- p(this, "_mapDelete");
626
- p(this, "_mapClear");
627
- p(this, "_nextId", Number.MIN_SAFE_INTEGER);
698
+ d(this, "ctx");
699
+ d(this, "_keyToId", /* @__PURE__ */ new Map());
700
+ d(this, "_key2ToId", /* @__PURE__ */ new Map());
701
+ d(this, "_idToHandle", /* @__PURE__ */ new Map());
702
+ d(this, "_idToHandle2", /* @__PURE__ */ new Map());
703
+ d(this, "_idToKey", /* @__PURE__ */ new Map());
704
+ d(this, "_idToKey2", /* @__PURE__ */ new Map());
705
+ d(this, "_disposables", /* @__PURE__ */ new Set());
706
+ d(this, "_mapGet");
707
+ d(this, "_mapSet");
708
+ d(this, "_mapDelete");
709
+ d(this, "_mapClear");
710
+ d(this, "_nextId", Number.MIN_SAFE_INTEGER);
628
711
  this.ctx = e;
629
712
  const t = e.unwrapResult(
630
713
  e.evalCode(`() => {
@@ -655,15 +738,15 @@ class I {
655
738
  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);
656
739
  }
657
740
  set(e, t, r, s) {
658
- var f;
741
+ var a;
659
742
  if (!t.alive || s && !s.alive) return !1;
660
- const i = (f = this.get(e)) != null ? f : this.get(r);
743
+ const i = (a = this.get(e)) != null ? a : this.get(r);
661
744
  if (i)
662
745
  return i === t || i === s;
663
- const o = this._nextId++;
664
- return this._keyToId.set(e, o), this._idToHandle.set(o, t), this._idToKey.set(o, e), r && (this._key2ToId.set(r, o), this._idToKey2.set(o, r), s && this._idToHandle2.set(o, s)), this.ctx.newNumber(o).consume((u) => {
746
+ const o = this._nextId;
747
+ return j(this.ctx.newNumber(o), (u) => {
665
748
  this._call(this._mapSet, void 0, t, u, s != null ? s : this.ctx.undefined);
666
- }), !0;
749
+ }), this._nextId++, this._keyToId.set(e, o), this._idToHandle.set(o, t), this._idToKey.set(o, e), r && (this._key2ToId.set(r, o), this._idToKey2.set(o, r), s && this._idToHandle2.set(o, s)), !0;
667
750
  }
668
751
  merge(e) {
669
752
  if (e)
@@ -702,10 +785,10 @@ class I {
702
785
  this._call(
703
786
  this._mapDelete,
704
787
  void 0,
705
- ...[s, i].filter((a) => !!(a != null && a.alive))
788
+ ...[s, i].filter((f) => !!(f != null && f.alive))
706
789
  );
707
- const o = this._idToKey.get(r), f = this._idToKey2.get(r);
708
- typeof o != "undefined" && this._keyToId.delete(o), typeof f != "undefined" && this._key2ToId.delete(f), this._idToHandle.delete(r), this._idToHandle2.delete(r), this._idToKey.delete(r), this._idToKey2.delete(r), t && (s != null && s.alive && s.dispose(), i != null && i.alive && i.dispose());
790
+ const o = this._idToKey.get(r), a = this._idToKey2.get(r);
791
+ typeof o != "undefined" && this._keyToId.delete(o), typeof a != "undefined" && this._key2ToId.delete(a), this._idToHandle.delete(r), this._idToHandle2.delete(r), this._idToKey.delete(r), this._idToKey2.delete(r), t && (s != null && s.alive && s.dispose(), i != null && i.alive && i.dispose());
709
792
  }
710
793
  deleteByHandle(e, t) {
711
794
  const r = this.getByHandle(e);
@@ -754,102 +837,112 @@ class I {
754
837
  );
755
838
  }
756
839
  }
757
- function Me(n, e, t, r, s, i, o, f = !0) {
758
- if (!S(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || o && !o(e))
840
+ function Be(n, e, t, r, s, i, o, a = !0) {
841
+ if (!P(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || o && !o(e))
759
842
  return;
760
- if (Be(e, t) || !f) return e;
843
+ if (De(e, t) || !a) return e;
761
844
  const u = new Proxy(e, {
762
- get(a, d) {
763
- return d === t ? a : Reflect.get(a, d);
845
+ get(f, l) {
846
+ return l === t ? f : Reflect.get(f, l);
764
847
  },
765
- set(a, d, y, h) {
766
- var _;
767
- const c = P(y, t), l = (_ = i == null ? void 0 : i(h)) != null ? _ : "host";
768
- return l !== "vm" && !Reflect.set(a, d, c) || l === "host" || !n.alive || H(
769
- [s(h), s(d), s(c)],
770
- (b, v, j) => {
771
- const [w, k] = E(n, b, r);
772
- k ? w.consume((O) => n.setProp(O, v, j)) : n.setProp(w, v, j);
848
+ set(f, l, c, m) {
849
+ var h;
850
+ const p = S(c, t), y = (h = i == null ? void 0 : i(m)) != null ? h : "host";
851
+ return y !== "vm" && !Reflect.set(f, l, p) || y === "host" || !n.alive || O(
852
+ [s(m), s(l), s(p)],
853
+ (g, _, w) => {
854
+ const [v, H] = T(n, g, r);
855
+ H ? j(v, (k) => n.setProp(k, _, w)) : n.setProp(v, _, w);
773
856
  }
774
857
  ), !0;
775
858
  },
776
- deleteProperty(a, d) {
777
- var h;
778
- const y = (h = i == null ? void 0 : i(u)) != null ? h : "host";
779
- return H([s(u), s(d)], (c, l) => {
780
- const [_, b] = E(n, c, r);
781
- if (y === "vm" || Reflect.deleteProperty(a, d)) {
782
- if (y === "host" || !n.alive) return !0;
783
- b ? _.consume((v) => m(n, "(a, b) => delete a[b]", void 0, v, l)) : m(n, "(a, b) => delete a[b]", void 0, _, l);
859
+ deleteProperty(f, l) {
860
+ var m;
861
+ const c = (m = i == null ? void 0 : i(u)) != null ? m : "host";
862
+ return O([s(u), s(l)], (p, y) => {
863
+ const [h, g] = T(n, p, r);
864
+ if (c === "vm" || Reflect.deleteProperty(f, l)) {
865
+ if (c === "host" || !n.alive) return !0;
866
+ g ? j(h, (_) => b(n, "(a, b) => delete a[b]", void 0, _, y)) : b(n, "(a, b) => delete a[b]", void 0, h, y);
784
867
  }
785
868
  return !0;
786
869
  });
787
870
  },
788
- defineProperty(a, d, y) {
789
- var l;
790
- const h = (l = i == null ? void 0 : i(u)) != null ? l : "host", c = F({}, y);
791
- return "value" in c && (c.value = P(c.value, t)), typeof c.get == "function" && (c.get = P(c.get, t)), typeof c.set == "function" && (c.set = P(c.set, t)), h !== "vm" && !Reflect.defineProperty(a, d, c) ? !1 : (h === "host" || !n.alive || H(
792
- [s(u), s(d), s(c)],
793
- (_, b, v) => {
794
- const [j, w] = E(n, _, r), k = (O) => m(
871
+ defineProperty(f, l, c) {
872
+ var y;
873
+ const m = (y = i == null ? void 0 : i(u)) != null ? y : "host", p = I({}, c);
874
+ return "value" in p && (p.value = S(p.value, t)), typeof p.get == "function" && (p.get = S(p.get, t)), typeof p.set == "function" && (p.set = S(p.set, t)), m !== "vm" && !Reflect.defineProperty(f, l, p) ? !1 : (m === "host" || !n.alive || O(
875
+ [s(u), s(l), s(p)],
876
+ (h, g, _) => {
877
+ const [w, v] = T(n, h, r), H = (k) => b(
795
878
  n,
796
879
  "(o, k, d) => { Object.defineProperty(o, k, d); }",
797
880
  void 0,
798
- O,
799
- b,
800
- v
881
+ k,
882
+ g,
883
+ _
801
884
  ).dispose();
802
- w ? j.consume(k) : k(j);
885
+ v ? j(w, H) : H(w);
803
886
  }
804
887
  ), !0);
805
888
  }
806
889
  });
807
890
  return u;
808
891
  }
809
- function Ce(n, e, t, r, s, i, o, f = !0) {
810
- if (!ee(n, e) || o && !o(e, n))
811
- return [void 0, !1];
812
- if (W(n, e, r)) return [e, !1];
813
- if (!f) return [e, !1];
814
- const u = (c) => {
815
- const l = i == null ? void 0 : i(s(c));
816
- return typeof l == "string" ? n.newString(l) : n.undefined;
817
- }, a = (c, l, _) => {
818
- const b = s(c);
819
- if (!b) return;
820
- const v = s(l);
821
- if (v === "__proto__") return;
822
- const j = s(_);
823
- P(b, t)[v] = j;
824
- }, d = (c, l) => {
825
- const _ = s(c);
892
+ function Ne(n, e, t, r, s, i, o = !0) {
893
+ let a;
894
+ const u = (y) => {
895
+ const h = s == null ? void 0 : s(r(y));
896
+ return typeof h == "string" ? n.newString(h) : n.undefined;
897
+ }, f = (y, h, g) => {
898
+ const _ = r(y);
899
+ if (!_) return;
900
+ const w = r(h);
901
+ if (w === "__proto__") return;
902
+ const v = r(g);
903
+ S(_, e)[w] = v;
904
+ }, l = (y, h) => {
905
+ const g = r(y);
906
+ if (!g) return;
907
+ const _ = r(h);
908
+ Reflect.deleteProperty(S(g, e), _);
909
+ }, c = (y, h, g) => {
910
+ const _ = r(y);
826
911
  if (!_) return;
827
- const b = s(l);
828
- Reflect.deleteProperty(P(_, t), b);
829
- }, y = (c, l, _) => {
830
- const b = s(c);
831
- if (!b) return;
832
- const v = s(l);
833
- if (v === "__proto__") return;
834
- const j = s(_);
835
- Object.defineProperty(P(b, t), v, j);
836
- }, h = n.newFunction("proxyFuncs", (c, ...l) => {
837
- switch (n.getNumber(c)) {
912
+ const w = r(h);
913
+ if (w === "__proto__") return;
914
+ const v = r(g);
915
+ Object.defineProperty(S(_, e), w, v);
916
+ }, m = () => (a && a.alive || (a = n.newFunction("proxyFuncs", (y, ...h) => {
917
+ switch (n.getNumber(y)) {
838
918
  case 1:
839
- return u(l[0]);
919
+ return u(h[0]);
840
920
  case 2:
841
- return a(l[0], l[1], l[2]);
921
+ return f(h[0], h[1], h[2]);
842
922
  case 3:
843
- return d(l[0], l[1]);
923
+ return l(h[0], h[1]);
844
924
  case 4:
845
- return y(l[0], l[1], l[2]);
925
+ return c(h[0], h[1], h[2]);
846
926
  }
847
927
  return n.undefined;
848
- });
849
- return g(h, (c) => [
850
- m(
851
- n,
852
- `(target, sym, proxyFuncs) => {
928
+ })), a);
929
+ return {
930
+ wrapHandle: (y) => {
931
+ if (!U(n, y) || i && !i(y, n))
932
+ return [void 0, !1];
933
+ if (!o) return [y, !1];
934
+ const h = b(
935
+ n,
936
+ `(target, sym, proxyFuncs) => {
937
+ if (
938
+ (target instanceof Promise) ||
939
+ (target instanceof Date) ||
940
+ (target instanceof ArrayBuffer) ||
941
+ (ArrayBuffer.isView(target)) ||
942
+ (target instanceof Map) ||
943
+ (target instanceof Set) ||
944
+ target[sym]
945
+ ) return null;
853
946
  const rec = new Proxy(target, {
854
947
  get(obj, key, receiver) {
855
948
  return key === sym ? obj : Reflect.get(obj, key, receiver)
@@ -887,44 +980,42 @@ function Ce(n, e, t, r, s, i, o, f = !0) {
887
980
  });
888
981
  return rec;
889
982
  }`,
890
- void 0,
891
- e,
892
- r,
893
- c
894
- ),
895
- !0
896
- ]);
983
+ void 0,
984
+ y,
985
+ t,
986
+ m()
987
+ );
988
+ return n.sameValue(h, n.null) ? (h.dispose(), [y, !1]) : [h, !0];
989
+ },
990
+ dispose: () => {
991
+ a && a.alive && a.dispose(), a = void 0;
992
+ }
993
+ };
897
994
  }
898
- function P(n, e) {
995
+ function S(n, e) {
899
996
  var t;
900
- return S(n) && (t = n[e]) != null ? t : n;
901
- }
902
- function E(n, e, t) {
903
- return W(n, e, t) ? [n.getProp(e, t), !0] : [e, !1];
997
+ return P(n) && (t = n[e]) != null ? t : n;
904
998
  }
905
- function Be(n, e) {
906
- return S(n) && !!n[e];
907
- }
908
- function W(n, e, t) {
909
- return !!n.dump(
910
- m(
911
- n,
912
- // Built-ins that must not be wrapped (internal slots / non-property access)
913
- // report as "wrapped" so wrapHandle leaves them alone.
914
- '(a, s) => (a instanceof Promise) || (a instanceof Date) || (a instanceof ArrayBuffer) || (ArrayBuffer.isView(a)) || (a instanceof Map) || (a instanceof Set) || (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',
915
- void 0,
916
- e,
917
- t
918
- )
999
+ function T(n, e, t) {
1000
+ const r = b(
1001
+ n,
1002
+ '(a, s) => (typeof a === "object" && a !== null || typeof a === "function") && a[s] || null',
1003
+ void 0,
1004
+ e,
1005
+ t
919
1006
  );
1007
+ return n.sameValue(r, n.null) ? (r.dispose(), [e, !1]) : [r, !0];
920
1008
  }
921
- class Fe {
1009
+ function De(n, e) {
1010
+ return P(n) && !!n[e];
1011
+ }
1012
+ class Ue {
922
1013
  /** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
923
1014
  constructor(e, t) {
924
- p(this, "context");
925
- p(this, "_map");
926
- p(this, "_registeredMap");
927
- p(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
1015
+ d(this, "context");
1016
+ d(this, "_map");
1017
+ d(this, "_registeredMap");
1018
+ d(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
928
1019
  // Handles with no owner: "json" copies and BigInt values. Unlike
929
1020
  // proxy-marshalled objects they are not identity-tracked in `_map`. A nested
930
1021
  // one is disposed by its parent consumer via `_disposeTransient` as soon as
@@ -932,32 +1023,40 @@ class Fe {
932
1023
  // were never nested (e.g. a top-level value before its caller consumes it) on
933
1024
  // dispose. Top-level handles are removed in `_marshal` since their caller
934
1025
  // disposes them via `mayConsume`.
935
- p(this, "_transientHandles", /* @__PURE__ */ new Set());
936
- p(this, "_sync", /* @__PURE__ */ new Set());
937
- p(this, "_temporalSync", /* @__PURE__ */ new Set());
938
- p(this, "_symbol", /* @__PURE__ */ Symbol());
939
- p(this, "_symbolHandle");
940
- p(this, "_options");
941
- p(this, "_isMarshalable", (e) => {
1026
+ d(this, "_transientHandles", /* @__PURE__ */ new Set());
1027
+ d(this, "_sync", /* @__PURE__ */ new Set());
1028
+ d(this, "_temporalSync", /* @__PURE__ */ new Set());
1029
+ d(this, "_symbol", /* @__PURE__ */ Symbol());
1030
+ d(this, "_symbolHandle");
1031
+ d(this, "_wrapHandleImpl");
1032
+ d(this, "_options");
1033
+ d(this, "_isMarshalable", (e) => {
942
1034
  var r, s;
943
1035
  const t = (r = this._options) == null ? void 0 : r.isMarshalable;
944
1036
  return (s = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? s : "json";
945
1037
  });
946
- p(this, "_marshalByReference", (e) => {
1038
+ d(this, "_marshalByReference", (e) => {
947
1039
  var t, r;
948
1040
  return !!((r = (t = this._options) == null ? void 0 : t.marshalByReference) != null && r.call(t, this._unwrap(e)));
949
1041
  });
1042
+ d(this, "_asyncify", (e) => {
1043
+ var s;
1044
+ const t = (s = this._options) == null ? void 0 : s.asyncify;
1045
+ if (!t) return !1;
1046
+ const r = this._unwrap(e);
1047
+ return typeof t == "function" ? typeof r == "function" && t(r) : Object.prototype.toString.call(r) === "[object AsyncFunction]";
1048
+ });
950
1049
  // Register an opaque HostRef handle by its host value without wrapping it.
951
- p(this, "_registerHostRef", (e, t) => {
1050
+ d(this, "_registerHostRef", (e, t) => {
952
1051
  const r = this._unwrap(e), s = this._map.get(r);
953
1052
  return s || (this._map.set(r, t), t);
954
1053
  });
955
- p(this, "_marshalFind", (e) => {
1054
+ d(this, "_marshalFind", (e) => {
956
1055
  var s, i, o;
957
1056
  const t = this._unwrap(e);
958
1057
  return (o = (i = (s = this._registeredMap.get(e)) != null ? s : t !== e ? this._registeredMap.get(t) : void 0) != null ? i : this._map.get(e)) != null ? o : t !== e ? this._map.get(t) : void 0;
959
1058
  });
960
- p(this, "_marshalPre", (e, t, r) => {
1059
+ d(this, "_marshalPre", (e, t, r) => {
961
1060
  if (r === "json") {
962
1061
  this._registerTransient(C(t));
963
1062
  return;
@@ -966,14 +1065,14 @@ class Fe {
966
1065
  if (s) return s[1];
967
1066
  this._registeredMap.has(e) || this._registerTransient(C(t));
968
1067
  });
969
- p(this, "_registerTransient", (e) => {
1068
+ d(this, "_registerTransient", (e) => {
970
1069
  this._transientHandles.add(e);
971
1070
  });
972
- p(this, "_disposeTransient", (e) => {
1071
+ d(this, "_disposeTransient", (e) => {
973
1072
  this._transientHandles.delete(e) && e.alive && e.dispose();
974
1073
  });
975
- p(this, "_marshalPreApply", (e, t, r) => {
976
- const s = S(t) ? this._unwrap(t) : void 0;
1074
+ d(this, "_marshalPreApply", (e, t, r) => {
1075
+ const s = P(t) ? this._unwrap(t) : void 0;
977
1076
  s && this._temporalSync.add(s);
978
1077
  try {
979
1078
  return e.apply(t, r);
@@ -981,12 +1080,12 @@ class Fe {
981
1080
  s && this._temporalSync.delete(s);
982
1081
  }
983
1082
  });
984
- p(this, "_marshal", (e) => {
985
- var o, f, u, a;
1083
+ d(this, "_marshal", (e) => {
1084
+ var o, a, u, f, l;
986
1085
  const t = this._registeredMap.get(e);
987
1086
  if (t)
988
1087
  return [t, !1];
989
- const r = this._marshalByReference(e) ? this._unwrap(e) : (o = this._wrap(e)) != null ? o : e, s = U(r, {
1088
+ const r = this._marshalByReference(e) ? this._unwrap(e) : (o = this._wrap(e)) != null ? o : e, s = W(r, {
990
1089
  ctx: this.context,
991
1090
  unmarshal: this._unmarshal,
992
1091
  isMarshalable: this._isMarshalable,
@@ -998,56 +1097,72 @@ class Fe {
998
1097
  disposeTransient: this._disposeTransient,
999
1098
  preApply: this._marshalPreApply,
1000
1099
  prepareReturn: this._prepareMarshalReturn,
1001
- custom: (f = this._options) == null ? void 0 : f.customMarshaller
1100
+ unwrap: (c) => this._unwrap(c),
1101
+ asyncify: (a = this._options) != null && a.asyncify ? this._asyncify : void 0,
1102
+ custom: (u = this._options) == null ? void 0 : u.customMarshaller
1002
1103
  });
1003
- this._transientHandles.delete(s);
1004
- const i = (a = (u = this._options) == null ? void 0 : u.syncEnabled) != null ? a : !0;
1005
- return [s, !i || !this._map.hasHandle(s)];
1104
+ return this._transientHandles.delete(s), !((l = (f = this._options) == null ? void 0 : f.syncEnabled) != null ? l : !0) || !P(e) ? [s, !0] : [s, !this._map.hasHandle(s)];
1006
1105
  });
1007
- p(this, "_prepareMarshalReturn", (e) => {
1106
+ d(this, "_prepareMarshalReturn", (e) => {
1008
1107
  var r, s;
1009
- return ((s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0) && e.alive && this._map.hasHandle(e) ? e.dup() : e;
1108
+ return ((s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0) && e.alive && U(this.context, e) && this._map.hasHandle(e) ? e.dup() : e;
1010
1109
  });
1011
- p(this, "_preUnmarshal", (e, t) => {
1110
+ d(this, "_preUnmarshal", (e, t) => {
1012
1111
  var r, s, i;
1013
1112
  return (i = this._register(e, t, void 0, (s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0)) == null ? void 0 : i[0];
1014
1113
  });
1015
- p(this, "_unmarshalFind", (e) => {
1114
+ d(this, "_unmarshalFind", (e) => {
1016
1115
  var t;
1017
1116
  return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
1018
1117
  });
1019
- p(this, "_unmarshal", (e) => {
1020
- var s, i, o;
1021
- const t = this._registeredMap.getByHandle(e);
1022
- if (typeof t != "undefined")
1023
- return t;
1024
- if ((s = this._options) != null && s.marshalByReference) {
1025
- const f = G(this.context, e);
1026
- if (f) return f.value;
1118
+ d(this, "_unmarshal", (e) => {
1119
+ var u, f, l;
1120
+ const [t, r] = K(this.context, e);
1121
+ if (r) return t;
1122
+ const s = this._registeredMap.getByHandle(e);
1123
+ if (typeof s != "undefined")
1124
+ return s;
1125
+ if ((u = this._options) != null && u.marshalByReference) {
1126
+ const c = $(this.context, e);
1127
+ if (c) return c.value;
1128
+ }
1129
+ const [i, o] = this._wrapHandle(e);
1130
+ let a = !1;
1131
+ try {
1132
+ const c = Ae(i != null ? i : e, {
1133
+ ctx: this.context,
1134
+ marshal: this._marshal,
1135
+ find: this._unmarshalFind,
1136
+ pre: this._preUnmarshal,
1137
+ custom: (f = this._options) == null ? void 0 : f.customUnmarshaller,
1138
+ hostRef: !!((l = this._options) != null && l.marshalByReference)
1139
+ });
1140
+ return a = !0, c;
1141
+ } finally {
1142
+ !a && o && (i != null && i.alive) && i !== e && i.dispose();
1027
1143
  }
1028
- const [r] = this._wrapHandle(e);
1029
- return Oe(r != null ? r : e, {
1030
- ctx: this.context,
1031
- marshal: this._marshal,
1032
- find: this._unmarshalFind,
1033
- pre: this._preUnmarshal,
1034
- custom: (i = this._options) == null ? void 0 : i.customUnmarshaller,
1035
- hostRef: !!((o = this._options) != null && o.marshalByReference)
1036
- });
1037
1144
  });
1038
- p(this, "_syncMode", (e) => {
1145
+ d(this, "_syncMode", (e) => {
1039
1146
  const t = this._unwrap(e);
1040
1147
  return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
1041
1148
  });
1042
- p(this, "_unwrapIfNotSynced", (e) => {
1149
+ d(this, "_unwrapIfNotSynced", (e) => {
1043
1150
  const t = this._unwrap(e);
1044
1151
  return t instanceof Promise || !this._sync.has(t) ? t : e;
1045
1152
  });
1046
- var r;
1153
+ var r, s, i, o;
1047
1154
  t != null && t.compat && !("runtime" in e) && (e.runtime = {
1048
1155
  hasPendingJob: () => e.hasPendingJob(),
1049
- executePendingJobs: (s) => e.executePendingJobs(s)
1050
- }), this.context = t != null && t.experimentalContextEx ? K(e) : e, Y(this.context), this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._map = new I(e), this._registeredMap = new I(e), this.registerAll((r = t == null ? void 0 : t.registeredObjects) != null ? r : Q);
1156
+ executePendingJobs: (a) => e.executePendingJobs(a)
1157
+ }), this.context = t != null && t.experimentalContextEx ? ae(e) : e, te(this.context), this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._wrapHandleImpl = Ne(
1158
+ this.context,
1159
+ this._symbol,
1160
+ this._symbolHandle,
1161
+ this._unmarshal,
1162
+ this._syncMode,
1163
+ (r = this._options) == null ? void 0 : r.isHandleWrappable,
1164
+ (i = (s = this._options) == null ? void 0 : s.syncEnabled) != null ? i : !0
1165
+ ), this._map = new D(e), this._registeredMap = new D(e), this.registerAll((o = t == null ? void 0 : t.registeredObjects) != null ? o : fe);
1051
1166
  }
1052
1167
  /**
1053
1168
  * Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
@@ -1056,7 +1171,7 @@ class Fe {
1056
1171
  var e, t;
1057
1172
  for (const r of this._transientHandles)
1058
1173
  r.alive && r.dispose();
1059
- this._transientHandles.clear(), this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose(), Z(this.context), (t = (e = this.context).disposeEx) == null || t.call(e);
1174
+ this._transientHandles.clear(), this._map.dispose(), this._registeredMap.dispose(), this._wrapHandleImpl.dispose(), this._symbolHandle.dispose(), ne(this.context), (t = (e = this.context).disposeEx) == null || t.call(e);
1060
1175
  }
1061
1176
  /** Allows `using arena = new Arena(...)` to dispose the arena automatically. */
1062
1177
  [Symbol.dispose]() {
@@ -1064,10 +1179,16 @@ class Fe {
1064
1179
  }
1065
1180
  /**
1066
1181
  * 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.
1182
+ *
1183
+ * @param code - The JS code to evaluate
1184
+ * @param filename - Optional filename used in error stacks and for debugging
1185
+ * @param options - Optional eval options forwarded to quickjs-emscripten's
1186
+ * `evalCode`, either an `EvalFlags` bitmask (`number`) or a
1187
+ * {@link ContextEvalOptions} object (e.g. `{ strict: true }`)
1067
1188
  */
1068
- evalCode(e) {
1069
- const t = this.context.evalCode(e);
1070
- return this._unwrapResultAndUnmarshal(t);
1189
+ evalCode(e, t, r) {
1190
+ const s = this.context.evalCode(e, t, r);
1191
+ return this._unwrapResultAndUnmarshal(s);
1071
1192
  }
1072
1193
  /**
1073
1194
  * Evaluate ES module code in the VM and get the module's exports.
@@ -1076,6 +1197,10 @@ class Fe {
1076
1197
  *
1077
1198
  * @param code - The ES module code to evaluate
1078
1199
  * @param filename - Optional filename for debugging purposes (default: "module.js")
1200
+ * @param options - Optional {@link ContextEvalOptions}. `type` is always forced
1201
+ * to `"module"`, so any `type` in `options` is overridden. A numeric
1202
+ * `EvalFlags` bitmask cannot be merged with the forced module type and is
1203
+ * therefore not supported here; if a number is passed it is ignored.
1079
1204
  * @returns The module's exports object, or a Promise resolving to exports if using top-level await
1080
1205
  *
1081
1206
  * @example
@@ -1101,9 +1226,11 @@ class Fe {
1101
1226
  * console.log(exports.data); // 123
1102
1227
  * ```
1103
1228
  */
1104
- evalModule(e, t = "module.js") {
1105
- const r = this.context.evalCode(e, t, { type: "module" });
1106
- return this._unwrapResultAndUnmarshal(r);
1229
+ evalModule(e, t = "module.js", r) {
1230
+ const s = this.context.evalCode(e, t, N(I({}, typeof r == "number" ? {} : r), {
1231
+ type: "module"
1232
+ }));
1233
+ return this._unwrapResultAndUnmarshal(s);
1107
1234
  }
1108
1235
  /**
1109
1236
  * Almost same as `vm.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.
@@ -1112,7 +1239,7 @@ class Fe {
1112
1239
  const t = this.context.runtime.executePendingJobs(e);
1113
1240
  if ("value" in t)
1114
1241
  return t.value;
1115
- throw this._unwrapIfNotSynced(g(t.error, this._unmarshal));
1242
+ throw this._unwrapIfNotSynced(j(t.error, this._unmarshal));
1116
1243
  }
1117
1244
  /**
1118
1245
  * Set the max memory this runtime can allocate.
@@ -1160,6 +1287,43 @@ class Fe {
1160
1287
  setMaxStackSize(e) {
1161
1288
  this.context.runtime.setMaxStackSize(e);
1162
1289
  }
1290
+ /**
1291
+ * Set a callback which is regularly called by the QuickJS engine when it is
1292
+ * executing code. This callback can be used to implement an execution
1293
+ * timeout: return `true` from the handler to interrupt the running code.
1294
+ *
1295
+ * This is useful for preventing runaway CPU usage (e.g. infinite loops) in
1296
+ * untrusted code.
1297
+ *
1298
+ * @param cb - The interrupt handler. Return `true` to interrupt execution.
1299
+ *
1300
+ * @example
1301
+ * ```js
1302
+ * // Interrupt evaluation after 1 second
1303
+ * const deadline = Date.now() + 1000;
1304
+ * arena.setInterruptHandler(() => Date.now() > deadline);
1305
+ *
1306
+ * try {
1307
+ * arena.evalCode(`while (true) {}`);
1308
+ * } catch (e) {
1309
+ * console.log("Execution interrupted");
1310
+ * }
1311
+ * ```
1312
+ */
1313
+ setInterruptHandler(e) {
1314
+ this.context.runtime.setInterruptHandler(e);
1315
+ }
1316
+ /**
1317
+ * Remove the interrupt handler previously set with `setInterruptHandler`.
1318
+ *
1319
+ * @example
1320
+ * ```js
1321
+ * arena.removeInterruptHandler();
1322
+ * ```
1323
+ */
1324
+ removeInterruptHandler() {
1325
+ this.context.runtime.removeInterruptHandler();
1326
+ }
1163
1327
  /**
1164
1328
  * Get detailed memory usage statistics for this runtime.
1165
1329
  *
@@ -1207,7 +1371,7 @@ class Fe {
1207
1371
  */
1208
1372
  expose(e) {
1209
1373
  for (const [t, r] of Object.entries(e))
1210
- re(this._marshal(r), (s) => {
1374
+ ie(this._marshal(r), (s) => {
1211
1375
  this.context.setProp(this.context.global, t, s);
1212
1376
  });
1213
1377
  }
@@ -1218,7 +1382,7 @@ class Fe {
1218
1382
  */
1219
1383
  sync(e) {
1220
1384
  const t = this._wrap(e);
1221
- return typeof t == "undefined" ? e : (N(t, (r) => {
1385
+ return typeof t == "undefined" ? e : (G(t, (r) => {
1222
1386
  const s = this._unwrap(r);
1223
1387
  this._sync.add(s);
1224
1388
  }), t);
@@ -1254,7 +1418,7 @@ class Fe {
1254
1418
  this.unregister(r, t);
1255
1419
  }
1256
1420
  startSync(e) {
1257
- if (!S(e)) return;
1421
+ if (!P(e)) return;
1258
1422
  const t = this._unwrap(e);
1259
1423
  this._sync.add(t);
1260
1424
  }
@@ -1264,28 +1428,33 @@ class Fe {
1264
1428
  _unwrapResult(e) {
1265
1429
  if ("value" in e)
1266
1430
  return e.value;
1267
- throw this._unwrapIfNotSynced(g(e.error, this._unmarshal));
1431
+ throw this._unwrapIfNotSynced(j(e.error, this._unmarshal));
1268
1432
  }
1269
1433
  _unwrapResultAndUnmarshal(e) {
1270
1434
  if (e)
1271
- return this._unwrapIfNotSynced(g(this._unwrapResult(e), this._unmarshal));
1435
+ return this._unwrapIfNotSynced(j(this._unwrapResult(e), this._unmarshal));
1272
1436
  }
1273
1437
  _register(e, t, r = this._map, s) {
1274
1438
  if (this._registeredMap.has(e) || this._registeredMap.hasHandle(t))
1275
1439
  return;
1276
1440
  let i = this._wrap(e);
1277
- const [o] = this._wrapHandle(t), f = e instanceof Promise;
1278
- if (!o || !i && !f) return;
1279
- f && (i = e);
1280
- const u = this._unwrap(e), [a, d] = this._unwrapHandle(t);
1281
- if (r.set(i, o, u, a))
1282
- s && this._sync.add(u);
1283
- else throw d && a.dispose(), new Error("already registered");
1284
- return [i, o];
1441
+ const [o, a] = this._wrapHandle(t), u = e instanceof Promise;
1442
+ if (!o || !i && !u) return;
1443
+ u && (i = e);
1444
+ const f = this._unwrap(e);
1445
+ let l, c = !1, m = !1;
1446
+ try {
1447
+ if ([l, c] = this._unwrapHandle(t), r.set(i, o, f, l))
1448
+ s && this._sync.add(f);
1449
+ else throw new Error("already registered");
1450
+ return m = !0, [i, o];
1451
+ } finally {
1452
+ m || (a && o.alive && o.dispose(), c && (l != null && l.alive) && l.dispose());
1453
+ }
1285
1454
  }
1286
1455
  _wrap(e) {
1287
1456
  var t, r, s;
1288
- return Me(
1457
+ return Be(
1289
1458
  this.context,
1290
1459
  e,
1291
1460
  this._symbol,
@@ -1297,56 +1466,52 @@ class Fe {
1297
1466
  );
1298
1467
  }
1299
1468
  _unwrap(e) {
1300
- return P(e, this._symbol);
1469
+ return S(e, this._symbol);
1301
1470
  }
1302
1471
  _wrapHandle(e) {
1303
- var t, r, s;
1304
- return Ce(
1305
- this.context,
1306
- e,
1307
- this._symbol,
1308
- this._symbolHandle,
1309
- this._unmarshal,
1310
- this._syncMode,
1311
- (t = this._options) == null ? void 0 : t.isHandleWrappable,
1312
- (s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0
1313
- );
1472
+ return this._wrapHandleImpl.wrapHandle(e);
1314
1473
  }
1315
1474
  _unwrapHandle(e) {
1316
- return E(this.context, e, this._symbolHandle);
1475
+ return T(this.context, e, this._symbolHandle);
1317
1476
  }
1318
1477
  }
1319
- class Ne extends Fe {
1478
+ class Je extends Ue {
1320
1479
  constructor(t, r) {
1321
1480
  super(t, r);
1322
- p(this, "asyncContext");
1481
+ d(this, "asyncContext");
1323
1482
  this.asyncContext = t;
1324
1483
  }
1325
1484
  /**
1326
1485
  * Evaluate JS code asynchronously in the VM and get the result on the host
1327
1486
  * side. Like `evalCode`, it converts and re-throws errors thrown during
1328
1487
  * evaluation. Use this when the code awaits host-provided promises.
1488
+ *
1489
+ * @param code - The JS code to evaluate
1490
+ * @param filename - Optional filename used in error stacks and for debugging
1491
+ * @param options - Optional eval options forwarded to quickjs-emscripten's
1492
+ * `evalCodeAsync`, either an `EvalFlags` bitmask (`number`) or a
1493
+ * {@link ContextEvalOptions} object (e.g. `{ strict: true }`)
1329
1494
  */
1330
- evalCodeAsync(t, r) {
1331
- return A(this, null, function* () {
1332
- const s = yield this.asyncContext.evalCodeAsync(t, r);
1333
- return this._unwrapResultAndUnmarshal(s);
1495
+ evalCodeAsync(t, r, s) {
1496
+ return F(this, null, function* () {
1497
+ const i = yield this.asyncContext.evalCodeAsync(t, r, s);
1498
+ return this._unwrapResultAndUnmarshal(i);
1334
1499
  });
1335
1500
  }
1336
1501
  }
1337
1502
  export {
1338
- Fe as Arena,
1339
- Ne as AsyncArena,
1340
- I as VMMap,
1341
- m as call,
1342
- Ie as complexity,
1343
- ne as consumeAll,
1344
- Q as defaultRegisteredObjects,
1345
- ce as isES2015Class,
1346
- ee as isHandleObject,
1347
- S as isObject,
1348
- te as json,
1349
- U as marshal,
1350
- Oe as unmarshal,
1351
- N as walkObject
1503
+ Ue as Arena,
1504
+ Je as AsyncArena,
1505
+ D as VMMap,
1506
+ b as call,
1507
+ Ge as complexity,
1508
+ V as consumeAll,
1509
+ fe as defaultRegisteredObjects,
1510
+ he as isES2015Class,
1511
+ U as isHandleObject,
1512
+ P as isObject,
1513
+ se as json,
1514
+ W as marshal,
1515
+ Ae as unmarshal,
1516
+ G as walkObject
1352
1517
  };