@kevinwang15/byok-ai 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/lib/AskAI.js +383 -0
- package/dist/lib/AskAIHistory.js +120 -0
- package/dist/lib/AskAIProvider.js +255 -0
- package/dist/lib/Markdown.js +111 -0
- package/dist/lib/PageElements.js +127 -0
- package/dist/lib/agent.js +223 -0
- package/dist/lib/answer-components.js +49 -0
- package/dist/lib/connection.d.ts +15 -0
- package/dist/lib/connection.js +32 -0
- package/dist/lib/context.js +9 -0
- package/dist/lib/conversation-files.js +164 -0
- package/dist/lib/entries/agent.d.ts +9 -0
- package/dist/lib/entries/agent.js +5 -0
- package/dist/lib/entries/connection.d.ts +2 -0
- package/dist/lib/entries/connection.js +1 -0
- package/dist/lib/entries/script-engine.d.ts +3 -0
- package/dist/lib/entries/script-engine.js +5 -0
- package/dist/lib/history.js +16 -0
- package/dist/lib/images.js +79 -0
- package/dist/lib/index.d.ts +6 -2
- package/dist/lib/index.js +18 -2326
- package/dist/lib/local-storage.d.ts +8 -0
- package/dist/lib/local-storage.js +23 -0
- package/dist/lib/mcp-result.d.ts +4 -1
- package/dist/lib/mcp-result.js +18 -0
- package/dist/lib/mount.js +9 -0
- package/dist/lib/node_modules/@jitl/quickjs-ffi-types/dist/index.js +46 -0
- package/dist/lib/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.js +330 -0
- package/dist/lib/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.js +76 -0
- package/dist/lib/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.js +7 -0
- package/dist/lib/node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.js +1142 -0
- package/dist/lib/node_modules/quickjs-emscripten-core/dist/index.js +21 -0
- package/dist/lib/node_modules/quickjs-emscripten-core/dist/module-ES6BEMUI.js +1 -0
- package/dist/lib/page-context.js +185 -0
- package/dist/lib/page-picker.js +119 -0
- package/dist/lib/providers.js +84 -0
- package/dist/lib/rendering-context.js +4 -0
- package/dist/lib/sandbox.js +102 -0
- package/dist/lib/script-runner.js +26 -0
- package/dist/lib/script.js +9 -0
- package/dist/lib/storage.d.ts +0 -13
- package/dist/lib/storage.js +67 -0
- package/dist/lib/useAskAIImage.js +26 -0
- package/dist/lib/usePanelLayout.js +168 -0
- package/dist/lib/workspace-tools.js +182 -0
- package/package.json +14 -1
- /package/dist/lib/{sandbox-worker-BdFlhTIS.js → sandbox-worker.js} +0 -0
|
@@ -0,0 +1,1142 @@
|
|
|
1
|
+
import { EvalFlags as e, GetOwnPropertyNamesFlags as t, IntrinsicsFlags as n, IsEqualOp as r, JSPromiseStateEnum as i } from "../../@jitl/quickjs-ffi-types/dist/index.js";
|
|
2
|
+
// node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.mjs
|
|
3
|
+
var a = Object.defineProperty, o = (e, t) => {
|
|
4
|
+
for (var n in t) a(e, n, {
|
|
5
|
+
get: t[n],
|
|
6
|
+
enumerable: !0
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
function s(...e) {}
|
|
10
|
+
var c = {};
|
|
11
|
+
o(c, {
|
|
12
|
+
QuickJSAsyncifyError: () => p,
|
|
13
|
+
QuickJSAsyncifySuspended: () => m,
|
|
14
|
+
QuickJSEmptyGetOwnPropertyNames: () => y,
|
|
15
|
+
QuickJSEmscriptenModuleError: () => g,
|
|
16
|
+
QuickJSHostRefInvalid: () => x,
|
|
17
|
+
QuickJSHostRefRangeExceeded: () => b,
|
|
18
|
+
QuickJSMemoryLeakDetected: () => h,
|
|
19
|
+
QuickJSNotImplemented: () => f,
|
|
20
|
+
QuickJSPromisePending: () => v,
|
|
21
|
+
QuickJSUnknownIntrinsic: () => _,
|
|
22
|
+
QuickJSUnwrapError: () => l,
|
|
23
|
+
QuickJSUseAfterFree: () => d,
|
|
24
|
+
QuickJSWrongOwner: () => u
|
|
25
|
+
});
|
|
26
|
+
var l = class extends Error {
|
|
27
|
+
constructor(e, t) {
|
|
28
|
+
let n = typeof e == "object" && e && "message" in e ? String(e.message) : String(e);
|
|
29
|
+
super(n), this.cause = e, this.context = t, this.name = "QuickJSUnwrapError";
|
|
30
|
+
}
|
|
31
|
+
}, u = class extends Error {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments), this.name = "QuickJSWrongOwner";
|
|
34
|
+
}
|
|
35
|
+
}, d = class extends Error {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments), this.name = "QuickJSUseAfterFree";
|
|
38
|
+
}
|
|
39
|
+
}, f = class extends Error {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments), this.name = "QuickJSNotImplemented";
|
|
42
|
+
}
|
|
43
|
+
}, p = class extends Error {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments), this.name = "QuickJSAsyncifyError";
|
|
46
|
+
}
|
|
47
|
+
}, m = class extends Error {
|
|
48
|
+
constructor() {
|
|
49
|
+
super(...arguments), this.name = "QuickJSAsyncifySuspended";
|
|
50
|
+
}
|
|
51
|
+
}, h = class extends Error {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments), this.name = "QuickJSMemoryLeakDetected";
|
|
54
|
+
}
|
|
55
|
+
}, g = class extends Error {
|
|
56
|
+
constructor() {
|
|
57
|
+
super(...arguments), this.name = "QuickJSEmscriptenModuleError";
|
|
58
|
+
}
|
|
59
|
+
}, _ = class extends TypeError {
|
|
60
|
+
constructor() {
|
|
61
|
+
super(...arguments), this.name = "QuickJSUnknownIntrinsic";
|
|
62
|
+
}
|
|
63
|
+
}, v = class extends Error {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments), this.name = "QuickJSPromisePending";
|
|
66
|
+
}
|
|
67
|
+
}, y = class extends Error {
|
|
68
|
+
constructor() {
|
|
69
|
+
super(...arguments), this.name = "QuickJSEmptyGetOwnPropertyNames";
|
|
70
|
+
}
|
|
71
|
+
}, b = class extends Error {
|
|
72
|
+
constructor() {
|
|
73
|
+
super(...arguments), this.name = "QuickJSHostRefRangeExceeded";
|
|
74
|
+
}
|
|
75
|
+
}, x = class extends Error {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments), this.name = "QuickJSHostRefInvalid";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function* S(e) {
|
|
81
|
+
return yield e;
|
|
82
|
+
}
|
|
83
|
+
function ee(e) {
|
|
84
|
+
return S(T(e));
|
|
85
|
+
}
|
|
86
|
+
var C = S;
|
|
87
|
+
C.of = ee;
|
|
88
|
+
function w(e, t) {
|
|
89
|
+
return (...n) => T(t.call(e, C, ...n));
|
|
90
|
+
}
|
|
91
|
+
function te(e, t) {
|
|
92
|
+
return T(t.call(e, C));
|
|
93
|
+
}
|
|
94
|
+
function T(e) {
|
|
95
|
+
function t(n) {
|
|
96
|
+
return n.done ? n.value : n.value instanceof Promise ? n.value.then((n) => t(e.next(n)), (n) => t(e.throw(n))) : t(e.next(n.value));
|
|
97
|
+
}
|
|
98
|
+
return t(e.next());
|
|
99
|
+
}
|
|
100
|
+
var E = class {
|
|
101
|
+
[Symbol.dispose]() {
|
|
102
|
+
return this.dispose();
|
|
103
|
+
}
|
|
104
|
+
}, D = Symbol.dispose ?? Symbol.for("Symbol.dispose"), O = E.prototype;
|
|
105
|
+
O[D] || (O[D] = function() {
|
|
106
|
+
return this.dispose();
|
|
107
|
+
});
|
|
108
|
+
var k = class e extends E {
|
|
109
|
+
constructor(e, t, n, r) {
|
|
110
|
+
super(), this._value = e, this.copier = t, this.disposer = n, this._owner = r, this._alive = !0, this._constructorStack = void 0;
|
|
111
|
+
}
|
|
112
|
+
get alive() {
|
|
113
|
+
return this._alive;
|
|
114
|
+
}
|
|
115
|
+
get value() {
|
|
116
|
+
return this.assertAlive(), this._value;
|
|
117
|
+
}
|
|
118
|
+
get owner() {
|
|
119
|
+
return this._owner;
|
|
120
|
+
}
|
|
121
|
+
get dupable() {
|
|
122
|
+
return !!this.copier;
|
|
123
|
+
}
|
|
124
|
+
dup() {
|
|
125
|
+
if (this.assertAlive(), !this.copier) throw Error("Non-dupable lifetime");
|
|
126
|
+
return new e(this.copier(this._value), this.copier, this.disposer, this._owner);
|
|
127
|
+
}
|
|
128
|
+
consume(e) {
|
|
129
|
+
this.assertAlive();
|
|
130
|
+
let t = e(this);
|
|
131
|
+
return this.dispose(), t;
|
|
132
|
+
}
|
|
133
|
+
map(e) {
|
|
134
|
+
return this.assertAlive(), e(this);
|
|
135
|
+
}
|
|
136
|
+
tap(e) {
|
|
137
|
+
return e(this), this;
|
|
138
|
+
}
|
|
139
|
+
dispose() {
|
|
140
|
+
this.assertAlive(), this.disposer && this.disposer(this._value), this._alive = !1;
|
|
141
|
+
}
|
|
142
|
+
assertAlive() {
|
|
143
|
+
if (!this.alive) throw this._constructorStack ? new d(`Lifetime not alive
|
|
144
|
+
${this._constructorStack}
|
|
145
|
+
Lifetime used`) : new d("Lifetime not alive");
|
|
146
|
+
}
|
|
147
|
+
}, A = class extends k {
|
|
148
|
+
constructor(e, t) {
|
|
149
|
+
super(e, void 0, void 0, t);
|
|
150
|
+
}
|
|
151
|
+
get dupable() {
|
|
152
|
+
return !0;
|
|
153
|
+
}
|
|
154
|
+
dup() {
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
dispose() {}
|
|
158
|
+
}, j = class extends k {
|
|
159
|
+
constructor(e, t, n, r) {
|
|
160
|
+
super(e, t, n, r);
|
|
161
|
+
}
|
|
162
|
+
dispose() {
|
|
163
|
+
this._alive = !1;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
function M(e, t) {
|
|
167
|
+
let n;
|
|
168
|
+
try {
|
|
169
|
+
e.dispose();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
n = e;
|
|
172
|
+
}
|
|
173
|
+
if (t && n) throw Object.assign(t, {
|
|
174
|
+
message: `${t.message}
|
|
175
|
+
Then, failed to dispose scope: ${n.message}`,
|
|
176
|
+
disposeError: n
|
|
177
|
+
}), t;
|
|
178
|
+
if (t || n) throw t || n;
|
|
179
|
+
}
|
|
180
|
+
var N = class e extends E {
|
|
181
|
+
constructor() {
|
|
182
|
+
super(...arguments), this._disposables = new k(/* @__PURE__ */ new Set()), this.manage = (e) => (this._disposables.value.add(e), e);
|
|
183
|
+
}
|
|
184
|
+
static withScope(t) {
|
|
185
|
+
let n = new e(), r;
|
|
186
|
+
try {
|
|
187
|
+
return t(n);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
throw r = e, e;
|
|
190
|
+
} finally {
|
|
191
|
+
M(n, r);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
static withScopeMaybeAsync(t, n) {
|
|
195
|
+
return te(void 0, function* (r) {
|
|
196
|
+
let i = new e(), a;
|
|
197
|
+
try {
|
|
198
|
+
return yield* r.of(n.call(t, r, i));
|
|
199
|
+
} catch (e) {
|
|
200
|
+
throw a = e, e;
|
|
201
|
+
} finally {
|
|
202
|
+
M(i, a);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
static async withScopeAsync(t) {
|
|
207
|
+
let n = new e(), r;
|
|
208
|
+
try {
|
|
209
|
+
return await t(n);
|
|
210
|
+
} catch (e) {
|
|
211
|
+
throw r = e, e;
|
|
212
|
+
} finally {
|
|
213
|
+
M(n, r);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
get alive() {
|
|
217
|
+
return this._disposables.alive;
|
|
218
|
+
}
|
|
219
|
+
dispose() {
|
|
220
|
+
let e = Array.from(this._disposables.value.values()).reverse();
|
|
221
|
+
for (let t of e) t.alive && t.dispose();
|
|
222
|
+
this._disposables.dispose();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
function P(e) {
|
|
226
|
+
let t = e ? Array.from(e) : [];
|
|
227
|
+
function n() {
|
|
228
|
+
return t.forEach((e) => e.alive ? e.dispose() : void 0);
|
|
229
|
+
}
|
|
230
|
+
function r() {
|
|
231
|
+
return t.some((e) => e.alive);
|
|
232
|
+
}
|
|
233
|
+
return Object.defineProperty(t, D, {
|
|
234
|
+
configurable: !0,
|
|
235
|
+
enumerable: !1,
|
|
236
|
+
value: n
|
|
237
|
+
}), Object.defineProperty(t, "dispose", {
|
|
238
|
+
configurable: !0,
|
|
239
|
+
enumerable: !1,
|
|
240
|
+
value: n
|
|
241
|
+
}), Object.defineProperty(t, "alive", {
|
|
242
|
+
configurable: !0,
|
|
243
|
+
enumerable: !1,
|
|
244
|
+
get: r
|
|
245
|
+
}), t;
|
|
246
|
+
}
|
|
247
|
+
function F(e) {
|
|
248
|
+
return !!(e && (typeof e == "object" || typeof e == "function") && "alive" in e && typeof e.alive == "boolean" && "dispose" in e && typeof e.dispose == "function");
|
|
249
|
+
}
|
|
250
|
+
var I = class e extends E {
|
|
251
|
+
static success(e) {
|
|
252
|
+
return new L(e);
|
|
253
|
+
}
|
|
254
|
+
static fail(e, t) {
|
|
255
|
+
return new R(e, t);
|
|
256
|
+
}
|
|
257
|
+
static is(t) {
|
|
258
|
+
return t instanceof e;
|
|
259
|
+
}
|
|
260
|
+
}, L = class extends I {
|
|
261
|
+
constructor(e) {
|
|
262
|
+
super(), this.value = e;
|
|
263
|
+
}
|
|
264
|
+
get alive() {
|
|
265
|
+
return !F(this.value) || this.value.alive;
|
|
266
|
+
}
|
|
267
|
+
dispose() {
|
|
268
|
+
F(this.value) && this.value.dispose();
|
|
269
|
+
}
|
|
270
|
+
unwrap() {
|
|
271
|
+
return this.value;
|
|
272
|
+
}
|
|
273
|
+
unwrapOr(e) {
|
|
274
|
+
return this.value;
|
|
275
|
+
}
|
|
276
|
+
}, R = class extends I {
|
|
277
|
+
constructor(e, t) {
|
|
278
|
+
super(), this.error = e, this.onUnwrap = t;
|
|
279
|
+
}
|
|
280
|
+
get alive() {
|
|
281
|
+
return !F(this.error) || this.error.alive;
|
|
282
|
+
}
|
|
283
|
+
dispose() {
|
|
284
|
+
F(this.error) && this.error.dispose();
|
|
285
|
+
}
|
|
286
|
+
unwrap() {
|
|
287
|
+
throw this.onUnwrap(this), this.error;
|
|
288
|
+
}
|
|
289
|
+
unwrapOr(e) {
|
|
290
|
+
return e;
|
|
291
|
+
}
|
|
292
|
+
}, z = I, B = class extends E {
|
|
293
|
+
constructor(e) {
|
|
294
|
+
super(), this.resolve = (e) => {
|
|
295
|
+
this.resolveHandle.alive && (this.context.unwrapResult(this.context.callFunction(this.resolveHandle, this.context.undefined, e || this.context.undefined)).dispose(), this.disposeResolvers(), this.onSettled());
|
|
296
|
+
}, this.reject = (e) => {
|
|
297
|
+
this.rejectHandle.alive && (this.context.unwrapResult(this.context.callFunction(this.rejectHandle, this.context.undefined, e || this.context.undefined)).dispose(), this.disposeResolvers(), this.onSettled());
|
|
298
|
+
}, this.dispose = () => {
|
|
299
|
+
this.handle.alive && this.handle.dispose(), this.disposeResolvers();
|
|
300
|
+
}, this.context = e.context, this.owner = e.context.runtime, this.handle = e.promiseHandle, this.settled = new Promise((e) => {
|
|
301
|
+
this.onSettled = e;
|
|
302
|
+
}), this.resolveHandle = e.resolveHandle, this.rejectHandle = e.rejectHandle;
|
|
303
|
+
}
|
|
304
|
+
get alive() {
|
|
305
|
+
return this.handle.alive || this.resolveHandle.alive || this.rejectHandle.alive;
|
|
306
|
+
}
|
|
307
|
+
disposeResolvers() {
|
|
308
|
+
this.resolveHandle.alive && this.resolveHandle.dispose(), this.rejectHandle.alive && this.rejectHandle.dispose();
|
|
309
|
+
}
|
|
310
|
+
}, V = class {
|
|
311
|
+
constructor(e) {
|
|
312
|
+
this.module = e;
|
|
313
|
+
}
|
|
314
|
+
toPointerArray(e) {
|
|
315
|
+
let t = new Int32Array(e.map((e) => e.value)), n = t.length * t.BYTES_PER_ELEMENT, r = this.module._malloc(n);
|
|
316
|
+
return new Uint8Array(this.module.HEAPU8.buffer, r, n).set(new Uint8Array(t.buffer)), new k(r, void 0, (e) => this.module._free(e));
|
|
317
|
+
}
|
|
318
|
+
newTypedArray(e, t) {
|
|
319
|
+
let n = new e(Array(t).fill(0)), r = n.length * n.BYTES_PER_ELEMENT, i = this.module._malloc(r), a = new e(this.module.HEAPU8.buffer, i, t);
|
|
320
|
+
return a.set(n), new k({
|
|
321
|
+
typedArray: a,
|
|
322
|
+
ptr: i
|
|
323
|
+
}, void 0, (e) => this.module._free(e.ptr));
|
|
324
|
+
}
|
|
325
|
+
newMutablePointerArray(e) {
|
|
326
|
+
return this.newTypedArray(Int32Array, e);
|
|
327
|
+
}
|
|
328
|
+
newHeapCharPointer(e) {
|
|
329
|
+
let t = this.module.lengthBytesUTF8(e), n = t + 1, r = this.module._malloc(n);
|
|
330
|
+
return this.module.stringToUTF8(e, r, n), new k({
|
|
331
|
+
ptr: r,
|
|
332
|
+
strlen: t
|
|
333
|
+
}, void 0, (e) => this.module._free(e.ptr));
|
|
334
|
+
}
|
|
335
|
+
newHeapBufferPointer(e) {
|
|
336
|
+
let t = e.byteLength, n = this.module._malloc(t);
|
|
337
|
+
return this.module.HEAPU8.set(e, n), new k({
|
|
338
|
+
pointer: n,
|
|
339
|
+
numBytes: t
|
|
340
|
+
}, void 0, (e) => this.module._free(e.pointer));
|
|
341
|
+
}
|
|
342
|
+
consumeHeapCharPointer(e) {
|
|
343
|
+
let t = this.module.UTF8ToString(e);
|
|
344
|
+
return this.module._free(e), t;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
Object.freeze({
|
|
348
|
+
BaseObjects: !0,
|
|
349
|
+
Date: !0,
|
|
350
|
+
Eval: !0,
|
|
351
|
+
StringNormalize: !0,
|
|
352
|
+
RegExp: !0,
|
|
353
|
+
JSON: !0,
|
|
354
|
+
Proxy: !0,
|
|
355
|
+
MapSet: !0,
|
|
356
|
+
TypedArrays: !0,
|
|
357
|
+
Promise: !0
|
|
358
|
+
});
|
|
359
|
+
function H(e) {
|
|
360
|
+
if (!e) return 0;
|
|
361
|
+
let t = 0;
|
|
362
|
+
for (let [r, i] of Object.entries(e)) {
|
|
363
|
+
if (!(r in n)) throw new _(r);
|
|
364
|
+
i && (t |= n[r]);
|
|
365
|
+
}
|
|
366
|
+
return t;
|
|
367
|
+
}
|
|
368
|
+
function U(t) {
|
|
369
|
+
if (typeof t == "number") return t;
|
|
370
|
+
if (t === void 0) return 0;
|
|
371
|
+
let { type: n, strict: r, strip: i, compileOnly: a, backtraceBarrier: o } = t, s = 0;
|
|
372
|
+
return n === "global" && (s |= e.JS_EVAL_TYPE_GLOBAL), n === "module" && (s |= e.JS_EVAL_TYPE_MODULE), r && (s |= e.JS_EVAL_FLAG_STRICT), i && (s |= e.JS_EVAL_FLAG_STRIP), a && (s |= e.JS_EVAL_FLAG_COMPILE_ONLY), o && (s |= e.JS_EVAL_FLAG_BACKTRACE_BARRIER), s;
|
|
373
|
+
}
|
|
374
|
+
function ne(e) {
|
|
375
|
+
if (typeof e == "number") return e;
|
|
376
|
+
if (e === void 0) return 0;
|
|
377
|
+
let { strings: n, symbols: r, quickjsPrivate: i, onlyEnumerable: a, numbers: o, numbersAsStrings: s } = e, c = 0;
|
|
378
|
+
return n && (c |= t.JS_GPN_STRING_MASK), r && (c |= t.JS_GPN_SYMBOL_MASK), i && (c |= t.JS_GPN_PRIVATE_MASK), a && (c |= t.JS_GPN_ENUM_ONLY), o && (c |= t.QTS_GPN_NUMBER_MASK), s && (c |= t.QTS_STANDARD_COMPLIANT_NUMBER), c;
|
|
379
|
+
}
|
|
380
|
+
function re(...e) {
|
|
381
|
+
let t = [];
|
|
382
|
+
for (let n of e) n !== void 0 && (t = t.concat(n));
|
|
383
|
+
return t;
|
|
384
|
+
}
|
|
385
|
+
var ie = class extends E {
|
|
386
|
+
constructor(e, t) {
|
|
387
|
+
super(), this.handle = e, this.context = t, this._isDone = !1, this.owner = t.runtime;
|
|
388
|
+
}
|
|
389
|
+
[Symbol.iterator]() {
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
next(e) {
|
|
393
|
+
if (!this.alive || this._isDone) return {
|
|
394
|
+
done: !0,
|
|
395
|
+
value: void 0
|
|
396
|
+
};
|
|
397
|
+
let t = this._next ??= this.context.getProp(this.handle, "next");
|
|
398
|
+
return this.callIteratorMethod(t, e);
|
|
399
|
+
}
|
|
400
|
+
return(e) {
|
|
401
|
+
if (!this.alive) return {
|
|
402
|
+
done: !0,
|
|
403
|
+
value: void 0
|
|
404
|
+
};
|
|
405
|
+
let t = this.context.getProp(this.handle, "return");
|
|
406
|
+
if (t === this.context.undefined && e === void 0) return this.dispose(), {
|
|
407
|
+
done: !0,
|
|
408
|
+
value: void 0
|
|
409
|
+
};
|
|
410
|
+
let n = this.callIteratorMethod(t, e);
|
|
411
|
+
return t.dispose(), this.dispose(), n;
|
|
412
|
+
}
|
|
413
|
+
throw(e) {
|
|
414
|
+
if (!this.alive) return {
|
|
415
|
+
done: !0,
|
|
416
|
+
value: void 0
|
|
417
|
+
};
|
|
418
|
+
let t = e instanceof k ? e : this.context.newError(e), n = this.context.getProp(this.handle, "throw"), r = this.callIteratorMethod(n, e);
|
|
419
|
+
return t.alive && t.dispose(), n.dispose(), this.dispose(), r;
|
|
420
|
+
}
|
|
421
|
+
get alive() {
|
|
422
|
+
return this.handle.alive;
|
|
423
|
+
}
|
|
424
|
+
dispose() {
|
|
425
|
+
this._isDone = !0, this.handle.dispose(), this._next?.dispose();
|
|
426
|
+
}
|
|
427
|
+
callIteratorMethod(e, t) {
|
|
428
|
+
let n = t ? this.context.callFunction(e, this.handle, t) : this.context.callFunction(e, this.handle);
|
|
429
|
+
if (n.error) return this.dispose(), { value: n };
|
|
430
|
+
let r = this.context.getProp(n.value, "done").consume((e) => this.context.dump(e)), i = this.context.getProp(n.value, "value");
|
|
431
|
+
return n.value.dispose(), r && this.dispose(), {
|
|
432
|
+
value: z.success(i),
|
|
433
|
+
done: r
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}, W = -2147483648, G = 2147483647, K = 0;
|
|
437
|
+
function q(e) {
|
|
438
|
+
return e >> 8;
|
|
439
|
+
}
|
|
440
|
+
var ae = class {
|
|
441
|
+
constructor() {
|
|
442
|
+
this.nextId = W, this.freelist = [], this.groups = /* @__PURE__ */ new Map();
|
|
443
|
+
}
|
|
444
|
+
put(e) {
|
|
445
|
+
let t = this.allocateId(), n = q(t), r = this.groups.get(n);
|
|
446
|
+
return r || (r = /* @__PURE__ */ new Map(), this.groups.set(n, r)), r.set(t, e), t;
|
|
447
|
+
}
|
|
448
|
+
get(e) {
|
|
449
|
+
if (e === K) throw new x("no host reference id defined");
|
|
450
|
+
let t = q(e), n = this.groups.get(t);
|
|
451
|
+
if (!n) throw new x(`host reference id ${e} is not defined`);
|
|
452
|
+
let r = n.get(e);
|
|
453
|
+
if (!r) throw new x(`host reference id ${e} is not defined`);
|
|
454
|
+
return r;
|
|
455
|
+
}
|
|
456
|
+
delete(e) {
|
|
457
|
+
if (e === K) throw new x("no host reference id defined");
|
|
458
|
+
let t = q(e), n = this.groups.get(t);
|
|
459
|
+
if (!n) throw new x(`host reference id ${e} is not defined`);
|
|
460
|
+
n.delete(e), n.size === 0 && this.groups.delete(t), this.freelist.push(e);
|
|
461
|
+
}
|
|
462
|
+
allocateId() {
|
|
463
|
+
if (this.freelist.length > 0) return this.freelist.shift();
|
|
464
|
+
if (this.nextId === K && this.nextId++, this.nextId > G) throw new b(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${G - W}`);
|
|
465
|
+
return this.nextId++;
|
|
466
|
+
}
|
|
467
|
+
}, J = class extends E {
|
|
468
|
+
constructor(e, t, n) {
|
|
469
|
+
if (n === K) throw new x("cannot create HostRef with undefined id");
|
|
470
|
+
super(), this.runtime = e, this.handle = t, this.id = n;
|
|
471
|
+
}
|
|
472
|
+
get alive() {
|
|
473
|
+
return this.handle.alive;
|
|
474
|
+
}
|
|
475
|
+
dispose() {
|
|
476
|
+
this.handle.dispose();
|
|
477
|
+
}
|
|
478
|
+
get value() {
|
|
479
|
+
return this.runtime.hostRefs.get(this.id);
|
|
480
|
+
}
|
|
481
|
+
}, oe = class extends V {
|
|
482
|
+
constructor(e) {
|
|
483
|
+
super(e.module), this.scope = new N(), this.copyJSValue = (e) => this.ffi.QTS_DupValuePointer(this.ctx.value, e), this.freeJSValue = (e) => {
|
|
484
|
+
this.ffi.QTS_FreeValuePointer(this.ctx.value, e);
|
|
485
|
+
}, e.ownedLifetimes?.forEach((e) => this.scope.manage(e)), this.owner = e.owner, this.module = e.module, this.ffi = e.ffi, this.rt = e.rt, this.ctx = this.scope.manage(e.ctx);
|
|
486
|
+
}
|
|
487
|
+
get alive() {
|
|
488
|
+
return this.scope.alive;
|
|
489
|
+
}
|
|
490
|
+
dispose() {
|
|
491
|
+
return this.scope.dispose();
|
|
492
|
+
}
|
|
493
|
+
[Symbol.dispose]() {
|
|
494
|
+
return this.dispose();
|
|
495
|
+
}
|
|
496
|
+
manage(e) {
|
|
497
|
+
return this.scope.manage(e);
|
|
498
|
+
}
|
|
499
|
+
consumeJSCharPointer(e) {
|
|
500
|
+
let t = this.module.UTF8ToString(e);
|
|
501
|
+
return this.ffi.QTS_FreeCString(this.ctx.value, e), t;
|
|
502
|
+
}
|
|
503
|
+
heapValueHandle(e, t) {
|
|
504
|
+
let n = t ? (e) => {
|
|
505
|
+
t(), this.freeJSValue(e);
|
|
506
|
+
} : this.freeJSValue;
|
|
507
|
+
return new k(e, this.copyJSValue, n, this.owner);
|
|
508
|
+
}
|
|
509
|
+
staticHeapValueHandle(e) {
|
|
510
|
+
return this.manage(this.heapValueHandle(e)), new A(e, this.owner);
|
|
511
|
+
}
|
|
512
|
+
}, Y = class extends E {
|
|
513
|
+
constructor(e) {
|
|
514
|
+
super(), this._undefined = void 0, this._null = void 0, this._false = void 0, this._true = void 0, this._global = void 0, this._BigInt = void 0, this._Symbol = void 0, this._SymbolIterator = void 0, this._SymbolAsyncIterator = void 0, this.cToHostCallbacks = { callFunction: (e, t, n, r, i) => {
|
|
515
|
+
if (e !== this.ctx.value) throw Error("QuickJSContext instance received C -> JS call with mismatched ctx");
|
|
516
|
+
let a = this.getFunction(i);
|
|
517
|
+
return N.withScopeMaybeAsync(this, function* (e, i) {
|
|
518
|
+
let o = i.manage(new j(t, this.memory.copyJSValue, this.memory.freeJSValue, this.runtime)), s = Array(n);
|
|
519
|
+
for (let e = 0; e < n; e++) {
|
|
520
|
+
let t = this.ffi.QTS_ArgvGetJSValueConstPointer(r, e);
|
|
521
|
+
s[e] = i.manage(new j(t, this.memory.copyJSValue, this.memory.freeJSValue, this.runtime));
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
let t = yield* e(a.apply(o, s));
|
|
525
|
+
if (t) {
|
|
526
|
+
if ("error" in t && t.error) throw this.runtime.debugLog("throw error", t.error), t.error;
|
|
527
|
+
let e = i.manage(t instanceof k ? t : t.value);
|
|
528
|
+
return this.ffi.QTS_DupValuePointer(this.ctx.value, e.value);
|
|
529
|
+
}
|
|
530
|
+
return 0;
|
|
531
|
+
} catch (e) {
|
|
532
|
+
return this.errorToHandle(e).consume((e) => this.ffi.QTS_Throw(this.ctx.value, e.value));
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
} }, this.runtime = e.runtime, this.module = e.module, this.ffi = e.ffi, this.rt = e.rt, this.ctx = e.ctx, this.memory = new oe({
|
|
536
|
+
...e,
|
|
537
|
+
owner: this.runtime
|
|
538
|
+
}), e.callbacks.setContextCallbacks(this.ctx.value, this.cToHostCallbacks), this.dump = this.dump.bind(this), this.getString = this.getString.bind(this), this.getNumber = this.getNumber.bind(this), this.resolvePromise = this.resolvePromise.bind(this), this.uint32Out = this.memory.manage(this.memory.newTypedArray(Uint32Array, 1));
|
|
539
|
+
}
|
|
540
|
+
get alive() {
|
|
541
|
+
return this.memory.alive;
|
|
542
|
+
}
|
|
543
|
+
dispose() {
|
|
544
|
+
this.memory.dispose();
|
|
545
|
+
}
|
|
546
|
+
get undefined() {
|
|
547
|
+
if (this._undefined) return this._undefined;
|
|
548
|
+
let e = this.ffi.QTS_GetUndefined();
|
|
549
|
+
return this._undefined = new A(e);
|
|
550
|
+
}
|
|
551
|
+
get null() {
|
|
552
|
+
if (this._null) return this._null;
|
|
553
|
+
let e = this.ffi.QTS_GetNull();
|
|
554
|
+
return this._null = new A(e);
|
|
555
|
+
}
|
|
556
|
+
get true() {
|
|
557
|
+
if (this._true) return this._true;
|
|
558
|
+
let e = this.ffi.QTS_GetTrue();
|
|
559
|
+
return this._true = new A(e);
|
|
560
|
+
}
|
|
561
|
+
get false() {
|
|
562
|
+
if (this._false) return this._false;
|
|
563
|
+
let e = this.ffi.QTS_GetFalse();
|
|
564
|
+
return this._false = new A(e);
|
|
565
|
+
}
|
|
566
|
+
get global() {
|
|
567
|
+
if (this._global) return this._global;
|
|
568
|
+
let e = this.ffi.QTS_GetGlobalObject(this.ctx.value);
|
|
569
|
+
return this._global = this.memory.staticHeapValueHandle(e), this._global;
|
|
570
|
+
}
|
|
571
|
+
newNumber(e) {
|
|
572
|
+
return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value, e));
|
|
573
|
+
}
|
|
574
|
+
newString(e) {
|
|
575
|
+
let t = this.memory.newHeapCharPointer(e).consume((e) => this.ffi.QTS_NewString(this.ctx.value, e.value.ptr));
|
|
576
|
+
return this.memory.heapValueHandle(t);
|
|
577
|
+
}
|
|
578
|
+
newUniqueSymbol(e) {
|
|
579
|
+
let t = (typeof e == "symbol" ? e.description : e) ?? "", n = this.memory.newHeapCharPointer(t).consume((e) => this.ffi.QTS_NewSymbol(this.ctx.value, e.value.ptr, 0));
|
|
580
|
+
return this.memory.heapValueHandle(n);
|
|
581
|
+
}
|
|
582
|
+
newSymbolFor(e) {
|
|
583
|
+
let t = (typeof e == "symbol" ? e.description : e) ?? "", n = this.memory.newHeapCharPointer(t).consume((e) => this.ffi.QTS_NewSymbol(this.ctx.value, e.value.ptr, 1));
|
|
584
|
+
return this.memory.heapValueHandle(n);
|
|
585
|
+
}
|
|
586
|
+
getWellKnownSymbol(e) {
|
|
587
|
+
return this._Symbol ??= this.memory.manage(this.getProp(this.global, "Symbol")), this.getProp(this._Symbol, e);
|
|
588
|
+
}
|
|
589
|
+
newBigInt(e) {
|
|
590
|
+
if (!this._BigInt) {
|
|
591
|
+
let e = this.getProp(this.global, "BigInt");
|
|
592
|
+
this.memory.manage(e), this._BigInt = new A(e.value, this.runtime);
|
|
593
|
+
}
|
|
594
|
+
let t = this._BigInt, n = String(e);
|
|
595
|
+
return this.newString(n).consume((e) => this.unwrapResult(this.callFunction(t, this.undefined, e)));
|
|
596
|
+
}
|
|
597
|
+
newObject(e) {
|
|
598
|
+
e && this.runtime.assertOwned(e);
|
|
599
|
+
let t = e ? this.ffi.QTS_NewObjectProto(this.ctx.value, e.value) : this.ffi.QTS_NewObject(this.ctx.value);
|
|
600
|
+
return this.memory.heapValueHandle(t);
|
|
601
|
+
}
|
|
602
|
+
newArray() {
|
|
603
|
+
let e = this.ffi.QTS_NewArray(this.ctx.value);
|
|
604
|
+
return this.memory.heapValueHandle(e);
|
|
605
|
+
}
|
|
606
|
+
newArrayBuffer(e) {
|
|
607
|
+
let t = new Uint8Array(e), n = this.memory.newHeapBufferPointer(t), r = this.ffi.QTS_NewArrayBuffer(this.ctx.value, n.value.pointer, t.length);
|
|
608
|
+
return this.memory.heapValueHandle(r);
|
|
609
|
+
}
|
|
610
|
+
newPromise(e) {
|
|
611
|
+
let t = N.withScope((e) => {
|
|
612
|
+
let t = e.manage(this.memory.newMutablePointerArray(2)), n = this.ffi.QTS_NewPromiseCapability(this.ctx.value, t.value.ptr), r = this.memory.heapValueHandle(n), [i, a] = Array.from(t.value.typedArray).map((e) => this.memory.heapValueHandle(e));
|
|
613
|
+
return new B({
|
|
614
|
+
context: this,
|
|
615
|
+
promiseHandle: r,
|
|
616
|
+
resolveHandle: i,
|
|
617
|
+
rejectHandle: a
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
return e && typeof e == "function" && (e = new Promise(e)), e && Promise.resolve(e).then(t.resolve, (e) => e instanceof k ? t.reject(e) : this.newError(e).consume(t.reject)), t;
|
|
621
|
+
}
|
|
622
|
+
newFunction(e, t) {
|
|
623
|
+
let n = typeof e == "function" ? e : t;
|
|
624
|
+
if (!n) throw TypeError("Expected a function");
|
|
625
|
+
return this.newFunctionWithOptions({
|
|
626
|
+
name: typeof e == "string" ? e : void 0,
|
|
627
|
+
length: n.length,
|
|
628
|
+
isConstructor: !1,
|
|
629
|
+
fn: n
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
newConstructorFunction(e, t) {
|
|
633
|
+
let n = typeof e == "function" ? e : t;
|
|
634
|
+
if (!n) throw TypeError("Expected a function");
|
|
635
|
+
return this.newFunctionWithOptions({
|
|
636
|
+
name: typeof e == "string" ? e : void 0,
|
|
637
|
+
length: n.length,
|
|
638
|
+
isConstructor: !0,
|
|
639
|
+
fn: n
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
newFunctionWithOptions(e) {
|
|
643
|
+
let { name: t, length: n, isConstructor: r, fn: i } = e, a = this.runtime.hostRefs.put(i);
|
|
644
|
+
try {
|
|
645
|
+
return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value, t ?? "", n, r, a));
|
|
646
|
+
} catch (e) {
|
|
647
|
+
throw this.runtime.hostRefs.delete(a), e;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
newError(e) {
|
|
651
|
+
let t = this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));
|
|
652
|
+
return e && typeof e == "object" ? (e.name !== void 0 && this.newString(e.name).consume((e) => this.setProp(t, "name", e)), e.message !== void 0 && this.newString(e.message).consume((e) => this.setProp(t, "message", e))) : typeof e == "string" ? this.newString(e).consume((e) => this.setProp(t, "message", e)) : e !== void 0 && this.newString(String(e)).consume((e) => this.setProp(t, "message", e)), t;
|
|
653
|
+
}
|
|
654
|
+
newHostRef(e) {
|
|
655
|
+
let t = this.runtime.hostRefs.put(e);
|
|
656
|
+
try {
|
|
657
|
+
let e = this.memory.heapValueHandle(this.ffi.QTS_NewHostRef(this.ctx.value, t));
|
|
658
|
+
return new J(this.runtime, e, t);
|
|
659
|
+
} catch (e) {
|
|
660
|
+
throw this.runtime.hostRefs.delete(t), e;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
toHostRef(e) {
|
|
664
|
+
let t = this.ffi.QTS_GetHostRefId(e.value);
|
|
665
|
+
if (t !== 0) return this.runtime.hostRefs.get(t), new J(this.runtime, e.dup(), t);
|
|
666
|
+
}
|
|
667
|
+
unwrapHostRef(e) {
|
|
668
|
+
let t = this.ffi.QTS_GetHostRefId(e.value);
|
|
669
|
+
if (t === 0) throw new x("handle is not a HostRef");
|
|
670
|
+
return this.runtime.hostRefs.get(t);
|
|
671
|
+
}
|
|
672
|
+
typeof(e) {
|
|
673
|
+
return this.runtime.assertOwned(e), this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value, e.value));
|
|
674
|
+
}
|
|
675
|
+
getNumber(e) {
|
|
676
|
+
return this.runtime.assertOwned(e), this.ffi.QTS_GetFloat64(this.ctx.value, e.value);
|
|
677
|
+
}
|
|
678
|
+
getString(e) {
|
|
679
|
+
return this.runtime.assertOwned(e), this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value, e.value));
|
|
680
|
+
}
|
|
681
|
+
getSymbol(e) {
|
|
682
|
+
this.runtime.assertOwned(e);
|
|
683
|
+
let t = this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value, e.value));
|
|
684
|
+
return this.ffi.QTS_IsGlobalSymbol(this.ctx.value, e.value) ? Symbol.for(t) : Symbol(t);
|
|
685
|
+
}
|
|
686
|
+
getBigInt(e) {
|
|
687
|
+
this.runtime.assertOwned(e);
|
|
688
|
+
let t = this.getString(e);
|
|
689
|
+
return BigInt(t);
|
|
690
|
+
}
|
|
691
|
+
getArrayBuffer(e) {
|
|
692
|
+
this.runtime.assertOwned(e);
|
|
693
|
+
let t = this.ffi.QTS_GetArrayBufferLength(this.ctx.value, e.value), n = this.ffi.QTS_GetArrayBuffer(this.ctx.value, e.value);
|
|
694
|
+
if (!n) throw Error("Couldn't allocate memory to get ArrayBuffer");
|
|
695
|
+
return new k(this.module.HEAPU8.subarray(n, n + t), void 0, () => this.module._free(n));
|
|
696
|
+
}
|
|
697
|
+
getPromiseState(e) {
|
|
698
|
+
this.runtime.assertOwned(e);
|
|
699
|
+
let t = this.ffi.QTS_PromiseState(this.ctx.value, e.value);
|
|
700
|
+
if (t < 0) return {
|
|
701
|
+
type: "fulfilled",
|
|
702
|
+
value: e,
|
|
703
|
+
notAPromise: !0
|
|
704
|
+
};
|
|
705
|
+
if (t === i.Pending) return {
|
|
706
|
+
type: "pending",
|
|
707
|
+
get error() {
|
|
708
|
+
return new v("Cannot unwrap a pending promise");
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
let n = this.ffi.QTS_PromiseResult(this.ctx.value, e.value), r = this.memory.heapValueHandle(n);
|
|
712
|
+
if (t === i.Fulfilled) return {
|
|
713
|
+
type: "fulfilled",
|
|
714
|
+
value: r
|
|
715
|
+
};
|
|
716
|
+
if (t === i.Rejected) return {
|
|
717
|
+
type: "rejected",
|
|
718
|
+
error: r
|
|
719
|
+
};
|
|
720
|
+
throw r.dispose(), /* @__PURE__ */ Error(`Unknown JSPromiseStateEnum: ${t}`);
|
|
721
|
+
}
|
|
722
|
+
resolvePromise(e) {
|
|
723
|
+
this.runtime.assertOwned(e);
|
|
724
|
+
let t = N.withScope((t) => {
|
|
725
|
+
let n = t.manage(this.getProp(this.global, "Promise")), r = t.manage(this.getProp(n, "resolve"));
|
|
726
|
+
return this.callFunction(r, n, e);
|
|
727
|
+
});
|
|
728
|
+
return t.error ? Promise.resolve(t) : new Promise((e) => {
|
|
729
|
+
N.withScope((n) => {
|
|
730
|
+
let r = n.manage(this.newFunction("resolve", (t) => {
|
|
731
|
+
e(this.success(t && t.dup()));
|
|
732
|
+
})), i = n.manage(this.newFunction("reject", (t) => {
|
|
733
|
+
e(this.fail(t && t.dup()));
|
|
734
|
+
})), a = n.manage(t.value), o = n.manage(this.getProp(a, "then"));
|
|
735
|
+
this.callFunction(o, a, r, i).unwrap().dispose();
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
isEqual(e, t, n = r.IsStrictlyEqual) {
|
|
740
|
+
if (e === t) return !0;
|
|
741
|
+
this.runtime.assertOwned(e), this.runtime.assertOwned(t);
|
|
742
|
+
let i = this.ffi.QTS_IsEqual(this.ctx.value, e.value, t.value, n);
|
|
743
|
+
if (i === -1) throw new f("WASM variant does not expose equality");
|
|
744
|
+
return !!i;
|
|
745
|
+
}
|
|
746
|
+
eq(e, t) {
|
|
747
|
+
return this.isEqual(e, t, r.IsStrictlyEqual);
|
|
748
|
+
}
|
|
749
|
+
sameValue(e, t) {
|
|
750
|
+
return this.isEqual(e, t, r.IsSameValue);
|
|
751
|
+
}
|
|
752
|
+
sameValueZero(e, t) {
|
|
753
|
+
return this.isEqual(e, t, r.IsSameValueZero);
|
|
754
|
+
}
|
|
755
|
+
getProp(e, t) {
|
|
756
|
+
this.runtime.assertOwned(e);
|
|
757
|
+
let n;
|
|
758
|
+
return n = typeof t == "number" && t >= 0 ? this.ffi.QTS_GetPropNumber(this.ctx.value, e.value, t) : this.borrowPropertyKey(t).consume((t) => this.ffi.QTS_GetProp(this.ctx.value, e.value, t.value)), this.memory.heapValueHandle(n);
|
|
759
|
+
}
|
|
760
|
+
getLength(e) {
|
|
761
|
+
if (this.runtime.assertOwned(e), !(this.ffi.QTS_GetLength(this.ctx.value, this.uint32Out.value.ptr, e.value) < 0)) return this.uint32Out.value.typedArray[0];
|
|
762
|
+
}
|
|
763
|
+
getOwnPropertyNames(e, t = {
|
|
764
|
+
strings: !0,
|
|
765
|
+
numbersAsStrings: !0
|
|
766
|
+
}) {
|
|
767
|
+
this.runtime.assertOwned(e), e.value;
|
|
768
|
+
let n = ne(t);
|
|
769
|
+
if (n === 0) throw new y("No options set, will return an empty array");
|
|
770
|
+
return N.withScope((t) => {
|
|
771
|
+
let r = t.manage(this.memory.newMutablePointerArray(1)), i = this.ffi.QTS_GetOwnPropertyNames(this.ctx.value, r.value.ptr, this.uint32Out.value.ptr, e.value, n);
|
|
772
|
+
if (i) return this.fail(this.memory.heapValueHandle(i));
|
|
773
|
+
let a = this.uint32Out.value.typedArray[0], o = r.value.typedArray[0], s = new Uint32Array(this.module.HEAP8.buffer, o, a), c = Array.from(s).map((e) => this.memory.heapValueHandle(e));
|
|
774
|
+
return this.ffi.QTS_FreeVoidPointer(this.ctx.value, o), this.success(P(c));
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
getIterator(e) {
|
|
778
|
+
let t = this._SymbolIterator ??= this.memory.manage(this.getWellKnownSymbol("iterator"));
|
|
779
|
+
return N.withScope((n) => {
|
|
780
|
+
let r = n.manage(this.getProp(e, t)), i = this.callFunction(r, e);
|
|
781
|
+
return i.error ? i : this.success(new ie(i.value, this));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
setProp(e, t, n) {
|
|
785
|
+
this.runtime.assertOwned(e), this.borrowPropertyKey(t).consume((t) => this.ffi.QTS_SetProp(this.ctx.value, e.value, t.value, n.value));
|
|
786
|
+
}
|
|
787
|
+
defineProp(e, t, n) {
|
|
788
|
+
this.runtime.assertOwned(e), N.withScope((r) => {
|
|
789
|
+
let i = r.manage(this.borrowPropertyKey(t)), a = n.value || this.undefined, o = !!n.configurable, s = !!n.enumerable, c = !!n.value, l = n.get ? r.manage(this.newFunction(n.get.name, n.get)) : this.undefined, u = n.set ? r.manage(this.newFunction(n.set.name, n.set)) : this.undefined;
|
|
790
|
+
this.ffi.QTS_DefineProp(this.ctx.value, e.value, i.value, a.value, l.value, u.value, o, s, c);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
callFunction(e, t, ...n) {
|
|
794
|
+
this.runtime.assertOwned(e);
|
|
795
|
+
let r, i = n[0];
|
|
796
|
+
r = i === void 0 || Array.isArray(i) ? i ?? [] : n;
|
|
797
|
+
let a = this.memory.toPointerArray(r).consume((n) => this.ffi.QTS_Call(this.ctx.value, e.value, t.value, r.length, n.value)), o = this.ffi.QTS_ResolveException(this.ctx.value, a);
|
|
798
|
+
return o ? (this.ffi.QTS_FreeValuePointer(this.ctx.value, a), this.fail(this.memory.heapValueHandle(o))) : this.success(this.memory.heapValueHandle(a));
|
|
799
|
+
}
|
|
800
|
+
callMethod(e, t, n = []) {
|
|
801
|
+
return this.getProp(e, t).consume((t) => this.callFunction(t, e, n));
|
|
802
|
+
}
|
|
803
|
+
evalCode(e, t = "eval.js", n) {
|
|
804
|
+
let r = +(n === void 0), i = U(n), a = this.memory.newHeapCharPointer(e).consume((e) => this.ffi.QTS_Eval(this.ctx.value, e.value.ptr, e.value.strlen, t, r, i)), o = this.ffi.QTS_ResolveException(this.ctx.value, a);
|
|
805
|
+
return o ? (this.ffi.QTS_FreeValuePointer(this.ctx.value, a), this.fail(this.memory.heapValueHandle(o))) : this.success(this.memory.heapValueHandle(a));
|
|
806
|
+
}
|
|
807
|
+
throw(e) {
|
|
808
|
+
return this.errorToHandle(e).consume((e) => this.ffi.QTS_Throw(this.ctx.value, e.value));
|
|
809
|
+
}
|
|
810
|
+
borrowPropertyKey(e) {
|
|
811
|
+
return typeof e == "number" ? this.newNumber(e) : typeof e == "string" ? this.newString(e) : new A(e.value, this.runtime);
|
|
812
|
+
}
|
|
813
|
+
getMemory(e) {
|
|
814
|
+
if (e === this.rt.value) return this.memory;
|
|
815
|
+
throw Error("Private API. Cannot get memory from a different runtime");
|
|
816
|
+
}
|
|
817
|
+
dump(e) {
|
|
818
|
+
this.runtime.assertOwned(e);
|
|
819
|
+
let t = this.typeof(e);
|
|
820
|
+
if (t === "string") return this.getString(e);
|
|
821
|
+
if (t === "number") return this.getNumber(e);
|
|
822
|
+
if (t === "bigint") return this.getBigInt(e);
|
|
823
|
+
if (t === "undefined") return;
|
|
824
|
+
if (t === "symbol") return this.getSymbol(e);
|
|
825
|
+
let n = this.getPromiseState(e);
|
|
826
|
+
if (n.type === "fulfilled" && !n.notAPromise) return e.dispose(), {
|
|
827
|
+
type: n.type,
|
|
828
|
+
value: n.value.consume(this.dump)
|
|
829
|
+
};
|
|
830
|
+
if (n.type === "pending") return e.dispose(), { type: n.type };
|
|
831
|
+
if (n.type === "rejected") return e.dispose(), {
|
|
832
|
+
type: n.type,
|
|
833
|
+
error: n.error.consume(this.dump)
|
|
834
|
+
};
|
|
835
|
+
let r = this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value, e.value));
|
|
836
|
+
try {
|
|
837
|
+
return JSON.parse(r);
|
|
838
|
+
} catch {
|
|
839
|
+
return r;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
unwrapResult(e) {
|
|
843
|
+
if (e.error) {
|
|
844
|
+
let t = "context" in e.error ? e.error.context : this, n = e.error.consume((e) => this.dump(e));
|
|
845
|
+
if (n && typeof n == "object" && typeof n.message == "string") {
|
|
846
|
+
let { message: e, name: r, stack: i, ...a } = n, o = new l(n, t);
|
|
847
|
+
typeof r == "string" && (o.name = n.name), o.message = e;
|
|
848
|
+
let s = o.stack;
|
|
849
|
+
throw typeof i == "string" && (o.stack = `${r}: ${e}
|
|
850
|
+
${n.stack}Host: ${s}`), Object.assign(o, a), o;
|
|
851
|
+
}
|
|
852
|
+
throw new l(n);
|
|
853
|
+
}
|
|
854
|
+
return e.value;
|
|
855
|
+
}
|
|
856
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
857
|
+
return this.alive ? `${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }` : `${this.constructor.name} { disposed }`;
|
|
858
|
+
}
|
|
859
|
+
getFunction(e) {
|
|
860
|
+
let t = this.runtime.hostRefs.get(e);
|
|
861
|
+
if (typeof t != "function") throw Error(`Host reference ${e} is not a function`);
|
|
862
|
+
return t;
|
|
863
|
+
}
|
|
864
|
+
errorToHandle(e) {
|
|
865
|
+
return e instanceof k ? e : this.newError(e);
|
|
866
|
+
}
|
|
867
|
+
encodeBinaryJSON(e) {
|
|
868
|
+
let t = this.ffi.QTS_bjson_encode(this.ctx.value, e.value);
|
|
869
|
+
return this.memory.heapValueHandle(t);
|
|
870
|
+
}
|
|
871
|
+
decodeBinaryJSON(e) {
|
|
872
|
+
let t = this.ffi.QTS_bjson_decode(this.ctx.value, e.value);
|
|
873
|
+
return this.memory.heapValueHandle(t);
|
|
874
|
+
}
|
|
875
|
+
success(e) {
|
|
876
|
+
return z.success(e);
|
|
877
|
+
}
|
|
878
|
+
fail(e) {
|
|
879
|
+
return z.fail(e, (e) => this.unwrapResult(e));
|
|
880
|
+
}
|
|
881
|
+
}, X = class extends E {
|
|
882
|
+
constructor(e) {
|
|
883
|
+
super(), this.scope = new N(), this.contextMap = /* @__PURE__ */ new Map(), this.hostRefs = new ae(), this._debugMode = !1, this.cToHostCallbacks = {
|
|
884
|
+
freeHostRef: (e, t) => {
|
|
885
|
+
if (e !== this.rt.value) throw Error("Runtime pointer mismatch");
|
|
886
|
+
this.hostRefs.delete(t);
|
|
887
|
+
},
|
|
888
|
+
shouldInterrupt: (e) => {
|
|
889
|
+
if (e !== this.rt.value) throw Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");
|
|
890
|
+
let t = this.interruptHandler;
|
|
891
|
+
if (!t) throw Error("QuickJSContext had no interrupt handler");
|
|
892
|
+
return +!!t(this);
|
|
893
|
+
},
|
|
894
|
+
loadModuleSource: w(this, function* (e, t, n, r) {
|
|
895
|
+
let i = this.moduleLoader;
|
|
896
|
+
if (!i) throw Error("Runtime has no module loader");
|
|
897
|
+
if (t !== this.rt.value) throw Error("Runtime pointer mismatch");
|
|
898
|
+
let a = this.contextMap.get(n) ?? this.newContext({ contextPointer: n });
|
|
899
|
+
try {
|
|
900
|
+
let t = yield* e(i(r, a));
|
|
901
|
+
if (typeof t == "object" && "error" in t && t.error) throw this.debugLog("cToHostLoadModule: loader returned error", t.error), t.error;
|
|
902
|
+
let n = typeof t == "string" ? t : "value" in t ? t.value : t;
|
|
903
|
+
return this.memory.newHeapCharPointer(n).value.ptr;
|
|
904
|
+
} catch (e) {
|
|
905
|
+
return this.debugLog("cToHostLoadModule: caught error", e), a.throw(e), 0;
|
|
906
|
+
}
|
|
907
|
+
}),
|
|
908
|
+
normalizeModule: w(this, function* (e, t, n, r, i) {
|
|
909
|
+
let a = this.moduleNormalizer;
|
|
910
|
+
if (!a) throw Error("Runtime has no module normalizer");
|
|
911
|
+
if (t !== this.rt.value) throw Error("Runtime pointer mismatch");
|
|
912
|
+
let o = this.contextMap.get(n) ?? this.newContext({ contextPointer: n });
|
|
913
|
+
try {
|
|
914
|
+
let t = yield* e(a(r, i, o));
|
|
915
|
+
if (typeof t == "object" && "error" in t && t.error) throw this.debugLog("cToHostNormalizeModule: normalizer returned error", t.error), t.error;
|
|
916
|
+
let n = typeof t == "string" ? t : t.value;
|
|
917
|
+
return o.getMemory(this.rt.value).newHeapCharPointer(n).value.ptr;
|
|
918
|
+
} catch (e) {
|
|
919
|
+
return this.debugLog("normalizeModule: caught error", e), o.throw(e), 0;
|
|
920
|
+
}
|
|
921
|
+
})
|
|
922
|
+
}, e.ownedLifetimes?.forEach((e) => this.scope.manage(e)), this.module = e.module, this.memory = new V(this.module), this.ffi = e.ffi, this.rt = e.rt, this.callbacks = e.callbacks, this.scope.manage(this.rt), this.callbacks.setRuntimeCallbacks(this.rt.value, this.cToHostCallbacks), this.executePendingJobs = this.executePendingJobs.bind(this);
|
|
923
|
+
}
|
|
924
|
+
get alive() {
|
|
925
|
+
return this.scope.alive;
|
|
926
|
+
}
|
|
927
|
+
dispose() {
|
|
928
|
+
return this.scope.dispose();
|
|
929
|
+
}
|
|
930
|
+
newContext(e = {}) {
|
|
931
|
+
let t = H(e.intrinsics), n = new k(e.contextPointer || this.ffi.QTS_NewContext(this.rt.value, t), void 0, (e) => {
|
|
932
|
+
this.contextMap.delete(e), this.callbacks.deleteContext(e), this.ffi.QTS_FreeContext(e);
|
|
933
|
+
}), r = new Y({
|
|
934
|
+
module: this.module,
|
|
935
|
+
ctx: n,
|
|
936
|
+
ffi: this.ffi,
|
|
937
|
+
rt: this.rt,
|
|
938
|
+
ownedLifetimes: e.ownedLifetimes,
|
|
939
|
+
runtime: this,
|
|
940
|
+
callbacks: this.callbacks
|
|
941
|
+
});
|
|
942
|
+
return this.contextMap.set(n.value, r), r;
|
|
943
|
+
}
|
|
944
|
+
setModuleLoader(e, t) {
|
|
945
|
+
this.moduleLoader = e, this.moduleNormalizer = t, this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value, +!!this.moduleNormalizer);
|
|
946
|
+
}
|
|
947
|
+
removeModuleLoader() {
|
|
948
|
+
this.moduleLoader = void 0, this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value);
|
|
949
|
+
}
|
|
950
|
+
hasPendingJob() {
|
|
951
|
+
return !!this.ffi.QTS_IsJobPending(this.rt.value);
|
|
952
|
+
}
|
|
953
|
+
setInterruptHandler(e) {
|
|
954
|
+
let t = this.interruptHandler;
|
|
955
|
+
this.interruptHandler = e, t || this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value);
|
|
956
|
+
}
|
|
957
|
+
removeInterruptHandler() {
|
|
958
|
+
this.interruptHandler &&= (this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value), void 0);
|
|
959
|
+
}
|
|
960
|
+
executePendingJobs(e = -1) {
|
|
961
|
+
let t = this.memory.newMutablePointerArray(1), n = this.ffi.QTS_ExecutePendingJob(this.rt.value, e ?? -1, t.value.ptr), r = t.value.typedArray[0];
|
|
962
|
+
if (t.dispose(), r === 0) return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value, n), z.success(0);
|
|
963
|
+
let i = this.contextMap.get(r) ?? this.newContext({ contextPointer: r }), a = i.getMemory(this.rt.value).heapValueHandle(n);
|
|
964
|
+
if (i.typeof(a) === "number") {
|
|
965
|
+
let e = i.getNumber(a);
|
|
966
|
+
return a.dispose(), z.success(e);
|
|
967
|
+
}
|
|
968
|
+
{
|
|
969
|
+
let e = Object.assign(a, { context: i });
|
|
970
|
+
return z.fail(e, (e) => i.unwrapResult(e));
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
setMemoryLimit(e) {
|
|
974
|
+
if (e < 0 && e !== -1) throw Error("Cannot set memory limit to negative number. To unset, pass -1");
|
|
975
|
+
this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value, e);
|
|
976
|
+
}
|
|
977
|
+
computeMemoryUsage() {
|
|
978
|
+
let e = this.getSystemContext().getMemory(this.rt.value);
|
|
979
|
+
return e.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value, e.ctx.value));
|
|
980
|
+
}
|
|
981
|
+
dumpMemoryUsage() {
|
|
982
|
+
return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value));
|
|
983
|
+
}
|
|
984
|
+
setMaxStackSize(e) {
|
|
985
|
+
if (e < 0) throw Error("Cannot set memory limit to negative number. To unset, pass 0.");
|
|
986
|
+
this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value, e);
|
|
987
|
+
}
|
|
988
|
+
assertOwned(e) {
|
|
989
|
+
if (e.owner && e.owner.rt !== this.rt) throw new u(`Handle is not owned by this runtime: ${e.owner.rt.value} != ${this.rt.value}`);
|
|
990
|
+
}
|
|
991
|
+
setDebugMode(e) {
|
|
992
|
+
this._debugMode = e, this.ffi.DEBUG && this.rt.alive && this.ffi.QTS_SetDebugLogEnabled(this.rt.value, +!!e);
|
|
993
|
+
}
|
|
994
|
+
isDebugMode() {
|
|
995
|
+
return this._debugMode;
|
|
996
|
+
}
|
|
997
|
+
debugLog(...e) {
|
|
998
|
+
this._debugMode && console.log("quickjs-emscripten:", ...e);
|
|
999
|
+
}
|
|
1000
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1001
|
+
return this.alive ? `${this.constructor.name} { rt: ${this.rt.value} }` : `${this.constructor.name} { disposed }`;
|
|
1002
|
+
}
|
|
1003
|
+
getSystemContext() {
|
|
1004
|
+
return this.context ||= this.scope.manage(this.newContext()), this.context;
|
|
1005
|
+
}
|
|
1006
|
+
}, se = class {
|
|
1007
|
+
constructor(e) {
|
|
1008
|
+
this.freeHostRef = e.freeHostRef, this.callFunction = e.callFunction, this.shouldInterrupt = e.shouldInterrupt, this.loadModuleSource = e.loadModuleSource, this.normalizeModule = e.normalizeModule;
|
|
1009
|
+
}
|
|
1010
|
+
}, Z = class {
|
|
1011
|
+
constructor(e) {
|
|
1012
|
+
this.contextCallbacks = /* @__PURE__ */ new Map(), this.runtimeCallbacks = /* @__PURE__ */ new Map(), this.suspendedCount = 0, this.cToHostCallbacks = new se({
|
|
1013
|
+
freeHostRef: (e, t, n) => {
|
|
1014
|
+
let r = this.runtimeCallbacks.get(t);
|
|
1015
|
+
if (!r) throw Error(`QuickJSRuntime(rt = ${t}) not found when trying to free HostRef(id = ${n})`);
|
|
1016
|
+
r.freeHostRef(t, n);
|
|
1017
|
+
},
|
|
1018
|
+
callFunction: (e, t, n, r, i, a) => this.handleAsyncify(e, () => {
|
|
1019
|
+
try {
|
|
1020
|
+
let e = this.contextCallbacks.get(t);
|
|
1021
|
+
if (!e) throw Error(`QuickJSContext(ctx = ${t}) not found for C function call "${a}"`);
|
|
1022
|
+
return e.callFunction(t, n, r, i, a);
|
|
1023
|
+
} catch (e) {
|
|
1024
|
+
return console.error("[C to host error: returning null]", e), 0;
|
|
1025
|
+
}
|
|
1026
|
+
}),
|
|
1027
|
+
shouldInterrupt: (e, t) => this.handleAsyncify(e, () => {
|
|
1028
|
+
try {
|
|
1029
|
+
let e = this.runtimeCallbacks.get(t);
|
|
1030
|
+
if (!e) throw Error(`QuickJSRuntime(rt = ${t}) not found for C interrupt`);
|
|
1031
|
+
return e.shouldInterrupt(t);
|
|
1032
|
+
} catch (e) {
|
|
1033
|
+
return console.error("[C to host interrupt: returning error]", e), 1;
|
|
1034
|
+
}
|
|
1035
|
+
}),
|
|
1036
|
+
loadModuleSource: (e, t, n, r) => this.handleAsyncify(e, () => {
|
|
1037
|
+
try {
|
|
1038
|
+
let e = this.runtimeCallbacks.get(t);
|
|
1039
|
+
if (!e) throw Error(`QuickJSRuntime(rt = ${t}) not found for C module loader`);
|
|
1040
|
+
let i = e.loadModuleSource;
|
|
1041
|
+
if (!i) throw Error(`QuickJSRuntime(rt = ${t}) does not support module loading`);
|
|
1042
|
+
return i(t, n, r);
|
|
1043
|
+
} catch (e) {
|
|
1044
|
+
return console.error("[C to host module loader error: returning null]", e), 0;
|
|
1045
|
+
}
|
|
1046
|
+
}),
|
|
1047
|
+
normalizeModule: (e, t, n, r, i) => this.handleAsyncify(e, () => {
|
|
1048
|
+
try {
|
|
1049
|
+
let e = this.runtimeCallbacks.get(t);
|
|
1050
|
+
if (!e) throw Error(`QuickJSRuntime(rt = ${t}) not found for C module loader`);
|
|
1051
|
+
let a = e.normalizeModule;
|
|
1052
|
+
if (!a) throw Error(`QuickJSRuntime(rt = ${t}) does not support module loading`);
|
|
1053
|
+
return a(t, n, r, i);
|
|
1054
|
+
} catch (e) {
|
|
1055
|
+
return console.error("[C to host module loader error: returning null]", e), 0;
|
|
1056
|
+
}
|
|
1057
|
+
})
|
|
1058
|
+
}), this.module = e, this.module.callbacks = this.cToHostCallbacks;
|
|
1059
|
+
}
|
|
1060
|
+
setRuntimeCallbacks(e, t) {
|
|
1061
|
+
this.runtimeCallbacks.set(e, t);
|
|
1062
|
+
}
|
|
1063
|
+
deleteRuntime(e) {
|
|
1064
|
+
this.runtimeCallbacks.delete(e);
|
|
1065
|
+
}
|
|
1066
|
+
setContextCallbacks(e, t) {
|
|
1067
|
+
this.contextCallbacks.set(e, t);
|
|
1068
|
+
}
|
|
1069
|
+
deleteContext(e) {
|
|
1070
|
+
this.contextCallbacks.delete(e);
|
|
1071
|
+
}
|
|
1072
|
+
handleAsyncify(e, t) {
|
|
1073
|
+
if (e) return e.handleSleep((e) => {
|
|
1074
|
+
try {
|
|
1075
|
+
let n = t();
|
|
1076
|
+
if (!(n instanceof Promise)) {
|
|
1077
|
+
e(n);
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
if (this.suspended) throw new p(`Already suspended at: ${this.suspended.stack}
|
|
1081
|
+
Attempted to suspend at:`);
|
|
1082
|
+
this.suspended = new m(`(${this.suspendedCount++})`), this.suspended, n.then((t) => {
|
|
1083
|
+
this.suspended = void 0, e(t);
|
|
1084
|
+
}, (e) => {
|
|
1085
|
+
console.error("QuickJS: cannot handle error in suspended function", e), this.suspended = void 0;
|
|
1086
|
+
});
|
|
1087
|
+
} catch (e) {
|
|
1088
|
+
throw this.suspended = void 0, e;
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
let n = t();
|
|
1092
|
+
if (n instanceof Promise) throw Error("Promise return value not supported in non-asyncify context.");
|
|
1093
|
+
return n;
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
function Q(e, t) {
|
|
1097
|
+
t.interruptHandler && e.setInterruptHandler(t.interruptHandler), t.maxStackSizeBytes !== void 0 && e.setMaxStackSize(t.maxStackSizeBytes), t.memoryLimitBytes !== void 0 && e.setMemoryLimit(t.memoryLimitBytes);
|
|
1098
|
+
}
|
|
1099
|
+
function $(e, t) {
|
|
1100
|
+
t.moduleLoader && e.setModuleLoader(t.moduleLoader), t.shouldInterrupt && e.setInterruptHandler(t.shouldInterrupt), t.memoryLimitBytes !== void 0 && e.setMemoryLimit(t.memoryLimitBytes), t.maxStackSizeBytes !== void 0 && e.setMaxStackSize(t.maxStackSizeBytes);
|
|
1101
|
+
}
|
|
1102
|
+
var ce = class {
|
|
1103
|
+
constructor(e, t) {
|
|
1104
|
+
this.module = e, this.ffi = t, this.callbacks = new Z(e);
|
|
1105
|
+
}
|
|
1106
|
+
newRuntime(e = {}) {
|
|
1107
|
+
let t = new k(this.ffi.QTS_NewRuntime(), void 0, (e) => {
|
|
1108
|
+
this.ffi.QTS_FreeRuntime(e), this.callbacks.deleteRuntime(e);
|
|
1109
|
+
}), n = new X({
|
|
1110
|
+
module: this.module,
|
|
1111
|
+
callbacks: this.callbacks,
|
|
1112
|
+
ffi: this.ffi,
|
|
1113
|
+
rt: t
|
|
1114
|
+
});
|
|
1115
|
+
return Q(n, e), e.moduleLoader && n.setModuleLoader(e.moduleLoader), n;
|
|
1116
|
+
}
|
|
1117
|
+
newContext(e = {}) {
|
|
1118
|
+
let t = this.newRuntime(), n = t.newContext({
|
|
1119
|
+
...e,
|
|
1120
|
+
ownedLifetimes: re(t, e.ownedLifetimes)
|
|
1121
|
+
});
|
|
1122
|
+
return t.context = n, n;
|
|
1123
|
+
}
|
|
1124
|
+
evalCode(e, t = {}) {
|
|
1125
|
+
return N.withScope((n) => {
|
|
1126
|
+
let r = n.manage(this.newContext());
|
|
1127
|
+
$(r.runtime, t);
|
|
1128
|
+
let i = r.evalCode(e, "eval.js");
|
|
1129
|
+
if (t.memoryLimitBytes !== void 0 && r.runtime.setMemoryLimit(-1), i.error) throw r.dump(n.manage(i.error));
|
|
1130
|
+
return r.dump(n.manage(i.value));
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
getWasmMemory() {
|
|
1134
|
+
let e = this.module.quickjsEmscriptenInit?.(() => {})?.getWasmMemory?.();
|
|
1135
|
+
if (!e) throw Error("Variant does not support getting WebAssembly.Memory");
|
|
1136
|
+
return e;
|
|
1137
|
+
}
|
|
1138
|
+
getFFI() {
|
|
1139
|
+
return this.ffi;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
export { R as DisposableFail, z as DisposableResult, L as DisposableSuccess, k as Lifetime, Y as QuickJSContext, B as QuickJSDeferredPromise, g as QuickJSEmscriptenModuleError, h as QuickJSMemoryLeakDetected, Z as QuickJSModuleCallbacks, f as QuickJSNotImplemented, X as QuickJSRuntime, ce as QuickJSWASMModule, N as Scope, A as StaticLifetime, E as UsingDisposable, j as WeakLifetime, Q as applyBaseRuntimeOptions, $ as applyModuleEvalRuntimeOptions, P as createDisposableArray, s as debugLog, c as errors_exports, U as evalOptionsToFlags, H as intrinsicsToFlags };
|