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