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