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