quickjs-emscripten-sync 1.7.0 → 1.8.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 +0 -2
- package/dist/quickjs-emscripten-sync.mjs +58 -62
- package/dist/quickjs-emscripten-sync.umd.js +7 -7
- package/package.json +2 -2
- package/src/index.ts +2 -3
- package/src/marshal/function.test.ts +2 -2
- package/src/marshal/primitive.test.ts +4 -6
- package/src/vmutil.test.ts +2 -3
- package/src/vmutil.ts +0 -4
- package/src/wrapper.test.ts +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -231,8 +231,6 @@ export declare function consumeAll<T extends QuickJSHandle[], K>(handles: T, cb:
|
|
|
231
231
|
*/
|
|
232
232
|
export declare const defaultRegisteredObjects: [any, string][];
|
|
233
233
|
|
|
234
|
-
export declare function eq(ctx: QuickJSContext, a: QuickJSHandle, b: QuickJSHandle): boolean;
|
|
235
|
-
|
|
236
234
|
export { Intrinsics }
|
|
237
235
|
|
|
238
236
|
export declare function isES2015Class(cls: any): cls is new (...args: any[]) => any;
|
|
@@ -99,21 +99,18 @@ function y(n, e, t, ...r) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
function G(n, e, t) {
|
|
102
|
-
return n.dump(y(n, "Object.is", void 0, e, t));
|
|
103
|
-
}
|
|
104
|
-
function J(n, e, t) {
|
|
105
102
|
return n.dump(y(n, "(a, b) => a instanceof b", void 0, e, t));
|
|
106
103
|
}
|
|
107
|
-
function
|
|
104
|
+
function J(n, e) {
|
|
108
105
|
return n.dump(
|
|
109
106
|
y(n, 'a => typeof a === "object" && a !== null || typeof a === "function"', void 0, e)
|
|
110
107
|
);
|
|
111
108
|
}
|
|
112
|
-
function
|
|
109
|
+
function W(n, e) {
|
|
113
110
|
const t = JSON.stringify(e);
|
|
114
111
|
return t ? y(n, "JSON.parse", void 0, n.newString(t)) : n.undefined;
|
|
115
112
|
}
|
|
116
|
-
function
|
|
113
|
+
function _e(n, e) {
|
|
117
114
|
try {
|
|
118
115
|
return e(n);
|
|
119
116
|
} finally {
|
|
@@ -121,7 +118,7 @@ function be(n, e) {
|
|
|
121
118
|
t.alive && t.dispose();
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
|
-
function
|
|
121
|
+
function z([n, e], t) {
|
|
125
122
|
try {
|
|
126
123
|
return t(n);
|
|
127
124
|
} finally {
|
|
@@ -136,20 +133,20 @@ function g(n, e) {
|
|
|
136
133
|
r && t.dispose();
|
|
137
134
|
}
|
|
138
135
|
}
|
|
139
|
-
function
|
|
136
|
+
function $(n) {
|
|
140
137
|
return "handle" in n;
|
|
141
138
|
}
|
|
142
|
-
function
|
|
143
|
-
return
|
|
139
|
+
function L(n) {
|
|
140
|
+
return $(n) ? n.handle : n;
|
|
144
141
|
}
|
|
145
|
-
function
|
|
142
|
+
function V(n, e, t, r) {
|
|
146
143
|
var o;
|
|
147
144
|
let s;
|
|
148
145
|
for (const i of r)
|
|
149
146
|
if (s = i(e, n), s) break;
|
|
150
147
|
return s ? (o = t(e, s)) != null ? o : s : void 0;
|
|
151
148
|
}
|
|
152
|
-
function
|
|
149
|
+
function Q(n, e) {
|
|
153
150
|
return typeof n != "symbol" ? void 0 : y(
|
|
154
151
|
e,
|
|
155
152
|
"d => Symbol(d)",
|
|
@@ -157,11 +154,11 @@ function V(n, e) {
|
|
|
157
154
|
n.description ? e.newString(n.description) : e.undefined
|
|
158
155
|
);
|
|
159
156
|
}
|
|
160
|
-
function
|
|
157
|
+
function q(n, e) {
|
|
161
158
|
return n instanceof Date ? y(e, "d => new Date(d)", void 0, e.newNumber(n.getTime())) : void 0;
|
|
162
159
|
}
|
|
163
|
-
const
|
|
164
|
-
function
|
|
160
|
+
const X = [Q, q];
|
|
161
|
+
function Y(n) {
|
|
165
162
|
return typeof n == "function" && /^class\s/.test(Function.prototype.toString.call(n));
|
|
166
163
|
}
|
|
167
164
|
function v(n) {
|
|
@@ -185,10 +182,10 @@ function E(n, e) {
|
|
|
185
182
|
};
|
|
186
183
|
return r(n), t;
|
|
187
184
|
}
|
|
188
|
-
function
|
|
185
|
+
function be(n, e) {
|
|
189
186
|
return E(n, e ? (t, r) => r.size < e : void 0).size;
|
|
190
187
|
}
|
|
191
|
-
function
|
|
188
|
+
function Z() {
|
|
192
189
|
let n = () => {
|
|
193
190
|
}, e = () => {
|
|
194
191
|
};
|
|
@@ -212,12 +209,12 @@ function M(n, e, t, r) {
|
|
|
212
209
|
}, i = Object.getOwnPropertyDescriptors(e);
|
|
213
210
|
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();
|
|
214
211
|
}
|
|
215
|
-
function
|
|
212
|
+
function K(n, e, t, r, s, o) {
|
|
216
213
|
var u;
|
|
217
214
|
if (typeof e != "function") return;
|
|
218
215
|
const i = n.newFunction(e.name, function(...p) {
|
|
219
216
|
const l = r(this), f = p.map((d) => r(d));
|
|
220
|
-
if (
|
|
217
|
+
if (Y(e) && v(l)) {
|
|
221
218
|
const d = new e(...f);
|
|
222
219
|
return Object.entries(d).forEach(([m, h]) => {
|
|
223
220
|
n.setProp(this, m, t(h));
|
|
@@ -242,18 +239,18 @@ function x(n, e, t, r, s, o) {
|
|
|
242
239
|
), a = (u = s(e, i)) != null ? u : i;
|
|
243
240
|
return M(n, e, i, t), a;
|
|
244
241
|
}
|
|
245
|
-
function
|
|
242
|
+
function x(n, e, t) {
|
|
246
243
|
var o;
|
|
247
|
-
const r =
|
|
244
|
+
const r = W(n, e);
|
|
248
245
|
return (o = t(e, r)) != null ? o : r;
|
|
249
246
|
}
|
|
250
|
-
function
|
|
247
|
+
function ee(n, e, t, r) {
|
|
251
248
|
var u;
|
|
252
249
|
if (typeof e != "object" || e === null) return;
|
|
253
250
|
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
251
|
return a && y(n, "Object.setPrototypeOf", void 0, o, a).dispose(), M(n, e, s, t), o;
|
|
255
252
|
}
|
|
256
|
-
function
|
|
253
|
+
function te(n, e) {
|
|
257
254
|
switch (typeof e) {
|
|
258
255
|
case "undefined":
|
|
259
256
|
return n.undefined;
|
|
@@ -267,7 +264,7 @@ function ne(n, e) {
|
|
|
267
264
|
return e === null ? n.null : void 0;
|
|
268
265
|
}
|
|
269
266
|
}
|
|
270
|
-
function
|
|
267
|
+
function ne(n, e, t, r) {
|
|
271
268
|
var o;
|
|
272
269
|
if (!(e instanceof Promise)) return;
|
|
273
270
|
const s = n.newPromise();
|
|
@@ -280,7 +277,7 @@ function R(n, e) {
|
|
|
280
277
|
var l, f, d, m, h;
|
|
281
278
|
const { ctx: t, unmarshal: r, isMarshalable: s, find: o, pre: i } = e;
|
|
282
279
|
{
|
|
283
|
-
const _ =
|
|
280
|
+
const _ = te(t, n);
|
|
284
281
|
if (_)
|
|
285
282
|
return _;
|
|
286
283
|
}
|
|
@@ -293,28 +290,28 @@ function R(n, e) {
|
|
|
293
290
|
return t.undefined;
|
|
294
291
|
const u = (_, b) => i(_, b, a);
|
|
295
292
|
if (a === "json")
|
|
296
|
-
return
|
|
293
|
+
return x(t, n, u);
|
|
297
294
|
const p = (_) => R(_, e);
|
|
298
|
-
return (h = (m = (d = (f =
|
|
295
|
+
return (h = (m = (d = (f = V(t, n, u, [...X, ...(l = e.custom) != null ? l : []])) != null ? f : ne(t, n, p, u)) != null ? d : K(t, n, p, r, u, e.preApply)) != null ? m : ee(t, n, p, u)) != null ? h : t.undefined;
|
|
299
296
|
}
|
|
300
|
-
function
|
|
297
|
+
function re(n, e, t, r) {
|
|
301
298
|
var o;
|
|
302
299
|
let s;
|
|
303
300
|
for (const i of r)
|
|
304
301
|
if (s = i(e, n), s) break;
|
|
305
302
|
return s ? (o = t(s, e)) != null ? o : s : void 0;
|
|
306
303
|
}
|
|
307
|
-
function
|
|
304
|
+
function se(n, e) {
|
|
308
305
|
if (e.typeof(n) !== "symbol") return;
|
|
309
306
|
const t = e.getString(e.getProp(n, "description"));
|
|
310
307
|
return Symbol(t);
|
|
311
308
|
}
|
|
312
|
-
function
|
|
309
|
+
function oe(n, e) {
|
|
313
310
|
if (!e.dump(y(e, "a => a instanceof Date", void 0, n))) return;
|
|
314
311
|
const t = e.getNumber(y(e, "a => a.getTime()", void 0, n));
|
|
315
312
|
return new Date(t);
|
|
316
313
|
}
|
|
317
|
-
const
|
|
314
|
+
const ie = [se, oe];
|
|
318
315
|
function k(n, e, t, r) {
|
|
319
316
|
n.newFunction("", (s, o) => {
|
|
320
317
|
const [i] = r(s);
|
|
@@ -350,7 +347,7 @@ function k(n, e, t, r) {
|
|
|
350
347
|
).dispose();
|
|
351
348
|
});
|
|
352
349
|
}
|
|
353
|
-
function
|
|
350
|
+
function ue(n, e, t, r, s) {
|
|
354
351
|
var a;
|
|
355
352
|
if (n.typeof(e) !== "function") return;
|
|
356
353
|
const o = function(...u) {
|
|
@@ -370,7 +367,7 @@ function ae(n, e, t, r, s) {
|
|
|
370
367
|
}, i = (a = s(o, e)) != null ? a : o;
|
|
371
368
|
return k(n, e, o, r), i;
|
|
372
369
|
}
|
|
373
|
-
function
|
|
370
|
+
function ae(n, e, t, r) {
|
|
374
371
|
var a;
|
|
375
372
|
if (n.typeof(e) !== "object" || // null check
|
|
376
373
|
n.unwrapResult(n.evalCode("o => o === null")).consume((u) => n.dump(n.unwrapResult(n.callFunction(u, n.undefined, e)))))
|
|
@@ -390,20 +387,20 @@ function pe(n, e, t, r) {
|
|
|
390
387
|
});
|
|
391
388
|
return typeof i == "object" && Object.setPrototypeOf(o, i), k(n, e, s, t), o;
|
|
392
389
|
}
|
|
393
|
-
function
|
|
390
|
+
function pe(n, e) {
|
|
394
391
|
const t = n.typeof(e);
|
|
395
392
|
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];
|
|
396
393
|
}
|
|
397
|
-
function
|
|
394
|
+
function fe(n, e, t, r) {
|
|
398
395
|
var p;
|
|
399
|
-
if (!
|
|
400
|
-
const s =
|
|
396
|
+
if (!ce(n, e)) return;
|
|
397
|
+
const s = Z(), [o, i] = t(s.resolve), [a, u] = t(s.reject);
|
|
401
398
|
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;
|
|
402
399
|
}
|
|
403
|
-
function
|
|
404
|
-
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ?
|
|
400
|
+
function ce(n, e) {
|
|
401
|
+
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? G(n, e, t) : !1) : !1;
|
|
405
402
|
}
|
|
406
|
-
function
|
|
403
|
+
function le(n, e) {
|
|
407
404
|
const [t] = C(n, e);
|
|
408
405
|
return t;
|
|
409
406
|
}
|
|
@@ -411,7 +408,7 @@ function C(n, e) {
|
|
|
411
408
|
var u, p, l, f;
|
|
412
409
|
const { ctx: t, marshal: r, find: s, pre: o } = e;
|
|
413
410
|
{
|
|
414
|
-
const [d, m] =
|
|
411
|
+
const [d, m] = pe(t, n);
|
|
415
412
|
if (m) return [d, !1];
|
|
416
413
|
}
|
|
417
414
|
{
|
|
@@ -420,7 +417,7 @@ function C(n, e) {
|
|
|
420
417
|
return [d, !0];
|
|
421
418
|
}
|
|
422
419
|
const i = (d) => C(d, e);
|
|
423
|
-
return [(f = (l = (p =
|
|
420
|
+
return [(f = (l = (p = re(t, n, o, [...ie, ...(u = e.custom) != null ? u : []])) != null ? p : fe(t, n, r, o)) != null ? l : ue(t, n, r, i, o)) != null ? f : ae(t, n, i, o), !1];
|
|
424
421
|
}
|
|
425
422
|
class O {
|
|
426
423
|
constructor(e) {
|
|
@@ -582,10 +579,10 @@ class O {
|
|
|
582
579
|
);
|
|
583
580
|
}
|
|
584
581
|
}
|
|
585
|
-
function
|
|
582
|
+
function de(n, e, t, r, s, o, i) {
|
|
586
583
|
if (!v(e) || e instanceof Promise || e instanceof Date || i && !i(e))
|
|
587
584
|
return;
|
|
588
|
-
if (
|
|
585
|
+
if (he(e, t)) return e;
|
|
589
586
|
const a = new Proxy(e, {
|
|
590
587
|
get(u, p) {
|
|
591
588
|
return p === t ? u : Reflect.get(u, p);
|
|
@@ -616,8 +613,8 @@ function me(n, e, t, r, s, o, i) {
|
|
|
616
613
|
});
|
|
617
614
|
return a;
|
|
618
615
|
}
|
|
619
|
-
function
|
|
620
|
-
if (!
|
|
616
|
+
function me(n, e, t, r, s, o, i) {
|
|
617
|
+
if (!J(n, e) || i && !i(e, n))
|
|
621
618
|
return [void 0, !1];
|
|
622
619
|
if (F(n, e, r)) return [e, !1];
|
|
623
620
|
const a = (l) => {
|
|
@@ -693,7 +690,7 @@ function w(n, e) {
|
|
|
693
690
|
function j(n, e, t) {
|
|
694
691
|
return F(n, e, t) ? [n.getProp(e, t), !0] : [e, !1];
|
|
695
692
|
}
|
|
696
|
-
function
|
|
693
|
+
function he(n, e) {
|
|
697
694
|
return v(n) && !!n[e];
|
|
698
695
|
}
|
|
699
696
|
function F(n, e, t) {
|
|
@@ -708,7 +705,7 @@ function F(n, e, t) {
|
|
|
708
705
|
)
|
|
709
706
|
);
|
|
710
707
|
}
|
|
711
|
-
class
|
|
708
|
+
class ve {
|
|
712
709
|
/** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
|
|
713
710
|
constructor(e, t) {
|
|
714
711
|
c(this, "context");
|
|
@@ -733,7 +730,7 @@ class we {
|
|
|
733
730
|
c(this, "_marshalPre", (e, t, r) => {
|
|
734
731
|
var s;
|
|
735
732
|
if (r !== "json")
|
|
736
|
-
return (s = this._register(e,
|
|
733
|
+
return (s = this._register(e, L(t), this._map)) == null ? void 0 : s[1];
|
|
737
734
|
});
|
|
738
735
|
c(this, "_marshalPreApply", (e, t, r) => {
|
|
739
736
|
const s = v(t) ? this._unwrap(t) : void 0;
|
|
@@ -774,7 +771,7 @@ class we {
|
|
|
774
771
|
if (typeof t != "undefined")
|
|
775
772
|
return t;
|
|
776
773
|
const [r] = this._wrapHandle(e);
|
|
777
|
-
return
|
|
774
|
+
return le(r != null ? r : e, {
|
|
778
775
|
ctx: this.context,
|
|
779
776
|
marshal: this._marshal,
|
|
780
777
|
find: this._unmarshalFind,
|
|
@@ -948,7 +945,7 @@ class we {
|
|
|
948
945
|
*/
|
|
949
946
|
expose(e) {
|
|
950
947
|
for (const [t, r] of Object.entries(e))
|
|
951
|
-
|
|
948
|
+
z(this._marshal(r), (s) => {
|
|
952
949
|
this.context.setProp(this.context.global, t, s);
|
|
953
950
|
});
|
|
954
951
|
}
|
|
@@ -972,7 +969,7 @@ class we {
|
|
|
972
969
|
register(e, t) {
|
|
973
970
|
if (this._registeredMap.has(e)) return;
|
|
974
971
|
const r = typeof t == "string" ? this._unwrapResult(this.context.evalCode(t)) : t;
|
|
975
|
-
|
|
972
|
+
this.context.sameValue(r, this.context.undefined) || (typeof t == "string" && this._registeredMapDispose.add(e), this._registeredMap.set(e, r));
|
|
976
973
|
}
|
|
977
974
|
/**
|
|
978
975
|
* Execute `register` methods for each pair.
|
|
@@ -1026,7 +1023,7 @@ class we {
|
|
|
1026
1023
|
}
|
|
1027
1024
|
_wrap(e) {
|
|
1028
1025
|
var t;
|
|
1029
|
-
return
|
|
1026
|
+
return de(
|
|
1030
1027
|
this.context,
|
|
1031
1028
|
e,
|
|
1032
1029
|
this._symbol,
|
|
@@ -1041,7 +1038,7 @@ class we {
|
|
|
1041
1038
|
}
|
|
1042
1039
|
_wrapHandle(e) {
|
|
1043
1040
|
var t;
|
|
1044
|
-
return
|
|
1041
|
+
return me(
|
|
1045
1042
|
this.context,
|
|
1046
1043
|
e,
|
|
1047
1044
|
this._symbol,
|
|
@@ -1056,18 +1053,17 @@ class we {
|
|
|
1056
1053
|
}
|
|
1057
1054
|
}
|
|
1058
1055
|
export {
|
|
1059
|
-
|
|
1056
|
+
ve as Arena,
|
|
1060
1057
|
O as VMMap,
|
|
1061
1058
|
y as call,
|
|
1062
|
-
|
|
1063
|
-
|
|
1059
|
+
be as complexity,
|
|
1060
|
+
_e as consumeAll,
|
|
1064
1061
|
I as defaultRegisteredObjects,
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
W as isHandleObject,
|
|
1062
|
+
Y as isES2015Class,
|
|
1063
|
+
J as isHandleObject,
|
|
1068
1064
|
v as isObject,
|
|
1069
|
-
|
|
1065
|
+
W as json,
|
|
1070
1066
|
R as marshal,
|
|
1071
|
-
|
|
1067
|
+
le as unmarshal,
|
|
1072
1068
|
E as walkObject
|
|
1073
1069
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
(function(m,v){typeof exports=="object"&&typeof module!="undefined"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(m=typeof globalThis!="undefined"?globalThis:m||self,v(m.QuickjsEmscriptenSync={}))})(this,(function(m){"use strict";var
|
|
1
|
+
(function(m,v){typeof exports=="object"&&typeof module!="undefined"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(m=typeof globalThis!="undefined"?globalThis:m||self,v(m.QuickjsEmscriptenSync={}))})(this,(function(m){"use strict";var be=Object.defineProperty;var ve=(m,v,j)=>v in m?be(m,v,{enumerable:!0,configurable:!0,writable:!0,value:j}):m[v]=j;var c=(m,v,j)=>ve(m,typeof v!="symbol"?v+"":v,j);const v=n=>{const e=new j(n);return new Proxy(n,{get(t,r,s){return r in e?e[r]:Reflect.get(t,r,s)}})};class j{constructor(e){c(this,"context");c(this,"fn");c(this,"fnGenerator");c(this,"fnCounter",Number.MIN_SAFE_INTEGER);c(this,"fnMap",new Map);c(this,"newFunction",(e,t)=>{this.fnCounter++;const r=this.fnCounter;return this.fnMap.set(r,t),this.context.unwrapResult(this.context.callFunction(this.fnGenerator,this.context.undefined,this.context.newString(e),this.context.newNumber(t.length),this.context.newNumber(r),this.fn))});this.context=e;const t=this.fnMap;this.fn=this.context.newFunction("",function(r,...s){const o=e.getNumber(r),i=t.get(o);if(!i)throw new Error("function is not registered");return i.call(this,...s)}),this.fnGenerator=e.unwrapResult(e.evalCode(`((name, length, id, f) => {
|
|
2
2
|
const fn = function(...args) {
|
|
3
3
|
return f.call(this, id, ...args);
|
|
4
4
|
};
|
|
5
5
|
fn.name = name;
|
|
6
6
|
fn.length = length;
|
|
7
7
|
return fn;
|
|
8
|
-
})`))}disposeEx(){this.fnGenerator.dispose(),this.fn.dispose()}}const k=[[Symbol,"Symbol"],[Symbol.prototype,"Symbol.prototype"],[Object,"Object"],[Object.prototype,"Object.prototype"],[Function,"Function"],[Function.prototype,"Function.prototype"],[Boolean,"Boolean"],[Boolean.prototype,"Boolean.prototype"],[Array,"Array"],[Array.prototype,"Array.prototype"],[Error,"Error"],[Error.prototype,"Error.prototype"],[EvalError,"EvalError"],[EvalError.prototype,"EvalError.prototype"],[RangeError,"RangeError"],[RangeError.prototype,"RangeError.prototype"],[ReferenceError,"ReferenceError"],[ReferenceError.prototype,"ReferenceError.prototype"],[SyntaxError,"SyntaxError"],[SyntaxError.prototype,"SyntaxError.prototype"],[TypeError,"TypeError"],[TypeError.prototype,"TypeError.prototype"],[URIError,"URIError"],[URIError.prototype,"URIError.prototype"],...Object.getOwnPropertyNames(Symbol).filter(n=>typeof Symbol[n]=="symbol").map(n=>[Symbol[n],`Symbol.${n}`])];function
|
|
8
|
+
})`))}disposeEx(){this.fnGenerator.dispose(),this.fn.dispose()}}const k=[[Symbol,"Symbol"],[Symbol.prototype,"Symbol.prototype"],[Object,"Object"],[Object.prototype,"Object.prototype"],[Function,"Function"],[Function.prototype,"Function.prototype"],[Boolean,"Boolean"],[Boolean.prototype,"Boolean.prototype"],[Array,"Array"],[Array.prototype,"Array.prototype"],[Error,"Error"],[Error.prototype,"Error.prototype"],[EvalError,"EvalError"],[EvalError.prototype,"EvalError.prototype"],[RangeError,"RangeError"],[RangeError.prototype,"RangeError.prototype"],[ReferenceError,"ReferenceError"],[ReferenceError.prototype,"ReferenceError.prototype"],[SyntaxError,"SyntaxError"],[SyntaxError.prototype,"SyntaxError.prototype"],[TypeError,"TypeError"],[TypeError.prototype,"TypeError.prototype"],[URIError,"URIError"],[URIError.prototype,"URIError.prototype"],...Object.getOwnPropertyNames(Symbol).filter(n=>typeof Symbol[n]=="symbol").map(n=>[Symbol[n],`Symbol.${n}`])];function G(n,e){const t=n.unwrapResult(n.evalCode(e)),r=(o,...i)=>n.unwrapResult(n.callFunction(t,o!=null?o:n.undefined,...i)),s=()=>t.dispose();return r.dispose=s,r[Symbol.dispose]=s,r.alive=!0,Object.defineProperty(r,"alive",{get:()=>t.alive}),r}function _(n,e,t,...r){const s=G(n,e);try{return s(t,...r)}finally{s.dispose()}}function J(n,e,t){return n.dump(_(n,"(a, b) => a instanceof b",void 0,e,t))}function C(n,e){return n.dump(_(n,'a => typeof a === "object" && a !== null || typeof a === "function"',void 0,e))}function F(n,e){const t=JSON.stringify(e);return t?_(n,"JSON.parse",void 0,n.newString(t)):n.undefined}function W(n,e){try{return e(n)}finally{for(const t of n)t.alive&&t.dispose()}}function z([n,e],t){try{return t(n)}finally{e&&n.dispose()}}function S(n,e){try{return e(...n.map(t=>t[0]))}finally{for(const[t,r]of n)r&&t.dispose()}}function $(n){return"handle"in n}function V(n){return $(n)?n.handle:n}function L(n,e,t,r){var o;let s;for(const i of r)if(s=i(e,n),s)break;return s?(o=t(e,s))!=null?o:s:void 0}function Q(n,e){return typeof n!="symbol"?void 0:_(e,"d => Symbol(d)",void 0,n.description?e.newString(n.description):e.undefined)}function q(n,e){return n instanceof Date?_(e,"d => new Date(d)",void 0,e.newNumber(n.getTime())):void 0}const X=[Q,q];function H(n){return typeof n=="function"&&/^class\s/.test(Function.prototype.toString.call(n))}function g(n){return typeof n=="function"||typeof n=="object"&&n!==null}function O(n,e){const t=new Set,r=s=>{if(!(!g(s)||t.has(s)||(e==null?void 0:e(s,t))===!1)){if(t.add(s),Array.isArray(s)){for(const o of s)r(o);return}if(typeof s=="object"){const o=Object.getPrototypeOf(s);o&&o!==Object.prototype&&r(o)}for(const o of Object.values(Object.getOwnPropertyDescriptors(s)))"value"in o&&r(o.value),"get"in o&&r(o.get),"set"in o&&r(o.set)}};return r(n),t}function Y(n,e){return O(n,e?(t,r)=>r.size<e:void 0).size}function Z(){let n=()=>{},e=()=>{};return{promise:new Promise((r,s)=>{n=r,e=s}),resolve:n,reject:e}}function N(n,e,t,r){const s=n.newObject(),o=(a,u)=>{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);n.newObject().consume(h=>{Object.entries(u).forEach(([y,b])=>{const w=y==="value"?l:y==="get"?f:y==="set"?d:b?n.true:n.false;w&&n.setProp(h,y,w)}),n.setProp(s,p,h)})},i=Object.getOwnPropertyDescriptors(e);Object.entries(i).forEach(([a,u])=>o(a,u)),Object.getOwnPropertySymbols(i).forEach(a=>o(a,i[a])),_(n,"Object.defineProperties",void 0,t,s).dispose(),s.dispose()}function K(n,e,t,r,s,o){var u;if(typeof e!="function")return;const i=n.newFunction(e.name,function(...p){const l=r(this),f=p.map(d=>r(d));if(H(e)&&g(l)){const d=new e(...f);return Object.entries(d).forEach(([h,y])=>{n.setProp(this,h,t(y))}),this}return t(o?o(e,l,f):e.apply(l,f))}).consume(p=>_(n,`Cls => {
|
|
9
9
|
const fn = function(...args) { return Cls.apply(this, args); };
|
|
10
10
|
fn.name = Cls.name;
|
|
11
11
|
fn.length = Cls.length;
|
|
12
12
|
return fn;
|
|
13
|
-
}`,void 0,p)),a=(u=s(e,i))!=null?u:i;return
|
|
13
|
+
}`,void 0,p)),a=(u=s(e,i))!=null?u:i;return N(n,e,i,t),a}function x(n,e,t){var o;const r=F(n,e);return(o=t(e,r))!=null?o:r}function ee(n,e,t,r){var u;if(typeof e!="object"||e===null)return;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;return a&&_(n,"Object.setPrototypeOf",void 0,o,a).dispose(),N(n,e,s,t),o}function te(n,e){switch(typeof e){case"undefined":return n.undefined;case"number":return n.newNumber(e);case"string":return n.newString(e);case"boolean":return e?n.true:n.false;case"object":return e===null?n.null:void 0}}function ne(n,e,t,r){var o;if(!(e instanceof Promise))return;const s=n.newPromise();return e.then(i=>s.resolve(t(i)),i=>s.reject(t(i))),(o=r(e,s))!=null?o:s.handle}function E(n,e){var l,f,d,h,y;const{ctx:t,unmarshal:r,isMarshalable:s,find:o,pre:i}=e;{const b=te(t,n);if(b)return b}{const b=o(n);if(b)return b}const a=s==null?void 0:s(n);if(a===!1)return t.undefined;const u=(b,w)=>i(b,w,a);if(a==="json")return x(t,n,u);const p=b=>E(b,e);return(y=(h=(d=(f=L(t,n,u,[...X,...(l=e.custom)!=null?l:[]]))!=null?f:ne(t,n,p,u))!=null?d:K(t,n,p,r,u,e.preApply))!=null?h:ee(t,n,p,u))!=null?y:t.undefined}function re(n,e,t,r){var o;let s;for(const i of r)if(s=i(e,n),s)break;return s?(o=t(s,e))!=null?o:s:void 0}function se(n,e){if(e.typeof(n)!=="symbol")return;const t=e.getString(e.getProp(n,"description"));return Symbol(t)}function oe(n,e){if(!e.dump(_(e,"a => a instanceof Date",void 0,n)))return;const t=e.getNumber(_(e,"a => a.getTime()",void 0,n));return new Date(t)}const ie=[se,oe];function A(n,e,t,r){n.newFunction("",(s,o)=>{const[i]=r(s);if(typeof i!="string"&&typeof i!="number"&&typeof i!="symbol")return;const a=[["value",!0],["get",!0],["set",!0],["configurable",!1],["enumerable",!1],["writable",!1]].reduce((u,[p,l])=>{const f=n.getProp(o,p),d=n.typeof(f);if(d==="undefined")return u;if(!l&&d==="boolean")return u[p]=n.dump(n.getProp(o,p)),u;const[h,y]=r(f);return y&&f.dispose(),u[p]=h,u},{});Object.defineProperty(t,i,a)}).consume(s=>{_(n,`(o, fn) => {
|
|
14
14
|
const descs = Object.getOwnPropertyDescriptors(o);
|
|
15
15
|
Object.entries(descs).forEach(([k, v]) => fn(k, v));
|
|
16
16
|
Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));
|
|
17
|
-
}`,void 0,e,s).dispose()})}function
|
|
17
|
+
}`,void 0,e,s).dispose()})}function ue(n,e,t,r,s){var a;if(n.typeof(e)!=="function")return;const o=function(...u){return S([t(this),...u.map(p=>t(p))],(p,...l)=>{if(new.target){const[y]=r(_(n,"(Cls, ...args) => new Cls(...args)",p,e,...l));return Object.defineProperties(this,Object.getOwnPropertyDescriptors(y)),this}const f=n.unwrapResult(n.callFunction(e,p,...l)),[d,h]=r(f);return h&&f.dispose(),d})},i=(a=s(o,e))!=null?a:o;return A(n,e,o,r),i}function ae(n,e,t,r){var a;if(n.typeof(e)!=="object"||n.unwrapResult(n.evalCode("o => o === null")).consume(u=>n.dump(n.unwrapResult(n.callFunction(u,n.undefined,e)))))return;const s=_(n,"Array.isArray",void 0,e).consume(u=>n.dump(u))?[]:{},o=(a=r(s,e))!=null?a:s,i=_(n,`o => {
|
|
18
18
|
const p = Object.getPrototypeOf(o);
|
|
19
19
|
return !p || p === Object.prototype || p === Array.prototype ? undefined : p;
|
|
20
|
-
}`,void 0,e).consume(u=>{if(n.typeof(u)==="undefined")return;const[p]=t(u);return p});return typeof i=="object"&&Object.setPrototypeOf(o,i),
|
|
20
|
+
}`,void 0,e).consume(u=>{if(n.typeof(u)==="undefined")return;const[p]=t(u);return p});return typeof i=="object"&&Object.setPrototypeOf(o,i),A(n,e,s,t),o}function pe(n,e){const t=n.typeof(e);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]}function fe(n,e,t,r){var p;if(!ce(n,e))return;const s=Z(),[o,i]=t(s.resolve),[a,u]=t(s.reject);return _(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}function ce(n,e){return e.owner?n.unwrapResult(n.evalCode("Promise")).consume(t=>e.owner?J(n,e,t):!1):!1}function D(n,e){const[t]=B(n,e);return t}function B(n,e){var u,p,l,f;const{ctx:t,marshal:r,find:s,pre:o}=e;{const[d,h]=pe(t,n);if(h)return[d,!1]}{const d=s(n);if(d)return[d,!0]}const i=d=>B(d,e);return[(f=(l=(p=re(t,n,o,[...ie,...(u=e.custom)!=null?u:[]]))!=null?p:fe(t,n,r,o))!=null?l:ue(t,n,r,i,o))!=null?f:ae(t,n,i,o),!1]}class M{constructor(e){c(this,"ctx");c(this,"_map1",new Map);c(this,"_map2",new Map);c(this,"_map3",new Map);c(this,"_map4",new Map);c(this,"_counterMap",new Map);c(this,"_disposables",new Set);c(this,"_mapGet");c(this,"_mapSet");c(this,"_mapDelete");c(this,"_mapClear");c(this,"_counter",Number.MIN_SAFE_INTEGER);this.ctx=e;const t=e.unwrapResult(e.evalCode(`() => {
|
|
21
21
|
const mapSym = new Map();
|
|
22
22
|
let map = new WeakMap();
|
|
23
23
|
let map2 = new WeakMap();
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
map2 = new WeakMap();
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
}`)).consume(r=>this._call(r,void 0));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)}set(e,t,r,s){var a;if(!t.alive||s&&!s.alive)return!1;const o=(a=this.get(e))!=null?a:this.get(r);if(o)return o===t||o===s;const i=this._counter++;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=>{this._call(this._mapSet,void 0,t,u,s!=null?s:this.ctx.undefined)}),!0}merge(e){if(e)for(const t of e)t&&t[1]&&this.set(t[0],t[1],t[2],t[3])}get(e){var s;const t=(s=this._map1.get(e))!=null?s:this._map2.get(e),r=typeof t=="number"?this._map3.get(t):void 0;if(r){if(!r.alive){this.delete(e);return}return r}}getByHandle(e){if(e.alive)return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet,void 0,e)))}has(e){return!!this.get(e)}hasHandle(e){return typeof this.getByHandle(e)!="undefined"}keys(){return this._map1.keys()}delete(e,t){var i;const r=(i=this._map1.get(e))!=null?i:this._map2.get(e);if(typeof r=="undefined")return;const s=this._map3.get(r),o=this._map4.get(r);this._call(this._mapDelete,void 0,...[s,o].filter(a=>!!(a!=null&&a.alive))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(r),this._map4.delete(r);for(const[a,u]of this._map1)if(u===r){this._map1.delete(a);break}for(const[a,u]of this._map2)if(u===r){this._map2.delete(a);break}for(const[a,u]of this._counterMap)if(u===e){this._counterMap.delete(a);break}t&&(s!=null&&s.alive&&s.dispose(),o!=null&&o.alive&&o.dispose())}deleteByHandle(e,t){const r=this.getByHandle(e);typeof r!="undefined"&&this.delete(r,t)}clear(){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)}dispose(){for(const e of this._disposables.values())e.alive&&e.dispose();for(const e of this._map3.values())e.alive&&e.dispose();for(const e of this._map4.values())e.alive&&e.dispose();this._disposables.clear(),this.clear()}get size(){return this._map1.size}[Symbol.iterator](){const e=this._map1.keys();return{next:()=>{for(;;){const t=e.next();if(t.done)return{value:void 0,done:!0};const r=this._map1.get(t.value);if(typeof r=="undefined")continue;const s=this._map3.get(r),o=this._map4.get(r);if(!s)continue;const i=this._get2(r);return{value:[t.value,s,i,o],done:!1}}}}}_get2(e){for(const[t,r]of this._map2)if(r===e)return t}_call(e,t,...r){return this.ctx.unwrapResult(this.ctx.callFunction(e,typeof t=="undefined"?this.ctx.undefined:t,...r))}}function
|
|
43
|
+
}`)).consume(r=>this._call(r,void 0));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)}set(e,t,r,s){var a;if(!t.alive||s&&!s.alive)return!1;const o=(a=this.get(e))!=null?a:this.get(r);if(o)return o===t||o===s;const i=this._counter++;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=>{this._call(this._mapSet,void 0,t,u,s!=null?s:this.ctx.undefined)}),!0}merge(e){if(e)for(const t of e)t&&t[1]&&this.set(t[0],t[1],t[2],t[3])}get(e){var s;const t=(s=this._map1.get(e))!=null?s:this._map2.get(e),r=typeof t=="number"?this._map3.get(t):void 0;if(r){if(!r.alive){this.delete(e);return}return r}}getByHandle(e){if(e.alive)return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet,void 0,e)))}has(e){return!!this.get(e)}hasHandle(e){return typeof this.getByHandle(e)!="undefined"}keys(){return this._map1.keys()}delete(e,t){var i;const r=(i=this._map1.get(e))!=null?i:this._map2.get(e);if(typeof r=="undefined")return;const s=this._map3.get(r),o=this._map4.get(r);this._call(this._mapDelete,void 0,...[s,o].filter(a=>!!(a!=null&&a.alive))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(r),this._map4.delete(r);for(const[a,u]of this._map1)if(u===r){this._map1.delete(a);break}for(const[a,u]of this._map2)if(u===r){this._map2.delete(a);break}for(const[a,u]of this._counterMap)if(u===e){this._counterMap.delete(a);break}t&&(s!=null&&s.alive&&s.dispose(),o!=null&&o.alive&&o.dispose())}deleteByHandle(e,t){const r=this.getByHandle(e);typeof r!="undefined"&&this.delete(r,t)}clear(){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)}dispose(){for(const e of this._disposables.values())e.alive&&e.dispose();for(const e of this._map3.values())e.alive&&e.dispose();for(const e of this._map4.values())e.alive&&e.dispose();this._disposables.clear(),this.clear()}get size(){return this._map1.size}[Symbol.iterator](){const e=this._map1.keys();return{next:()=>{for(;;){const t=e.next();if(t.done)return{value:void 0,done:!0};const r=this._map1.get(t.value);if(typeof r=="undefined")continue;const s=this._map3.get(r),o=this._map4.get(r);if(!s)continue;const i=this._get2(r);return{value:[t.value,s,i,o],done:!1}}}}}_get2(e){for(const[t,r]of this._map2)if(r===e)return t}_call(e,t,...r){return this.ctx.unwrapResult(this.ctx.callFunction(e,typeof t=="undefined"?this.ctx.undefined:t,...r))}}function le(n,e,t,r,s,o,i){if(!g(e)||e instanceof Promise||e instanceof Date||i&&!i(e))return;if(me(e,t))return e;const a=new Proxy(e,{get(u,p){return p===t?u:Reflect.get(u,p)},set(u,p,l,f){var y;const d=P(l,t),h=(y=o==null?void 0:o(f))!=null?y:"host";return h!=="vm"&&!Reflect.set(u,p,d,f)||h==="host"||!n.alive||S([s(f),s(p),s(d)],(b,w,U)=>{const[I,ye]=R(n,b,r);ye?I.consume(_e=>n.setProp(_e,w,U)):n.setProp(I,w,U)}),!0},deleteProperty(u,p){var f;const l=(f=o==null?void 0:o(a))!=null?f:"host";return S([s(a),s(p)],(d,h)=>{const[y,b]=R(n,d,r);if(l==="vm"||Reflect.deleteProperty(u,p)){if(l==="host"||!n.alive)return!0;b?y.consume(w=>_(n,"(a, b) => delete a[b]",void 0,w,h)):_(n,"(a, b) => delete a[b]",void 0,y,h)}return!0})}});return a}function de(n,e,t,r,s,o,i){if(!C(n,e)||i&&!i(e,n))return[void 0,!1];if(T(n,e,r))return[e,!1];const a=l=>{const f=o==null?void 0:o(s(l));return typeof f=="string"?n.newString(f):n.undefined},u=(l,f,d)=>{const h=s(l);if(!h)return;const y=s(f);if(y==="__proto__")return;const b=s(d);P(h,t)[y]=b},p=(l,f)=>{const d=s(l);if(!d)return;const h=s(f);delete P(d,t)[h]};return n.newFunction("proxyFuncs",(l,...f)=>{switch(n.getNumber(l)){case 1:return a(f[0]);case 2:return u(f[0],f[1],f[2]);case 3:return p(f[0],f[1])}return n.undefined}).consume(l=>[_(n,`(target, sym, proxyFuncs) => {
|
|
44
44
|
const rec = new Proxy(target, {
|
|
45
45
|
get(obj, key, receiver) {
|
|
46
46
|
return key === sym ? obj : Reflect.get(obj, key, receiver)
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
return rec;
|
|
71
|
-
}`,void 0,e,r,l),!0])}function P(n,e){var t;return g(n)&&(t=n[e])!=null?t:n}function R(n,e,t){return
|
|
71
|
+
}`,void 0,e,r,l),!0])}function P(n,e){var t;return g(n)&&(t=n[e])!=null?t:n}function R(n,e,t){return T(n,e,t)?[n.getProp(e,t),!0]:[e,!1]}function me(n,e){return g(n)&&!!n[e]}function T(n,e,t){return!!n.dump(_(n,'(a, s) => (a instanceof Promise) || (a instanceof Date) || (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',void 0,e,t))}class he{constructor(e,t){c(this,"context");c(this,"_map");c(this,"_registeredMap");c(this,"_registeredMapDispose",new Set);c(this,"_sync",new Set);c(this,"_temporalSync",new Set);c(this,"_symbol",Symbol());c(this,"_symbolHandle");c(this,"_options");c(this,"_isMarshalable",e=>{var r,s;const t=(r=this._options)==null?void 0:r.isMarshalable;return(s=typeof t=="function"?t(this._unwrap(e)):t)!=null?s:"json"});c(this,"_marshalFind",e=>{var s,o,i;const t=this._unwrap(e);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});c(this,"_marshalPre",(e,t,r)=>{var s;if(r!=="json")return(s=this._register(e,V(t),this._map))==null?void 0:s[1]});c(this,"_marshalPreApply",(e,t,r)=>{const s=g(t)?this._unwrap(t):void 0;s&&this._temporalSync.add(s);try{return e.apply(t,r)}finally{s&&this._temporalSync.delete(s)}});c(this,"_marshal",e=>{var s,o;const t=this._registeredMap.get(e);if(t)return[t,!1];const r=E((s=this._wrap(e))!=null?s:e,{ctx:this.context,unmarshal:this._unmarshal,isMarshalable:this._isMarshalable,find:this._marshalFind,pre:this._marshalPre,preApply:this._marshalPreApply,custom:(o=this._options)==null?void 0:o.customMarshaller});return[r,!this._map.hasHandle(r)]});c(this,"_preUnmarshal",(e,t)=>{var r;return(r=this._register(e,t,void 0,!0))==null?void 0:r[0]});c(this,"_unmarshalFind",e=>{var t;return(t=this._registeredMap.getByHandle(e))!=null?t:this._map.getByHandle(e)});c(this,"_unmarshal",e=>{var s;const t=this._registeredMap.getByHandle(e);if(typeof t!="undefined")return t;const[r]=this._wrapHandle(e);return D(r!=null?r:e,{ctx:this.context,marshal:this._marshal,find:this._unmarshalFind,pre:this._preUnmarshal,custom:(s=this._options)==null?void 0:s.customUnmarshaller})});c(this,"_syncMode",e=>{const t=this._unwrap(e);return this._sync.has(t)||this._temporalSync.has(t)?"both":void 0});c(this,"_unwrapIfNotSynced",e=>{const t=this._unwrap(e);return t instanceof Promise||!this._sync.has(t)?t:e});var r;t!=null&&t.compat&&!("runtime"in e)&&(e.runtime={hasPendingJob:()=>e.hasPendingJob(),executePendingJobs:s=>e.executePendingJobs(s)}),this.context=t!=null&&t.experimentalContextEx?v(e):e,this._options=t,this._symbolHandle=e.unwrapResult(e.evalCode("Symbol()")),this._map=new M(e),this._registeredMap=new M(e),this.registerAll((r=t==null?void 0:t.registeredObjects)!=null?r:k)}dispose(){var e,t;this._map.dispose(),this._registeredMap.dispose(),this._symbolHandle.dispose(),(t=(e=this.context).disposeEx)==null||t.call(e)}evalCode(e){const t=this.context.evalCode(e);return this._unwrapResultAndUnmarshal(t)}evalModule(e,t="module.js"){const r=this.context.evalCode(e,t,{type:"module"});return this._unwrapResultAndUnmarshal(r)}executePendingJobs(e){const t=this.context.runtime.executePendingJobs(e);if("value"in t)return t.value;throw this._unwrapIfNotSynced(t.error.consume(this._unmarshal))}setMemoryLimit(e){this.context.runtime.setMemoryLimit(e)}setMaxStackSize(e){this.context.runtime.setMaxStackSize(e)}getMemoryUsage(){const e=this.context.runtime.computeMemoryUsage();try{return this.context.dump(e)}finally{e.dispose()}}dumpMemoryUsage(){return this.context.runtime.dumpMemoryUsage()}expose(e){for(const[t,r]of Object.entries(e))z(this._marshal(r),s=>{this.context.setProp(this.context.global,t,s)})}sync(e){const t=this._wrap(e);return typeof t=="undefined"?e:(O(t,r=>{const s=this._unwrap(r);this._sync.add(s)}),t)}register(e,t){if(this._registeredMap.has(e))return;const r=typeof t=="string"?this._unwrapResult(this.context.evalCode(t)):t;this.context.sameValue(r,this.context.undefined)||(typeof t=="string"&&this._registeredMapDispose.add(e),this._registeredMap.set(e,r))}registerAll(e){for(const[t,r]of e)this.register(t,r)}unregister(e,t){this._registeredMap.delete(e,this._registeredMapDispose.has(e)||t),this._registeredMapDispose.delete(e)}unregisterAll(e,t){for(const r of e)this.unregister(r,t)}startSync(e){if(!g(e))return;const t=this._unwrap(e);this._sync.add(t)}endSync(e){this._sync.delete(this._unwrap(e))}_unwrapResult(e){if("value"in e)return e.value;throw this._unwrapIfNotSynced(e.error.consume(this._unmarshal))}_unwrapResultAndUnmarshal(e){if(e)return this._unwrapIfNotSynced(this._unwrapResult(e).consume(this._unmarshal))}_register(e,t,r=this._map,s){if(this._registeredMap.has(e)||this._registeredMap.hasHandle(t))return;let o=this._wrap(e);const[i]=this._wrapHandle(t),a=e instanceof Promise;if(!i||!o&&!a)return;a&&(o=e);const u=this._unwrap(e),[p,l]=this._unwrapHandle(t);if(r.set(o,i,u,p))s&&this._sync.add(u);else throw l&&p.dispose(),new Error("already registered");return[o,i]}_wrap(e){var t;return le(this.context,e,this._symbol,this._symbolHandle,this._marshal,this._syncMode,(t=this._options)==null?void 0:t.isWrappable)}_unwrap(e){return P(e,this._symbol)}_wrapHandle(e){var t;return de(this.context,e,this._symbol,this._symbolHandle,this._unmarshal,this._syncMode,(t=this._options)==null?void 0:t.isHandleWrappable)}_unwrapHandle(e){return R(this.context,e,this._symbolHandle)}}m.Arena=he,m.VMMap=M,m.call=_,m.complexity=Y,m.consumeAll=W,m.defaultRegisteredObjects=k,m.isES2015Class=H,m.isHandleObject=C,m.isObject=g,m.json=F,m.marshal=E,m.unmarshal=D,m.walkObject=O,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickjs-emscripten-sync",
|
|
3
3
|
"author": "rot1024",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./dist/quickjs-emscripten-sync.umd.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"eslint": "^8.57.1",
|
|
36
36
|
"eslint-config-reearth": "^0.2.1",
|
|
37
37
|
"prettier": "^2.8.8",
|
|
38
|
-
"quickjs-emscripten": "^0.
|
|
38
|
+
"quickjs-emscripten": "^0.31.0",
|
|
39
39
|
"typescript": "^5.7.2",
|
|
40
40
|
"vite": "^6.0.3",
|
|
41
41
|
"vite-plugin-dts": "^4.3.0",
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ import marshal from "./marshal";
|
|
|
13
13
|
import unmarshal from "./unmarshal";
|
|
14
14
|
import { complexity, isES2015Class, isObject, walkObject } from "./util";
|
|
15
15
|
import VMMap from "./vmmap";
|
|
16
|
-
import { call,
|
|
16
|
+
import { call, isHandleObject, json, consumeAll, mayConsume, handleFrom } from "./vmutil";
|
|
17
17
|
import { wrap, wrapHandle, unwrap, unwrapHandle, Wrapped } from "./wrapper";
|
|
18
18
|
|
|
19
19
|
export {
|
|
@@ -26,7 +26,6 @@ export {
|
|
|
26
26
|
isObject,
|
|
27
27
|
walkObject,
|
|
28
28
|
call,
|
|
29
|
-
eq,
|
|
30
29
|
isHandleObject,
|
|
31
30
|
json,
|
|
32
31
|
consumeAll,
|
|
@@ -309,7 +308,7 @@ export class Arena {
|
|
|
309
308
|
typeof handleOrCode === "string"
|
|
310
309
|
? this._unwrapResult(this.context.evalCode(handleOrCode))
|
|
311
310
|
: handleOrCode;
|
|
312
|
-
if (
|
|
311
|
+
if (this.context.sameValue(handle, this.context.undefined)) return;
|
|
313
312
|
if (typeof handleOrCode === "string") {
|
|
314
313
|
this._registeredMapDispose.add(target);
|
|
315
314
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getQuickJS, QuickJSHandle } from "quickjs-emscripten";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { json,
|
|
4
|
+
import { json, call } from "../vmutil";
|
|
5
5
|
|
|
6
6
|
import marshalFunction from "./function";
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ test("normal func", async () => {
|
|
|
9
9
|
const ctx = (await getQuickJS()).newContext();
|
|
10
10
|
|
|
11
11
|
const marshal = vi.fn(v => json(ctx, v));
|
|
12
|
-
const unmarshal = vi.fn(v => (
|
|
12
|
+
const unmarshal = vi.fn(v => (ctx.sameValue(v, ctx.global) ? undefined : ctx.dump(v)));
|
|
13
13
|
const preMarshal = vi.fn((_, a) => a);
|
|
14
14
|
const innerfn = vi.fn((..._args: any[]) => "hoge");
|
|
15
15
|
const fn = (...args: any[]) => innerfn(...args);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getQuickJS } from "quickjs-emscripten";
|
|
2
2
|
import { expect, test } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { eq } from "../vmutil";
|
|
5
4
|
|
|
6
5
|
import marshalPrimitive from "./primitive";
|
|
7
6
|
|
|
@@ -12,12 +11,11 @@ test("works", async () => {
|
|
|
12
11
|
expect(marshalPrimitive(ctx, null)).toBe(ctx.null);
|
|
13
12
|
expect(marshalPrimitive(ctx, false)).toBe(ctx.false);
|
|
14
13
|
expect(marshalPrimitive(ctx, true)).toBe(ctx.true);
|
|
15
|
-
expect(
|
|
16
|
-
expect(
|
|
17
|
-
expect(
|
|
14
|
+
expect(ctx.sameValue(marshalPrimitive(ctx, 1) ?? ctx.undefined, ctx.newNumber(1))).toBe(true);
|
|
15
|
+
expect(ctx.sameValue(marshalPrimitive(ctx, -100) ?? ctx.undefined, ctx.newNumber(-100))).toBe(true);
|
|
16
|
+
expect(ctx.sameValue(marshalPrimitive(ctx, "hoge") ?? ctx.undefined, ctx.newString("hoge"))).toBe(true);
|
|
18
17
|
// expect(
|
|
19
|
-
//
|
|
20
|
-
// ctx,
|
|
18
|
+
// ctx.sameValue(
|
|
21
19
|
// marshalPrimitive(ctx, BigInt(1)) ?? ctx.undefined,
|
|
22
20
|
// ctx.unwrapResult(ctx.evalCode("BigInt(1)"))
|
|
23
21
|
// )
|
package/src/vmutil.test.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
fn,
|
|
6
6
|
call,
|
|
7
7
|
consumeAll,
|
|
8
|
-
eq,
|
|
9
8
|
instanceOf,
|
|
10
9
|
isHandleObject,
|
|
11
10
|
json,
|
|
@@ -57,8 +56,8 @@ test("eq", async () => {
|
|
|
57
56
|
const math2 = ctx.unwrapResult(ctx.evalCode("Math"));
|
|
58
57
|
const obj = ctx.newObject();
|
|
59
58
|
expect(math1 === math2).toBe(false);
|
|
60
|
-
expect(
|
|
61
|
-
expect(
|
|
59
|
+
expect(ctx.sameValue(math1, math2)).toBe(true);
|
|
60
|
+
expect(ctx.sameValue(math1, obj)).toBe(false);
|
|
62
61
|
|
|
63
62
|
math1.dispose();
|
|
64
63
|
math2.dispose();
|
package/src/vmutil.ts
CHANGED
|
@@ -37,10 +37,6 @@ export function call(
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function eq(ctx: QuickJSContext, a: QuickJSHandle, b: QuickJSHandle): boolean {
|
|
41
|
-
return ctx.dump(call(ctx, "Object.is", undefined, a, b));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
export function instanceOf(ctx: QuickJSContext, a: QuickJSHandle, b: QuickJSHandle): boolean {
|
|
45
41
|
return ctx.dump(call(ctx, "(a, b) => a instanceof b", undefined, a, b));
|
|
46
42
|
}
|
package/src/wrapper.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QuickJSHandle, getQuickJS } from "quickjs-emscripten";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { call,
|
|
4
|
+
import { call, json } from "./vmutil";
|
|
5
5
|
import {
|
|
6
6
|
wrap,
|
|
7
7
|
unwrap,
|
|
@@ -183,7 +183,7 @@ test("wrapHandle, unwrapHandle, isHandleWrapped", async () => {
|
|
|
183
183
|
const [handle2, unwrapped2] = unwrapHandle(ctx, wrapped, proxyKeySymbolHandle);
|
|
184
184
|
expect(unwrapped2).toBe(true);
|
|
185
185
|
handle2.consume(h => {
|
|
186
|
-
expect(
|
|
186
|
+
expect(ctx.sameValue(handle, h)).toBe(true);
|
|
187
187
|
});
|
|
188
188
|
|
|
189
189
|
const [wrapped2] = wrapHandle(
|
|
@@ -214,7 +214,7 @@ test("wrapHandle without sync", async () => {
|
|
|
214
214
|
const proxyKeySymbol = Symbol();
|
|
215
215
|
const proxyKeySymbolHandle = ctx.unwrapResult(ctx.evalCode(`Symbol()`));
|
|
216
216
|
const unmarshal = vi.fn((h: QuickJSHandle) =>
|
|
217
|
-
wrapped &&
|
|
217
|
+
wrapped && ctx.sameValue(h, wrapped) ? target : ctx.dump(h),
|
|
218
218
|
);
|
|
219
219
|
const syncMode = vi.fn();
|
|
220
220
|
|
|
@@ -253,7 +253,7 @@ test("wrapHandle with both sync", async () => {
|
|
|
253
253
|
const proxyKeySymbol = Symbol();
|
|
254
254
|
const proxyKeySymbolHandle = ctx.unwrapResult(ctx.evalCode(`Symbol()`));
|
|
255
255
|
const unmarshal = vi.fn((h: QuickJSHandle) => {
|
|
256
|
-
return wrapped &&
|
|
256
|
+
return wrapped && ctx.sameValue(h, wrapped) ? target : ctx.dump(h);
|
|
257
257
|
});
|
|
258
258
|
const syncMode = vi.fn((): SyncMode => "both");
|
|
259
259
|
|
|
@@ -303,7 +303,7 @@ test("wrapHandle with host sync", async () => {
|
|
|
303
303
|
const proxyKeySymbol = Symbol();
|
|
304
304
|
const proxyKeySymbolHandle = ctx.unwrapResult(ctx.evalCode(`Symbol()`));
|
|
305
305
|
const unmarshal = vi.fn((handle: QuickJSHandle) =>
|
|
306
|
-
wrapped &&
|
|
306
|
+
wrapped && ctx.sameValue(handle, wrapped) ? target : ctx.dump(handle),
|
|
307
307
|
);
|
|
308
308
|
const syncMode = vi.fn((): SyncMode => "host");
|
|
309
309
|
|
|
@@ -352,7 +352,7 @@ test("wrap and wrapHandle", async () => {
|
|
|
352
352
|
false,
|
|
353
353
|
]);
|
|
354
354
|
const unmarshal = vi.fn((handle: QuickJSHandle) =>
|
|
355
|
-
wrappedHandle &&
|
|
355
|
+
wrappedHandle && ctx.sameValue(handle, wrappedHandle) ? wrapped : ctx.dump(handle),
|
|
356
356
|
);
|
|
357
357
|
const syncMode = vi.fn((): SyncMode => "both");
|
|
358
358
|
|