quickjs-emscripten-sync 1.9.0 → 1.10.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.
- package/README.md +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/quickjs-emscripten-sync.js +424 -372
- package/dist/quickjs-emscripten-sync.umd.cjs +7 -7
- package/package.json +2 -1
- package/src/edge.test.ts +44 -2
- package/src/identity.test.ts +57 -0
- package/src/index.test.ts +20 -0
- package/src/index.ts +53 -2
- package/src/jsonleak.test.ts +178 -0
- package/src/marshal/function.test.ts +6 -4
- package/src/marshal/function.ts +25 -4
- package/src/marshal/index.ts +28 -3
- package/src/marshal/mapset.ts +11 -2
- package/src/marshal/object.ts +4 -1
- package/src/marshal/properties.ts +11 -0
- package/src/remarshalleak.test.ts +50 -0
- package/src/vmmap.ts +5 -1
- package/src/vmutil.ts +3 -1
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var M = (n, e, t) => e in n ?
|
|
1
|
+
var z = Object.defineProperty;
|
|
2
|
+
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) => {
|
|
5
5
|
for (var t in e || (e = {}))
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
for (var t of
|
|
9
|
-
|
|
6
|
+
$.call(e, t) && M(n, t, e[t]);
|
|
7
|
+
if (B)
|
|
8
|
+
for (var t of B(e))
|
|
9
|
+
L.call(e, t) && M(n, t, e[t]);
|
|
10
10
|
return n;
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
12
|
+
var p = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
|
|
13
|
+
var A = (n, e, t) => new Promise((r, s) => {
|
|
14
|
+
var i = (u) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
s(
|
|
16
|
+
f(t.next(u));
|
|
17
|
+
} catch (a) {
|
|
18
|
+
s(a);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, o = (u) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
s(
|
|
22
|
+
f(t.throw(u));
|
|
23
|
+
} catch (a) {
|
|
24
|
+
s(a);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
26
|
+
}, f = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(i, o);
|
|
27
|
+
f((t = t.apply(n, e)).next());
|
|
28
28
|
});
|
|
29
|
-
const
|
|
30
|
-
const e = new
|
|
29
|
+
const K = (n) => {
|
|
30
|
+
const e = new q(n);
|
|
31
31
|
return new Proxy(n, {
|
|
32
32
|
get(t, r, s) {
|
|
33
33
|
return r in e ? e[r] : Reflect.get(t, r, s);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
class
|
|
37
|
+
class q {
|
|
38
38
|
constructor(e) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
44
|
/** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
|
|
45
|
-
|
|
45
|
+
p(this, "newFunction", (e, t) => {
|
|
46
46
|
this.fnCounter++;
|
|
47
47
|
const r = this.fnCounter;
|
|
48
48
|
return this.fnMap.set(r, t), this.context.unwrapResult(
|
|
@@ -59,9 +59,9 @@ class K {
|
|
|
59
59
|
this.context = e;
|
|
60
60
|
const t = this.fnMap;
|
|
61
61
|
this.fn = this.context.newFunction("", function(r, ...s) {
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
return
|
|
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
65
|
}), this.fnGenerator = e.unwrapResult(
|
|
66
66
|
e.evalCode(`((name, length, id, f) => {
|
|
67
67
|
const fn = function(...args) {
|
|
@@ -77,7 +77,7 @@ class K {
|
|
|
77
77
|
this.fnGenerator.dispose(), this.fn.dispose();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const Q = [
|
|
81
81
|
// basic objects
|
|
82
82
|
[Symbol, "Symbol"],
|
|
83
83
|
[Symbol.prototype, "Symbol.prototype"],
|
|
@@ -109,13 +109,13 @@ const q = [
|
|
|
109
109
|
// built-in symbols
|
|
110
110
|
...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
|
|
111
111
|
];
|
|
112
|
-
function
|
|
112
|
+
function R(n, e) {
|
|
113
113
|
if ("error" in e && e.error) {
|
|
114
114
|
const { error: t } = e;
|
|
115
115
|
let r;
|
|
116
116
|
try {
|
|
117
117
|
r = n.dump(t);
|
|
118
|
-
} catch (
|
|
118
|
+
} catch (i) {
|
|
119
119
|
} finally {
|
|
120
120
|
t.alive && t.dispose();
|
|
121
121
|
}
|
|
@@ -126,56 +126,56 @@ function S(n, e) {
|
|
|
126
126
|
}
|
|
127
127
|
return e.value;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
const t =
|
|
129
|
+
function X(n, e) {
|
|
130
|
+
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
131
|
return r.dispose = s, r[Symbol.dispose] = s, Object.defineProperty(r, "alive", {
|
|
132
132
|
get: () => t.alive
|
|
133
133
|
}), r;
|
|
134
134
|
}
|
|
135
|
-
const
|
|
136
|
-
function X(n) {
|
|
137
|
-
k.has(n) || k.set(n, /* @__PURE__ */ new Map());
|
|
138
|
-
}
|
|
135
|
+
const T = /* @__PURE__ */ new WeakMap();
|
|
139
136
|
function Y(n) {
|
|
140
|
-
|
|
137
|
+
T.has(n) || T.set(n, /* @__PURE__ */ new Map());
|
|
138
|
+
}
|
|
139
|
+
function Z(n) {
|
|
140
|
+
const e = T.get(n);
|
|
141
141
|
if (e) {
|
|
142
142
|
for (const t of e.values())
|
|
143
143
|
t.alive && t.dispose();
|
|
144
|
-
|
|
144
|
+
T.delete(n);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
function m(n, e, t, ...r) {
|
|
148
|
-
const s =
|
|
148
|
+
const s = T.get(n);
|
|
149
149
|
if (!s) {
|
|
150
|
-
const
|
|
150
|
+
const o = X(n, e);
|
|
151
151
|
try {
|
|
152
|
-
return
|
|
152
|
+
return o(t, ...r);
|
|
153
153
|
} finally {
|
|
154
|
-
|
|
154
|
+
o.dispose();
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
let
|
|
158
|
-
return (!
|
|
157
|
+
let i = s.get(e);
|
|
158
|
+
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
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function x(n, e, t) {
|
|
161
161
|
return n.dump(m(n, "(a, b) => a instanceof b", void 0, e, t));
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function ee(n, e) {
|
|
164
164
|
const t = n.typeof(e);
|
|
165
165
|
return t === "function" || t === "object" && !n.sameValue(e, n.null);
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function te(n, e) {
|
|
168
168
|
const t = JSON.stringify(e);
|
|
169
|
-
return t ? m(n, "JSON.parse", void 0,
|
|
169
|
+
return t ? n.newString(t).consume((r) => m(n, "JSON.parse", void 0, r)) : n.undefined;
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function g(n, e) {
|
|
172
172
|
try {
|
|
173
173
|
return e(n);
|
|
174
174
|
} finally {
|
|
175
175
|
n.alive && n.dispose();
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function ne(n, e) {
|
|
179
179
|
try {
|
|
180
180
|
return e(n);
|
|
181
181
|
} finally {
|
|
@@ -183,14 +183,14 @@ function te(n, e) {
|
|
|
183
183
|
t.alive && t.dispose();
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function re([n, e], t) {
|
|
187
187
|
try {
|
|
188
188
|
return t(n);
|
|
189
189
|
} finally {
|
|
190
190
|
e && n.dispose();
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function H(n, e) {
|
|
194
194
|
try {
|
|
195
195
|
return e(...n.map((t) => t[0]));
|
|
196
196
|
} finally {
|
|
@@ -198,20 +198,20 @@ function O(n, e) {
|
|
|
198
198
|
r && t.dispose();
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function se(n) {
|
|
202
202
|
return "handle" in n;
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
return
|
|
204
|
+
function C(n) {
|
|
205
|
+
return se(n) ? n.handle : n;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
var
|
|
207
|
+
function ie(n, e, t, r) {
|
|
208
|
+
var i;
|
|
209
209
|
let s;
|
|
210
|
-
for (const
|
|
211
|
-
if (s =
|
|
212
|
-
return 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;
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function oe(n, e) {
|
|
215
215
|
return typeof n != "symbol" ? void 0 : m(
|
|
216
216
|
e,
|
|
217
217
|
"d => Symbol(d)",
|
|
@@ -227,39 +227,39 @@ function ae(n, e) {
|
|
|
227
227
|
return e.newArrayBuffer(n.slice(0));
|
|
228
228
|
if (ArrayBuffer.isView(n)) {
|
|
229
229
|
const t = new Uint8Array(n.buffer, n.byteOffset, n.byteLength).slice();
|
|
230
|
-
return
|
|
230
|
+
return ne(
|
|
231
231
|
[e.newArrayBuffer(t.buffer), e.newString(n.constructor.name)],
|
|
232
232
|
([r, s]) => m(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
const fe = [
|
|
236
|
+
const fe = [oe, ue, ae];
|
|
237
237
|
function ce(n) {
|
|
238
238
|
return typeof n == "function" && /^class\s/.test(Function.prototype.toString.call(n));
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function S(n) {
|
|
241
241
|
return typeof n == "function" || typeof n == "object" && n !== null;
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function N(n, e) {
|
|
244
244
|
const t = /* @__PURE__ */ new Set(), r = (s) => {
|
|
245
|
-
if (!(!
|
|
245
|
+
if (!(!S(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
|
|
246
246
|
if (t.add(s), Array.isArray(s)) {
|
|
247
|
-
for (const
|
|
248
|
-
r(
|
|
247
|
+
for (const i of s)
|
|
248
|
+
r(i);
|
|
249
249
|
return;
|
|
250
250
|
}
|
|
251
251
|
if (typeof s == "object") {
|
|
252
|
-
const
|
|
253
|
-
|
|
252
|
+
const i = Object.getPrototypeOf(s);
|
|
253
|
+
i && i !== Object.prototype && r(i);
|
|
254
254
|
}
|
|
255
|
-
for (const
|
|
256
|
-
"value" in
|
|
255
|
+
for (const i of Object.values(Object.getOwnPropertyDescriptors(s)))
|
|
256
|
+
"value" in i && r(i.value), "get" in i && r(i.get), "set" in i && r(i.set);
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
259
|
return r(n), t;
|
|
260
260
|
}
|
|
261
261
|
function Ie(n, e) {
|
|
262
|
-
return
|
|
262
|
+
return N(n, e ? (t, r) => r.size < e : void 0).size;
|
|
263
263
|
}
|
|
264
264
|
function pe() {
|
|
265
265
|
let n = () => {
|
|
@@ -273,37 +273,45 @@ function pe() {
|
|
|
273
273
|
reject: e
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
v
|
|
283
|
-
|
|
276
|
+
function D(n, e, t, r, s = () => {
|
|
277
|
+
}) {
|
|
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);
|
|
284
285
|
});
|
|
285
286
|
};
|
|
286
287
|
try {
|
|
287
|
-
const
|
|
288
|
-
Object.entries(
|
|
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);
|
|
289
291
|
} finally {
|
|
290
|
-
|
|
292
|
+
i.dispose();
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
|
-
function le(n, e, t, r, s, o) {
|
|
294
|
-
|
|
295
|
+
function le(n, e, t, r, s, i, o = () => {
|
|
296
|
+
}, f = (u) => u) {
|
|
297
|
+
var d;
|
|
295
298
|
if (typeof e != "function") return;
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
if (ce(e) &&
|
|
299
|
-
const
|
|
300
|
-
return Object.entries(
|
|
301
|
-
|
|
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);
|
|
302
306
|
}), this;
|
|
303
307
|
}
|
|
304
|
-
return
|
|
308
|
+
return f(
|
|
309
|
+
t(
|
|
310
|
+
i ? i(e, h, c) : e.apply(h, c)
|
|
311
|
+
)
|
|
312
|
+
);
|
|
305
313
|
}).consume(
|
|
306
|
-
(
|
|
314
|
+
(y) => (
|
|
307
315
|
// fucntions created by vm.newFunction are not callable as a class constrcutor
|
|
308
316
|
m(
|
|
309
317
|
n,
|
|
@@ -314,41 +322,47 @@ function le(n, e, t, r, s, o) {
|
|
|
314
322
|
return fn;
|
|
315
323
|
}`,
|
|
316
324
|
void 0,
|
|
317
|
-
|
|
325
|
+
y
|
|
318
326
|
)
|
|
319
327
|
)
|
|
320
|
-
), a = (
|
|
321
|
-
return
|
|
328
|
+
), a = (d = s(e, u)) != null ? d : u;
|
|
329
|
+
return D(n, e, u, t, o), a;
|
|
322
330
|
}
|
|
323
331
|
function de(n, e, t) {
|
|
324
332
|
if (!(typeof e != "object" && typeof e != "function") && e !== null)
|
|
325
333
|
return t(e, n.newHostRef(e).handle);
|
|
326
334
|
}
|
|
327
335
|
function ye(n, e, t) {
|
|
328
|
-
var
|
|
329
|
-
const r =
|
|
330
|
-
return (
|
|
336
|
+
var i;
|
|
337
|
+
const r = te(n, e);
|
|
338
|
+
return (i = t(e, r)) != null ? i : r;
|
|
331
339
|
}
|
|
332
|
-
function he(n, e, t, r) {
|
|
333
|
-
|
|
340
|
+
function he(n, e, t, r, s = () => {
|
|
341
|
+
}) {
|
|
342
|
+
var i, o;
|
|
334
343
|
if (e instanceof Map) {
|
|
335
|
-
const
|
|
336
|
-
for (const [
|
|
337
|
-
|
|
338
|
-
|
|
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);
|
|
348
|
+
}
|
|
349
|
+
return u;
|
|
339
350
|
}
|
|
340
351
|
if (e instanceof Set) {
|
|
341
|
-
const
|
|
342
|
-
for (const
|
|
343
|
-
|
|
344
|
-
|
|
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);
|
|
356
|
+
}
|
|
357
|
+
return u;
|
|
345
358
|
}
|
|
346
359
|
}
|
|
347
|
-
function me(n, e, t, r) {
|
|
348
|
-
|
|
360
|
+
function me(n, e, t, r, s = () => {
|
|
361
|
+
}) {
|
|
362
|
+
var a;
|
|
349
363
|
if (typeof e != "object" || e === null) return;
|
|
350
|
-
const
|
|
351
|
-
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;
|
|
352
366
|
}
|
|
353
367
|
function _e(n, e) {
|
|
354
368
|
switch (typeof e) {
|
|
@@ -367,45 +381,54 @@ function _e(n, e) {
|
|
|
367
381
|
}
|
|
368
382
|
}
|
|
369
383
|
function ve(n, e, t, r) {
|
|
370
|
-
var
|
|
384
|
+
var i;
|
|
371
385
|
if (!(e instanceof Promise)) return;
|
|
372
386
|
const s = n.newPromise();
|
|
373
387
|
return e.then(
|
|
374
|
-
(
|
|
375
|
-
(
|
|
376
|
-
), (
|
|
388
|
+
(o) => s.resolve(t(o)),
|
|
389
|
+
(o) => s.reject(t(o))
|
|
390
|
+
), (i = r(e, s)) != null ? i : s.handle;
|
|
377
391
|
}
|
|
378
|
-
function
|
|
379
|
-
var
|
|
380
|
-
const { ctx: t, unmarshal: r, isMarshalable: s, find:
|
|
392
|
+
function U(n, e) {
|
|
393
|
+
var y, h, c, l, _, b, v, j;
|
|
394
|
+
const { ctx: t, unmarshal: r, isMarshalable: s, find: i, pre: o } = e;
|
|
381
395
|
{
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
return
|
|
396
|
+
const w = _e(t, n);
|
|
397
|
+
if (w)
|
|
398
|
+
return typeof n == "bigint" && ((y = e.registerTransient) == null || y.call(e, w)), w;
|
|
385
399
|
}
|
|
386
400
|
{
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
401
|
+
const w = i(n);
|
|
402
|
+
if (w) return w;
|
|
389
403
|
}
|
|
390
|
-
if ((
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
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;
|
|
393
407
|
}
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
408
|
+
const f = s == null ? void 0 : s(n);
|
|
409
|
+
if (f === !1)
|
|
396
410
|
return t.undefined;
|
|
397
|
-
const u = (
|
|
398
|
-
if (
|
|
411
|
+
const u = (w, k) => o(w, k, f);
|
|
412
|
+
if (f === "json")
|
|
399
413
|
return ye(t, n, u);
|
|
400
|
-
const
|
|
401
|
-
return (
|
|
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(
|
|
416
|
+
t,
|
|
417
|
+
n,
|
|
418
|
+
a,
|
|
419
|
+
r,
|
|
420
|
+
u,
|
|
421
|
+
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;
|
|
402
425
|
}
|
|
403
426
|
function be(n, e, t, r) {
|
|
404
|
-
var
|
|
427
|
+
var i;
|
|
405
428
|
let s;
|
|
406
|
-
for (const
|
|
407
|
-
if (s =
|
|
408
|
-
return s ? (
|
|
429
|
+
for (const o of r)
|
|
430
|
+
if (s = o(e, n), s) break;
|
|
431
|
+
return s ? (i = t(s, e)) != null ? i : s : void 0;
|
|
409
432
|
}
|
|
410
433
|
function we(n, e) {
|
|
411
434
|
if (e.typeof(n) !== "symbol") return;
|
|
@@ -413,19 +436,19 @@ function we(n, e) {
|
|
|
413
436
|
return Symbol(t);
|
|
414
437
|
}
|
|
415
438
|
function ge(n, e) {
|
|
416
|
-
if (!
|
|
417
|
-
const t =
|
|
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));
|
|
418
441
|
return new Date(t);
|
|
419
442
|
}
|
|
420
443
|
function je(n, e) {
|
|
421
|
-
if (
|
|
444
|
+
if (g(m(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
|
|
422
445
|
const t = e.getArrayBuffer(n), r = t.value.slice();
|
|
423
446
|
return t.dispose(), r.buffer;
|
|
424
447
|
}
|
|
425
|
-
if (
|
|
426
|
-
const t =
|
|
448
|
+
if (g(m(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
|
|
449
|
+
const t = g(
|
|
427
450
|
m(e, "a => a.constructor.name", void 0, n),
|
|
428
|
-
(
|
|
451
|
+
(f) => e.getString(f)
|
|
429
452
|
), r = globalThis[t];
|
|
430
453
|
if (typeof r != "function") return;
|
|
431
454
|
const s = m(
|
|
@@ -433,33 +456,33 @@ function je(n, e) {
|
|
|
433
456
|
"a => a.buffer.slice(a.byteOffset, a.byteOffset + a.byteLength)",
|
|
434
457
|
void 0,
|
|
435
458
|
n
|
|
436
|
-
),
|
|
437
|
-
return
|
|
459
|
+
), i = e.getArrayBuffer(s), o = i.value.slice();
|
|
460
|
+
return i.dispose(), s.dispose(), new r(o.buffer);
|
|
438
461
|
}
|
|
439
462
|
}
|
|
440
463
|
const Pe = [we, ge, je];
|
|
441
|
-
function
|
|
442
|
-
|
|
443
|
-
n.newFunction("", (s,
|
|
444
|
-
const [
|
|
445
|
-
if (typeof
|
|
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")
|
|
446
469
|
return;
|
|
447
|
-
const
|
|
470
|
+
const f = [
|
|
448
471
|
["value", !0],
|
|
449
472
|
["get", !0],
|
|
450
473
|
["set", !0],
|
|
451
474
|
["configurable", !1],
|
|
452
475
|
["enumerable", !1],
|
|
453
476
|
["writable", !1]
|
|
454
|
-
].reduce((u, [
|
|
455
|
-
const y = n.getProp(
|
|
477
|
+
].reduce((u, [a, d]) => {
|
|
478
|
+
const y = n.getProp(i, a), h = n.typeof(y);
|
|
456
479
|
if (h === "undefined") return u;
|
|
457
480
|
if (!d && h === "boolean")
|
|
458
|
-
return u[
|
|
459
|
-
const [c,
|
|
460
|
-
return
|
|
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;
|
|
461
484
|
}, {});
|
|
462
|
-
Object.defineProperty(t,
|
|
485
|
+
Object.defineProperty(t, o, f);
|
|
463
486
|
}),
|
|
464
487
|
(s) => {
|
|
465
488
|
m(
|
|
@@ -477,26 +500,26 @@ function U(n, e, t, r) {
|
|
|
477
500
|
);
|
|
478
501
|
}
|
|
479
502
|
function Se(n, e, t, r, s) {
|
|
480
|
-
var
|
|
503
|
+
var f;
|
|
481
504
|
if (n.typeof(e) !== "function") return;
|
|
482
|
-
const
|
|
483
|
-
return
|
|
484
|
-
[t(this), ...u.map((
|
|
485
|
-
(
|
|
505
|
+
const i = function(...u) {
|
|
506
|
+
return H(
|
|
507
|
+
[t(this), ...u.map((a) => t(a))],
|
|
508
|
+
(a, ...d) => {
|
|
486
509
|
if (new.target) {
|
|
487
|
-
const [
|
|
488
|
-
m(n, "(Cls, ...args) => new Cls(...args)",
|
|
510
|
+
const [l] = r(
|
|
511
|
+
m(n, "(Cls, ...args) => new Cls(...args)", a, e, ...d)
|
|
489
512
|
);
|
|
490
|
-
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(
|
|
513
|
+
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(l)), this;
|
|
491
514
|
}
|
|
492
|
-
const y =
|
|
515
|
+
const y = R(n, n.callFunction(e, a, ...d)), [h, c] = r(y);
|
|
493
516
|
return c && y.dispose(), h;
|
|
494
517
|
}
|
|
495
518
|
);
|
|
496
|
-
},
|
|
497
|
-
return
|
|
519
|
+
}, o = (f = s(i, e)) != null ? f : i;
|
|
520
|
+
return V(n, e, i, r), o;
|
|
498
521
|
}
|
|
499
|
-
function
|
|
522
|
+
function G(n, e) {
|
|
500
523
|
const t = n.toHostRef(e);
|
|
501
524
|
if (t)
|
|
502
525
|
try {
|
|
@@ -506,31 +529,31 @@ function V(n, e) {
|
|
|
506
529
|
}
|
|
507
530
|
}
|
|
508
531
|
function ke(n, e, t, r) {
|
|
509
|
-
const s =
|
|
510
|
-
if (!s && !
|
|
511
|
-
const
|
|
512
|
-
r(
|
|
513
|
-
const
|
|
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));
|
|
533
|
+
if (!s && !i) return;
|
|
534
|
+
const o = s ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
535
|
+
r(o, e);
|
|
536
|
+
const f = n.unwrapResult(n.getIterator(e));
|
|
514
537
|
try {
|
|
515
|
-
for (const u of
|
|
516
|
-
const
|
|
538
|
+
for (const u of f) {
|
|
539
|
+
const a = n.unwrapResult(u);
|
|
517
540
|
if (s) {
|
|
518
|
-
const d = n.getProp(
|
|
519
|
-
c && d.dispose(),
|
|
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();
|
|
520
543
|
} else {
|
|
521
|
-
const [d, y] = t(
|
|
522
|
-
y &&
|
|
544
|
+
const [d, y] = t(a);
|
|
545
|
+
y && a.dispose(), o.add(d);
|
|
523
546
|
}
|
|
524
547
|
}
|
|
525
548
|
} finally {
|
|
526
|
-
|
|
549
|
+
f.alive && f.dispose();
|
|
527
550
|
}
|
|
528
|
-
return
|
|
551
|
+
return o;
|
|
529
552
|
}
|
|
530
553
|
function Re(n, e, t, r) {
|
|
531
|
-
var
|
|
554
|
+
var f;
|
|
532
555
|
if (n.typeof(e) !== "object" || n.sameValue(e, n.null)) return;
|
|
533
|
-
const s =
|
|
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(
|
|
534
557
|
m(
|
|
535
558
|
n,
|
|
536
559
|
`o => {
|
|
@@ -542,66 +565,66 @@ function Re(n, e, t, r) {
|
|
|
542
565
|
),
|
|
543
566
|
(u) => {
|
|
544
567
|
if (n.typeof(u) === "undefined") return;
|
|
545
|
-
const [
|
|
546
|
-
return
|
|
568
|
+
const [a] = t(u);
|
|
569
|
+
return a;
|
|
547
570
|
}
|
|
548
571
|
);
|
|
549
|
-
return typeof
|
|
572
|
+
return typeof o == "object" && Object.setPrototypeOf(i, o), V(n, e, s, t), i;
|
|
550
573
|
}
|
|
551
|
-
function
|
|
574
|
+
function Te(n, e) {
|
|
552
575
|
const t = n.typeof(e);
|
|
553
576
|
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];
|
|
554
577
|
}
|
|
555
|
-
function
|
|
556
|
-
var
|
|
557
|
-
if (!
|
|
558
|
-
const s = pe(), [
|
|
559
|
-
return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e,
|
|
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;
|
|
560
583
|
}
|
|
561
|
-
function
|
|
562
|
-
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ?
|
|
584
|
+
function Ee(n, e) {
|
|
585
|
+
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? x(n, e, t) : !1) : !1;
|
|
563
586
|
}
|
|
564
|
-
function
|
|
565
|
-
const [t] =
|
|
587
|
+
function Oe(n, e) {
|
|
588
|
+
const [t] = J(n, e);
|
|
566
589
|
return t;
|
|
567
590
|
}
|
|
568
|
-
function
|
|
591
|
+
function J(n, e) {
|
|
569
592
|
var d, y, h;
|
|
570
|
-
const { ctx: t, marshal: r, find: s, pre:
|
|
593
|
+
const { ctx: t, marshal: r, find: s, pre: i } = e;
|
|
571
594
|
{
|
|
572
|
-
const [c,
|
|
573
|
-
if (
|
|
595
|
+
const [c, l] = Te(t, n);
|
|
596
|
+
if (l) return [c, !1];
|
|
574
597
|
}
|
|
575
598
|
{
|
|
576
599
|
const c = s(n);
|
|
577
600
|
if (c)
|
|
578
601
|
return [c, !0];
|
|
579
602
|
}
|
|
580
|
-
const
|
|
603
|
+
const o = (c) => J(c, e);
|
|
581
604
|
if (e.hostRef) {
|
|
582
|
-
const c =
|
|
605
|
+
const c = G(t, n);
|
|
583
606
|
if (c) return [c.value, !0];
|
|
584
607
|
}
|
|
585
|
-
const
|
|
586
|
-
if (
|
|
587
|
-
const u = ke(t, n,
|
|
588
|
-
return u ? [u, !0] : [(h = (y =
|
|
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];
|
|
589
612
|
}
|
|
590
|
-
class
|
|
613
|
+
class I {
|
|
591
614
|
constructor(e) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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);
|
|
605
628
|
this.ctx = e;
|
|
606
629
|
const t = e.unwrapResult(
|
|
607
630
|
e.evalCode(`() => {
|
|
@@ -632,13 +655,13 @@ class A {
|
|
|
632
655
|
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);
|
|
633
656
|
}
|
|
634
657
|
set(e, t, r, s) {
|
|
635
|
-
var
|
|
658
|
+
var f;
|
|
636
659
|
if (!t.alive || s && !s.alive) return !1;
|
|
637
|
-
const
|
|
638
|
-
if (
|
|
639
|
-
return
|
|
640
|
-
const
|
|
641
|
-
return this._keyToId.set(e,
|
|
660
|
+
const i = (f = this.get(e)) != null ? f : this.get(r);
|
|
661
|
+
if (i)
|
|
662
|
+
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) => {
|
|
642
665
|
this._call(this._mapSet, void 0, t, u, s != null ? s : this.ctx.undefined);
|
|
643
666
|
}), !0;
|
|
644
667
|
}
|
|
@@ -652,7 +675,7 @@ class A {
|
|
|
652
675
|
const t = (s = this._keyToId.get(e)) != null ? s : this._key2ToId.get(e), r = typeof t == "number" ? this._idToHandle.get(t) : void 0;
|
|
653
676
|
if (r) {
|
|
654
677
|
if (!r.alive) {
|
|
655
|
-
this.delete(e);
|
|
678
|
+
this.delete(e, !0);
|
|
656
679
|
return;
|
|
657
680
|
}
|
|
658
681
|
return r;
|
|
@@ -675,14 +698,14 @@ class A {
|
|
|
675
698
|
var u;
|
|
676
699
|
const r = (u = this._keyToId.get(e)) != null ? u : this._key2ToId.get(e);
|
|
677
700
|
if (typeof r == "undefined") return;
|
|
678
|
-
const s = this._idToHandle.get(r),
|
|
701
|
+
const s = this._idToHandle.get(r), i = this._idToHandle2.get(r);
|
|
679
702
|
this._call(
|
|
680
703
|
this._mapDelete,
|
|
681
704
|
void 0,
|
|
682
|
-
...[s,
|
|
705
|
+
...[s, i].filter((a) => !!(a != null && a.alive))
|
|
683
706
|
);
|
|
684
|
-
const
|
|
685
|
-
typeof
|
|
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());
|
|
686
709
|
}
|
|
687
710
|
deleteByHandle(e, t) {
|
|
688
711
|
const r = this.getByHandle(e);
|
|
@@ -712,16 +735,16 @@ class A {
|
|
|
712
735
|
if (t.done) return { value: void 0, done: !0 };
|
|
713
736
|
const r = this._keyToId.get(t.value);
|
|
714
737
|
if (typeof r == "undefined") continue;
|
|
715
|
-
const s = this._idToHandle.get(r),
|
|
738
|
+
const s = this._idToHandle.get(r), i = this._idToHandle2.get(r);
|
|
716
739
|
if (!s) continue;
|
|
717
|
-
const
|
|
718
|
-
return { value: [t.value, s,
|
|
740
|
+
const o = this._idToKey2.get(r);
|
|
741
|
+
return { value: [t.value, s, o, i], done: !1 };
|
|
719
742
|
}
|
|
720
743
|
}
|
|
721
744
|
};
|
|
722
745
|
}
|
|
723
746
|
_call(e, t, ...r) {
|
|
724
|
-
return
|
|
747
|
+
return R(
|
|
725
748
|
this.ctx,
|
|
726
749
|
this.ctx.callFunction(
|
|
727
750
|
e,
|
|
@@ -731,99 +754,99 @@ class A {
|
|
|
731
754
|
);
|
|
732
755
|
}
|
|
733
756
|
}
|
|
734
|
-
function Me(n, e, t, r, s,
|
|
735
|
-
if (!
|
|
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))
|
|
736
759
|
return;
|
|
737
|
-
if (Be(e, t) || !
|
|
760
|
+
if (Be(e, t) || !f) return e;
|
|
738
761
|
const u = new Proxy(e, {
|
|
739
|
-
get(
|
|
740
|
-
return d === t ?
|
|
762
|
+
get(a, d) {
|
|
763
|
+
return d === t ? a : Reflect.get(a, d);
|
|
741
764
|
},
|
|
742
|
-
set(
|
|
743
|
-
var
|
|
744
|
-
const c =
|
|
745
|
-
return
|
|
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(
|
|
746
769
|
[s(h), s(d), s(c)],
|
|
747
|
-
(b,
|
|
748
|
-
const [
|
|
749
|
-
|
|
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);
|
|
750
773
|
}
|
|
751
774
|
), !0;
|
|
752
775
|
},
|
|
753
|
-
deleteProperty(
|
|
776
|
+
deleteProperty(a, d) {
|
|
754
777
|
var h;
|
|
755
|
-
const y = (h =
|
|
756
|
-
return
|
|
757
|
-
const [
|
|
758
|
-
if (y === "vm" || Reflect.deleteProperty(
|
|
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)) {
|
|
759
782
|
if (y === "host" || !n.alive) return !0;
|
|
760
|
-
b ?
|
|
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);
|
|
761
784
|
}
|
|
762
785
|
return !0;
|
|
763
786
|
});
|
|
764
787
|
},
|
|
765
|
-
defineProperty(
|
|
766
|
-
var
|
|
767
|
-
const h = (
|
|
768
|
-
return "value" in c && (c.value =
|
|
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(
|
|
769
792
|
[s(u), s(d), s(c)],
|
|
770
|
-
(
|
|
771
|
-
const [
|
|
793
|
+
(_, b, v) => {
|
|
794
|
+
const [j, w] = E(n, _, r), k = (O) => m(
|
|
772
795
|
n,
|
|
773
796
|
"(o, k, d) => { Object.defineProperty(o, k, d); }",
|
|
774
797
|
void 0,
|
|
775
|
-
|
|
798
|
+
O,
|
|
776
799
|
b,
|
|
777
|
-
|
|
800
|
+
v
|
|
778
801
|
).dispose();
|
|
779
|
-
|
|
802
|
+
w ? j.consume(k) : k(j);
|
|
780
803
|
}
|
|
781
804
|
), !0);
|
|
782
805
|
}
|
|
783
806
|
});
|
|
784
807
|
return u;
|
|
785
808
|
}
|
|
786
|
-
function Ce(n, e, t, r, s,
|
|
787
|
-
if (!
|
|
809
|
+
function Ce(n, e, t, r, s, i, o, f = !0) {
|
|
810
|
+
if (!ee(n, e) || o && !o(e, n))
|
|
788
811
|
return [void 0, !1];
|
|
789
|
-
if (
|
|
790
|
-
if (!
|
|
812
|
+
if (W(n, e, r)) return [e, !1];
|
|
813
|
+
if (!f) return [e, !1];
|
|
791
814
|
const u = (c) => {
|
|
792
|
-
const
|
|
793
|
-
return typeof
|
|
794
|
-
},
|
|
815
|
+
const l = i == null ? void 0 : i(s(c));
|
|
816
|
+
return typeof l == "string" ? n.newString(l) : n.undefined;
|
|
817
|
+
}, a = (c, l, _) => {
|
|
795
818
|
const b = s(c);
|
|
796
819
|
if (!b) return;
|
|
797
|
-
const
|
|
798
|
-
if (
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
}, d = (c,
|
|
802
|
-
const
|
|
803
|
-
if (!
|
|
804
|
-
const b = s(
|
|
805
|
-
Reflect.deleteProperty(
|
|
806
|
-
}, y = (c,
|
|
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);
|
|
826
|
+
if (!_) return;
|
|
827
|
+
const b = s(l);
|
|
828
|
+
Reflect.deleteProperty(P(_, t), b);
|
|
829
|
+
}, y = (c, l, _) => {
|
|
807
830
|
const b = s(c);
|
|
808
831
|
if (!b) return;
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
811
|
-
const
|
|
812
|
-
Object.defineProperty(
|
|
813
|
-
}, h = n.newFunction("proxyFuncs", (c, ...
|
|
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) => {
|
|
814
837
|
switch (n.getNumber(c)) {
|
|
815
838
|
case 1:
|
|
816
|
-
return u(
|
|
839
|
+
return u(l[0]);
|
|
817
840
|
case 2:
|
|
818
|
-
return
|
|
841
|
+
return a(l[0], l[1], l[2]);
|
|
819
842
|
case 3:
|
|
820
|
-
return d(
|
|
843
|
+
return d(l[0], l[1]);
|
|
821
844
|
case 4:
|
|
822
|
-
return y(
|
|
845
|
+
return y(l[0], l[1], l[2]);
|
|
823
846
|
}
|
|
824
847
|
return n.undefined;
|
|
825
848
|
});
|
|
826
|
-
return
|
|
849
|
+
return g(h, (c) => [
|
|
827
850
|
m(
|
|
828
851
|
n,
|
|
829
852
|
`(target, sym, proxyFuncs) => {
|
|
@@ -872,17 +895,17 @@ function Ce(n, e, t, r, s, o, i, a = !0) {
|
|
|
872
895
|
!0
|
|
873
896
|
]);
|
|
874
897
|
}
|
|
875
|
-
function
|
|
898
|
+
function P(n, e) {
|
|
876
899
|
var t;
|
|
877
|
-
return
|
|
900
|
+
return S(n) && (t = n[e]) != null ? t : n;
|
|
878
901
|
}
|
|
879
|
-
function
|
|
880
|
-
return
|
|
902
|
+
function E(n, e, t) {
|
|
903
|
+
return W(n, e, t) ? [n.getProp(e, t), !0] : [e, !1];
|
|
881
904
|
}
|
|
882
905
|
function Be(n, e) {
|
|
883
|
-
return
|
|
906
|
+
return S(n) && !!n[e];
|
|
884
907
|
}
|
|
885
|
-
function
|
|
908
|
+
function W(n, e, t) {
|
|
886
909
|
return !!n.dump(
|
|
887
910
|
m(
|
|
888
911
|
n,
|
|
@@ -898,41 +921,59 @@ function J(n, e, t) {
|
|
|
898
921
|
class Fe {
|
|
899
922
|
/** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
|
|
900
923
|
constructor(e, t) {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
924
|
+
p(this, "context");
|
|
925
|
+
p(this, "_map");
|
|
926
|
+
p(this, "_registeredMap");
|
|
927
|
+
p(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
|
|
928
|
+
// Handles with no owner: "json" copies and BigInt values. Unlike
|
|
929
|
+
// proxy-marshalled objects they are not identity-tracked in `_map`. A nested
|
|
930
|
+
// one is disposed by its parent consumer via `_disposeTransient` as soon as
|
|
931
|
+
// the value has been copied; this set is the fallback that frees any that
|
|
932
|
+
// were never nested (e.g. a top-level value before its caller consumes it) on
|
|
933
|
+
// dispose. Top-level handles are removed in `_marshal` since their caller
|
|
934
|
+
// 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) => {
|
|
911
942
|
var r, s;
|
|
912
943
|
const t = (r = this._options) == null ? void 0 : r.isMarshalable;
|
|
913
944
|
return (s = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? s : "json";
|
|
914
945
|
});
|
|
915
|
-
|
|
946
|
+
p(this, "_marshalByReference", (e) => {
|
|
916
947
|
var t, r;
|
|
917
948
|
return !!((r = (t = this._options) == null ? void 0 : t.marshalByReference) != null && r.call(t, this._unwrap(e)));
|
|
918
949
|
});
|
|
919
950
|
// Register an opaque HostRef handle by its host value without wrapping it.
|
|
920
|
-
|
|
951
|
+
p(this, "_registerHostRef", (e, t) => {
|
|
921
952
|
const r = this._unwrap(e), s = this._map.get(r);
|
|
922
953
|
return s || (this._map.set(r, t), t);
|
|
923
954
|
});
|
|
924
|
-
|
|
925
|
-
var s,
|
|
955
|
+
p(this, "_marshalFind", (e) => {
|
|
956
|
+
var s, i, o;
|
|
926
957
|
const t = this._unwrap(e);
|
|
927
|
-
return (
|
|
958
|
+
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
|
+
});
|
|
960
|
+
p(this, "_marshalPre", (e, t, r) => {
|
|
961
|
+
if (r === "json") {
|
|
962
|
+
this._registerTransient(C(t));
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
const s = this._register(e, C(t), this._map);
|
|
966
|
+
if (s) return s[1];
|
|
967
|
+
this._registeredMap.has(e) || this._registerTransient(C(t));
|
|
928
968
|
});
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (r !== "json")
|
|
932
|
-
return (s = this._register(e, se(t), this._map)) == null ? void 0 : s[1];
|
|
969
|
+
p(this, "_registerTransient", (e) => {
|
|
970
|
+
this._transientHandles.add(e);
|
|
933
971
|
});
|
|
934
|
-
|
|
935
|
-
|
|
972
|
+
p(this, "_disposeTransient", (e) => {
|
|
973
|
+
this._transientHandles.delete(e) && e.alive && e.dispose();
|
|
974
|
+
});
|
|
975
|
+
p(this, "_marshalPreApply", (e, t, r) => {
|
|
976
|
+
const s = S(t) ? this._unwrap(t) : void 0;
|
|
936
977
|
s && this._temporalSync.add(s);
|
|
937
978
|
try {
|
|
938
979
|
return e.apply(t, r);
|
|
@@ -940,12 +981,12 @@ class Fe {
|
|
|
940
981
|
s && this._temporalSync.delete(s);
|
|
941
982
|
}
|
|
942
983
|
});
|
|
943
|
-
|
|
944
|
-
var
|
|
984
|
+
p(this, "_marshal", (e) => {
|
|
985
|
+
var o, f, u, a;
|
|
945
986
|
const t = this._registeredMap.get(e);
|
|
946
987
|
if (t)
|
|
947
988
|
return [t, !1];
|
|
948
|
-
const r = this._marshalByReference(e) ? this._unwrap(e) : (
|
|
989
|
+
const r = this._marshalByReference(e) ? this._unwrap(e) : (o = this._wrap(e)) != null ? o : e, s = U(r, {
|
|
949
990
|
ctx: this.context,
|
|
950
991
|
unmarshal: this._unmarshal,
|
|
951
992
|
isMarshalable: this._isMarshalable,
|
|
@@ -953,43 +994,52 @@ class Fe {
|
|
|
953
994
|
registerHostRef: this._registerHostRef,
|
|
954
995
|
find: this._marshalFind,
|
|
955
996
|
pre: this._marshalPre,
|
|
997
|
+
registerTransient: this._registerTransient,
|
|
998
|
+
disposeTransient: this._disposeTransient,
|
|
956
999
|
preApply: this._marshalPreApply,
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1000
|
+
prepareReturn: this._prepareMarshalReturn,
|
|
1001
|
+
custom: (f = this._options) == null ? void 0 : f.customMarshaller
|
|
1002
|
+
});
|
|
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)];
|
|
1006
|
+
});
|
|
1007
|
+
p(this, "_prepareMarshalReturn", (e) => {
|
|
1008
|
+
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;
|
|
960
1010
|
});
|
|
961
|
-
|
|
962
|
-
var r, s,
|
|
963
|
-
return (
|
|
1011
|
+
p(this, "_preUnmarshal", (e, t) => {
|
|
1012
|
+
var r, s, i;
|
|
1013
|
+
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];
|
|
964
1014
|
});
|
|
965
|
-
|
|
1015
|
+
p(this, "_unmarshalFind", (e) => {
|
|
966
1016
|
var t;
|
|
967
1017
|
return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
|
|
968
1018
|
});
|
|
969
|
-
|
|
970
|
-
var s,
|
|
1019
|
+
p(this, "_unmarshal", (e) => {
|
|
1020
|
+
var s, i, o;
|
|
971
1021
|
const t = this._registeredMap.getByHandle(e);
|
|
972
1022
|
if (typeof t != "undefined")
|
|
973
1023
|
return t;
|
|
974
1024
|
if ((s = this._options) != null && s.marshalByReference) {
|
|
975
|
-
const
|
|
976
|
-
if (
|
|
1025
|
+
const f = G(this.context, e);
|
|
1026
|
+
if (f) return f.value;
|
|
977
1027
|
}
|
|
978
1028
|
const [r] = this._wrapHandle(e);
|
|
979
|
-
return
|
|
1029
|
+
return Oe(r != null ? r : e, {
|
|
980
1030
|
ctx: this.context,
|
|
981
1031
|
marshal: this._marshal,
|
|
982
1032
|
find: this._unmarshalFind,
|
|
983
1033
|
pre: this._preUnmarshal,
|
|
984
|
-
custom: (
|
|
985
|
-
hostRef: !!((
|
|
1034
|
+
custom: (i = this._options) == null ? void 0 : i.customUnmarshaller,
|
|
1035
|
+
hostRef: !!((o = this._options) != null && o.marshalByReference)
|
|
986
1036
|
});
|
|
987
1037
|
});
|
|
988
|
-
|
|
1038
|
+
p(this, "_syncMode", (e) => {
|
|
989
1039
|
const t = this._unwrap(e);
|
|
990
1040
|
return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
|
|
991
1041
|
});
|
|
992
|
-
|
|
1042
|
+
p(this, "_unwrapIfNotSynced", (e) => {
|
|
993
1043
|
const t = this._unwrap(e);
|
|
994
1044
|
return t instanceof Promise || !this._sync.has(t) ? t : e;
|
|
995
1045
|
});
|
|
@@ -997,14 +1047,16 @@ class Fe {
|
|
|
997
1047
|
t != null && t.compat && !("runtime" in e) && (e.runtime = {
|
|
998
1048
|
hasPendingJob: () => e.hasPendingJob(),
|
|
999
1049
|
executePendingJobs: (s) => e.executePendingJobs(s)
|
|
1000
|
-
}), this.context = t != null && t.experimentalContextEx ?
|
|
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);
|
|
1001
1051
|
}
|
|
1002
1052
|
/**
|
|
1003
1053
|
* Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
|
|
1004
1054
|
*/
|
|
1005
1055
|
dispose() {
|
|
1006
1056
|
var e, t;
|
|
1007
|
-
|
|
1057
|
+
for (const r of this._transientHandles)
|
|
1058
|
+
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);
|
|
1008
1060
|
}
|
|
1009
1061
|
/** Allows `using arena = new Arena(...)` to dispose the arena automatically. */
|
|
1010
1062
|
[Symbol.dispose]() {
|
|
@@ -1060,7 +1112,7 @@ class Fe {
|
|
|
1060
1112
|
const t = this.context.runtime.executePendingJobs(e);
|
|
1061
1113
|
if ("value" in t)
|
|
1062
1114
|
return t.value;
|
|
1063
|
-
throw this._unwrapIfNotSynced(
|
|
1115
|
+
throw this._unwrapIfNotSynced(g(t.error, this._unmarshal));
|
|
1064
1116
|
}
|
|
1065
1117
|
/**
|
|
1066
1118
|
* Set the max memory this runtime can allocate.
|
|
@@ -1155,7 +1207,7 @@ class Fe {
|
|
|
1155
1207
|
*/
|
|
1156
1208
|
expose(e) {
|
|
1157
1209
|
for (const [t, r] of Object.entries(e))
|
|
1158
|
-
|
|
1210
|
+
re(this._marshal(r), (s) => {
|
|
1159
1211
|
this.context.setProp(this.context.global, t, s);
|
|
1160
1212
|
});
|
|
1161
1213
|
}
|
|
@@ -1166,7 +1218,7 @@ class Fe {
|
|
|
1166
1218
|
*/
|
|
1167
1219
|
sync(e) {
|
|
1168
1220
|
const t = this._wrap(e);
|
|
1169
|
-
return typeof t == "undefined" ? e : (
|
|
1221
|
+
return typeof t == "undefined" ? e : (N(t, (r) => {
|
|
1170
1222
|
const s = this._unwrap(r);
|
|
1171
1223
|
this._sync.add(s);
|
|
1172
1224
|
}), t);
|
|
@@ -1202,7 +1254,7 @@ class Fe {
|
|
|
1202
1254
|
this.unregister(r, t);
|
|
1203
1255
|
}
|
|
1204
1256
|
startSync(e) {
|
|
1205
|
-
if (!
|
|
1257
|
+
if (!S(e)) return;
|
|
1206
1258
|
const t = this._unwrap(e);
|
|
1207
1259
|
this._sync.add(t);
|
|
1208
1260
|
}
|
|
@@ -1212,24 +1264,24 @@ class Fe {
|
|
|
1212
1264
|
_unwrapResult(e) {
|
|
1213
1265
|
if ("value" in e)
|
|
1214
1266
|
return e.value;
|
|
1215
|
-
throw this._unwrapIfNotSynced(
|
|
1267
|
+
throw this._unwrapIfNotSynced(g(e.error, this._unmarshal));
|
|
1216
1268
|
}
|
|
1217
1269
|
_unwrapResultAndUnmarshal(e) {
|
|
1218
1270
|
if (e)
|
|
1219
|
-
return this._unwrapIfNotSynced(
|
|
1271
|
+
return this._unwrapIfNotSynced(g(this._unwrapResult(e), this._unmarshal));
|
|
1220
1272
|
}
|
|
1221
1273
|
_register(e, t, r = this._map, s) {
|
|
1222
1274
|
if (this._registeredMap.has(e) || this._registeredMap.hasHandle(t))
|
|
1223
1275
|
return;
|
|
1224
|
-
let
|
|
1225
|
-
const [
|
|
1226
|
-
if (!
|
|
1227
|
-
|
|
1228
|
-
const u = this._unwrap(e), [
|
|
1229
|
-
if (r.set(
|
|
1276
|
+
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))
|
|
1230
1282
|
s && this._sync.add(u);
|
|
1231
|
-
else throw d &&
|
|
1232
|
-
return [
|
|
1283
|
+
else throw d && a.dispose(), new Error("already registered");
|
|
1284
|
+
return [i, o];
|
|
1233
1285
|
}
|
|
1234
1286
|
_wrap(e) {
|
|
1235
1287
|
var t, r, s;
|
|
@@ -1245,7 +1297,7 @@ class Fe {
|
|
|
1245
1297
|
);
|
|
1246
1298
|
}
|
|
1247
1299
|
_unwrap(e) {
|
|
1248
|
-
return
|
|
1300
|
+
return P(e, this._symbol);
|
|
1249
1301
|
}
|
|
1250
1302
|
_wrapHandle(e) {
|
|
1251
1303
|
var t, r, s;
|
|
@@ -1261,13 +1313,13 @@ class Fe {
|
|
|
1261
1313
|
);
|
|
1262
1314
|
}
|
|
1263
1315
|
_unwrapHandle(e) {
|
|
1264
|
-
return
|
|
1316
|
+
return E(this.context, e, this._symbolHandle);
|
|
1265
1317
|
}
|
|
1266
1318
|
}
|
|
1267
1319
|
class Ne extends Fe {
|
|
1268
1320
|
constructor(t, r) {
|
|
1269
1321
|
super(t, r);
|
|
1270
|
-
|
|
1322
|
+
p(this, "asyncContext");
|
|
1271
1323
|
this.asyncContext = t;
|
|
1272
1324
|
}
|
|
1273
1325
|
/**
|
|
@@ -1276,7 +1328,7 @@ class Ne extends Fe {
|
|
|
1276
1328
|
* evaluation. Use this when the code awaits host-provided promises.
|
|
1277
1329
|
*/
|
|
1278
1330
|
evalCodeAsync(t, r) {
|
|
1279
|
-
return
|
|
1331
|
+
return A(this, null, function* () {
|
|
1280
1332
|
const s = yield this.asyncContext.evalCodeAsync(t, r);
|
|
1281
1333
|
return this._unwrapResultAndUnmarshal(s);
|
|
1282
1334
|
});
|
|
@@ -1285,16 +1337,16 @@ class Ne extends Fe {
|
|
|
1285
1337
|
export {
|
|
1286
1338
|
Fe as Arena,
|
|
1287
1339
|
Ne as AsyncArena,
|
|
1288
|
-
|
|
1340
|
+
I as VMMap,
|
|
1289
1341
|
m as call,
|
|
1290
1342
|
Ie as complexity,
|
|
1291
|
-
|
|
1292
|
-
|
|
1343
|
+
ne as consumeAll,
|
|
1344
|
+
Q as defaultRegisteredObjects,
|
|
1293
1345
|
ce as isES2015Class,
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1346
|
+
ee as isHandleObject,
|
|
1347
|
+
S as isObject,
|
|
1348
|
+
te as json,
|
|
1349
|
+
U as marshal,
|
|
1350
|
+
Oe as unmarshal,
|
|
1351
|
+
N as walkObject
|
|
1300
1352
|
};
|