@beff/aula-cli 0.0.1 → 0.1.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/README.md +11 -1
- package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
- package/dist/licenses/espeak-ng-COPYING.txt +674 -0
- package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
- package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
- package/dist/src/aula-render.core.wasm +0 -0
- package/dist/src/aula-voice-tts-ZXQ7XXHJ.js +14 -0
- package/dist/src/chunk-2XGNOG2U.js +28 -0
- package/dist/src/chunk-3IBMAZRS.js +21 -0
- package/dist/src/chunk-EYXQ2I7K.js +604 -0
- package/dist/src/chunk-GFCJYE75.js +42 -0
- package/dist/src/chunk-KLE5UOUB.js +57 -0
- package/dist/src/chunk-OMBYV6CK.js +1063 -0
- package/dist/src/chunk-PYRORQA5.js +88 -0
- package/dist/src/chunk-SDFXIMLW.js +1083 -0
- package/dist/src/chunk-UREQAEFC.js +491 -0
- package/dist/src/chunk-X3HJY34X.js +81 -0
- package/dist/src/cli.js +269 -0
- package/dist/src/commands-VDGWDVWT.js +28 -0
- package/dist/src/problems-OGUR4BLZ.js +12 -0
- package/dist/src/project-M63R4ENB.js +11 -0
- package/dist/src/render-child.js +3771 -0
- package/dist/src/run-CY72QGZJ.js +127 -0
- package/dist/src/server-ZG6K7Z7H.js +280 -0
- package/dist/web/app/assets/__vite-browser-external-Bbi05A7N.js +1 -0
- package/dist/web/app/assets/__vite-browser-external-BtQTJ51O.js +1 -0
- package/dist/web/app/assets/aula-method.js +1 -0
- package/dist/web/app/assets/aula-voice-worker-BL6WcrSe.js +52 -0
- package/dist/web/app/assets/aula.core-BtiPQSZi.wasm +0 -0
- package/dist/web/app/assets/aula.core5-BdGB-M10.wasm +0 -0
- package/dist/web/app/assets/aula.js +1 -0
- package/dist/web/app/assets/build-worker.js +697 -0
- package/dist/web/app/assets/esbuild-BaXVPFT2.wasm +0 -0
- package/dist/web/app/assets/index-BVQqteYG.js +53 -0
- package/dist/web/app/assets/index-CS60sOpp.css +2 -0
- package/dist/web/app/assets/protocol-Ds4jI5bY.js +15 -0
- package/dist/web/app/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
- package/dist/web/app/assets/src-BbJ5r410.js +25 -0
- package/dist/web/app/index.html +15 -0
- package/package.json +27 -5
|
@@ -0,0 +1,3771 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VIDEO
|
|
3
|
+
} from "./chunk-GFCJYE75.js";
|
|
4
|
+
import "./chunk-2XGNOG2U.js";
|
|
5
|
+
|
|
6
|
+
// src/render-child.ts
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
// src/generated/aula-render.js
|
|
12
|
+
function __jcoEmbeddedRuntime$promiseWithResolvers() {
|
|
13
|
+
if (Promise.withResolvers) return Promise.withResolvers();
|
|
14
|
+
let resolve;
|
|
15
|
+
let reject;
|
|
16
|
+
return {
|
|
17
|
+
promise: new Promise((res, rej) => {
|
|
18
|
+
resolve = res;
|
|
19
|
+
reject = rej;
|
|
20
|
+
}),
|
|
21
|
+
resolve,
|
|
22
|
+
reject
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function __jcoEmbeddedRuntime$isPromiseLike(value) {
|
|
26
|
+
return value !== null && (typeof value == "object" || typeof value == "function") && typeof value.then == "function";
|
|
27
|
+
}
|
|
28
|
+
var __jcoEmbeddedRuntime$debugLog = (...args) => {
|
|
29
|
+
if (!globalThis?.process?.env?.JCO_DEBUG) return;
|
|
30
|
+
console.debug(...args);
|
|
31
|
+
};
|
|
32
|
+
var __jcoEmbeddedRuntime$initializeTaskRegisters = () => ({});
|
|
33
|
+
function __jcoEmbeddedRuntime$validate(args) {
|
|
34
|
+
if (!args) throw TypeError("args missing");
|
|
35
|
+
if (args.taskID === void 0) throw TypeError("missing task ID");
|
|
36
|
+
if (args.threadID === void 0) throw TypeError("missing thread ID");
|
|
37
|
+
if (args.componentIdx === void 0) throw TypeError("missing component idx");
|
|
38
|
+
}
|
|
39
|
+
var __jcoEmbeddedRuntime$getCurrentTaskMeta = (registers, componentIdx) => {
|
|
40
|
+
let value = componentIdx == null ? registers.current : registers[componentIdx];
|
|
41
|
+
return value == null ? void 0 : { ...value };
|
|
42
|
+
};
|
|
43
|
+
function __jcoEmbeddedRuntime$withCurrentTaskMeta(registers, args) {
|
|
44
|
+
__jcoEmbeddedRuntime$debugLog("[_withGlobalCurrentThreadMeta()] args", args);
|
|
45
|
+
__jcoEmbeddedRuntime$validate(args);
|
|
46
|
+
if (!args.fn) throw TypeError("missing fn");
|
|
47
|
+
let { taskID, threadID, componentIdx, fn } = args;
|
|
48
|
+
let previous = registers[componentIdx] ?? null;
|
|
49
|
+
let previousCurrent = registers.current ?? null;
|
|
50
|
+
try {
|
|
51
|
+
registers.current = registers[componentIdx] = {
|
|
52
|
+
taskID,
|
|
53
|
+
threadID,
|
|
54
|
+
componentIdx
|
|
55
|
+
};
|
|
56
|
+
return fn();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
__jcoEmbeddedRuntime$debugLog("error while executing sync callee/callback", {
|
|
59
|
+
...args,
|
|
60
|
+
err: error
|
|
61
|
+
});
|
|
62
|
+
throw error;
|
|
63
|
+
} finally {
|
|
64
|
+
registers[componentIdx] = previous;
|
|
65
|
+
registers.current = previousCurrent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function __jcoEmbeddedRuntime$withCurrentTaskMetaAsync(registers, args) {
|
|
69
|
+
__jcoEmbeddedRuntime$debugLog("[_withGlobalCurrentThreadMetaAsync()] args", args);
|
|
70
|
+
__jcoEmbeddedRuntime$validate(args);
|
|
71
|
+
if (!args.fn) throw TypeError("missing fn");
|
|
72
|
+
let { taskID, threadID, componentIdx, fn } = args;
|
|
73
|
+
let previous = registers[componentIdx] ?? null;
|
|
74
|
+
let previousCurrent = registers.current ?? null;
|
|
75
|
+
let result;
|
|
76
|
+
try {
|
|
77
|
+
registers.current = registers[componentIdx] = {
|
|
78
|
+
taskID,
|
|
79
|
+
threadID,
|
|
80
|
+
componentIdx
|
|
81
|
+
};
|
|
82
|
+
result = fn();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
__jcoEmbeddedRuntime$debugLog("error while executing sync callee/callback", {
|
|
85
|
+
...args,
|
|
86
|
+
err: error
|
|
87
|
+
});
|
|
88
|
+
registers[componentIdx] = previous;
|
|
89
|
+
registers.current = previousCurrent;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
if (!__jcoEmbeddedRuntime$isPromiseLike(result)) {
|
|
93
|
+
registers[componentIdx] = previous;
|
|
94
|
+
registers.current = previousCurrent;
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
return (async () => {
|
|
98
|
+
try {
|
|
99
|
+
return await result;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
__jcoEmbeddedRuntime$debugLog("error while executing async callee/callback", {
|
|
102
|
+
...args,
|
|
103
|
+
err: error
|
|
104
|
+
});
|
|
105
|
+
throw error;
|
|
106
|
+
} finally {
|
|
107
|
+
registers[componentIdx]?.threadID === threadID && registers[componentIdx]?.taskID === taskID && (registers[componentIdx] = null);
|
|
108
|
+
registers.current?.threadID === threadID && registers.current?.taskID === taskID && (registers.current = null);
|
|
109
|
+
}
|
|
110
|
+
})();
|
|
111
|
+
}
|
|
112
|
+
var __jcoEmbeddedRuntime$reportTrap = (context, err) => {
|
|
113
|
+
let { storeTrap, RuntimeError } = context;
|
|
114
|
+
if (storeTrap.onTrap === null || storeTrap.stopped) return;
|
|
115
|
+
if (!(err instanceof RuntimeError) || storeTrap.trapsReported.has(err)) return;
|
|
116
|
+
storeTrap.trapsReported.add(err);
|
|
117
|
+
let trap = __jcoEmbeddedRuntime$normalizeCoreTrap(context.normalization, err);
|
|
118
|
+
try {
|
|
119
|
+
storeTrap.onTrap(trap);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
queueMicrotask(() => {
|
|
122
|
+
throw e;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function __jcoEmbeddedRuntime$isIdle(context) {
|
|
127
|
+
if (context.storeTrap.error !== null) return true;
|
|
128
|
+
for (let [componentIdx, metas] of context.tasks) if (componentIdx !== -1 && metas.length > 0) return false;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
var __jcoEmbeddedRuntime$checkIdle = (context) => {
|
|
132
|
+
context.checkCalls?.();
|
|
133
|
+
let { idleWaiters } = context.storeAsyncState;
|
|
134
|
+
if (idleWaiters.size === 0 || !__jcoEmbeddedRuntime$isIdle(context)) return;
|
|
135
|
+
let waiters = [...idleWaiters];
|
|
136
|
+
idleWaiters.clear();
|
|
137
|
+
for (let resolve of waiters) resolve();
|
|
138
|
+
};
|
|
139
|
+
var __jcoEmbeddedRuntime$whenIdle = (context) => {
|
|
140
|
+
if (__jcoEmbeddedRuntime$isIdle(context)) return Promise.resolve();
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
context.storeAsyncState.idleWaiters.add(resolve);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
var __jcoEmbeddedRuntime$stopInstance = (context) => {
|
|
146
|
+
let { storeTrap, storeAsyncState, asyncState, symbolDispose: symbolDispose2 } = context;
|
|
147
|
+
if (storeTrap.stopped) return;
|
|
148
|
+
storeTrap.stopped = true;
|
|
149
|
+
let err = new context.RuntimeError("component instance has been stopped");
|
|
150
|
+
storeTrap.error ??= err;
|
|
151
|
+
clearTimeout(storeAsyncState.deadlockCheck);
|
|
152
|
+
storeAsyncState.deadlockCheck = null;
|
|
153
|
+
for (let state of asyncState.values()) state.markTrapped(err);
|
|
154
|
+
for (let reject of storeTrap.stopWaiters) reject(err);
|
|
155
|
+
storeTrap.stopWaiters.clear();
|
|
156
|
+
let pending = [...context.tasks.values()].flat().map((meta) => meta.task);
|
|
157
|
+
for (let task of pending) task.stop(err);
|
|
158
|
+
for (let state of asyncState.values()) state.stop();
|
|
159
|
+
let errors = [];
|
|
160
|
+
for (let channels of context.channels) for (let i = 2, data = channels.data(); i < data.length; i += 2) {
|
|
161
|
+
let channel = data[i];
|
|
162
|
+
if (channel === void 0 || channel === context.RepTable.FREE) continue;
|
|
163
|
+
try {
|
|
164
|
+
channel.onInstanceStop?.();
|
|
165
|
+
} catch (e) {
|
|
166
|
+
errors.push(e);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let resources = /* @__PURE__ */ new Set();
|
|
170
|
+
for (let { handles, captures } of storeTrap.resourceTables) for (let i = 2; i < handles.length; i += 2) {
|
|
171
|
+
if (handles[i] & 1073741824 || !(handles[i + 1] >= __jcoEmbeddedRuntime$tableOwn)) continue;
|
|
172
|
+
let resource = captures.get(handles[i + 1] - __jcoEmbeddedRuntime$tableOwn);
|
|
173
|
+
resource !== void 0 && resources.add(resource);
|
|
174
|
+
}
|
|
175
|
+
for (let { captures } of storeTrap.resourceTables) captures.clear();
|
|
176
|
+
storeTrap.resourceTables.length = 0;
|
|
177
|
+
for (let resource of resources) {
|
|
178
|
+
if (storeTrap.disposed.has(resource)) continue;
|
|
179
|
+
try {
|
|
180
|
+
resource[symbolDispose2]?.();
|
|
181
|
+
} catch (error) {
|
|
182
|
+
errors.push(error);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (errors.length) throw AggregateError(errors, "failed to dispose stopped instance resources");
|
|
186
|
+
};
|
|
187
|
+
var __jcoEmbeddedRuntime$initializeInstanceFlags = () => /* @__PURE__ */ new Map();
|
|
188
|
+
var __jcoEmbeddedRuntime$initializeStoreTrap = (onTrap = null) => ({
|
|
189
|
+
error: null,
|
|
190
|
+
stopped: false,
|
|
191
|
+
resourceTables: [],
|
|
192
|
+
stopWaiters: /* @__PURE__ */ new Set(),
|
|
193
|
+
disposed: /* @__PURE__ */ new WeakSet(),
|
|
194
|
+
onTrap,
|
|
195
|
+
trapsReported: /* @__PURE__ */ new WeakSet()
|
|
196
|
+
});
|
|
197
|
+
var __jcoEmbeddedRuntime$initializeStoreAsyncState = () => ({
|
|
198
|
+
deadlockCheck: null,
|
|
199
|
+
pendingHostOperations: 0,
|
|
200
|
+
idleWaiters: /* @__PURE__ */ new Set()
|
|
201
|
+
});
|
|
202
|
+
var __jcoEmbeddedRuntime$initializeComponentAsyncStates = () => /* @__PURE__ */ new Map();
|
|
203
|
+
var __jcoEmbeddedRuntime$initializeCoreTrapMessages = (messages) => new Map(Object.entries(messages));
|
|
204
|
+
function __jcoEmbeddedRuntime$normalizeCoreTrap(context, err) {
|
|
205
|
+
let { RuntimeError, messages: trapMessages } = context;
|
|
206
|
+
if (!(err instanceof RuntimeError)) return err;
|
|
207
|
+
let message = trapMessages.get(err.message);
|
|
208
|
+
message !== void 0 && (err.message = message);
|
|
209
|
+
return err;
|
|
210
|
+
}
|
|
211
|
+
function __jcoEmbeddedRuntime$checkForDeadlock(context) {
|
|
212
|
+
let { RuntimeError, storeAsyncState, storeTrap, asyncState } = context;
|
|
213
|
+
if (storeAsyncState.deadlockCheck !== null || storeTrap.error !== null) return;
|
|
214
|
+
storeAsyncState.deadlockCheck = setTimeout(() => {
|
|
215
|
+
storeAsyncState.deadlockCheck = null;
|
|
216
|
+
if (storeTrap.error !== null || storeAsyncState.pendingHostOperations > 0) return;
|
|
217
|
+
let suspendedTasks = /* @__PURE__ */ new Set();
|
|
218
|
+
for (let state of asyncState.values()) {
|
|
219
|
+
if (state.hasPendingSchedulerWork()) {
|
|
220
|
+
state.runTickLoop();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
for (let meta of state.suspendedTaskMetas()) suspendedTasks.add(meta.task);
|
|
224
|
+
}
|
|
225
|
+
let unresolvedRoots = /* @__PURE__ */ new Set();
|
|
226
|
+
for (let task of suspendedTasks) {
|
|
227
|
+
let root = task.getRootTask();
|
|
228
|
+
root.isResolvedState() || unresolvedRoots.add(root);
|
|
229
|
+
}
|
|
230
|
+
if (unresolvedRoots.size === 0) return;
|
|
231
|
+
let err = new RuntimeError("wasm trap: deadlock detected: event loop cannot make further progress");
|
|
232
|
+
err.deadlockDetail = {
|
|
233
|
+
pendingHostOperations: storeAsyncState.pendingHostOperations,
|
|
234
|
+
suspendedTasks: [...suspendedTasks].map((task) => ({
|
|
235
|
+
taskID: task.id(),
|
|
236
|
+
componentIdx: task.componentIdx(),
|
|
237
|
+
state: task.taskState(),
|
|
238
|
+
rootTaskID: task.getRootTask().id()
|
|
239
|
+
})),
|
|
240
|
+
unresolvedRootTaskIDs: [...unresolvedRoots].map((root) => root.id())
|
|
241
|
+
};
|
|
242
|
+
storeTrap.error = err;
|
|
243
|
+
for (let root of unresolvedRoots) {
|
|
244
|
+
root.setErrored(err);
|
|
245
|
+
root.reject(err);
|
|
246
|
+
}
|
|
247
|
+
for (let task of suspendedTasks) if (!task.isResolvedState() && unresolvedRoots.has(task.getRootTask())) {
|
|
248
|
+
task.setErrored(err);
|
|
249
|
+
task.reject(err);
|
|
250
|
+
}
|
|
251
|
+
for (let state of asyncState.values()) state.markTrapped(err);
|
|
252
|
+
for (let state of asyncState.values()) state.abandonLockWaiters();
|
|
253
|
+
for (let state of asyncState.values()) state.abandonAdmissionWaiters();
|
|
254
|
+
for (let state of asyncState.values()) state.runTickLoop();
|
|
255
|
+
}, 0);
|
|
256
|
+
}
|
|
257
|
+
function __jcoEmbeddedRuntime$checkMayLeave(context, componentIdx) {
|
|
258
|
+
let { RuntimeError, instanceFlags } = context;
|
|
259
|
+
if (instanceFlags.get(componentIdx)?.value !== 1) throw new RuntimeError("cannot leave component instance");
|
|
260
|
+
}
|
|
261
|
+
function __jcoEmbeddedRuntime$guardMayLeave(context, componentIdx, fn) {
|
|
262
|
+
return function(...args) {
|
|
263
|
+
__jcoEmbeddedRuntime$checkMayLeave(context, componentIdx);
|
|
264
|
+
return fn.apply(this, args);
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function __jcoEmbeddedRuntime$recordTrap(context, componentIdx, err, convertsRangeErrors = false) {
|
|
268
|
+
let { RuntimeError, registers: currentTaskMeta } = context;
|
|
269
|
+
convertsRangeErrors && err instanceof RangeError && (err = new RuntimeError("out of bounds memory access"));
|
|
270
|
+
if (err instanceof RuntimeError) {
|
|
271
|
+
let idx = componentIdx ?? currentTaskMeta.current?.componentIdx;
|
|
272
|
+
idx != null && __jcoEmbeddedRuntime$getOrCreateAsyncState(context.lookup, idx).markTrapped(err);
|
|
273
|
+
}
|
|
274
|
+
return err;
|
|
275
|
+
}
|
|
276
|
+
function __jcoEmbeddedRuntime$guardTrap(context, componentIdx, fn, convertsRangeErrors = false) {
|
|
277
|
+
return function(...args) {
|
|
278
|
+
try {
|
|
279
|
+
return fn.apply(this, args);
|
|
280
|
+
} catch (err) {
|
|
281
|
+
throw __jcoEmbeddedRuntime$recordTrap(context, componentIdx, err, convertsRangeErrors);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function __jcoEmbeddedRuntime$getOrCreateAsyncState(context, componentIdx) {
|
|
286
|
+
let { asyncState, ComponentAsyncState } = context;
|
|
287
|
+
if (!asyncState.has(componentIdx)) {
|
|
288
|
+
let newState = new ComponentAsyncState({ componentIdx });
|
|
289
|
+
asyncState.set(componentIdx, newState);
|
|
290
|
+
}
|
|
291
|
+
return asyncState.get(componentIdx);
|
|
292
|
+
}
|
|
293
|
+
var __jcoEmbeddedRuntime$TICK_DONE = "done";
|
|
294
|
+
var __jcoEmbeddedRuntime$TICK_RESUMED = "resumed";
|
|
295
|
+
var __jcoEmbeddedRuntime$TICK_IDLE = "idle";
|
|
296
|
+
function __jcoEmbeddedRuntime$initializeComponentAsyncStateClass(context) {
|
|
297
|
+
let { RuntimeError, RepTable: RepTable2, indexSpaces, instanceFlags, storeTrap, normalization, cannotEnter, deadlock, Waitable: Waitable2 } = context;
|
|
298
|
+
class ComponentAsyncState {
|
|
299
|
+
static EVENT_HANDLER_EVENTS = ["backpressure-change"];
|
|
300
|
+
static TickResult = {
|
|
301
|
+
DONE: __jcoEmbeddedRuntime$TICK_DONE,
|
|
302
|
+
RESUMED: __jcoEmbeddedRuntime$TICK_RESUMED,
|
|
303
|
+
IDLE: __jcoEmbeddedRuntime$TICK_IDLE
|
|
304
|
+
};
|
|
305
|
+
#componentIdx;
|
|
306
|
+
#callingAsyncImport = false;
|
|
307
|
+
#syncImportWait = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
308
|
+
#lockHolderTaskID = null;
|
|
309
|
+
#lockWaiters = [];
|
|
310
|
+
#admissionQueue = [];
|
|
311
|
+
#lockHandoffScheduled = false;
|
|
312
|
+
#pendingTaskStarts = 0;
|
|
313
|
+
#suspendedThreadsByRef = /* @__PURE__ */ new Map();
|
|
314
|
+
#errored = null;
|
|
315
|
+
#trapped = false;
|
|
316
|
+
#trapError = null;
|
|
317
|
+
#backpressure = 0;
|
|
318
|
+
#backpressureWaiters = 0n;
|
|
319
|
+
#handlers = [];
|
|
320
|
+
#nextHandlerID = 0n;
|
|
321
|
+
#tickLoop = null;
|
|
322
|
+
#onExclusiveReleaseHandlers = [];
|
|
323
|
+
#mayLeave = true;
|
|
324
|
+
handles;
|
|
325
|
+
subtasks;
|
|
326
|
+
threads;
|
|
327
|
+
constructor(args) {
|
|
328
|
+
this.#componentIdx = args.componentIdx;
|
|
329
|
+
this.handles = new RepTable2({
|
|
330
|
+
target: `component [${this.#componentIdx}] handles (waitable objects)`,
|
|
331
|
+
space: __jcoEmbeddedRuntime$getHandleIndexSpace(indexSpaces, this.#componentIdx)
|
|
332
|
+
});
|
|
333
|
+
this.subtasks = new RepTable2({ target: `component [${this.#componentIdx}] subtasks` });
|
|
334
|
+
this.threads = new RepTable2({ target: `component [${this.#componentIdx}] threads` });
|
|
335
|
+
}
|
|
336
|
+
componentIdx() {
|
|
337
|
+
return this.#componentIdx;
|
|
338
|
+
}
|
|
339
|
+
get mayLeave() {
|
|
340
|
+
let flags = instanceFlags.get(this.#componentIdx);
|
|
341
|
+
return flags === void 0 ? this.#mayLeave : flags.value === 1;
|
|
342
|
+
}
|
|
343
|
+
set mayLeave(value) {
|
|
344
|
+
if (typeof value != "boolean") throw TypeError("mayLeave must be a boolean");
|
|
345
|
+
this.#mayLeave = value;
|
|
346
|
+
let flags = instanceFlags.get(this.#componentIdx);
|
|
347
|
+
flags !== void 0 && (flags.value = +!!value);
|
|
348
|
+
}
|
|
349
|
+
errored() {
|
|
350
|
+
return this.#errored !== null;
|
|
351
|
+
}
|
|
352
|
+
setErrored(err) {
|
|
353
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#setErrored()] component errored", {
|
|
354
|
+
err,
|
|
355
|
+
componentIdx: this.#componentIdx
|
|
356
|
+
});
|
|
357
|
+
if (this.#errored) return;
|
|
358
|
+
err ||= Object.assign(Error("error elswehere (see other component instance error)"), { componentIdx: this.#componentIdx });
|
|
359
|
+
this.#errored = err;
|
|
360
|
+
}
|
|
361
|
+
markTrapped(err) {
|
|
362
|
+
if (!(err instanceof RuntimeError)) return false;
|
|
363
|
+
let trap = __jcoEmbeddedRuntime$normalizeCoreTrap(normalization, err);
|
|
364
|
+
this.#trapped = true;
|
|
365
|
+
this.#trapError === null && (this.#trapError = trap);
|
|
366
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#markTrapped()] component trapped", {
|
|
367
|
+
err,
|
|
368
|
+
componentIdx: this.#componentIdx
|
|
369
|
+
});
|
|
370
|
+
storeTrap.error === null && (storeTrap.error = trap);
|
|
371
|
+
context.reportTrap?.(trap);
|
|
372
|
+
context.checkIdle?.();
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
isTrapped() {
|
|
376
|
+
return this.#trapped;
|
|
377
|
+
}
|
|
378
|
+
throwIfInterrupted() {
|
|
379
|
+
if (storeTrap.stopped) throw storeTrap.error;
|
|
380
|
+
if (this.#trapped) throw this.#trapError ?? new RuntimeError(cannotEnter);
|
|
381
|
+
}
|
|
382
|
+
throwIfTrapped() {
|
|
383
|
+
if (storeTrap.stopped) throw storeTrap.error;
|
|
384
|
+
if (this.#trapped) throw new RuntimeError(cannotEnter);
|
|
385
|
+
}
|
|
386
|
+
callingSyncImport(val) {
|
|
387
|
+
if (val === void 0) return this.#callingAsyncImport;
|
|
388
|
+
if (typeof val != "boolean") throw TypeError("invalid setting for async import");
|
|
389
|
+
let prev = this.#callingAsyncImport;
|
|
390
|
+
this.#callingAsyncImport = val;
|
|
391
|
+
prev === true && this.#callingAsyncImport === false && this.#notifySyncImportEnd();
|
|
392
|
+
}
|
|
393
|
+
#notifySyncImportEnd() {
|
|
394
|
+
let existing = this.#syncImportWait;
|
|
395
|
+
this.#syncImportWait = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
396
|
+
existing.resolve();
|
|
397
|
+
}
|
|
398
|
+
async waitForSyncImportCallEnd() {
|
|
399
|
+
await this.#syncImportWait.promise;
|
|
400
|
+
}
|
|
401
|
+
setBackpressure(v) {
|
|
402
|
+
this.#backpressure = v;
|
|
403
|
+
for (let handler of this.#handlers.filter((handler2) => handler2.event === "backpressure-change")) handler.fn(v);
|
|
404
|
+
return this.#backpressure;
|
|
405
|
+
}
|
|
406
|
+
getBackpressure() {
|
|
407
|
+
return this.#backpressure;
|
|
408
|
+
}
|
|
409
|
+
incrementBackpressure() {
|
|
410
|
+
let current = this.#backpressure;
|
|
411
|
+
if (current < 0 || current > 2 ** 16) throw Error(`invalid current backpressure value [${current}]`);
|
|
412
|
+
let newValue = this.getBackpressure() + 1;
|
|
413
|
+
if (newValue >= 2 ** 16) throw Error(`invalid new backpressure value [${newValue}], overflow`);
|
|
414
|
+
return this.setBackpressure(newValue);
|
|
415
|
+
}
|
|
416
|
+
decrementBackpressure() {
|
|
417
|
+
let current = this.#backpressure;
|
|
418
|
+
if (current < 0 || current > 2 ** 16) throw Error(`invalid current backpressure value [${current}]`);
|
|
419
|
+
let newValue = current - 1;
|
|
420
|
+
if (newValue < 0) throw new RuntimeError("backpressure counter underflow");
|
|
421
|
+
return this.setBackpressure(newValue);
|
|
422
|
+
}
|
|
423
|
+
hasBackpressure() {
|
|
424
|
+
return this.#backpressure > 0;
|
|
425
|
+
}
|
|
426
|
+
waitForBackpressure() {
|
|
427
|
+
if (!this.hasBackpressure()) return Promise.resolve(null);
|
|
428
|
+
this.addBackpressureWaiter();
|
|
429
|
+
return new Promise((resolve) => {
|
|
430
|
+
let pending = true;
|
|
431
|
+
let handlerID = this.registerHandler({
|
|
432
|
+
event: "backpressure-change",
|
|
433
|
+
fn: (bp) => {
|
|
434
|
+
if (bp !== 0 || !pending) return;
|
|
435
|
+
pending = false;
|
|
436
|
+
this.removeHandler({
|
|
437
|
+
event: "backpressure-change",
|
|
438
|
+
handlerID
|
|
439
|
+
});
|
|
440
|
+
this.removeBackpressureWaiter();
|
|
441
|
+
resolve(null);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
registerHandler(args) {
|
|
447
|
+
let { event, fn } = args;
|
|
448
|
+
if (!event) throw Error("missing handler event");
|
|
449
|
+
if (!fn) throw Error("missing handler fn");
|
|
450
|
+
if (!ComponentAsyncState.EVENT_HANDLER_EVENTS.includes(event)) throw Error(`unrecognized event handler [${event}]`);
|
|
451
|
+
let handlerID = this.#nextHandlerID++;
|
|
452
|
+
this.#handlers.push({
|
|
453
|
+
id: handlerID,
|
|
454
|
+
fn,
|
|
455
|
+
event
|
|
456
|
+
});
|
|
457
|
+
return handlerID;
|
|
458
|
+
}
|
|
459
|
+
removeHandler(args) {
|
|
460
|
+
let { event, handlerID } = args;
|
|
461
|
+
this.#handlers = this.#handlers.filter((handler) => handler.event !== event || handler.id !== handlerID);
|
|
462
|
+
}
|
|
463
|
+
getBackpressureWaiters() {
|
|
464
|
+
return this.#backpressureWaiters;
|
|
465
|
+
}
|
|
466
|
+
addBackpressureWaiter() {
|
|
467
|
+
this.#backpressureWaiters++;
|
|
468
|
+
}
|
|
469
|
+
removeBackpressureWaiter() {
|
|
470
|
+
this.#backpressureWaiters--;
|
|
471
|
+
if (this.#backpressureWaiters < 0) throw Error("unexepctedly negative number of backpressure waiters");
|
|
472
|
+
}
|
|
473
|
+
isExclusivelyLocked() {
|
|
474
|
+
return this.#lockHolderTaskID !== null;
|
|
475
|
+
}
|
|
476
|
+
exclusivelyLockedBy(taskID) {
|
|
477
|
+
return this.#lockHolderTaskID === taskID;
|
|
478
|
+
}
|
|
479
|
+
exclusiveLock(taskID) {
|
|
480
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#exclusiveLock()]", {
|
|
481
|
+
holder: this.#lockHolderTaskID,
|
|
482
|
+
requester: taskID,
|
|
483
|
+
componentIdx: this.#componentIdx
|
|
484
|
+
});
|
|
485
|
+
if (taskID == null) throw Error("exclusive lock requires the acquiring task id");
|
|
486
|
+
if (this.#lockHolderTaskID !== null) throw Error(`component [${this.#componentIdx}] exclusive lock held by task [${this.#lockHolderTaskID}], requested by [${taskID}]`);
|
|
487
|
+
this.#lockHolderTaskID = taskID;
|
|
488
|
+
}
|
|
489
|
+
acquireExclusiveLock(taskID) {
|
|
490
|
+
if (taskID == null) throw Error("exclusive lock requires the acquiring task id");
|
|
491
|
+
if (this.#lockHolderTaskID === null) {
|
|
492
|
+
this.#lockHolderTaskID = taskID;
|
|
493
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#acquireExclusiveLock()] acquired", {
|
|
494
|
+
holder: taskID,
|
|
495
|
+
componentIdx: this.#componentIdx
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (this.#lockHolderTaskID === taskID) throw Error(`task [${taskID}] already holds the lock for component [${this.#componentIdx}]`);
|
|
500
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#acquireExclusiveLock()] waiting", {
|
|
501
|
+
holder: this.#lockHolderTaskID,
|
|
502
|
+
requester: taskID,
|
|
503
|
+
componentIdx: this.#componentIdx,
|
|
504
|
+
queued: this.#lockWaiters.length
|
|
505
|
+
});
|
|
506
|
+
return new Promise((resolve) => {
|
|
507
|
+
this.#lockWaiters.push({
|
|
508
|
+
taskID,
|
|
509
|
+
resolve
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
takeAdmissionTicket(taskID) {
|
|
514
|
+
let ticket = {
|
|
515
|
+
taskID,
|
|
516
|
+
...__jcoEmbeddedRuntime$promiseWithResolvers()
|
|
517
|
+
};
|
|
518
|
+
this.#admissionQueue.push(ticket);
|
|
519
|
+
return ticket;
|
|
520
|
+
}
|
|
521
|
+
hasPendingAdmissions() {
|
|
522
|
+
return this.#admissionQueue.length > 0;
|
|
523
|
+
}
|
|
524
|
+
waitForAdmissionTurn(ticket) {
|
|
525
|
+
if (this.#admissionQueue[0] === ticket) return;
|
|
526
|
+
return ticket.promise;
|
|
527
|
+
}
|
|
528
|
+
releaseAdmissionTicket(ticket) {
|
|
529
|
+
let idx = this.#admissionQueue.indexOf(ticket);
|
|
530
|
+
if (idx === -1) return;
|
|
531
|
+
this.#admissionQueue.splice(idx, 1);
|
|
532
|
+
idx === 0 && this.#admissionQueue.length > 0 && this.#admissionQueue[0].resolve();
|
|
533
|
+
}
|
|
534
|
+
abandonAdmissionWaiters() {
|
|
535
|
+
let tickets = this.#admissionQueue.splice(0);
|
|
536
|
+
for (let ticket of tickets) ticket.resolve();
|
|
537
|
+
}
|
|
538
|
+
abandonLockWaiters() {
|
|
539
|
+
let waiters = this.#lockWaiters.splice(0);
|
|
540
|
+
for (let waiter of waiters) waiter.resolve();
|
|
541
|
+
}
|
|
542
|
+
cancelExclusiveLockWaiter(taskID) {
|
|
543
|
+
let idx = this.#lockWaiters.findIndex((waiter2) => waiter2.taskID === taskID);
|
|
544
|
+
if (idx === -1) return false;
|
|
545
|
+
let [waiter] = this.#lockWaiters.splice(idx, 1);
|
|
546
|
+
waiter.resolve();
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
exclusiveRelease(taskID) {
|
|
550
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#exclusiveRelease()] args", {
|
|
551
|
+
holder: this.#lockHolderTaskID,
|
|
552
|
+
releaser: taskID,
|
|
553
|
+
componentIdx: this.#componentIdx
|
|
554
|
+
});
|
|
555
|
+
if (this.#lockHolderTaskID !== taskID) {
|
|
556
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#exclusiveRelease()] ignoring foreign release", {
|
|
557
|
+
holder: this.#lockHolderTaskID,
|
|
558
|
+
releaser: taskID,
|
|
559
|
+
componentIdx: this.#componentIdx
|
|
560
|
+
});
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
this.#lockHolderTaskID = null;
|
|
564
|
+
this.#onExclusiveReleaseHandlers = this.#onExclusiveReleaseHandlers.filter((v) => !!v);
|
|
565
|
+
for (let [idx, f] of this.#onExclusiveReleaseHandlers.entries()) try {
|
|
566
|
+
this.#onExclusiveReleaseHandlers[idx] = null;
|
|
567
|
+
f();
|
|
568
|
+
} catch (err) {
|
|
569
|
+
__jcoEmbeddedRuntime$debugLog("error while executing handler for next exclusive release", err);
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
this.#scheduleLockHandoff();
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
#scheduleLockHandoff() {
|
|
576
|
+
if (this.#lockHandoffScheduled || this.#lockWaiters.length === 0) return;
|
|
577
|
+
this.#lockHandoffScheduled = true;
|
|
578
|
+
queueMicrotask(() => {
|
|
579
|
+
this.#lockHandoffScheduled = false;
|
|
580
|
+
if (this.#lockHolderTaskID !== null) return;
|
|
581
|
+
let next = this.#lockWaiters.shift();
|
|
582
|
+
if (!next) return;
|
|
583
|
+
this.#lockHolderTaskID = next.taskID;
|
|
584
|
+
next.resolve();
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
onNextExclusiveRelease(fn) {
|
|
588
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#()onNextExclusiveRelease] registering");
|
|
589
|
+
this.#onExclusiveReleaseHandlers.push(fn);
|
|
590
|
+
}
|
|
591
|
+
async waitForExclusiveRelease() {
|
|
592
|
+
for (; this.isExclusivelyLocked(); ) await new Promise((resolve) => this.onNextExclusiveRelease(resolve));
|
|
593
|
+
}
|
|
594
|
+
#getSuspendedTaskMeta(taskID) {
|
|
595
|
+
let metas = [...this.#suspendedThreadsByRef.values()].filter((meta) => meta.thread.taskID() === taskID);
|
|
596
|
+
return metas.find((meta) => meta.cancellable && this.suspendedThreadReady(meta.thread)) ?? metas[0];
|
|
597
|
+
}
|
|
598
|
+
suspendTask(args) {
|
|
599
|
+
let { task, ...opts } = args;
|
|
600
|
+
task.endFirstSlice();
|
|
601
|
+
return this.suspendThread({
|
|
602
|
+
thread: task.defaultThread(),
|
|
603
|
+
...opts
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
resumeTaskByID(taskID) {
|
|
607
|
+
let meta = this.#getSuspendedTaskMeta(taskID);
|
|
608
|
+
return meta ? this.resumeThread(meta.thread) : false;
|
|
609
|
+
}
|
|
610
|
+
suspendedTaskReady(taskID) {
|
|
611
|
+
let meta = this.#getSuspendedTaskMeta(taskID);
|
|
612
|
+
return meta ? this.suspendedThreadReady(meta.thread) : false;
|
|
613
|
+
}
|
|
614
|
+
suspendedTaskCancellable(taskID) {
|
|
615
|
+
return !!this.#getSuspendedTaskMeta(taskID)?.cancellable;
|
|
616
|
+
}
|
|
617
|
+
isTaskSuspended(taskID) {
|
|
618
|
+
return !!this.#getSuspendedTaskMeta(taskID);
|
|
619
|
+
}
|
|
620
|
+
*suspendedTaskMetas() {
|
|
621
|
+
for (let meta of this.#suspendedThreadsByRef.values()) yield {
|
|
622
|
+
...meta,
|
|
623
|
+
task: meta.thread.task()
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
#removeSuspendedThreadMeta(thread) {
|
|
627
|
+
let meta = this.#suspendedThreadsByRef.get(thread);
|
|
628
|
+
this.#suspendedThreadsByRef.delete(thread);
|
|
629
|
+
return meta;
|
|
630
|
+
}
|
|
631
|
+
suspendThread(args) {
|
|
632
|
+
let { thread, readyFn, cancellable, onResume, suspended = false } = args;
|
|
633
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#suspendThread()]", {
|
|
634
|
+
threadID: thread.id(),
|
|
635
|
+
taskID: thread.taskID(),
|
|
636
|
+
componentIdx: this.#componentIdx
|
|
637
|
+
});
|
|
638
|
+
if (thread.componentIdx() !== this.#componentIdx) throw Error("assert: thread component idx should match async state");
|
|
639
|
+
if (this.#suspendedThreadsByRef.has(thread)) throw Error(`thread [${thread.id()}] already suspended`);
|
|
640
|
+
let promise;
|
|
641
|
+
let resume;
|
|
642
|
+
if (onResume) resume = () => onResume(!thread.isCancelled() && !thread.isRejected() && !this.isTrapped());
|
|
643
|
+
else {
|
|
644
|
+
let resolvers = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
645
|
+
promise = resolvers.promise;
|
|
646
|
+
resume = () => resolvers.resolve(!thread.isCancelled() && !thread.isRejected() && !this.isTrapped());
|
|
647
|
+
}
|
|
648
|
+
if (storeTrap.stopped) {
|
|
649
|
+
this.markTrapped(storeTrap.error);
|
|
650
|
+
resume();
|
|
651
|
+
return promise;
|
|
652
|
+
}
|
|
653
|
+
this.#suspendedThreadsByRef.set(thread, {
|
|
654
|
+
thread,
|
|
655
|
+
cancellable,
|
|
656
|
+
readyFn,
|
|
657
|
+
resume,
|
|
658
|
+
suspended
|
|
659
|
+
});
|
|
660
|
+
thread.notifyProgress();
|
|
661
|
+
this.runTickLoop();
|
|
662
|
+
__jcoEmbeddedRuntime$checkForDeadlock(deadlock);
|
|
663
|
+
return promise;
|
|
664
|
+
}
|
|
665
|
+
resumeThread(thread) {
|
|
666
|
+
let meta = this.#removeSuspendedThreadMeta(thread);
|
|
667
|
+
if (!meta) return false;
|
|
668
|
+
meta.resume();
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
markThreadReady(thread) {
|
|
672
|
+
let meta = this.#suspendedThreadsByRef.get(thread);
|
|
673
|
+
if (!meta || !meta.suspended) return false;
|
|
674
|
+
meta.suspended = false;
|
|
675
|
+
meta.readyFn = () => true;
|
|
676
|
+
this.runTickLoop();
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
isThreadSuspended(thread) {
|
|
680
|
+
return this.#suspendedThreadsByRef.get(thread)?.suspended ?? false;
|
|
681
|
+
}
|
|
682
|
+
isThreadReady(thread) {
|
|
683
|
+
let meta = this.#suspendedThreadsByRef.get(thread);
|
|
684
|
+
return !!meta && !meta.suspended && (meta.thread.isRejected() || meta.readyFn());
|
|
685
|
+
}
|
|
686
|
+
suspendedThreadReady(thread) {
|
|
687
|
+
let meta = this.#suspendedThreadsByRef.get(thread);
|
|
688
|
+
if (!meta) return false;
|
|
689
|
+
if (!meta.readyFn) throw Error(`suspended thread [${thread.id()}] is missing a readiness function`);
|
|
690
|
+
if (this.isTrapped() || meta.thread.isRejected()) return true;
|
|
691
|
+
if (!meta.readyFn()) return false;
|
|
692
|
+
let task = meta.thread.task();
|
|
693
|
+
return !task.needsExclusiveLock() || !this.isExclusivelyLocked() || this.exclusivelyLockedBy(task.id());
|
|
694
|
+
}
|
|
695
|
+
addPendingTaskStart() {
|
|
696
|
+
this.#pendingTaskStarts++;
|
|
697
|
+
}
|
|
698
|
+
removePendingTaskStart() {
|
|
699
|
+
this.#pendingTaskStarts--;
|
|
700
|
+
}
|
|
701
|
+
hasPendingSchedulerWork() {
|
|
702
|
+
if (this.#pendingTaskStarts > 0) return true;
|
|
703
|
+
if (this.#lockHandoffScheduled) return true;
|
|
704
|
+
for (let meta of this.#suspendedThreadsByRef.values()) if (this.suspendedThreadReady(meta.thread)) return true;
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
stop() {
|
|
708
|
+
this.#tickLoop !== null && clearTimeout(this.#tickLoop);
|
|
709
|
+
this.#tickLoop = null;
|
|
710
|
+
this.abandonLockWaiters();
|
|
711
|
+
this.abandonAdmissionWaiters();
|
|
712
|
+
for (let thread of [...this.#suspendedThreadsByRef.keys()]) this.resumeThread(thread);
|
|
713
|
+
}
|
|
714
|
+
runTickLoop() {
|
|
715
|
+
if (storeTrap.stopped || this.#tickLoop !== null) return;
|
|
716
|
+
let run = () => {
|
|
717
|
+
if (storeTrap.stopped) {
|
|
718
|
+
this.#tickLoop = null;
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
let result = this.tick();
|
|
722
|
+
if (storeTrap.stopped || result === __jcoEmbeddedRuntime$TICK_DONE) {
|
|
723
|
+
this.#tickLoop = null;
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
result === __jcoEmbeddedRuntime$TICK_IDLE && __jcoEmbeddedRuntime$checkForDeadlock(deadlock);
|
|
727
|
+
let delay = result === __jcoEmbeddedRuntime$TICK_RESUMED ? 0 : 10;
|
|
728
|
+
this.#tickLoop = setTimeout(run, delay);
|
|
729
|
+
};
|
|
730
|
+
this.#tickLoop = setTimeout(run, 10);
|
|
731
|
+
}
|
|
732
|
+
tick() {
|
|
733
|
+
for (let [thread, meta] of this.#suspendedThreadsByRef) {
|
|
734
|
+
if (!meta || !meta.readyFn) throw Error(`missing/invalid thread meta despite thread [${thread.id()}] being present`);
|
|
735
|
+
if (this.isTrapped() || meta.thread.isRejected()) {
|
|
736
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#tick()] detected thread rejection, leaving early", { meta });
|
|
737
|
+
this.resumeThread(thread);
|
|
738
|
+
return __jcoEmbeddedRuntime$TICK_RESUMED;
|
|
739
|
+
}
|
|
740
|
+
if (!this.suspendedThreadReady(thread)) continue;
|
|
741
|
+
__jcoEmbeddedRuntime$debugLog("[ComponentAsyncState#tick()] resuming thread via tick", {
|
|
742
|
+
threadID: thread.id(),
|
|
743
|
+
componentIdx: this.#componentIdx
|
|
744
|
+
});
|
|
745
|
+
this.resumeThread(thread);
|
|
746
|
+
return __jcoEmbeddedRuntime$TICK_RESUMED;
|
|
747
|
+
}
|
|
748
|
+
return this.#suspendedThreadsByRef.size > 0 ? __jcoEmbeddedRuntime$TICK_IDLE : __jcoEmbeddedRuntime$TICK_DONE;
|
|
749
|
+
}
|
|
750
|
+
createWaitable(args) {
|
|
751
|
+
return new Waitable2({ target: args?.target });
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return ComponentAsyncState;
|
|
755
|
+
}
|
|
756
|
+
var __jcoEmbeddedRuntime$postReturnTrap = (context, componentIdx, error) => {
|
|
757
|
+
let trap;
|
|
758
|
+
if (error instanceof context.RuntimeError) trap = error;
|
|
759
|
+
else {
|
|
760
|
+
let message = /call stack|stack overflow|too much recursion/i.test(error?.message ?? "") ? context.stackOverflow : context.uncaughtException;
|
|
761
|
+
trap = new context.RuntimeError(message, { cause: error });
|
|
762
|
+
}
|
|
763
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(context.lookup, componentIdx).markTrapped(trap);
|
|
764
|
+
return trap;
|
|
765
|
+
};
|
|
766
|
+
function __jcoEmbeddedRuntime$createNewCurrentImplicitThread(_context, args) {
|
|
767
|
+
__jcoEmbeddedRuntime$debugLog("[createNewCurrentImplicitThread()] args", args);
|
|
768
|
+
let { componentIdx, isAsync, isManualAsync, preserveFutureResult, entryFnName, callbackFnName, getCallbackFn, stringEncoding, errHandling, getCalleeParamsFn, resultPtr, callingWasmExport } = args;
|
|
769
|
+
if (componentIdx == null) throw Error("missing/invalid component instance index while starting task");
|
|
770
|
+
let taskMetas = _context.tasks.get(componentIdx);
|
|
771
|
+
let callbackFn = getCallbackFn ? getCallbackFn() : null;
|
|
772
|
+
let newTask = new _context.AsyncTask({
|
|
773
|
+
componentIdx,
|
|
774
|
+
isAsync,
|
|
775
|
+
isManualAsync,
|
|
776
|
+
preserveFutureResult,
|
|
777
|
+
entryFnName,
|
|
778
|
+
callbackFn,
|
|
779
|
+
callbackFnName,
|
|
780
|
+
stringEncoding,
|
|
781
|
+
getCalleeParamsFn,
|
|
782
|
+
resultPtr,
|
|
783
|
+
errHandling,
|
|
784
|
+
callingWasmExport
|
|
785
|
+
});
|
|
786
|
+
let thread = newTask.addThread(new _context.AsyncThread({
|
|
787
|
+
componentIdx,
|
|
788
|
+
task: newTask
|
|
789
|
+
}));
|
|
790
|
+
let newTaskID = newTask.id();
|
|
791
|
+
let newTaskMeta = {
|
|
792
|
+
id: newTaskID,
|
|
793
|
+
componentIdx,
|
|
794
|
+
task: newTask
|
|
795
|
+
};
|
|
796
|
+
_context.taskIds.push(newTaskID);
|
|
797
|
+
_context.componentIdxs.push(componentIdx);
|
|
798
|
+
if (taskMetas) taskMetas.push(newTaskMeta);
|
|
799
|
+
else {
|
|
800
|
+
taskMetas = [newTaskMeta];
|
|
801
|
+
_context.tasks.set(componentIdx, [newTaskMeta]);
|
|
802
|
+
}
|
|
803
|
+
return {
|
|
804
|
+
task: newTask,
|
|
805
|
+
taskID: newTaskID,
|
|
806
|
+
thread,
|
|
807
|
+
threadID: thread.id()
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
function __jcoEmbeddedRuntime$clearCurrentThread(_context, componentIdx, taskID, options = {}) {
|
|
811
|
+
__jcoEmbeddedRuntime$debugLog("[clearCurrentThread()] args", {
|
|
812
|
+
componentIdx,
|
|
813
|
+
taskID
|
|
814
|
+
});
|
|
815
|
+
if (componentIdx == null) throw Error("missing/invalid component instance index while ending current task");
|
|
816
|
+
let tasks = _context.tasks.get(componentIdx);
|
|
817
|
+
if (!tasks || !Array.isArray(tasks)) throw Error("missing/invalid tasks for component instance while ending task");
|
|
818
|
+
if (tasks.length == 0) throw Error(`no current tasks for component instance [${componentIdx}] while ending task`);
|
|
819
|
+
let taskIdx = taskID === void 0 ? tasks.length - 1 : tasks.findIndex((meta) => meta.id === taskID);
|
|
820
|
+
if (taskIdx === -1) return;
|
|
821
|
+
let taskMeta = tasks[taskIdx];
|
|
822
|
+
if (!options.preserveTask) {
|
|
823
|
+
tasks.splice(taskIdx, 1);
|
|
824
|
+
_context.checkIdle?.();
|
|
825
|
+
}
|
|
826
|
+
let globalTaskIdx = _context.taskIds.lastIndexOf(taskMeta.id);
|
|
827
|
+
if (globalTaskIdx !== -1) {
|
|
828
|
+
_context.taskIds.splice(globalTaskIdx, 1);
|
|
829
|
+
_context.componentIdxs.splice(globalTaskIdx, 1);
|
|
830
|
+
}
|
|
831
|
+
return taskMeta.task;
|
|
832
|
+
}
|
|
833
|
+
var __jcoEmbeddedRuntime$RESOURCE_TABLE_FLAG = 1 << 30;
|
|
834
|
+
var __jcoEmbeddedRuntime$RESOURCE_TABLE_OWN = 2 ** 32;
|
|
835
|
+
var __jcoEmbeddedRuntime$tableOwn = __jcoEmbeddedRuntime$RESOURCE_TABLE_OWN;
|
|
836
|
+
var __jcoEmbeddedRuntime$initializeHandleIndexSpaces = () => /* @__PURE__ */ new Map();
|
|
837
|
+
var __jcoEmbeddedRuntime$initializeHandleTables = () => [];
|
|
838
|
+
var __jcoEmbeddedRuntime$initializeResourceScopeCounter = () => ({ value: 0 });
|
|
839
|
+
var __jcoEmbeddedRuntime$initializeResourceScopeTasks = () => /* @__PURE__ */ new Map();
|
|
840
|
+
var __jcoEmbeddedRuntime$getHandleIndexSpace = (spaces, key) => {
|
|
841
|
+
let space = spaces.get(key);
|
|
842
|
+
if (space === void 0) {
|
|
843
|
+
space = {
|
|
844
|
+
next: 1,
|
|
845
|
+
free: [],
|
|
846
|
+
alloc() {
|
|
847
|
+
return this.free.length > 0 ? this.free.pop() : this.next++;
|
|
848
|
+
},
|
|
849
|
+
release(index) {
|
|
850
|
+
this.free.push(index);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
spaces.set(key, space);
|
|
854
|
+
}
|
|
855
|
+
return space;
|
|
856
|
+
};
|
|
857
|
+
var __jcoEmbeddedRuntime$tableCreateOwn = (spaces, table, rep) => {
|
|
858
|
+
rep >>>= 0;
|
|
859
|
+
table._createdReps.add(rep);
|
|
860
|
+
let handle = __jcoEmbeddedRuntime$getHandleIndexSpace(spaces, table._componentIdx ?? table).alloc();
|
|
861
|
+
table[handle << 1] = 0;
|
|
862
|
+
table[(handle << 1) + 1] = rep + __jcoEmbeddedRuntime$RESOURCE_TABLE_OWN;
|
|
863
|
+
return handle;
|
|
864
|
+
};
|
|
865
|
+
var __jcoEmbeddedRuntime$tableRemove = (context, table, handle) => {
|
|
866
|
+
let scope = table[handle << 1];
|
|
867
|
+
let value = table[(handle << 1) + 1];
|
|
868
|
+
let own = value >= __jcoEmbeddedRuntime$RESOURCE_TABLE_OWN;
|
|
869
|
+
let rep = own ? value - __jcoEmbeddedRuntime$RESOURCE_TABLE_OWN : value;
|
|
870
|
+
if (value === void 0 || scope & __jcoEmbeddedRuntime$RESOURCE_TABLE_FLAG) throw new context.RuntimeError("unknown handle index " + handle);
|
|
871
|
+
if (own && scope !== 0) throw new context.RuntimeError("cannot remove owned resource while borrowed");
|
|
872
|
+
let borrowTask = own ? void 0 : context.scopeTasks.get(scope);
|
|
873
|
+
table[handle << 1] = __jcoEmbeddedRuntime$RESOURCE_TABLE_FLAG;
|
|
874
|
+
table[(handle << 1) + 1] = 0;
|
|
875
|
+
__jcoEmbeddedRuntime$getHandleIndexSpace(context.indexSpaces, table._componentIdx ?? table).release(handle);
|
|
876
|
+
borrowTask?.removeBorrowedHandle();
|
|
877
|
+
return {
|
|
878
|
+
rep,
|
|
879
|
+
scope,
|
|
880
|
+
own
|
|
881
|
+
};
|
|
882
|
+
};
|
|
883
|
+
var __jcoEmbeddedRuntime$isInt8 = (value) => typeof value == "number" && value === value << 24 >> 24;
|
|
884
|
+
var __jcoEmbeddedRuntime$isUint8 = (value) => typeof value == "number" && value === (value & 255);
|
|
885
|
+
var __jcoEmbeddedRuntime$isInt16 = (value) => typeof value == "number" && value === value << 16 >> 16;
|
|
886
|
+
var __jcoEmbeddedRuntime$isUint16 = (value) => typeof value == "number" && value === (value & 65535);
|
|
887
|
+
var __jcoEmbeddedRuntime$isInt32 = (value) => typeof value == "number" && value === (value | 0);
|
|
888
|
+
var __jcoEmbeddedRuntime$isUint32 = (value) => typeof value == "number" && value === value >>> 0;
|
|
889
|
+
var __jcoEmbeddedRuntime$isInt64 = (value) => typeof value == "bigint" && value === BigInt.asIntN(64, value);
|
|
890
|
+
var __jcoEmbeddedRuntime$isUint64 = (value) => typeof value == "bigint" && value === BigInt.asUintN(64, value);
|
|
891
|
+
function __jcoEmbeddedRuntime$invalidNumericPrimitive(type, value) {
|
|
892
|
+
throw TypeError(`invalid ${type} value [${value}]`);
|
|
893
|
+
}
|
|
894
|
+
var __jcoEmbeddedRuntime$toUint32 = (context, value) => {
|
|
895
|
+
context.strict && !__jcoEmbeddedRuntime$isUint32(value) && __jcoEmbeddedRuntime$invalidNumericPrimitive("u32", value);
|
|
896
|
+
return value >>> 0;
|
|
897
|
+
};
|
|
898
|
+
var __jcoEmbeddedRuntime$isValidNumericPrimitive = (type, value) => {
|
|
899
|
+
switch (type) {
|
|
900
|
+
case "bool":
|
|
901
|
+
return value === 0 || value === 1;
|
|
902
|
+
case "s8":
|
|
903
|
+
return __jcoEmbeddedRuntime$isInt8(value);
|
|
904
|
+
case "u8":
|
|
905
|
+
return __jcoEmbeddedRuntime$isUint8(value);
|
|
906
|
+
case "s16":
|
|
907
|
+
return __jcoEmbeddedRuntime$isInt16(value);
|
|
908
|
+
case "u16":
|
|
909
|
+
return __jcoEmbeddedRuntime$isUint16(value);
|
|
910
|
+
case "s32":
|
|
911
|
+
return __jcoEmbeddedRuntime$isInt32(value);
|
|
912
|
+
case "u32":
|
|
913
|
+
return __jcoEmbeddedRuntime$isUint32(value);
|
|
914
|
+
case "s64":
|
|
915
|
+
return __jcoEmbeddedRuntime$isInt64(value);
|
|
916
|
+
case "u64":
|
|
917
|
+
return __jcoEmbeddedRuntime$isUint64(value);
|
|
918
|
+
case "f32":
|
|
919
|
+
case "f64":
|
|
920
|
+
return typeof value == "number";
|
|
921
|
+
default:
|
|
922
|
+
return false;
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
var __jcoEmbeddedRuntime$requireValidNumericPrimitive = (type, value) => {
|
|
926
|
+
__jcoEmbeddedRuntime$isValidNumericPrimitive(type, value) || __jcoEmbeddedRuntime$invalidNumericPrimitive(type, value);
|
|
927
|
+
return true;
|
|
928
|
+
};
|
|
929
|
+
function __jcoEmbeddedRuntime$getCurrentThread(context, componentIdx, threadID, taskID) {
|
|
930
|
+
if (componentIdx === -1 || threadID == null || threadID === 0) return;
|
|
931
|
+
let thread = __jcoEmbeddedRuntime$getOrCreateAsyncState(context.lookup, componentIdx).threads.get(threadID);
|
|
932
|
+
if (!thread || taskID !== void 0 && thread.taskID() !== taskID) return;
|
|
933
|
+
return {
|
|
934
|
+
id: threadID,
|
|
935
|
+
componentIdx,
|
|
936
|
+
taskID: thread.taskID(),
|
|
937
|
+
task: thread.task(),
|
|
938
|
+
thread
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
var __jcoEmbeddedRuntime$emptyFunc = () => {
|
|
942
|
+
};
|
|
943
|
+
var __jcoEmbeddedRuntime$initializeDataViewCache = () => ({ view: new DataView(new ArrayBuffer(0)) });
|
|
944
|
+
var __jcoEmbeddedRuntime$dataView = (context, memory) => context.view.buffer === memory.buffer ? context.view : context.view = new DataView(memory.buffer);
|
|
945
|
+
function __jcoEmbeddedRuntime$requireString(value) {
|
|
946
|
+
if (typeof value != "string") throw TypeError("expected a string, received [" + typeof value + "]");
|
|
947
|
+
return value;
|
|
948
|
+
}
|
|
949
|
+
function __jcoEmbeddedRuntime$utf8Size(s) {
|
|
950
|
+
let len = 0;
|
|
951
|
+
let codepoints = 0;
|
|
952
|
+
for (let i = 0; i < s.length; i++) {
|
|
953
|
+
let ch = s.charCodeAt(i);
|
|
954
|
+
codepoints++;
|
|
955
|
+
if (ch < 128) len += 1;
|
|
956
|
+
else if (ch < 2048) len += 2;
|
|
957
|
+
else if (ch >= 55296 && ch <= 56319 && i + 1 < s.length && (s.charCodeAt(i + 1) & 64512) == 56320) {
|
|
958
|
+
len += 4;
|
|
959
|
+
i++;
|
|
960
|
+
} else len += 3;
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
len,
|
|
964
|
+
codepoints
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
var __jcoEmbeddedRuntime$initializeUtf8Decoder = () => new TextDecoder("utf-8", {
|
|
968
|
+
fatal: true,
|
|
969
|
+
ignoreBOM: true
|
|
970
|
+
});
|
|
971
|
+
var __jcoEmbeddedRuntime$initializeUtf8Encoder = () => new TextEncoder();
|
|
972
|
+
function __jcoEmbeddedRuntime$writeUtf8(encoder, s, ptr, len, codepoints, memory) {
|
|
973
|
+
let { read, written } = encoder.encodeInto(s, new Uint8Array(memory.buffer, ptr, len));
|
|
974
|
+
if (read !== s.length || written !== len) throw Error("failed to encode whole string");
|
|
975
|
+
return {
|
|
976
|
+
ptr,
|
|
977
|
+
len,
|
|
978
|
+
codepoints
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
var __jcoEmbeddedRuntime$utf8Encode = (encoder, value, realloc, memory) => {
|
|
982
|
+
let s = __jcoEmbeddedRuntime$requireString(value);
|
|
983
|
+
if (s.length === 0) return {
|
|
984
|
+
ptr: 1,
|
|
985
|
+
len: 0
|
|
986
|
+
};
|
|
987
|
+
let { len, codepoints } = __jcoEmbeddedRuntime$utf8Size(s);
|
|
988
|
+
return __jcoEmbeddedRuntime$writeUtf8(encoder, s, realloc(0, 0, 1, len), len, codepoints, memory);
|
|
989
|
+
};
|
|
990
|
+
function __jcoEmbeddedRuntime$initializeRepTableClass(context) {
|
|
991
|
+
let { RuntimeError } = context;
|
|
992
|
+
let free = /* @__PURE__ */ Symbol("RepTable.free");
|
|
993
|
+
class RepTable2 {
|
|
994
|
+
static FREE = free;
|
|
995
|
+
#data = [0, null];
|
|
996
|
+
#size = 0;
|
|
997
|
+
target;
|
|
998
|
+
#space = null;
|
|
999
|
+
constructor(args) {
|
|
1000
|
+
this.target = args?.target;
|
|
1001
|
+
this.#space = args?.space ?? null;
|
|
1002
|
+
}
|
|
1003
|
+
data() {
|
|
1004
|
+
return this.#data;
|
|
1005
|
+
}
|
|
1006
|
+
insert(val) {
|
|
1007
|
+
if (this.#space !== null) {
|
|
1008
|
+
let rep = this.#space.alloc();
|
|
1009
|
+
this.#data[rep << 1] = val;
|
|
1010
|
+
this.#data[(rep << 1) + 1] = null;
|
|
1011
|
+
this.#size += 1;
|
|
1012
|
+
return rep;
|
|
1013
|
+
}
|
|
1014
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#insert()] args", {
|
|
1015
|
+
val,
|
|
1016
|
+
target: this.target
|
|
1017
|
+
});
|
|
1018
|
+
let freeIdx = this.#data[0];
|
|
1019
|
+
if (freeIdx === 0) {
|
|
1020
|
+
this.#data.push(val);
|
|
1021
|
+
this.#data.push(null);
|
|
1022
|
+
let rep = (this.#data.length >> 1) - 1;
|
|
1023
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#insert()] inserted", {
|
|
1024
|
+
val,
|
|
1025
|
+
target: this.target,
|
|
1026
|
+
rep
|
|
1027
|
+
});
|
|
1028
|
+
this.#size += 1;
|
|
1029
|
+
return rep;
|
|
1030
|
+
}
|
|
1031
|
+
let placementIdx = freeIdx << 1;
|
|
1032
|
+
if (this.#data[placementIdx] !== free) throw Error("corrupt rep table freelist: head does not point at a freed slot");
|
|
1033
|
+
this.#data[0] = this.#data[placementIdx + 1];
|
|
1034
|
+
this.#data[placementIdx] = val;
|
|
1035
|
+
this.#data[placementIdx + 1] = null;
|
|
1036
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#insert()] inserted", {
|
|
1037
|
+
val,
|
|
1038
|
+
target: this.target,
|
|
1039
|
+
rep: freeIdx
|
|
1040
|
+
});
|
|
1041
|
+
this.#size += 1;
|
|
1042
|
+
return freeIdx;
|
|
1043
|
+
}
|
|
1044
|
+
get(rep) {
|
|
1045
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#get()] args", {
|
|
1046
|
+
rep,
|
|
1047
|
+
target: this.target
|
|
1048
|
+
});
|
|
1049
|
+
if (rep === 0) throw new RuntimeError("invalid resource rep during get, (cannot be 0)");
|
|
1050
|
+
let baseIdx = rep << 1;
|
|
1051
|
+
let val = this.#data[baseIdx];
|
|
1052
|
+
if (val === free) return;
|
|
1053
|
+
return val;
|
|
1054
|
+
}
|
|
1055
|
+
contains(rep) {
|
|
1056
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#contains()] args", {
|
|
1057
|
+
rep,
|
|
1058
|
+
target: this.target
|
|
1059
|
+
});
|
|
1060
|
+
if (rep === 0) throw Error("invalid resource rep during contains, (cannot be 0)");
|
|
1061
|
+
let baseIdx = rep << 1;
|
|
1062
|
+
let val = this.#data[baseIdx];
|
|
1063
|
+
return val !== free && !!val;
|
|
1064
|
+
}
|
|
1065
|
+
remove(rep) {
|
|
1066
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#remove()] args", {
|
|
1067
|
+
rep,
|
|
1068
|
+
target: this.target
|
|
1069
|
+
});
|
|
1070
|
+
if (rep === 0) throw Error("invalid resource rep during remove, (cannot be 0)");
|
|
1071
|
+
if (this.#space !== null) {
|
|
1072
|
+
let baseIdx2 = rep << 1;
|
|
1073
|
+
let val2 = this.#data[baseIdx2];
|
|
1074
|
+
if (val2 === void 0 || val2 === free) throw new RuntimeError(`unknown handle index ${rep}`);
|
|
1075
|
+
this.#data[baseIdx2] = free;
|
|
1076
|
+
this.#data[baseIdx2 + 1] = null;
|
|
1077
|
+
--this.#size;
|
|
1078
|
+
this.#space.release(rep);
|
|
1079
|
+
return val2;
|
|
1080
|
+
}
|
|
1081
|
+
if (this.#data.length === 2) throw Error("invalid");
|
|
1082
|
+
let baseIdx = rep << 1;
|
|
1083
|
+
if (baseIdx >= this.#data.length) throw Error(`invalid rep [${rep}] during remove, out of range`);
|
|
1084
|
+
let val = this.#data[baseIdx];
|
|
1085
|
+
if (val === free) throw new RuntimeError(`double removal of rep [${rep}] (already freed)`);
|
|
1086
|
+
this.#data[baseIdx] = free;
|
|
1087
|
+
this.#data[baseIdx + 1] = this.#data[0];
|
|
1088
|
+
this.#data[0] = rep;
|
|
1089
|
+
--this.#size;
|
|
1090
|
+
return val;
|
|
1091
|
+
}
|
|
1092
|
+
size() {
|
|
1093
|
+
return this.#size;
|
|
1094
|
+
}
|
|
1095
|
+
clear() {
|
|
1096
|
+
__jcoEmbeddedRuntime$debugLog("[RepTable#clear()] args", { target: this.target });
|
|
1097
|
+
if (this.#space) for (let rep = 1; rep < this.#data.length / 2; rep++) this.#data[(rep << 1) + 1] === null && this.#data[rep << 1] !== free && this.#space.release(rep);
|
|
1098
|
+
this.#size = 0;
|
|
1099
|
+
this.#data = [0, null];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return RepTable2;
|
|
1103
|
+
}
|
|
1104
|
+
var __jcoEmbeddedRuntime$initializeAsyncDeterminism = (mode) => mode;
|
|
1105
|
+
var __jcoEmbeddedRuntime$initializeRuntimeErrorConstructor = (platform) => platform.RuntimeError;
|
|
1106
|
+
var __jcoEmbeddedRuntime$initializeComponentErrorClass = () => {
|
|
1107
|
+
class ComponentError2 extends Error {
|
|
1108
|
+
constructor(value) {
|
|
1109
|
+
let enumerable = typeof value != "string";
|
|
1110
|
+
super(enumerable ? `${String(value)} (see error.payload)` : value);
|
|
1111
|
+
Object.defineProperty(this, "payload", {
|
|
1112
|
+
value,
|
|
1113
|
+
enumerable
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return ComponentError2;
|
|
1118
|
+
};
|
|
1119
|
+
var __jcoEmbeddedRuntime$initializeSymbolResourceHandle = () => /* @__PURE__ */ Symbol("handle");
|
|
1120
|
+
var __jcoEmbeddedRuntime$initializeSymbolDispose = () => Symbol.dispose || /* @__PURE__ */ Symbol.for("dispose");
|
|
1121
|
+
var __jcoEmbeddedRuntime$initializeAsyncEventCodes = () => ({
|
|
1122
|
+
NONE: 0,
|
|
1123
|
+
SUBTASK: 1,
|
|
1124
|
+
STREAM_READ: 2,
|
|
1125
|
+
STREAM_WRITE: 3,
|
|
1126
|
+
FUTURE_READ: 4,
|
|
1127
|
+
FUTURE_WRITE: 5,
|
|
1128
|
+
TASK_CANCELLED: 6
|
|
1129
|
+
});
|
|
1130
|
+
var __jcoEmbeddedRuntime$initializeComponentMemoryMap = () => /* @__PURE__ */ new Map();
|
|
1131
|
+
var __jcoEmbeddedRuntime$initializeFileCompileCache = (nodejsCompat) => ({
|
|
1132
|
+
node: !!(nodejsCompat && globalThis.process?.versions?.node),
|
|
1133
|
+
fs: void 0
|
|
1134
|
+
});
|
|
1135
|
+
var __jcoEmbeddedRuntime$coinFlip = () => Math.random() > 0.5;
|
|
1136
|
+
var __jcoEmbeddedRuntime$base64Compile = (context, encoded) => {
|
|
1137
|
+
let host = globalThis;
|
|
1138
|
+
return context.WebAssembly.compile(context.nodejsCompat && host.Buffer !== void 0 ? host.Buffer.from(encoded, "base64") : Uint8Array.from(atob(encoded), (byte) => byte.charCodeAt(0)));
|
|
1139
|
+
};
|
|
1140
|
+
async function __jcoEmbeddedRuntime$fetchWithNode(context, url) {
|
|
1141
|
+
if (context.fileCache.node) {
|
|
1142
|
+
context.fileCache.fs = context.fileCache.fs || await import("node:fs/promises");
|
|
1143
|
+
return context.WebAssembly.compile(await context.fileCache.fs.readFile(url));
|
|
1144
|
+
}
|
|
1145
|
+
return fetch(url).then(context.WebAssembly.compileStreaming);
|
|
1146
|
+
}
|
|
1147
|
+
var __jcoEmbeddedRuntime$fetchCompile = (context, url) => context.nodejsCompat ? __jcoEmbeddedRuntime$fetchWithNode(context, url) : fetch(url).then(context.WebAssembly.compileStreaming);
|
|
1148
|
+
var __jcoEmbeddedRuntime$instantiateCore = (platform, module, imports) => platform.instantiate(module, imports);
|
|
1149
|
+
var __jcoEmbeddedRuntime$finalizationRegistryCreate = (cleanup) => {
|
|
1150
|
+
if (typeof FinalizationRegistry > "u") return { unregister() {
|
|
1151
|
+
} };
|
|
1152
|
+
return new FinalizationRegistry(cleanup);
|
|
1153
|
+
};
|
|
1154
|
+
var __jcoEmbeddedRuntime$disposeHostValue = (disposeSymbol, value, disposeFn) => {
|
|
1155
|
+
if (!disposeFn) {
|
|
1156
|
+
if (value === null || typeof value != "object" && typeof value != "function") return;
|
|
1157
|
+
let disposable = value;
|
|
1158
|
+
if (typeof Symbol.asyncDispose == "symbol" && typeof disposable[Symbol.asyncDispose] == "function") disposeFn = disposable[Symbol.asyncDispose];
|
|
1159
|
+
else if (typeof disposable[disposeSymbol] == "function") disposeFn = disposable[disposeSymbol];
|
|
1160
|
+
else return;
|
|
1161
|
+
}
|
|
1162
|
+
let dispose = disposeFn;
|
|
1163
|
+
let report = (error) => console.error("[jco] error while disposing discarded host value", error);
|
|
1164
|
+
queueMicrotask(() => {
|
|
1165
|
+
try {
|
|
1166
|
+
let result = dispose.call(value);
|
|
1167
|
+
result && typeof result.then == "function" && result.then(void 0, report);
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
report(error);
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
};
|
|
1173
|
+
function __jcoEmbeddedRuntime$lookupMemories(map, args) {
|
|
1174
|
+
let { componentIdx } = args ?? {};
|
|
1175
|
+
if (args.componentIdx === void 0) throw TypeError("missing component idx");
|
|
1176
|
+
let metas = map.get(componentIdx);
|
|
1177
|
+
if (!metas) return [];
|
|
1178
|
+
return args.memoryIdx === void 0 ? Object.values(metas) : metas[args.memoryIdx]?.memory;
|
|
1179
|
+
}
|
|
1180
|
+
function __jcoEmbeddedRuntime$initializeWaitableClass() {
|
|
1181
|
+
class Waitable2 {
|
|
1182
|
+
#componentIdx;
|
|
1183
|
+
#pendingEventFn = null;
|
|
1184
|
+
#promise;
|
|
1185
|
+
#resolve;
|
|
1186
|
+
#reject;
|
|
1187
|
+
#waitableSet = null;
|
|
1188
|
+
#hasSyncWaiter = false;
|
|
1189
|
+
#idx = null;
|
|
1190
|
+
target;
|
|
1191
|
+
constructor(args) {
|
|
1192
|
+
let { componentIdx } = args;
|
|
1193
|
+
this.#componentIdx = componentIdx;
|
|
1194
|
+
this.target = args.target;
|
|
1195
|
+
this.#resetPromise();
|
|
1196
|
+
}
|
|
1197
|
+
componentIdx() {
|
|
1198
|
+
return this.#componentIdx;
|
|
1199
|
+
}
|
|
1200
|
+
isInSet() {
|
|
1201
|
+
return this.#waitableSet !== null;
|
|
1202
|
+
}
|
|
1203
|
+
idx() {
|
|
1204
|
+
return this.#idx;
|
|
1205
|
+
}
|
|
1206
|
+
setIdx(idx) {
|
|
1207
|
+
if (idx === 0) throw Error("waitable idx cannot be zero");
|
|
1208
|
+
this.#idx = idx;
|
|
1209
|
+
}
|
|
1210
|
+
setTarget(tgt) {
|
|
1211
|
+
this.target = tgt;
|
|
1212
|
+
}
|
|
1213
|
+
#resetPromise() {
|
|
1214
|
+
let { promise, resolve, reject } = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
1215
|
+
this.#promise = promise;
|
|
1216
|
+
this.#resolve = resolve;
|
|
1217
|
+
this.#reject = reject;
|
|
1218
|
+
}
|
|
1219
|
+
resolve() {
|
|
1220
|
+
this.#resolve();
|
|
1221
|
+
}
|
|
1222
|
+
reject(err) {
|
|
1223
|
+
this.#reject(err);
|
|
1224
|
+
}
|
|
1225
|
+
promise() {
|
|
1226
|
+
return this.#promise;
|
|
1227
|
+
}
|
|
1228
|
+
hasPendingEvent() {
|
|
1229
|
+
return this.#pendingEventFn !== null;
|
|
1230
|
+
}
|
|
1231
|
+
setPendingEvent(fn) {
|
|
1232
|
+
__jcoEmbeddedRuntime$debugLog("[Waitable#setPendingEvent()] args", {
|
|
1233
|
+
waitable: this,
|
|
1234
|
+
inSet: this.#waitableSet
|
|
1235
|
+
});
|
|
1236
|
+
this.#pendingEventFn = fn;
|
|
1237
|
+
}
|
|
1238
|
+
getPendingEvent() {
|
|
1239
|
+
__jcoEmbeddedRuntime$debugLog("[Waitable#getPendingEvent()] args", {
|
|
1240
|
+
waitable: this,
|
|
1241
|
+
inSet: this.#waitableSet,
|
|
1242
|
+
hasPendingEvent: this.#pendingEventFn !== null
|
|
1243
|
+
});
|
|
1244
|
+
if (this.#pendingEventFn === null) return null;
|
|
1245
|
+
let eventFn = this.#pendingEventFn;
|
|
1246
|
+
this.#pendingEventFn = null;
|
|
1247
|
+
let e = eventFn();
|
|
1248
|
+
this.#resetPromise();
|
|
1249
|
+
return e;
|
|
1250
|
+
}
|
|
1251
|
+
join(waitableSet) {
|
|
1252
|
+
__jcoEmbeddedRuntime$debugLog("[Waitable#join()] args", {
|
|
1253
|
+
waitable: this,
|
|
1254
|
+
waitableSet,
|
|
1255
|
+
isRemoval: waitableSet === null
|
|
1256
|
+
});
|
|
1257
|
+
if (waitableSet === void 0) throw TypeError("waitable set must be not be undefined");
|
|
1258
|
+
this.#waitableSet && this.#waitableSet.removeWaitable(this);
|
|
1259
|
+
this.#waitableSet = waitableSet;
|
|
1260
|
+
waitableSet && waitableSet.addWaitable(this);
|
|
1261
|
+
}
|
|
1262
|
+
drop() {
|
|
1263
|
+
__jcoEmbeddedRuntime$debugLog("[Waitable#drop()] args", {
|
|
1264
|
+
componentIdx: this.#componentIdx,
|
|
1265
|
+
waitable: this
|
|
1266
|
+
});
|
|
1267
|
+
this.join(null);
|
|
1268
|
+
}
|
|
1269
|
+
async waitForPendingEvent(args) {
|
|
1270
|
+
let { cstate } = args;
|
|
1271
|
+
if (!cstate) throw TypeError("missing component state");
|
|
1272
|
+
if (this.#waitableSet !== null || this.#hasSyncWaiter) throw Error("waitable is already in a set/has a sync waiter");
|
|
1273
|
+
this.#hasSyncWaiter = true;
|
|
1274
|
+
try {
|
|
1275
|
+
await cstate.waitUntil({
|
|
1276
|
+
cancellable: false,
|
|
1277
|
+
readyFn: () => this.hasPendingEvent()
|
|
1278
|
+
});
|
|
1279
|
+
} finally {
|
|
1280
|
+
this.#hasSyncWaiter = false;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return Waitable2;
|
|
1285
|
+
}
|
|
1286
|
+
var __jcoEmbeddedRuntime$initializeTasksByComponent = () => /* @__PURE__ */ new Map();
|
|
1287
|
+
var __jcoEmbeddedRuntime$initializeCurrentTaskIds = () => [];
|
|
1288
|
+
var __jcoEmbeddedRuntime$initializeCurrentComponentIdxs = () => [];
|
|
1289
|
+
var __jcoEmbeddedRuntime$initializeCurrentTaskMayBlock = (platform) => {
|
|
1290
|
+
if (platform === false) return false;
|
|
1291
|
+
let Global = platform.Global;
|
|
1292
|
+
if (!Global) throw TypeError("async task registers require WebAssembly.Global");
|
|
1293
|
+
return new Global({
|
|
1294
|
+
value: "i32",
|
|
1295
|
+
mutable: true
|
|
1296
|
+
}, 0);
|
|
1297
|
+
};
|
|
1298
|
+
var __jcoEmbeddedRuntime$TASK_INITIAL = "initial";
|
|
1299
|
+
var __jcoEmbeddedRuntime$TASK_CANCEL_PENDING = "cancel-pending";
|
|
1300
|
+
var __jcoEmbeddedRuntime$TASK_CANCEL_DELIVERED = "cancel-delivered";
|
|
1301
|
+
var __jcoEmbeddedRuntime$TASK_RESOLVED = "resolved";
|
|
1302
|
+
function __jcoEmbeddedRuntime$initializeAsyncTaskClass(context) {
|
|
1303
|
+
let { lookup: _lookup, registers: _registers, clearing: _clearing, RuntimeError: _RuntimeError, AsyncSubtask: _Subtask, Waitable: _Waitable, events: _events, determinism: _determinism, FutureValue, scopeCounter: _scopeCounter, scopeTasks: _scopeTasks, storeTrap: _storeTrap } = context;
|
|
1304
|
+
class AsyncTask {
|
|
1305
|
+
static _ID = 0n;
|
|
1306
|
+
static #hostThreadID = 0;
|
|
1307
|
+
static State = {
|
|
1308
|
+
INITIAL: __jcoEmbeddedRuntime$TASK_INITIAL,
|
|
1309
|
+
CANCELLED: "cancelled",
|
|
1310
|
+
CANCEL_PENDING: __jcoEmbeddedRuntime$TASK_CANCEL_PENDING,
|
|
1311
|
+
CANCEL_DELIVERED: __jcoEmbeddedRuntime$TASK_CANCEL_DELIVERED,
|
|
1312
|
+
RESOLVED: __jcoEmbeddedRuntime$TASK_RESOLVED
|
|
1313
|
+
};
|
|
1314
|
+
static BlockResult = {
|
|
1315
|
+
CANCELLED: "block.cancelled",
|
|
1316
|
+
NOT_CANCELLED: "block.not-cancelled"
|
|
1317
|
+
};
|
|
1318
|
+
#id;
|
|
1319
|
+
#componentIdx;
|
|
1320
|
+
#state;
|
|
1321
|
+
#isAsync;
|
|
1322
|
+
#isManualAsync;
|
|
1323
|
+
#callingWasmExport = true;
|
|
1324
|
+
#lockFreeEntry = false;
|
|
1325
|
+
#preserveFutureResult;
|
|
1326
|
+
#entryFnName;
|
|
1327
|
+
#onResolveHandlers = [];
|
|
1328
|
+
#progressWaiters = [];
|
|
1329
|
+
#completionPromise;
|
|
1330
|
+
#completionValue;
|
|
1331
|
+
#completionReady = false;
|
|
1332
|
+
#settleCompletionPromise;
|
|
1333
|
+
#rejected = false;
|
|
1334
|
+
#exitPromise;
|
|
1335
|
+
#resolveExitPromise;
|
|
1336
|
+
#memoryIdx = null;
|
|
1337
|
+
#memory = null;
|
|
1338
|
+
#callbackFn = null;
|
|
1339
|
+
#callbackFnName = null;
|
|
1340
|
+
#postReturnFn = null;
|
|
1341
|
+
#getCalleeParamsFn = null;
|
|
1342
|
+
#calleeIsAsync = null;
|
|
1343
|
+
#admissionTicket = null;
|
|
1344
|
+
#funcTypeIsAsync = false;
|
|
1345
|
+
#returnResultTypeIdx = null;
|
|
1346
|
+
#parentSubtask = null;
|
|
1347
|
+
#errHandling;
|
|
1348
|
+
#returnLowerFns = null;
|
|
1349
|
+
#resourceScopeId;
|
|
1350
|
+
#resourceBorrowCount = 0;
|
|
1351
|
+
#resourceLenders = [];
|
|
1352
|
+
#resourceScopeExited = false;
|
|
1353
|
+
#subtasks = [];
|
|
1354
|
+
#threads = [];
|
|
1355
|
+
#entered = false;
|
|
1356
|
+
#exited = false;
|
|
1357
|
+
#errored = null;
|
|
1358
|
+
get storage() {
|
|
1359
|
+
return this.defaultThread().storage;
|
|
1360
|
+
}
|
|
1361
|
+
cancelled = false;
|
|
1362
|
+
cancelRequested = false;
|
|
1363
|
+
alwaysTaskReturn = false;
|
|
1364
|
+
returnCalls = 0;
|
|
1365
|
+
tmpRetI64HighBits = 0;
|
|
1366
|
+
constructor(opts) {
|
|
1367
|
+
this.#id = ++AsyncTask._ID;
|
|
1368
|
+
this.#resourceScopeId = ++_scopeCounter.value;
|
|
1369
|
+
_scopeTasks.set(this.#resourceScopeId, this);
|
|
1370
|
+
if (opts?.componentIdx === void 0) throw TypeError("missing component id during task creation");
|
|
1371
|
+
this.#componentIdx = opts.componentIdx;
|
|
1372
|
+
this.#state = __jcoEmbeddedRuntime$TASK_INITIAL;
|
|
1373
|
+
this.#isAsync = opts.isAsync ?? false;
|
|
1374
|
+
this.#isManualAsync = opts.isManualAsync ?? false;
|
|
1375
|
+
this.#preserveFutureResult = opts.preserveFutureResult ?? false;
|
|
1376
|
+
this.#entryFnName = opts.entryFnName;
|
|
1377
|
+
this.#callingWasmExport = opts.callingWasmExport !== false;
|
|
1378
|
+
let { promise: completionPromise, resolve: resolveCompletionPromise, reject: rejectCompletionPromise } = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
1379
|
+
this.#completionPromise = completionPromise;
|
|
1380
|
+
completionPromise.then(__jcoEmbeddedRuntime$emptyFunc, __jcoEmbeddedRuntime$emptyFunc);
|
|
1381
|
+
let completionSettled = false;
|
|
1382
|
+
let settleCompletionPromise = () => {
|
|
1383
|
+
if (completionSettled || !this.#completionReady) return;
|
|
1384
|
+
completionSettled = true;
|
|
1385
|
+
this.#errored === null ? this.#rejected ? rejectCompletionPromise(this.#completionValue) : this.#preserveFutureResult && this.#completionValue instanceof FutureValue ? this.#completionValue.resolveAsValue(resolveCompletionPromise) : resolveCompletionPromise(this.#completionValue) : rejectCompletionPromise(this.#errored);
|
|
1386
|
+
};
|
|
1387
|
+
this.#settleCompletionPromise = settleCompletionPromise;
|
|
1388
|
+
this.#onResolveHandlers.push((results) => {
|
|
1389
|
+
if (this.#parentSubtask !== null) return;
|
|
1390
|
+
if (!this.#isAsync && !this.#isManualAsync) return;
|
|
1391
|
+
this.#completionValue = results;
|
|
1392
|
+
this.#completionReady = true;
|
|
1393
|
+
});
|
|
1394
|
+
let { promise: exitPromise, resolve: resolveExitPromise } = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
1395
|
+
this.#exitPromise = exitPromise;
|
|
1396
|
+
this.#resolveExitPromise = resolveExitPromise;
|
|
1397
|
+
opts.callbackFn && (this.#callbackFn = opts.callbackFn);
|
|
1398
|
+
opts.callbackFnName && (this.#callbackFnName = opts.callbackFnName);
|
|
1399
|
+
opts.getCalleeParamsFn && (this.#getCalleeParamsFn = opts.getCalleeParamsFn);
|
|
1400
|
+
opts.parentSubtask && (this.#parentSubtask = opts.parentSubtask);
|
|
1401
|
+
opts.errHandling && (this.#errHandling = opts.errHandling);
|
|
1402
|
+
}
|
|
1403
|
+
taskState() {
|
|
1404
|
+
return this.#state;
|
|
1405
|
+
}
|
|
1406
|
+
id() {
|
|
1407
|
+
return this.#id;
|
|
1408
|
+
}
|
|
1409
|
+
componentIdx() {
|
|
1410
|
+
return this.#componentIdx;
|
|
1411
|
+
}
|
|
1412
|
+
entryFnName() {
|
|
1413
|
+
return this.#entryFnName;
|
|
1414
|
+
}
|
|
1415
|
+
resourceScopeId() {
|
|
1416
|
+
return this.#resourceScopeId;
|
|
1417
|
+
}
|
|
1418
|
+
addBorrowedHandle() {
|
|
1419
|
+
if (this.#resourceScopeExited) throw Error("cannot add a borrow to an exited resource scope");
|
|
1420
|
+
this.#resourceBorrowCount++;
|
|
1421
|
+
}
|
|
1422
|
+
removeBorrowedHandle() {
|
|
1423
|
+
if (this.#resourceBorrowCount === 0) throw Error("resource borrow count underflow");
|
|
1424
|
+
this.#resourceBorrowCount--;
|
|
1425
|
+
}
|
|
1426
|
+
addResourceLender(table, handle) {
|
|
1427
|
+
if (this.#resourceScopeExited) throw Error("cannot add a lender to an exited resource scope");
|
|
1428
|
+
this.#resourceLenders.push({
|
|
1429
|
+
table,
|
|
1430
|
+
handle
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
validateResourceBorrowScope() {
|
|
1434
|
+
if (this.#resourceScopeExited) return;
|
|
1435
|
+
if (_storeTrap.stopped) {
|
|
1436
|
+
this.#resourceLenders = [];
|
|
1437
|
+
this.#resourceScopeExited = true;
|
|
1438
|
+
_scopeTasks.delete(this.#resourceScopeId);
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
if (this.#resourceBorrowCount !== 0) throw new _RuntimeError("borrow handles still remain at the end of the call");
|
|
1442
|
+
for (let { table, handle } of this.#resourceLenders) {
|
|
1443
|
+
let idx = handle << 1;
|
|
1444
|
+
let lendCount = table[idx];
|
|
1445
|
+
if (!Number.isInteger(lendCount) || lendCount <= 0 || lendCount >= 2 ** 30) throw Error("invalid resource lender state at scope exit");
|
|
1446
|
+
table[idx] = lendCount - 1;
|
|
1447
|
+
}
|
|
1448
|
+
this.#resourceLenders = [];
|
|
1449
|
+
this.#resourceScopeExited = true;
|
|
1450
|
+
_scopeTasks.delete(this.#resourceScopeId);
|
|
1451
|
+
}
|
|
1452
|
+
completionPromise() {
|
|
1453
|
+
return this.#completionPromise;
|
|
1454
|
+
}
|
|
1455
|
+
settleCompletion() {
|
|
1456
|
+
this.#settleCompletionPromise();
|
|
1457
|
+
}
|
|
1458
|
+
exitPromise() {
|
|
1459
|
+
return this.#exitPromise;
|
|
1460
|
+
}
|
|
1461
|
+
waitForProgress() {
|
|
1462
|
+
let { promise, resolve } = __jcoEmbeddedRuntime$promiseWithResolvers();
|
|
1463
|
+
this.#progressWaiters.push(resolve);
|
|
1464
|
+
return promise;
|
|
1465
|
+
}
|
|
1466
|
+
notifyProgress() {
|
|
1467
|
+
let waiters = this.#progressWaiters;
|
|
1468
|
+
this.#progressWaiters = [];
|
|
1469
|
+
for (let resolve of waiters) resolve();
|
|
1470
|
+
}
|
|
1471
|
+
isAsync() {
|
|
1472
|
+
return this.#isAsync;
|
|
1473
|
+
}
|
|
1474
|
+
isManualAsync() {
|
|
1475
|
+
return this.#isManualAsync;
|
|
1476
|
+
}
|
|
1477
|
+
isSync() {
|
|
1478
|
+
return !this.isAsync();
|
|
1479
|
+
}
|
|
1480
|
+
getErrHandling() {
|
|
1481
|
+
return this.#errHandling;
|
|
1482
|
+
}
|
|
1483
|
+
hasCallback() {
|
|
1484
|
+
return this.#callbackFn !== null;
|
|
1485
|
+
}
|
|
1486
|
+
getReturnMemoryIdx() {
|
|
1487
|
+
return this.#memoryIdx;
|
|
1488
|
+
}
|
|
1489
|
+
setReturnMemoryIdx(idx) {
|
|
1490
|
+
if (idx === null) return;
|
|
1491
|
+
this.#memoryIdx = idx;
|
|
1492
|
+
}
|
|
1493
|
+
getReturnMemory() {
|
|
1494
|
+
return this.#memory;
|
|
1495
|
+
}
|
|
1496
|
+
setReturnMemory(m) {
|
|
1497
|
+
if (m === null) return;
|
|
1498
|
+
this.#memory = m;
|
|
1499
|
+
}
|
|
1500
|
+
setReturnLowerFns(fns) {
|
|
1501
|
+
this.#returnLowerFns = fns;
|
|
1502
|
+
}
|
|
1503
|
+
getReturnLowerFns() {
|
|
1504
|
+
return this.#returnLowerFns;
|
|
1505
|
+
}
|
|
1506
|
+
setCalleeIsAsync(value) {
|
|
1507
|
+
if (typeof value != "boolean") throw TypeError("callee async state must be a boolean");
|
|
1508
|
+
this.#calleeIsAsync = value;
|
|
1509
|
+
}
|
|
1510
|
+
setParentSubtask(subtask) {
|
|
1511
|
+
if (!subtask || !(subtask instanceof _Subtask)) return;
|
|
1512
|
+
if (this.#parentSubtask) throw Error("parent subtask can only be set once");
|
|
1513
|
+
this.#parentSubtask = subtask;
|
|
1514
|
+
}
|
|
1515
|
+
getParentSubtask() {
|
|
1516
|
+
return this.#parentSubtask;
|
|
1517
|
+
}
|
|
1518
|
+
getRootTask() {
|
|
1519
|
+
let currentSubtask = this.getParentSubtask();
|
|
1520
|
+
let task = this;
|
|
1521
|
+
for (; currentSubtask; ) {
|
|
1522
|
+
task = currentSubtask.getParentTask();
|
|
1523
|
+
currentSubtask = task.getParentSubtask();
|
|
1524
|
+
}
|
|
1525
|
+
return task;
|
|
1526
|
+
}
|
|
1527
|
+
setPostReturnFn(f) {
|
|
1528
|
+
if (!f) return;
|
|
1529
|
+
if (this.#postReturnFn) throw Error("postReturn fn can only be set once");
|
|
1530
|
+
this.#postReturnFn = f;
|
|
1531
|
+
}
|
|
1532
|
+
setCallbackFn(f, name) {
|
|
1533
|
+
if (!f) return;
|
|
1534
|
+
if (this.#callbackFn) throw Error("callback fn can only be set once");
|
|
1535
|
+
this.#callbackFn = f;
|
|
1536
|
+
this.#callbackFnName = name;
|
|
1537
|
+
}
|
|
1538
|
+
getCallbackFnName() {
|
|
1539
|
+
if (!this.#callbackFnName) return;
|
|
1540
|
+
return this.#callbackFnName;
|
|
1541
|
+
}
|
|
1542
|
+
runCallbackFn(...args) {
|
|
1543
|
+
if (!this.#callbackFn) throw Error("no callback function has been set for task");
|
|
1544
|
+
if (this.#callbackFn._jcoMaySuspend === false) return __jcoEmbeddedRuntime$withCurrentTaskMeta(_registers, {
|
|
1545
|
+
taskID: this.#id,
|
|
1546
|
+
threadID: this.defaultThread().id(),
|
|
1547
|
+
componentIdx: this.#componentIdx,
|
|
1548
|
+
fn: () => this.#callbackFn.apply(null, args)
|
|
1549
|
+
});
|
|
1550
|
+
return __jcoEmbeddedRuntime$withCurrentTaskMetaAsync(_registers, {
|
|
1551
|
+
taskID: this.#id,
|
|
1552
|
+
threadID: this.defaultThread().id(),
|
|
1553
|
+
componentIdx: this.#componentIdx,
|
|
1554
|
+
fn: () => this.#callbackFn.apply(null, args)
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
getCalleeParams() {
|
|
1558
|
+
if (!this.#getCalleeParamsFn) throw Error("missing/invalid getCalleeParamsFn");
|
|
1559
|
+
return this.#getCalleeParamsFn();
|
|
1560
|
+
}
|
|
1561
|
+
mayBlock() {
|
|
1562
|
+
return this.isAsync() || this.isManualAsync() || this.isResolvedState() || this.#funcTypeIsAsync;
|
|
1563
|
+
}
|
|
1564
|
+
setFuncTypeIsAsync(v) {
|
|
1565
|
+
this.#funcTypeIsAsync = v;
|
|
1566
|
+
}
|
|
1567
|
+
setReturnResultTypeIdx(v) {
|
|
1568
|
+
this.#returnResultTypeIdx = v;
|
|
1569
|
+
}
|
|
1570
|
+
returnResultTypeIdx() {
|
|
1571
|
+
return this.#returnResultTypeIdx;
|
|
1572
|
+
}
|
|
1573
|
+
mayEnter(task) {
|
|
1574
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1575
|
+
if (cstate.hasBackpressure()) {
|
|
1576
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#mayEnter()] disallowed due to backpressure", { taskID: this.#id });
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
if (!cstate.callingSyncImport()) {
|
|
1580
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#mayEnter()] disallowed due to sync import call", { taskID: this.#id });
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
if (!Reflect.get(cstate, "callingSyncExport") || task.isAsync) {
|
|
1584
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#mayEnter()] disallowed due to sync export w/ sync pending", { taskID: this.#id });
|
|
1585
|
+
return false;
|
|
1586
|
+
}
|
|
1587
|
+
return true;
|
|
1588
|
+
}
|
|
1589
|
+
enterSync() {
|
|
1590
|
+
if (this.needsExclusiveLock()) {
|
|
1591
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1592
|
+
if (!cstate.isExclusivelyLocked()) cstate.exclusiveLock(this.#id);
|
|
1593
|
+
else {
|
|
1594
|
+
this.#lockFreeEntry = true;
|
|
1595
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#enterSync()] entering without exclusive lock", {
|
|
1596
|
+
taskID: this.#id,
|
|
1597
|
+
componentIdx: this.#componentIdx
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return true;
|
|
1602
|
+
}
|
|
1603
|
+
tryEnter() {
|
|
1604
|
+
if (this.#entered) throw Error(`task with ID [${this.#id}] should not be entered twice`);
|
|
1605
|
+
if (this.deliverPendingCancel({ cancellable: true })) {
|
|
1606
|
+
this.cancel();
|
|
1607
|
+
return false;
|
|
1608
|
+
}
|
|
1609
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1610
|
+
if (this.isSync()) {
|
|
1611
|
+
this.#entered = true;
|
|
1612
|
+
return true;
|
|
1613
|
+
}
|
|
1614
|
+
if (cstate.hasBackpressure()) return null;
|
|
1615
|
+
if (cstate.hasPendingAdmissions()) return null;
|
|
1616
|
+
if (this.needsExclusiveLock()) {
|
|
1617
|
+
if (cstate.isExclusivelyLocked()) return null;
|
|
1618
|
+
cstate.exclusiveLock(this.#id);
|
|
1619
|
+
}
|
|
1620
|
+
if (this.deliverPendingCancel({ cancellable: true })) {
|
|
1621
|
+
cstate.exclusiveRelease(this.#id);
|
|
1622
|
+
this.cancel();
|
|
1623
|
+
return false;
|
|
1624
|
+
}
|
|
1625
|
+
this.#entered = true;
|
|
1626
|
+
return true;
|
|
1627
|
+
}
|
|
1628
|
+
async enter(opts) {
|
|
1629
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#enter()] args", {
|
|
1630
|
+
taskID: this.#id,
|
|
1631
|
+
componentIdx: this.#componentIdx,
|
|
1632
|
+
subtaskID: this.getParentSubtask()?.id(),
|
|
1633
|
+
args: opts,
|
|
1634
|
+
entryFnName: this.#entryFnName
|
|
1635
|
+
});
|
|
1636
|
+
if (opts?.isHost) return this.enterHost();
|
|
1637
|
+
if (this.#entered) throw Error(`task with ID [${this.#id}] should not be entered twice`);
|
|
1638
|
+
if (this.deliverPendingCancel({ cancellable: true })) {
|
|
1639
|
+
this.cancel();
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1643
|
+
if (this.isSync()) {
|
|
1644
|
+
this.#entered = true;
|
|
1645
|
+
this.#isManualAsync && this.needsExclusiveLock() && await cstate.acquireExclusiveLock(this.#id);
|
|
1646
|
+
return this.#entered;
|
|
1647
|
+
}
|
|
1648
|
+
let ticket = cstate.takeAdmissionTicket(this.#id);
|
|
1649
|
+
this.#admissionTicket = ticket;
|
|
1650
|
+
let entered = false;
|
|
1651
|
+
try {
|
|
1652
|
+
entered = await this.#enterQueued(cstate, ticket);
|
|
1653
|
+
return entered;
|
|
1654
|
+
} finally {
|
|
1655
|
+
entered || this.endFirstSlice();
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
endFirstSlice() {
|
|
1659
|
+
let ticket = this.#admissionTicket;
|
|
1660
|
+
if (ticket === null) return;
|
|
1661
|
+
this.#admissionTicket = null;
|
|
1662
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx).releaseAdmissionTicket(ticket);
|
|
1663
|
+
}
|
|
1664
|
+
async #enterQueued(cstate, ticket) {
|
|
1665
|
+
await cstate.waitForAdmissionTurn(ticket);
|
|
1666
|
+
if (this.isResolvedState() || this.isCancelled()) return false;
|
|
1667
|
+
for (; ; ) {
|
|
1668
|
+
if (cstate.hasBackpressure()) {
|
|
1669
|
+
cstate.addBackpressureWaiter();
|
|
1670
|
+
let result = await this.waitUntil({
|
|
1671
|
+
readyFn: () => !cstate.hasBackpressure(),
|
|
1672
|
+
cancellable: true
|
|
1673
|
+
});
|
|
1674
|
+
cstate.removeBackpressureWaiter();
|
|
1675
|
+
if (!result || this.isCancelled()) {
|
|
1676
|
+
this.isResolvedState() || this.cancel();
|
|
1677
|
+
return false;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
if (this.needsExclusiveLock()) {
|
|
1681
|
+
await cstate.acquireExclusiveLock(this.#id);
|
|
1682
|
+
if (cstate.hasBackpressure()) {
|
|
1683
|
+
cstate.exclusiveRelease(this.#id);
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
try {
|
|
1690
|
+
cstate.throwIfInterrupted();
|
|
1691
|
+
} catch (err) {
|
|
1692
|
+
cstate.exclusiveRelease(this.#id);
|
|
1693
|
+
this.setErrored(err);
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
if (this.isResolvedState() || this.isCancelled()) {
|
|
1697
|
+
cstate.exclusiveRelease(this.#id);
|
|
1698
|
+
return false;
|
|
1699
|
+
}
|
|
1700
|
+
if (this.deliverPendingCancel({ cancellable: true })) {
|
|
1701
|
+
cstate.exclusiveRelease(this.#id);
|
|
1702
|
+
this.cancel();
|
|
1703
|
+
return false;
|
|
1704
|
+
}
|
|
1705
|
+
this.#entered = true;
|
|
1706
|
+
return this.#entered;
|
|
1707
|
+
}
|
|
1708
|
+
isRunningState() {
|
|
1709
|
+
return this.#state !== __jcoEmbeddedRuntime$TASK_RESOLVED;
|
|
1710
|
+
}
|
|
1711
|
+
isResolvedState() {
|
|
1712
|
+
return this.#state === __jcoEmbeddedRuntime$TASK_RESOLVED;
|
|
1713
|
+
}
|
|
1714
|
+
isResolved() {
|
|
1715
|
+
return this.#state === __jcoEmbeddedRuntime$TASK_RESOLVED;
|
|
1716
|
+
}
|
|
1717
|
+
isExited() {
|
|
1718
|
+
return this.#exited;
|
|
1719
|
+
}
|
|
1720
|
+
async waitUntil(opts) {
|
|
1721
|
+
let { readyFn, cancellable } = opts;
|
|
1722
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#waitUntil()] args", {
|
|
1723
|
+
taskID: this.#id,
|
|
1724
|
+
args: { cancellable }
|
|
1725
|
+
});
|
|
1726
|
+
return await this.suspendUntil({
|
|
1727
|
+
readyFn,
|
|
1728
|
+
cancellable
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
async yieldUntil(opts) {
|
|
1732
|
+
let { readyFn, cancellable } = opts;
|
|
1733
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#yieldUntil()]", {
|
|
1734
|
+
taskID: this.#id,
|
|
1735
|
+
args: { cancellable },
|
|
1736
|
+
componentIdx: this.#componentIdx
|
|
1737
|
+
});
|
|
1738
|
+
return {
|
|
1739
|
+
code: await this.immediateSuspend({
|
|
1740
|
+
readyFn,
|
|
1741
|
+
cancellable
|
|
1742
|
+
}) ? _events.NONE : _events.TASK_CANCELLED,
|
|
1743
|
+
payload0: 0,
|
|
1744
|
+
payload1: 0
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
async suspendUntil(opts) {
|
|
1748
|
+
let { cancellable, readyFn } = opts;
|
|
1749
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#suspendUntil()] args", {
|
|
1750
|
+
taskID: this.#id,
|
|
1751
|
+
args: { cancellable },
|
|
1752
|
+
componentIdx: this.#componentIdx
|
|
1753
|
+
});
|
|
1754
|
+
if (this.deliverPendingCancel({ cancellable })) return false;
|
|
1755
|
+
return await this.immediateSuspendUntil({
|
|
1756
|
+
readyFn,
|
|
1757
|
+
cancellable
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
suspendUntilCallback(opts, onResume) {
|
|
1761
|
+
let { cancellable, readyFn } = opts;
|
|
1762
|
+
if (this.deliverPendingCancel({ cancellable })) {
|
|
1763
|
+
onResume(false);
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx).suspendTask({
|
|
1767
|
+
task: this,
|
|
1768
|
+
cancellable: !!cancellable,
|
|
1769
|
+
readyFn: () => {
|
|
1770
|
+
if (cancellable && this.#state === __jcoEmbeddedRuntime$TASK_CANCEL_PENDING) return true;
|
|
1771
|
+
return readyFn();
|
|
1772
|
+
},
|
|
1773
|
+
onResume: (keepGoing) => {
|
|
1774
|
+
keepGoing && this.deliverPendingCancel({ cancellable }) && (keepGoing = false);
|
|
1775
|
+
onResume(keepGoing);
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
async immediateSuspendUntil(opts) {
|
|
1780
|
+
let { cancellable, readyFn } = opts;
|
|
1781
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#immediateSuspendUntil()] args", {
|
|
1782
|
+
args: {
|
|
1783
|
+
cancellable,
|
|
1784
|
+
readyFn
|
|
1785
|
+
},
|
|
1786
|
+
taskID: this.#id,
|
|
1787
|
+
componentIdx: this.#componentIdx
|
|
1788
|
+
});
|
|
1789
|
+
if (readyFn() && _determinism === "random" && __jcoEmbeddedRuntime$coinFlip()) return true;
|
|
1790
|
+
return await this.immediateSuspend({
|
|
1791
|
+
cancellable,
|
|
1792
|
+
readyFn
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
async immediateSuspend(opts) {
|
|
1796
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1797
|
+
let thread = this.#entered ? cstate.threads.get(__jcoEmbeddedRuntime$getCurrentTaskMeta(_registers, this.#componentIdx).threadID) : this.defaultThread();
|
|
1798
|
+
if (!thread || thread.task() !== this) throw Error("invalid current thread for wait");
|
|
1799
|
+
return thread.suspend({
|
|
1800
|
+
...opts,
|
|
1801
|
+
releaseLock: false
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
deliverPendingCancel(opts) {
|
|
1805
|
+
let { cancellable } = opts;
|
|
1806
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#deliverPendingCancel()]", {
|
|
1807
|
+
args: { cancellable },
|
|
1808
|
+
taskID: this.#id,
|
|
1809
|
+
componentIdx: this.#componentIdx
|
|
1810
|
+
});
|
|
1811
|
+
if (cancellable && this.#state === __jcoEmbeddedRuntime$TASK_CANCEL_PENDING) {
|
|
1812
|
+
this.#state = __jcoEmbeddedRuntime$TASK_CANCEL_DELIVERED;
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1815
|
+
return false;
|
|
1816
|
+
}
|
|
1817
|
+
isCancelled() {
|
|
1818
|
+
return this.cancelled;
|
|
1819
|
+
}
|
|
1820
|
+
cancellationRequested() {
|
|
1821
|
+
return this.cancelRequested;
|
|
1822
|
+
}
|
|
1823
|
+
requestCancellation() {
|
|
1824
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#requestCancellation()] args", {
|
|
1825
|
+
taskID: this.#id,
|
|
1826
|
+
componentIdx: this.#componentIdx,
|
|
1827
|
+
state: this.#state
|
|
1828
|
+
});
|
|
1829
|
+
if (this.isResolvedState() || this.cancelRequested) return;
|
|
1830
|
+
this.cancelRequested = true;
|
|
1831
|
+
if (this.#state === __jcoEmbeddedRuntime$TASK_INITIAL) {
|
|
1832
|
+
this.#state = __jcoEmbeddedRuntime$TASK_CANCEL_PENDING;
|
|
1833
|
+
if (!this.#entered) {
|
|
1834
|
+
this.deliverPendingCancel({ cancellable: true });
|
|
1835
|
+
this.cancel();
|
|
1836
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1837
|
+
cstate.resumeTaskByID(this.#id);
|
|
1838
|
+
cstate.cancelExclusiveLockWaiter(this.#id);
|
|
1839
|
+
this.exit({ skipExclusiveLockCheck: true });
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx).runTickLoop();
|
|
1844
|
+
}
|
|
1845
|
+
cancel(args) {
|
|
1846
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#cancel()] args", {});
|
|
1847
|
+
if (this.taskState() !== __jcoEmbeddedRuntime$TASK_CANCEL_DELIVERED) throw Error("`task.cancel` called by task which has not been cancelled");
|
|
1848
|
+
this.validateResourceBorrowScope();
|
|
1849
|
+
this.cancelled = true;
|
|
1850
|
+
this.onResolve(args?.error ?? null);
|
|
1851
|
+
this.#state = __jcoEmbeddedRuntime$TASK_RESOLVED;
|
|
1852
|
+
this.#entered || this.notifyProgress();
|
|
1853
|
+
}
|
|
1854
|
+
onResolve(taskValue) {
|
|
1855
|
+
let handlers = this.#onResolveHandlers;
|
|
1856
|
+
this.#onResolveHandlers = [];
|
|
1857
|
+
for (let f of handlers) try {
|
|
1858
|
+
f(taskValue);
|
|
1859
|
+
} catch (err) {
|
|
1860
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#onResolve] error during task resolve handler", err);
|
|
1861
|
+
throw err;
|
|
1862
|
+
}
|
|
1863
|
+
if (this.#rejected) {
|
|
1864
|
+
this.#parentSubtask?.reject(taskValue);
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
let parentSubtaskPending = this.#parentSubtask && !this.#parentSubtask.isResolved();
|
|
1868
|
+
let taskReturned = !this.isCancelled();
|
|
1869
|
+
if (parentSubtaskPending && taskReturned) {
|
|
1870
|
+
let meta = this.#parentSubtask.getCallMetadata();
|
|
1871
|
+
if (meta.returnFn && !meta.returnFnCalled) {
|
|
1872
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#onResolve()] running returnFn", {
|
|
1873
|
+
componentIdx: this.#componentIdx,
|
|
1874
|
+
taskID: this.#id,
|
|
1875
|
+
subtaskID: this.#parentSubtask.id()
|
|
1876
|
+
});
|
|
1877
|
+
let callerTask = this.#parentSubtask.getParentTask();
|
|
1878
|
+
__jcoEmbeddedRuntime$withCurrentTaskMeta(_registers, {
|
|
1879
|
+
taskID: callerTask.id(),
|
|
1880
|
+
threadID: meta.callerThreadID,
|
|
1881
|
+
componentIdx: callerTask.componentIdx(),
|
|
1882
|
+
fn: () => meta.returnFn.apply(null, [taskValue, meta.resultPtr])
|
|
1883
|
+
});
|
|
1884
|
+
meta.returnFnCalled = true;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
if (this.#postReturnFn && taskReturned) {
|
|
1888
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#onResolve()] running post return ", {
|
|
1889
|
+
componentIdx: this.#componentIdx,
|
|
1890
|
+
taskID: this.#id
|
|
1891
|
+
});
|
|
1892
|
+
try {
|
|
1893
|
+
__jcoEmbeddedRuntime$withCurrentTaskMeta(_registers, {
|
|
1894
|
+
taskID: this.#id,
|
|
1895
|
+
threadID: this.defaultThread().id(),
|
|
1896
|
+
componentIdx: this.#componentIdx,
|
|
1897
|
+
fn: () => this.#postReturnFn(taskValue)
|
|
1898
|
+
});
|
|
1899
|
+
} catch (err) {
|
|
1900
|
+
err = __jcoEmbeddedRuntime$postReturnTrap(context.postReturn, this.#componentIdx, err);
|
|
1901
|
+
this.reject(err);
|
|
1902
|
+
throw err;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
parentSubtaskPending && this.#parentSubtask.onResolve(taskValue);
|
|
1906
|
+
}
|
|
1907
|
+
registerOnResolveHandler(f) {
|
|
1908
|
+
this.#onResolveHandlers.push(f);
|
|
1909
|
+
}
|
|
1910
|
+
isRejected() {
|
|
1911
|
+
return this.#rejected;
|
|
1912
|
+
}
|
|
1913
|
+
isErrored() {
|
|
1914
|
+
return this.#errored;
|
|
1915
|
+
}
|
|
1916
|
+
setErrored(err) {
|
|
1917
|
+
this.#errored === null && (this.#errored = err);
|
|
1918
|
+
}
|
|
1919
|
+
stop(err) {
|
|
1920
|
+
this.reject(err);
|
|
1921
|
+
this.#completionReady = true;
|
|
1922
|
+
this.#settleCompletionPromise();
|
|
1923
|
+
}
|
|
1924
|
+
reject(taskErr) {
|
|
1925
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#reject()] args", {
|
|
1926
|
+
componentIdx: this.#componentIdx,
|
|
1927
|
+
taskID: this.#id,
|
|
1928
|
+
parentSubtask: this.#parentSubtask,
|
|
1929
|
+
parentSubtaskID: this.#parentSubtask?.id(),
|
|
1930
|
+
entryFnName: this.entryFnName(),
|
|
1931
|
+
callbackFnName: this.#callbackFnName,
|
|
1932
|
+
errMsg: taskErr.message
|
|
1933
|
+
});
|
|
1934
|
+
this.setErrored(taskErr);
|
|
1935
|
+
if (this.#rejected) return;
|
|
1936
|
+
if (this.isResolvedState()) {
|
|
1937
|
+
this.#rejected = true;
|
|
1938
|
+
this.#errored = taskErr;
|
|
1939
|
+
let parentTask = this.#parentSubtask?.getParentTask();
|
|
1940
|
+
parentTask && parentTask.reject(taskErr);
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
this.#rejected = true;
|
|
1944
|
+
this.cancelRequested = true;
|
|
1945
|
+
this.#state = __jcoEmbeddedRuntime$TASK_CANCEL_PENDING;
|
|
1946
|
+
this.deliverPendingCancel({ cancellable: true });
|
|
1947
|
+
this.cancel({ error: taskErr });
|
|
1948
|
+
}
|
|
1949
|
+
resolve(results) {
|
|
1950
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#resolve()] args", {
|
|
1951
|
+
componentIdx: this.#componentIdx,
|
|
1952
|
+
taskID: this.#id,
|
|
1953
|
+
entryFnName: this.entryFnName(),
|
|
1954
|
+
callbackFnName: this.#callbackFnName
|
|
1955
|
+
});
|
|
1956
|
+
if (this.#state === __jcoEmbeddedRuntime$TASK_RESOLVED) {
|
|
1957
|
+
if (this.#errored !== null) throw this.#errored;
|
|
1958
|
+
throw Error(`(component [${this.#componentIdx}]) task [${this.#id}] is already resolved (did you forget to wait for an import?)`);
|
|
1959
|
+
}
|
|
1960
|
+
this.validateResourceBorrowScope();
|
|
1961
|
+
this.#state = __jcoEmbeddedRuntime$TASK_RESOLVED;
|
|
1962
|
+
switch (results.length) {
|
|
1963
|
+
case 0:
|
|
1964
|
+
this.onResolve(void 0);
|
|
1965
|
+
break;
|
|
1966
|
+
case 1:
|
|
1967
|
+
this.onResolve(results[0]);
|
|
1968
|
+
break;
|
|
1969
|
+
default:
|
|
1970
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#resolve()] unexpected number of results", {
|
|
1971
|
+
componentIdx: this.#componentIdx,
|
|
1972
|
+
results,
|
|
1973
|
+
taskID: this.#id,
|
|
1974
|
+
subtaskID: this.#parentSubtask?.id(),
|
|
1975
|
+
entryFnName: this.#entryFnName,
|
|
1976
|
+
callbackFnName: this.#callbackFnName
|
|
1977
|
+
});
|
|
1978
|
+
throw Error("unexpected number of results");
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
exit(args) {
|
|
1982
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#exit()]", {
|
|
1983
|
+
componentIdx: this.#componentIdx,
|
|
1984
|
+
taskID: this.#id
|
|
1985
|
+
});
|
|
1986
|
+
this.endFirstSlice();
|
|
1987
|
+
if (this.#exited) throw Error("task has already exited");
|
|
1988
|
+
this.#checkThreadExit();
|
|
1989
|
+
this.validateResourceBorrowScope();
|
|
1990
|
+
let state = this.#componentIdx === -1 ? null : __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
1991
|
+
if (!state && this.#componentIdx !== -1) throw Error("missing async state for component [" + this.#componentIdx + "]");
|
|
1992
|
+
if (state && !args?.skipExclusiveLockCheck && !this.#lockFreeEntry && this.needsExclusiveLock() && !state.exclusivelyLockedBy(this.#id)) throw Error(`task [${this.#id}] exit: component [${this.#componentIdx}] should have been exclusively locked by it`);
|
|
1993
|
+
state && state.exclusiveRelease(this.#id);
|
|
1994
|
+
this.notifyProgress();
|
|
1995
|
+
try {
|
|
1996
|
+
this.#parentSubtask === null && (this.#isAsync || this.#isManualAsync) && this.#settleCompletionPromise();
|
|
1997
|
+
this.#resolveExitPromise();
|
|
1998
|
+
} catch (err) {
|
|
1999
|
+
console.error("error during task exit handler", err);
|
|
2000
|
+
throw err;
|
|
2001
|
+
}
|
|
2002
|
+
this.#exited = true;
|
|
2003
|
+
this.removeThread(this.defaultThread());
|
|
2004
|
+
this.#threads.length > 0 && __jcoEmbeddedRuntime$clearCurrentThread(_clearing, this.#componentIdx, this.#id, { preserveTask: true });
|
|
2005
|
+
}
|
|
2006
|
+
needsExclusiveLock() {
|
|
2007
|
+
if (this.#componentIdx === -1) return false;
|
|
2008
|
+
if (!this.#callingWasmExport) return false;
|
|
2009
|
+
if (!this.#funcTypeIsAsync) return false;
|
|
2010
|
+
return !this.#isAsync || this.hasCallback() || this.#calleeIsAsync === false;
|
|
2011
|
+
}
|
|
2012
|
+
createSubtask(args) {
|
|
2013
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#createSubtask()] args", args);
|
|
2014
|
+
let { componentIdx, childTask, callMetadata, fnName, isAsync, isManualAsync } = args;
|
|
2015
|
+
if (!__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx)) throw Error(`invalid/missing async state for component idx [${componentIdx}]`);
|
|
2016
|
+
let waitable = new _Waitable({
|
|
2017
|
+
componentIdx: this.#componentIdx,
|
|
2018
|
+
target: `subtask (internal ID [${this.#id}])`
|
|
2019
|
+
});
|
|
2020
|
+
let newSubtask = new _Subtask({
|
|
2021
|
+
componentIdx,
|
|
2022
|
+
childTask,
|
|
2023
|
+
parentTask: this,
|
|
2024
|
+
callMetadata,
|
|
2025
|
+
isAsync,
|
|
2026
|
+
isManualAsync,
|
|
2027
|
+
fnName,
|
|
2028
|
+
waitable
|
|
2029
|
+
});
|
|
2030
|
+
this.#subtasks.push(newSubtask);
|
|
2031
|
+
newSubtask.setTarget(`subtask (internal ID [${newSubtask.id()}], waitable [${waitable.idx()}], component [${componentIdx}])`);
|
|
2032
|
+
return newSubtask;
|
|
2033
|
+
}
|
|
2034
|
+
getLatestSubtask() {
|
|
2035
|
+
return this.#subtasks.at(-1);
|
|
2036
|
+
}
|
|
2037
|
+
getSubtaskByWaitableRep(rep) {
|
|
2038
|
+
if (rep === void 0) throw TypeError("missing rep");
|
|
2039
|
+
return this.#subtasks.find((s) => s.waitableRep() === rep);
|
|
2040
|
+
}
|
|
2041
|
+
currentSubtask() {
|
|
2042
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncTask#currentSubtask()]");
|
|
2043
|
+
if (this.#subtasks.length === 0) return;
|
|
2044
|
+
return this.#subtasks.at(-1);
|
|
2045
|
+
}
|
|
2046
|
+
removeSubtask(subtask) {
|
|
2047
|
+
if (this.#subtasks.length === 0) throw Error("cannot end current subtask: no current subtask");
|
|
2048
|
+
this.#subtasks = this.#subtasks.filter((t) => t !== subtask);
|
|
2049
|
+
return subtask;
|
|
2050
|
+
}
|
|
2051
|
+
cancellationPending() {
|
|
2052
|
+
return this.#state === __jcoEmbeddedRuntime$TASK_CANCEL_PENDING;
|
|
2053
|
+
}
|
|
2054
|
+
enterHost() {
|
|
2055
|
+
if (this.#entered) throw Error(`task with ID [${this.#id}] should not be entered twice`);
|
|
2056
|
+
if (this.deliverPendingCancel({ cancellable: true })) {
|
|
2057
|
+
this.cancel();
|
|
2058
|
+
return false;
|
|
2059
|
+
}
|
|
2060
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
2061
|
+
this.#entered = true;
|
|
2062
|
+
let parentTask = this.#parentSubtask?.getParentTask();
|
|
2063
|
+
(parentTask?.taskState() === __jcoEmbeddedRuntime$TASK_CANCEL_DELIVERED || parentTask && !parentTask.hasCallback()) && parentTask.notifyProgress();
|
|
2064
|
+
return this.#entered;
|
|
2065
|
+
}
|
|
2066
|
+
defaultThread() {
|
|
2067
|
+
return this.#threads[0];
|
|
2068
|
+
}
|
|
2069
|
+
removeThread(thread) {
|
|
2070
|
+
this.#checkThreadExit();
|
|
2071
|
+
this.settleCompletion();
|
|
2072
|
+
this.#componentIdx !== -1 && __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx).threads.remove(thread.id());
|
|
2073
|
+
this.#threads = this.#threads.filter((t) => t !== thread);
|
|
2074
|
+
this.#exited && this.#threads.length === 0 && __jcoEmbeddedRuntime$clearCurrentThread(_clearing, this.#componentIdx, this.#id);
|
|
2075
|
+
}
|
|
2076
|
+
#checkThreadExit() {
|
|
2077
|
+
if (this.#threads.length === 1 && !this.isResolvedState() && !this.isRejected()) {
|
|
2078
|
+
let err = new _RuntimeError(`(component [${this.#componentIdx}]) task [${this.#id}] exited without resolution`);
|
|
2079
|
+
throw this.#componentIdx === -1 ? err : __jcoEmbeddedRuntime$recordTrap(context.traps, this.#componentIdx, err);
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
addThread(thread) {
|
|
2083
|
+
if (this.#componentIdx === -1) {
|
|
2084
|
+
thread.setId(++AsyncTask.#hostThreadID);
|
|
2085
|
+
this.#threads.push(thread);
|
|
2086
|
+
return thread;
|
|
2087
|
+
}
|
|
2088
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
2089
|
+
thread.setId(cstate.threads.insert(thread));
|
|
2090
|
+
this.#threads.push(thread);
|
|
2091
|
+
return thread;
|
|
2092
|
+
}
|
|
2093
|
+
calleeIsAsync() {
|
|
2094
|
+
return this.#calleeIsAsync === true;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
return AsyncTask;
|
|
2098
|
+
}
|
|
2099
|
+
function __jcoEmbeddedRuntime$initializeAsyncSubtaskClass(context) {
|
|
2100
|
+
let { lookup: _lookup, memories: _memories, disposeSymbol: _disposeSymbol, RuntimeError } = context;
|
|
2101
|
+
class AsyncSubtask2 {
|
|
2102
|
+
static _ID = 0n;
|
|
2103
|
+
static State = {
|
|
2104
|
+
STARTING: 0,
|
|
2105
|
+
STARTED: 1,
|
|
2106
|
+
RETURNED: 2,
|
|
2107
|
+
CANCELLED_BEFORE_STARTED: 3,
|
|
2108
|
+
CANCELLED_BEFORE_RETURNED: 4
|
|
2109
|
+
};
|
|
2110
|
+
#id;
|
|
2111
|
+
#state = 0;
|
|
2112
|
+
#componentIdx;
|
|
2113
|
+
#parentTask;
|
|
2114
|
+
#childTask = null;
|
|
2115
|
+
#cancelRequested = false;
|
|
2116
|
+
#lenders = null;
|
|
2117
|
+
#waitable;
|
|
2118
|
+
#callbackFn = null;
|
|
2119
|
+
#postReturnFn = null;
|
|
2120
|
+
#onProgressFn = null;
|
|
2121
|
+
#callMetadata = {};
|
|
2122
|
+
#resolved = false;
|
|
2123
|
+
#onResolveHandlers = [];
|
|
2124
|
+
#onStartHandlers = [];
|
|
2125
|
+
#result = null;
|
|
2126
|
+
#resultSet = false;
|
|
2127
|
+
#hostPendingResult = null;
|
|
2128
|
+
fnName;
|
|
2129
|
+
target;
|
|
2130
|
+
isAsync;
|
|
2131
|
+
isManualAsync;
|
|
2132
|
+
cancelProgress = null;
|
|
2133
|
+
constructor(args) {
|
|
2134
|
+
if (typeof args.componentIdx != "number") throw Error("invalid componentIdx for subtask creation");
|
|
2135
|
+
this.#componentIdx = args.componentIdx;
|
|
2136
|
+
this.#id = ++AsyncSubtask2._ID;
|
|
2137
|
+
this.fnName = args.fnName;
|
|
2138
|
+
if (!args.parentTask) throw Error("missing parent task during subtask creation");
|
|
2139
|
+
this.#parentTask = args.parentTask;
|
|
2140
|
+
args.childTask && (this.#childTask = args.childTask);
|
|
2141
|
+
if (!args.waitable) throw Error("missing/invalid waitable");
|
|
2142
|
+
this.#waitable = args.waitable;
|
|
2143
|
+
args.callMetadata && (this.#callMetadata = args.callMetadata);
|
|
2144
|
+
this.#lenders = [];
|
|
2145
|
+
this.target = args.target;
|
|
2146
|
+
this.isAsync = args.isAsync;
|
|
2147
|
+
this.isManualAsync = args.isManualAsync;
|
|
2148
|
+
}
|
|
2149
|
+
id() {
|
|
2150
|
+
return this.#id;
|
|
2151
|
+
}
|
|
2152
|
+
parentTaskID() {
|
|
2153
|
+
return this.#parentTask?.id();
|
|
2154
|
+
}
|
|
2155
|
+
childTaskID() {
|
|
2156
|
+
return this.#childTask?.id();
|
|
2157
|
+
}
|
|
2158
|
+
state() {
|
|
2159
|
+
return this.#state;
|
|
2160
|
+
}
|
|
2161
|
+
getWaitable() {
|
|
2162
|
+
return this.#waitable;
|
|
2163
|
+
}
|
|
2164
|
+
waitable() {
|
|
2165
|
+
return this.#waitable;
|
|
2166
|
+
}
|
|
2167
|
+
waitableRep() {
|
|
2168
|
+
return this.#waitable.idx();
|
|
2169
|
+
}
|
|
2170
|
+
ensureHandle() {
|
|
2171
|
+
let existing = this.#waitable.idx();
|
|
2172
|
+
if (existing != null) return existing;
|
|
2173
|
+
let idx = this.#getComponentState().handles.insert(this);
|
|
2174
|
+
this.#waitable.setIdx(idx);
|
|
2175
|
+
this.#waitable.setTarget(`waitable for subtask (waitable id [${idx}], subtask internal ID [${this.id()}])`);
|
|
2176
|
+
return idx;
|
|
2177
|
+
}
|
|
2178
|
+
join(set) {
|
|
2179
|
+
return this.#waitable.join(set);
|
|
2180
|
+
}
|
|
2181
|
+
getPendingEvent() {
|
|
2182
|
+
return this.#waitable.getPendingEvent();
|
|
2183
|
+
}
|
|
2184
|
+
hasPendingEvent() {
|
|
2185
|
+
return this.#waitable.hasPendingEvent();
|
|
2186
|
+
}
|
|
2187
|
+
setPendingEvent(fn) {
|
|
2188
|
+
return this.#waitable.setPendingEvent(fn);
|
|
2189
|
+
}
|
|
2190
|
+
setTarget(tgt) {
|
|
2191
|
+
this.target = tgt;
|
|
2192
|
+
}
|
|
2193
|
+
getResult() {
|
|
2194
|
+
if (!this.#resultSet) throw Error("subtask result has not been set");
|
|
2195
|
+
return this.#result;
|
|
2196
|
+
}
|
|
2197
|
+
setResult(v) {
|
|
2198
|
+
if (this.#resultSet) throw Error("subtask result has already been set");
|
|
2199
|
+
this.#result = v;
|
|
2200
|
+
this.#resultSet = true;
|
|
2201
|
+
}
|
|
2202
|
+
componentIdx() {
|
|
2203
|
+
return this.#componentIdx;
|
|
2204
|
+
}
|
|
2205
|
+
setChildTask(t) {
|
|
2206
|
+
if (!t) throw Error("cannot set missing/invalid child task on subtask");
|
|
2207
|
+
if (this.#childTask) throw Error("child task is already set on subtask");
|
|
2208
|
+
if (this.#parentTask === t) throw Error("parent cannot be child");
|
|
2209
|
+
this.#childTask = t;
|
|
2210
|
+
}
|
|
2211
|
+
getChildTask() {
|
|
2212
|
+
return this.#childTask;
|
|
2213
|
+
}
|
|
2214
|
+
getParentTask() {
|
|
2215
|
+
return this.#parentTask;
|
|
2216
|
+
}
|
|
2217
|
+
setCallbackFn(f, _name) {
|
|
2218
|
+
if (!f) return;
|
|
2219
|
+
if (this.#callbackFn) throw Error("callback fn can only be set once");
|
|
2220
|
+
this.#callbackFn = f;
|
|
2221
|
+
}
|
|
2222
|
+
getCallbackFnName() {
|
|
2223
|
+
return this.#callbackFn?.name;
|
|
2224
|
+
}
|
|
2225
|
+
setPostReturnFn(f) {
|
|
2226
|
+
if (!f) return;
|
|
2227
|
+
if (this.#postReturnFn) throw Error("postReturn fn can only be set once");
|
|
2228
|
+
this.#postReturnFn = f;
|
|
2229
|
+
}
|
|
2230
|
+
setOnProgressFn(f) {
|
|
2231
|
+
if (this.#onProgressFn) throw Error("on progress fn can only be set once");
|
|
2232
|
+
this.#onProgressFn = f;
|
|
2233
|
+
}
|
|
2234
|
+
isNotStarted() {
|
|
2235
|
+
return this.#state == 0;
|
|
2236
|
+
}
|
|
2237
|
+
cancellationRequested() {
|
|
2238
|
+
return this.#cancelRequested;
|
|
2239
|
+
}
|
|
2240
|
+
requestCancellation() {
|
|
2241
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#requestCancellation()] args", {
|
|
2242
|
+
componentIdx: this.#componentIdx,
|
|
2243
|
+
subtaskID: this.#id,
|
|
2244
|
+
state: this.#state,
|
|
2245
|
+
childTaskID: this.childTaskID(),
|
|
2246
|
+
fnName: this.fnName
|
|
2247
|
+
});
|
|
2248
|
+
if (this.#cancelRequested) throw Error("cancellation has already been requested for this subtask");
|
|
2249
|
+
this.#cancelRequested = true;
|
|
2250
|
+
if (this.#resolved) return;
|
|
2251
|
+
if (this.#childTask) {
|
|
2252
|
+
this.#childTask.requestCancellation();
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
this.onResolve(null);
|
|
2256
|
+
this.#disposeHostPendingResult();
|
|
2257
|
+
}
|
|
2258
|
+
setHostPendingResult(v) {
|
|
2259
|
+
if (!__jcoEmbeddedRuntime$isPromiseLike(v)) return;
|
|
2260
|
+
this.#hostPendingResult = v;
|
|
2261
|
+
this.#resolved && this.#state !== 2 && this.#disposeHostPendingResult();
|
|
2262
|
+
}
|
|
2263
|
+
#disposeHostPendingResult() {
|
|
2264
|
+
let pending = this.#hostPendingResult;
|
|
2265
|
+
if (!pending) return;
|
|
2266
|
+
this.#hostPendingResult = null;
|
|
2267
|
+
__jcoEmbeddedRuntime$disposeHostValue(_disposeSymbol, pending);
|
|
2268
|
+
}
|
|
2269
|
+
registerOnStartHandler(f) {
|
|
2270
|
+
this.#onStartHandlers.push(f);
|
|
2271
|
+
}
|
|
2272
|
+
onStart(args) {
|
|
2273
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#onStart()] args", {
|
|
2274
|
+
componentIdx: this.#componentIdx,
|
|
2275
|
+
subtaskID: this.#id,
|
|
2276
|
+
parentTaskID: this.parentTaskID(),
|
|
2277
|
+
fnName: this.fnName,
|
|
2278
|
+
args
|
|
2279
|
+
});
|
|
2280
|
+
this.#onProgressFn?.();
|
|
2281
|
+
this.#parentTask.notifyProgress();
|
|
2282
|
+
this.#state = 1;
|
|
2283
|
+
let result;
|
|
2284
|
+
this.#callMetadata.startFn && (result = this.#callMetadata.startFn.apply(null, args?.startFnParams ?? []));
|
|
2285
|
+
return result;
|
|
2286
|
+
}
|
|
2287
|
+
registerOnResolveHandler(f) {
|
|
2288
|
+
this.#onResolveHandlers.push(f);
|
|
2289
|
+
}
|
|
2290
|
+
reject(subtaskErr) {
|
|
2291
|
+
if (this.#resolved) return;
|
|
2292
|
+
this.#onProgressFn?.();
|
|
2293
|
+
if (this.#state >= 2) throw Error("cannot reject a completed subtask");
|
|
2294
|
+
this.#state = this.#state === 0 ? 3 : 4;
|
|
2295
|
+
this.#resolved = true;
|
|
2296
|
+
this.#hostPendingResult = null;
|
|
2297
|
+
this.#parentTask.removeSubtask(this);
|
|
2298
|
+
this.#parentTask.reject(subtaskErr);
|
|
2299
|
+
}
|
|
2300
|
+
onResolve(subtaskValue) {
|
|
2301
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#onResolve()] args", {
|
|
2302
|
+
componentIdx: this.#componentIdx,
|
|
2303
|
+
subtaskID: this.#id,
|
|
2304
|
+
isAsync: this.isAsync,
|
|
2305
|
+
childTaskID: this.childTaskID(),
|
|
2306
|
+
parentTaskID: this.parentTaskID(),
|
|
2307
|
+
parentTaskFnName: this.#parentTask?.entryFnName(),
|
|
2308
|
+
fnName: this.fnName
|
|
2309
|
+
});
|
|
2310
|
+
if (this.#resolved) throw Error("subtask has already been resolved");
|
|
2311
|
+
this.#onProgressFn?.();
|
|
2312
|
+
if (subtaskValue === null && this.#cancelRequested) {
|
|
2313
|
+
if (this.#state >= 2) throw Error("resolved subtask must have been started before cancellation");
|
|
2314
|
+
this.#state = this.#state === 0 ? 3 : 4;
|
|
2315
|
+
} else {
|
|
2316
|
+
if (this.#state !== 1) throw Error("resolved subtask must have been started before completion");
|
|
2317
|
+
this.#state = 2;
|
|
2318
|
+
this.#hostPendingResult = null;
|
|
2319
|
+
}
|
|
2320
|
+
this.setResult(subtaskValue);
|
|
2321
|
+
for (let f of this.#onResolveHandlers) try {
|
|
2322
|
+
f(subtaskValue);
|
|
2323
|
+
} catch (err) {
|
|
2324
|
+
console.error("error during subtask resolve handler", err);
|
|
2325
|
+
throw err;
|
|
2326
|
+
}
|
|
2327
|
+
let callMetadata = this.getCallMetadata();
|
|
2328
|
+
let memory = callMetadata.memory ?? this.#parentTask?.getReturnMemory() ?? __jcoEmbeddedRuntime$lookupMemories(_memories, { componentIdx: this.#parentTask.componentIdx() })[0]?.memory;
|
|
2329
|
+
if (this.#state === 2 && callMetadata && !callMetadata.returnFn && (this.isAsync || callMetadata.funcTypeIsAsync) && callMetadata.resultPtr && memory) {
|
|
2330
|
+
let { resultPtr, realloc } = callMetadata;
|
|
2331
|
+
let lowers = callMetadata.lowers;
|
|
2332
|
+
lowers && lowers.length > 0 && lowers[0]({
|
|
2333
|
+
componentIdx: this.#componentIdx,
|
|
2334
|
+
memory,
|
|
2335
|
+
realloc,
|
|
2336
|
+
vals: [subtaskValue],
|
|
2337
|
+
storagePtr: resultPtr,
|
|
2338
|
+
stringEncoding: callMetadata.stringEncoding
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
this.#resolved = true;
|
|
2342
|
+
this.#parentTask.removeSubtask(this);
|
|
2343
|
+
if (!this.isAsync) {
|
|
2344
|
+
this.deliverResolve();
|
|
2345
|
+
let rep = this.waitableRep();
|
|
2346
|
+
if (rep) try {
|
|
2347
|
+
if (this.#getComponentState().handles.remove(rep) !== this) throw Error("unexpectedly received non-self Subtask from handle removal");
|
|
2348
|
+
this.drop();
|
|
2349
|
+
} catch (err) {
|
|
2350
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#onResolve()] failed to remove subtask after sync subtask completion", err);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
getStateNumber() {
|
|
2355
|
+
return this.#state;
|
|
2356
|
+
}
|
|
2357
|
+
isReturned() {
|
|
2358
|
+
return this.#state === 2;
|
|
2359
|
+
}
|
|
2360
|
+
getCallMetadata() {
|
|
2361
|
+
return this.#callMetadata;
|
|
2362
|
+
}
|
|
2363
|
+
isResolved() {
|
|
2364
|
+
return this.#state >= 2;
|
|
2365
|
+
}
|
|
2366
|
+
addLender(handle) {
|
|
2367
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#addLender()] args", { handle });
|
|
2368
|
+
if (!handle || typeof handle.lends != "number") throw Error("missing/invalid lender handle [" + handle + "]");
|
|
2369
|
+
if (this.#lenders === null || this.isResolved()) throw Error("subtask has no lendors or has already been resolved");
|
|
2370
|
+
handle.lends++;
|
|
2371
|
+
this.#lenders.push(handle);
|
|
2372
|
+
}
|
|
2373
|
+
deliverResolve() {
|
|
2374
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#deliverResolve()] args", {
|
|
2375
|
+
lenders: this.#lenders,
|
|
2376
|
+
parentTaskID: this.parentTaskID(),
|
|
2377
|
+
subtaskID: this.#id,
|
|
2378
|
+
childTaskID: this.childTaskID(),
|
|
2379
|
+
resolved: this.isResolved(),
|
|
2380
|
+
resolveDelivered: this.resolveDelivered()
|
|
2381
|
+
});
|
|
2382
|
+
if (this.resolveDelivered() || !this.isResolved()) throw Error("subtask cannot deliver resolution twice, and the subtask must be resolved");
|
|
2383
|
+
for (let lender of this.#lenders) lender.lends--;
|
|
2384
|
+
this.#lenders = null;
|
|
2385
|
+
}
|
|
2386
|
+
resolveDelivered() {
|
|
2387
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#resolveDelivered()] args", {});
|
|
2388
|
+
if (this.#lenders === null && !this.isResolved()) throw Error("invalid subtask state, lenders missing and subtask has not been resolved");
|
|
2389
|
+
return this.#lenders === null;
|
|
2390
|
+
}
|
|
2391
|
+
drop() {
|
|
2392
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#drop()] args", {
|
|
2393
|
+
componentIdx: this.#componentIdx,
|
|
2394
|
+
parentTaskID: this.#parentTask?.id(),
|
|
2395
|
+
parentTaskFnName: this.#parentTask?.entryFnName(),
|
|
2396
|
+
childTaskID: this.#childTask?.id(),
|
|
2397
|
+
childTaskFnName: this.#childTask?.entryFnName(),
|
|
2398
|
+
subtaskFnName: this.fnName
|
|
2399
|
+
});
|
|
2400
|
+
if (!this.#waitable) throw Error("missing/invalid inner waitable");
|
|
2401
|
+
if (!this.resolveDelivered()) throw new RuntimeError("cannot drop a subtask which has not yet resolved");
|
|
2402
|
+
this.#waitable && this.#waitable.drop();
|
|
2403
|
+
}
|
|
2404
|
+
#getComponentState() {
|
|
2405
|
+
let state = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
2406
|
+
if (!state) throw Error("invalid/missing async state for component [" + this.#componentIdx + "]");
|
|
2407
|
+
return state;
|
|
2408
|
+
}
|
|
2409
|
+
getWaitableHandleIdx() {
|
|
2410
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncSubtask#getWaitableHandleIdx()] args", {});
|
|
2411
|
+
if (!this.#waitable) throw Error("missing/invalid waitable");
|
|
2412
|
+
return this.waitableRep();
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
return AsyncSubtask2;
|
|
2416
|
+
}
|
|
2417
|
+
var __jcoEmbeddedRuntime$THREAD_NOT_STARTED = "not-started";
|
|
2418
|
+
var __jcoEmbeddedRuntime$THREAD_RUNNING = "running";
|
|
2419
|
+
var __jcoEmbeddedRuntime$THREAD_COMPLETED = "completed";
|
|
2420
|
+
function __jcoEmbeddedRuntime$initializeAsyncThreadClass(context) {
|
|
2421
|
+
let { lookup: _lookup, registers: _registers } = context;
|
|
2422
|
+
class AsyncThread {
|
|
2423
|
+
static State = {
|
|
2424
|
+
NOT_STARTED: __jcoEmbeddedRuntime$THREAD_NOT_STARTED,
|
|
2425
|
+
RUNNING: __jcoEmbeddedRuntime$THREAD_RUNNING,
|
|
2426
|
+
COMPLETED: __jcoEmbeddedRuntime$THREAD_COMPLETED
|
|
2427
|
+
};
|
|
2428
|
+
#id = null;
|
|
2429
|
+
#componentIdx;
|
|
2430
|
+
#task;
|
|
2431
|
+
#state;
|
|
2432
|
+
#startFn = null;
|
|
2433
|
+
storage = [0, 0];
|
|
2434
|
+
constructor(opts) {
|
|
2435
|
+
if (opts?.componentIdx === void 0) throw TypeError("missing component id during thread creation");
|
|
2436
|
+
this.#componentIdx = opts.componentIdx;
|
|
2437
|
+
if (!opts?.task) throw TypeError("missing task during thread creation");
|
|
2438
|
+
this.#task = opts.task;
|
|
2439
|
+
if (opts.startFn) {
|
|
2440
|
+
this.#startFn = opts.startFn;
|
|
2441
|
+
this.#state = __jcoEmbeddedRuntime$THREAD_NOT_STARTED;
|
|
2442
|
+
} else this.#state = __jcoEmbeddedRuntime$THREAD_RUNNING;
|
|
2443
|
+
}
|
|
2444
|
+
id() {
|
|
2445
|
+
return this.#id;
|
|
2446
|
+
}
|
|
2447
|
+
setId(id) {
|
|
2448
|
+
if (this.#id !== null) throw Error("thread id can only be assigned once");
|
|
2449
|
+
this.#id = id;
|
|
2450
|
+
}
|
|
2451
|
+
componentIdx() {
|
|
2452
|
+
return this.#componentIdx;
|
|
2453
|
+
}
|
|
2454
|
+
task() {
|
|
2455
|
+
return this.#task;
|
|
2456
|
+
}
|
|
2457
|
+
taskID() {
|
|
2458
|
+
return this.#task.id();
|
|
2459
|
+
}
|
|
2460
|
+
state() {
|
|
2461
|
+
return this.#state;
|
|
2462
|
+
}
|
|
2463
|
+
isCancelled() {
|
|
2464
|
+
return this.#task.isCancelled();
|
|
2465
|
+
}
|
|
2466
|
+
isRejected() {
|
|
2467
|
+
return this.#task.isRejected();
|
|
2468
|
+
}
|
|
2469
|
+
notifyProgress() {
|
|
2470
|
+
return this.#task.notifyProgress();
|
|
2471
|
+
}
|
|
2472
|
+
entryFnName() {
|
|
2473
|
+
return this.#task.entryFnName();
|
|
2474
|
+
}
|
|
2475
|
+
getParentSubtask() {
|
|
2476
|
+
return this.#task.getParentSubtask();
|
|
2477
|
+
}
|
|
2478
|
+
async suspend(opts) {
|
|
2479
|
+
let cstate = __jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx);
|
|
2480
|
+
let task = this.#task;
|
|
2481
|
+
task.endFirstSlice();
|
|
2482
|
+
task.settleCompletion();
|
|
2483
|
+
let { cancellable, readyFn, releaseLock = false } = opts;
|
|
2484
|
+
if (task.deliverPendingCancel({ cancellable })) return false;
|
|
2485
|
+
let reacquireLock = releaseLock && task.needsExclusiveLock() && cstate.exclusivelyLockedBy(task.id());
|
|
2486
|
+
reacquireLock && cstate.exclusiveRelease(task.id());
|
|
2487
|
+
try {
|
|
2488
|
+
let keepGoing = await cstate.suspendThread({
|
|
2489
|
+
...opts,
|
|
2490
|
+
cancellable: !!cancellable,
|
|
2491
|
+
thread: this,
|
|
2492
|
+
readyFn: () => cancellable && task.cancellationPending() || readyFn()
|
|
2493
|
+
});
|
|
2494
|
+
cstate.throwIfInterrupted();
|
|
2495
|
+
if (keepGoing && task.deliverPendingCancel({ cancellable })) return false;
|
|
2496
|
+
return !!keepGoing;
|
|
2497
|
+
} finally {
|
|
2498
|
+
reacquireLock && !cstate.exclusivelyLockedBy(task.id()) && await cstate.acquireExclusiveLock(task.id());
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
start() {
|
|
2502
|
+
if (this.#state !== __jcoEmbeddedRuntime$THREAD_NOT_STARTED) throw Error(`cannot start thread [${this.#id}] in state [${this.#state}]`);
|
|
2503
|
+
this.#state = __jcoEmbeddedRuntime$THREAD_RUNNING;
|
|
2504
|
+
let startFn = this.#startFn;
|
|
2505
|
+
this.#startFn = null;
|
|
2506
|
+
__jcoEmbeddedRuntime$withCurrentTaskMetaAsync(_registers, {
|
|
2507
|
+
threadID: this.#id,
|
|
2508
|
+
taskID: this.#task.id(),
|
|
2509
|
+
componentIdx: this.#componentIdx,
|
|
2510
|
+
fn: async () => {
|
|
2511
|
+
__jcoEmbeddedRuntime$getOrCreateAsyncState(_lookup, this.#componentIdx).throwIfInterrupted();
|
|
2512
|
+
return startFn();
|
|
2513
|
+
}
|
|
2514
|
+
}).then(() => {
|
|
2515
|
+
this.#state = __jcoEmbeddedRuntime$THREAD_COMPLETED;
|
|
2516
|
+
this.#task.removeThread(this);
|
|
2517
|
+
}).catch((err) => {
|
|
2518
|
+
err = __jcoEmbeddedRuntime$recordTrap(context.traps, this.#componentIdx, err);
|
|
2519
|
+
this.#state = __jcoEmbeddedRuntime$THREAD_COMPLETED;
|
|
2520
|
+
__jcoEmbeddedRuntime$debugLog("[AsyncThread#start()] spawned thread errored", {
|
|
2521
|
+
threadID: this.#id,
|
|
2522
|
+
taskID: this.#task.id(),
|
|
2523
|
+
componentIdx: this.#componentIdx,
|
|
2524
|
+
err
|
|
2525
|
+
});
|
|
2526
|
+
this.#task.setErrored(err);
|
|
2527
|
+
this.#task.reject(err);
|
|
2528
|
+
this.#task.removeThread(this);
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
return AsyncThread;
|
|
2533
|
+
}
|
|
2534
|
+
var __jcoEmbeddedRuntime$initializeStreams = (RepTable2) => new RepTable2({ target: "global stream map" });
|
|
2535
|
+
var __jcoEmbeddedRuntime$initializeFutures = (RepTable2) => new RepTable2({ target: "global future map" });
|
|
2536
|
+
var __jcoEmbeddedRuntime$decodeUtf8 = (RuntimeError, decoder, input) => {
|
|
2537
|
+
try {
|
|
2538
|
+
return decoder.decode(input);
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
if (!(error instanceof TypeError)) throw error;
|
|
2541
|
+
let bytes;
|
|
2542
|
+
try {
|
|
2543
|
+
bytes = ArrayBuffer.isView(input) ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength) : new Uint8Array(input);
|
|
2544
|
+
} catch {
|
|
2545
|
+
throw error;
|
|
2546
|
+
}
|
|
2547
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2548
|
+
let lead = bytes[i];
|
|
2549
|
+
if (lead < 128) continue;
|
|
2550
|
+
let count = lead >= 194 && lead <= 223 ? 1 : lead >= 224 && lead <= 239 ? 2 : lead >= 240 && lead <= 244 ? 3 : -1;
|
|
2551
|
+
if (count < 0) throw new RuntimeError("invalid utf-8");
|
|
2552
|
+
for (let j = 1; j <= count; j++) {
|
|
2553
|
+
if (i + j >= bytes.length) throw new RuntimeError("incomplete utf-8 byte sequence");
|
|
2554
|
+
let byte = bytes[i + j];
|
|
2555
|
+
if (byte < 128 || byte > 191 || j === 1 && (lead === 224 && byte < 160 || lead === 237 && byte > 159 || lead === 240 && byte < 144 || lead === 244 && byte > 143)) throw new RuntimeError("invalid utf-8");
|
|
2556
|
+
}
|
|
2557
|
+
i += count;
|
|
2558
|
+
}
|
|
2559
|
+
throw error;
|
|
2560
|
+
}
|
|
2561
|
+
};
|
|
2562
|
+
function __jcoEmbeddedRuntime$initializeFutureValueClass(disposeSymbol) {
|
|
2563
|
+
var _a;
|
|
2564
|
+
class FutureValue {
|
|
2565
|
+
#start;
|
|
2566
|
+
#dropFn;
|
|
2567
|
+
#dropped = false;
|
|
2568
|
+
#delivered = false;
|
|
2569
|
+
#settled;
|
|
2570
|
+
#hideThen = 0;
|
|
2571
|
+
#thenFn;
|
|
2572
|
+
constructor(start, dropFn) {
|
|
2573
|
+
if (typeof start != "function") throw TypeError("future start operation must be a function");
|
|
2574
|
+
this.#start = start;
|
|
2575
|
+
this.#dropFn = dropFn;
|
|
2576
|
+
this.#thenFn = this.#then.bind(this);
|
|
2577
|
+
}
|
|
2578
|
+
get then() {
|
|
2579
|
+
return this.#hideThen === 0 ? this.#thenFn : void 0;
|
|
2580
|
+
}
|
|
2581
|
+
#read() {
|
|
2582
|
+
this.#settled ||= Promise.resolve().then(this.#start);
|
|
2583
|
+
return this.#settled;
|
|
2584
|
+
}
|
|
2585
|
+
resolveAsValue(resolve) {
|
|
2586
|
+
this.#hideThen++;
|
|
2587
|
+
try {
|
|
2588
|
+
resolve(this);
|
|
2589
|
+
} finally {
|
|
2590
|
+
this.#hideThen--;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
#deliver(resolve, value) {
|
|
2594
|
+
if (value instanceof _a) {
|
|
2595
|
+
value.resolveAsValue(resolve);
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
resolve(value);
|
|
2599
|
+
}
|
|
2600
|
+
#then(resolve, reject) {
|
|
2601
|
+
let droppedError = () => Error("future was dropped");
|
|
2602
|
+
return (this.#dropped ? Promise.reject(droppedError()) : this.#read()).then((box) => {
|
|
2603
|
+
if (this.#dropped) {
|
|
2604
|
+
if (typeof reject == "function") return reject(droppedError());
|
|
2605
|
+
throw droppedError();
|
|
2606
|
+
}
|
|
2607
|
+
this.#delivered = true;
|
|
2608
|
+
return this.#deliver(resolve, box.value);
|
|
2609
|
+
}, reject);
|
|
2610
|
+
}
|
|
2611
|
+
[disposeSymbol]() {
|
|
2612
|
+
if (this.#dropped) return;
|
|
2613
|
+
this.#dropped = true;
|
|
2614
|
+
this.#dropFn?.();
|
|
2615
|
+
this.#settled?.then((box) => {
|
|
2616
|
+
this.#delivered || __jcoEmbeddedRuntime$disposeHostValue(disposeSymbol, box.value);
|
|
2617
|
+
}, () => {
|
|
2618
|
+
});
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
_a = FutureValue;
|
|
2622
|
+
return FutureValue;
|
|
2623
|
+
}
|
|
2624
|
+
var createNewCurrentImplicitThread = __jcoEmbeddedRuntime$createNewCurrentImplicitThread;
|
|
2625
|
+
var getCurrentThread = __jcoEmbeddedRuntime$getCurrentThread;
|
|
2626
|
+
var _jcoInitializeAsyncSubtaskClass = __jcoEmbeddedRuntime$initializeAsyncSubtaskClass;
|
|
2627
|
+
var _jcoInitializeAsyncTaskClass = __jcoEmbeddedRuntime$initializeAsyncTaskClass;
|
|
2628
|
+
var _jcoInitializeAsyncThreadClass = __jcoEmbeddedRuntime$initializeAsyncThreadClass;
|
|
2629
|
+
var _jcoInitializeCurrentComponentIdxs = __jcoEmbeddedRuntime$initializeCurrentComponentIdxs;
|
|
2630
|
+
var _jcoInitializeCurrentTaskIds = __jcoEmbeddedRuntime$initializeCurrentTaskIds;
|
|
2631
|
+
var _jcoInitializeCurrentTaskMayBlock = __jcoEmbeddedRuntime$initializeCurrentTaskMayBlock;
|
|
2632
|
+
var _jcoInitializeTasksByComponent = __jcoEmbeddedRuntime$initializeTasksByComponent;
|
|
2633
|
+
var _checkIdle = __jcoEmbeddedRuntime$checkIdle;
|
|
2634
|
+
var getOrCreateAsyncState = __jcoEmbeddedRuntime$getOrCreateAsyncState;
|
|
2635
|
+
var _guardMayLeave = __jcoEmbeddedRuntime$guardMayLeave;
|
|
2636
|
+
var _guardTrap = __jcoEmbeddedRuntime$guardTrap;
|
|
2637
|
+
var _jcoInitializeComponentAsyncStateClass = __jcoEmbeddedRuntime$initializeComponentAsyncStateClass;
|
|
2638
|
+
var _jcoInitializeComponentAsyncStates = __jcoEmbeddedRuntime$initializeComponentAsyncStates;
|
|
2639
|
+
var _jcoInitializeCoreTrapMessages = __jcoEmbeddedRuntime$initializeCoreTrapMessages;
|
|
2640
|
+
var _jcoInitializeInstanceFlags = __jcoEmbeddedRuntime$initializeInstanceFlags;
|
|
2641
|
+
var _jcoInitializeStoreAsyncState = __jcoEmbeddedRuntime$initializeStoreAsyncState;
|
|
2642
|
+
var _jcoInitializeStoreTrap = __jcoEmbeddedRuntime$initializeStoreTrap;
|
|
2643
|
+
var _postReturnTrap = __jcoEmbeddedRuntime$postReturnTrap;
|
|
2644
|
+
var _reportTrap = __jcoEmbeddedRuntime$reportTrap;
|
|
2645
|
+
var _stopInstance = __jcoEmbeddedRuntime$stopInstance;
|
|
2646
|
+
var _whenIdle = __jcoEmbeddedRuntime$whenIdle;
|
|
2647
|
+
var _requireValidNumericPrimitive = __jcoEmbeddedRuntime$requireValidNumericPrimitive;
|
|
2648
|
+
var toUint32 = __jcoEmbeddedRuntime$toUint32;
|
|
2649
|
+
var base64Compile = __jcoEmbeddedRuntime$base64Compile;
|
|
2650
|
+
var _debugLog = __jcoEmbeddedRuntime$debugLog;
|
|
2651
|
+
var fetchCompile = __jcoEmbeddedRuntime$fetchCompile;
|
|
2652
|
+
var finalizationRegistryCreate = __jcoEmbeddedRuntime$finalizationRegistryCreate;
|
|
2653
|
+
var _getGlobalCurrentThreadMeta = __jcoEmbeddedRuntime$getCurrentTaskMeta;
|
|
2654
|
+
var _jcoInitializeAsyncDeterminism = __jcoEmbeddedRuntime$initializeAsyncDeterminism;
|
|
2655
|
+
var _jcoInitializeAsyncEventCodes = __jcoEmbeddedRuntime$initializeAsyncEventCodes;
|
|
2656
|
+
var _jcoInitializeComponentErrorClass = __jcoEmbeddedRuntime$initializeComponentErrorClass;
|
|
2657
|
+
var _jcoInitializeComponentMemoryMap = __jcoEmbeddedRuntime$initializeComponentMemoryMap;
|
|
2658
|
+
var _jcoInitializeFileCompileCache = __jcoEmbeddedRuntime$initializeFileCompileCache;
|
|
2659
|
+
var _jcoInitializeRepTableClass = __jcoEmbeddedRuntime$initializeRepTableClass;
|
|
2660
|
+
var _jcoInitializeRuntimeErrorConstructor = __jcoEmbeddedRuntime$initializeRuntimeErrorConstructor;
|
|
2661
|
+
var _jcoInitializeSymbolDispose = __jcoEmbeddedRuntime$initializeSymbolDispose;
|
|
2662
|
+
var _jcoInitializeSymbolResourceHandle = __jcoEmbeddedRuntime$initializeSymbolResourceHandle;
|
|
2663
|
+
var _jcoInitializeTaskRegisters = __jcoEmbeddedRuntime$initializeTaskRegisters;
|
|
2664
|
+
var instantiateCore = __jcoEmbeddedRuntime$instantiateCore;
|
|
2665
|
+
var _withGlobalCurrentThreadMeta = __jcoEmbeddedRuntime$withCurrentTaskMeta;
|
|
2666
|
+
var _jcoInitializeFutureValueClass = __jcoEmbeddedRuntime$initializeFutureValueClass;
|
|
2667
|
+
var _jcoInitializeFutures = __jcoEmbeddedRuntime$initializeFutures;
|
|
2668
|
+
var dataView = __jcoEmbeddedRuntime$dataView;
|
|
2669
|
+
var emptyFunc = __jcoEmbeddedRuntime$emptyFunc;
|
|
2670
|
+
var _jcoInitializeDataViewCache = __jcoEmbeddedRuntime$initializeDataViewCache;
|
|
2671
|
+
var _decodeUtf8 = __jcoEmbeddedRuntime$decodeUtf8;
|
|
2672
|
+
var _jcoInitializeHandleIndexSpaces = __jcoEmbeddedRuntime$initializeHandleIndexSpaces;
|
|
2673
|
+
var _jcoInitializeHandleTables = __jcoEmbeddedRuntime$initializeHandleTables;
|
|
2674
|
+
var _jcoInitializeResourceScopeCounter = __jcoEmbeddedRuntime$initializeResourceScopeCounter;
|
|
2675
|
+
var _jcoInitializeResourceScopeTasks = __jcoEmbeddedRuntime$initializeResourceScopeTasks;
|
|
2676
|
+
var rscTableCreateOwn = __jcoEmbeddedRuntime$tableCreateOwn;
|
|
2677
|
+
var T_FLAG = 1073741824;
|
|
2678
|
+
var T_OWN = __jcoEmbeddedRuntime$tableOwn;
|
|
2679
|
+
var rscTableRemove = __jcoEmbeddedRuntime$tableRemove;
|
|
2680
|
+
var _jcoInitializeStreams = __jcoEmbeddedRuntime$initializeStreams;
|
|
2681
|
+
var _jcoInitializeUtf8Decoder = __jcoEmbeddedRuntime$initializeUtf8Decoder;
|
|
2682
|
+
var _jcoInitializeUtf8Encoder = __jcoEmbeddedRuntime$initializeUtf8Encoder;
|
|
2683
|
+
var _utf8AllocateAndEncode = __jcoEmbeddedRuntime$utf8Encode;
|
|
2684
|
+
var _jcoInitializeWaitableClass = __jcoEmbeddedRuntime$initializeWaitableClass;
|
|
2685
|
+
var _jcoDataViewCacheContext = _jcoInitializeDataViewCache();
|
|
2686
|
+
var _jcoStrictNumericContext = { strict: false };
|
|
2687
|
+
var TEXT_DECODER_UTF8 = _jcoInitializeUtf8Decoder();
|
|
2688
|
+
var TEXT_ENCODER_UTF8 = _jcoInitializeUtf8Encoder();
|
|
2689
|
+
var HANDLE_INDEX_SPACES = _jcoInitializeHandleIndexSpaces();
|
|
2690
|
+
var RESOURCE_SCOPE_TASKS = _jcoInitializeResourceScopeTasks();
|
|
2691
|
+
var _jcoResourceRemoveContext = {
|
|
2692
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2693
|
+
indexSpaces: HANDLE_INDEX_SPACES,
|
|
2694
|
+
scopeTasks: RESOURCE_SCOPE_TASKS
|
|
2695
|
+
};
|
|
2696
|
+
var ASYNC_STATE = _jcoInitializeComponentAsyncStates();
|
|
2697
|
+
var Waitable = _jcoInitializeWaitableClass();
|
|
2698
|
+
var RepTable = _jcoInitializeRepTableClass({ RuntimeError: WebAssembly.RuntimeError });
|
|
2699
|
+
var INSTANCE_FLAGS = _jcoInitializeInstanceFlags();
|
|
2700
|
+
var STORE_TRAP = _jcoInitializeStoreTrap();
|
|
2701
|
+
var CORE_TRAP_MESSAGES = _jcoInitializeCoreTrapMessages({
|
|
2702
|
+
unreachable: "wasm trap: wasm `unreachable` instruction executed",
|
|
2703
|
+
"memory access out of bounds": "wasm trap: out of bounds memory access",
|
|
2704
|
+
"divide by zero": "wasm trap: integer divide by zero",
|
|
2705
|
+
"remainder by zero": "wasm trap: integer divide by zero",
|
|
2706
|
+
"divide result unrepresentable": "wasm trap: integer overflow",
|
|
2707
|
+
"float unrepresentable in integer range": "wasm trap: invalid conversion to integer",
|
|
2708
|
+
"table index is out of bounds": "wasm trap: undefined element: out of bounds table access",
|
|
2709
|
+
"function signature mismatch": "wasm trap: indirect call type mismatch",
|
|
2710
|
+
"call stack exhausted": "wasm trap: call stack exhausted"
|
|
2711
|
+
});
|
|
2712
|
+
var _jcoComponentNormalizeTrapContext = {
|
|
2713
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2714
|
+
messages: CORE_TRAP_MESSAGES
|
|
2715
|
+
};
|
|
2716
|
+
var STORE_ASYNC_STATE = _jcoInitializeStoreAsyncState();
|
|
2717
|
+
var _jcoComponentDeadlockContext = {
|
|
2718
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2719
|
+
storeTrap: STORE_TRAP,
|
|
2720
|
+
storeAsyncState: STORE_ASYNC_STATE,
|
|
2721
|
+
asyncState: ASYNC_STATE
|
|
2722
|
+
};
|
|
2723
|
+
var _jcoComponentStateLookupContext = {
|
|
2724
|
+
asyncState: ASYNC_STATE,
|
|
2725
|
+
ComponentAsyncState: _jcoInitializeComponentAsyncStateClass({
|
|
2726
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2727
|
+
RepTable,
|
|
2728
|
+
indexSpaces: HANDLE_INDEX_SPACES,
|
|
2729
|
+
instanceFlags: INSTANCE_FLAGS,
|
|
2730
|
+
storeTrap: STORE_TRAP,
|
|
2731
|
+
normalization: _jcoComponentNormalizeTrapContext,
|
|
2732
|
+
cannotEnter: "wasm trap: cannot enter component instance",
|
|
2733
|
+
deadlock: _jcoComponentDeadlockContext,
|
|
2734
|
+
Waitable,
|
|
2735
|
+
reportTrap: (err) => _reportTrap(_jcoComponentReportTrapContext, err),
|
|
2736
|
+
checkIdle: () => _checkIdle(_jcoComponentIdleContext)
|
|
2737
|
+
})
|
|
2738
|
+
};
|
|
2739
|
+
var CURRENT_TASK_META = _jcoInitializeTaskRegisters();
|
|
2740
|
+
var _jcoThreadLookupContext = {
|
|
2741
|
+
lookup: _jcoComponentStateLookupContext,
|
|
2742
|
+
registers: CURRENT_TASK_META
|
|
2743
|
+
};
|
|
2744
|
+
var GLOBAL_COMPONENT_MEMORY_MAP = _jcoInitializeComponentMemoryMap();
|
|
2745
|
+
var symbolDispose = _jcoInitializeSymbolDispose();
|
|
2746
|
+
var AsyncSubtask = _jcoInitializeAsyncSubtaskClass({
|
|
2747
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2748
|
+
lookup: _jcoComponentStateLookupContext,
|
|
2749
|
+
memories: GLOBAL_COMPONENT_MEMORY_MAP,
|
|
2750
|
+
disposeSymbol: symbolDispose
|
|
2751
|
+
});
|
|
2752
|
+
var _jcoComponentPostReturnTrapContext = {
|
|
2753
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2754
|
+
lookup: _jcoComponentStateLookupContext,
|
|
2755
|
+
stackOverflow: "wasm trap: call stack exhausted",
|
|
2756
|
+
uncaughtException: "wasm trap: uncaught exception propagated out of component"
|
|
2757
|
+
};
|
|
2758
|
+
var _jcoComponentRecordTrapContext = {
|
|
2759
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2760
|
+
registers: CURRENT_TASK_META,
|
|
2761
|
+
lookup: _jcoComponentStateLookupContext
|
|
2762
|
+
};
|
|
2763
|
+
var WebAssemblyRuntimeError = _jcoInitializeRuntimeErrorConstructor(WebAssembly);
|
|
2764
|
+
var ASYNC_EVENT_CODE = _jcoInitializeAsyncEventCodes();
|
|
2765
|
+
var ASYNC_DETERMINISM = _jcoInitializeAsyncDeterminism("random");
|
|
2766
|
+
var _jcoResourceScopeCounterContext = _jcoInitializeResourceScopeCounter();
|
|
2767
|
+
var ASYNC_TASKS_BY_COMPONENT_IDX = _jcoInitializeTasksByComponent();
|
|
2768
|
+
var ASYNC_CURRENT_TASK_IDS = _jcoInitializeCurrentTaskIds();
|
|
2769
|
+
var ASYNC_CURRENT_COMPONENT_IDXS = _jcoInitializeCurrentComponentIdxs();
|
|
2770
|
+
var _jcoTaskCreateContext = {
|
|
2771
|
+
AsyncTask: _jcoInitializeAsyncTaskClass({
|
|
2772
|
+
RuntimeError: WebAssemblyRuntimeError,
|
|
2773
|
+
postReturn: _jcoComponentPostReturnTrapContext,
|
|
2774
|
+
traps: _jcoComponentRecordTrapContext,
|
|
2775
|
+
AsyncSubtask,
|
|
2776
|
+
Waitable,
|
|
2777
|
+
lookup: _jcoComponentStateLookupContext,
|
|
2778
|
+
events: ASYNC_EVENT_CODE,
|
|
2779
|
+
determinism: ASYNC_DETERMINISM,
|
|
2780
|
+
scopeCounter: _jcoResourceScopeCounterContext,
|
|
2781
|
+
scopeTasks: RESOURCE_SCOPE_TASKS,
|
|
2782
|
+
storeTrap: STORE_TRAP,
|
|
2783
|
+
clearing: {
|
|
2784
|
+
tasks: ASYNC_TASKS_BY_COMPONENT_IDX,
|
|
2785
|
+
taskIds: ASYNC_CURRENT_TASK_IDS,
|
|
2786
|
+
componentIdxs: ASYNC_CURRENT_COMPONENT_IDXS,
|
|
2787
|
+
checkIdle: () => _checkIdle(_jcoComponentIdleContext)
|
|
2788
|
+
},
|
|
2789
|
+
registers: CURRENT_TASK_META,
|
|
2790
|
+
FutureValue: _jcoInitializeFutureValueClass(symbolDispose)
|
|
2791
|
+
}),
|
|
2792
|
+
AsyncThread: _jcoInitializeAsyncThreadClass({
|
|
2793
|
+
lookup: _jcoComponentStateLookupContext,
|
|
2794
|
+
registers: CURRENT_TASK_META,
|
|
2795
|
+
traps: _jcoComponentRecordTrapContext
|
|
2796
|
+
}),
|
|
2797
|
+
tasks: ASYNC_TASKS_BY_COMPONENT_IDX,
|
|
2798
|
+
taskIds: ASYNC_CURRENT_TASK_IDS,
|
|
2799
|
+
componentIdxs: ASYNC_CURRENT_COMPONENT_IDXS
|
|
2800
|
+
};
|
|
2801
|
+
var CURRENT_TASK_MAY_BLOCK = _jcoInitializeCurrentTaskMayBlock(typeof WebAssembly > "u" ? false : { Global: WebAssembly.Global });
|
|
2802
|
+
var STREAMS = _jcoInitializeStreams(RepTable);
|
|
2803
|
+
var FUTURES = _jcoInitializeFutures(RepTable);
|
|
2804
|
+
var _jcoComponentStopContext = {
|
|
2805
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2806
|
+
storeTrap: STORE_TRAP,
|
|
2807
|
+
storeAsyncState: STORE_ASYNC_STATE,
|
|
2808
|
+
asyncState: ASYNC_STATE,
|
|
2809
|
+
tasks: ASYNC_TASKS_BY_COMPONENT_IDX,
|
|
2810
|
+
symbolDispose,
|
|
2811
|
+
RepTable,
|
|
2812
|
+
channels: [STREAMS, FUTURES]
|
|
2813
|
+
};
|
|
2814
|
+
var _jcoComponentIdleContext = {
|
|
2815
|
+
storeTrap: STORE_TRAP,
|
|
2816
|
+
storeAsyncState: STORE_ASYNC_STATE,
|
|
2817
|
+
tasks: ASYNC_TASKS_BY_COMPONENT_IDX
|
|
2818
|
+
};
|
|
2819
|
+
var _jcoComponentReportTrapContext = {
|
|
2820
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2821
|
+
storeTrap: STORE_TRAP,
|
|
2822
|
+
normalization: _jcoComponentNormalizeTrapContext
|
|
2823
|
+
};
|
|
2824
|
+
var _jcoComponentMayLeaveContext = {
|
|
2825
|
+
RuntimeError: WebAssembly.RuntimeError,
|
|
2826
|
+
instanceFlags: INSTANCE_FLAGS
|
|
2827
|
+
};
|
|
2828
|
+
var _jcoBase64CompileContext = {
|
|
2829
|
+
WebAssembly,
|
|
2830
|
+
nodejsCompat: true
|
|
2831
|
+
};
|
|
2832
|
+
var _jcoFileCompileCache = _jcoInitializeFileCompileCache(true);
|
|
2833
|
+
var _jcoFetchCompileContext = {
|
|
2834
|
+
WebAssembly,
|
|
2835
|
+
nodejsCompat: true,
|
|
2836
|
+
fileCache: _jcoFileCompileCache
|
|
2837
|
+
};
|
|
2838
|
+
var symbolRscHandle = _jcoInitializeSymbolResourceHandle();
|
|
2839
|
+
var HANDLE_TABLES = _jcoInitializeHandleTables();
|
|
2840
|
+
var ComponentError = _jcoInitializeComponentErrorClass();
|
|
2841
|
+
var exports0;
|
|
2842
|
+
var exports1;
|
|
2843
|
+
var exports2;
|
|
2844
|
+
var memory0;
|
|
2845
|
+
var realloc0;
|
|
2846
|
+
var postReturn0;
|
|
2847
|
+
var postReturn1;
|
|
2848
|
+
var postReturn2;
|
|
2849
|
+
var handleTable0 = [T_FLAG, 0];
|
|
2850
|
+
handleTable0._createdReps = /* @__PURE__ */ new Set();
|
|
2851
|
+
handleTable0._componentIdx = 0;
|
|
2852
|
+
var finalizationRegistry0 = finalizationRegistryCreate((handle) => {
|
|
2853
|
+
let { rep } = rscTableRemove(_jcoResourceRemoveContext, handleTable0, handle);
|
|
2854
|
+
STORE_TRAP.stopped || exports0[0](rep);
|
|
2855
|
+
});
|
|
2856
|
+
HANDLE_TABLES[0] = handleTable0;
|
|
2857
|
+
var handleTable1 = [T_FLAG, 0];
|
|
2858
|
+
handleTable1._createdReps = /* @__PURE__ */ new Set();
|
|
2859
|
+
handleTable1._componentIdx = 1;
|
|
2860
|
+
finalizationRegistryCreate((handle) => {
|
|
2861
|
+
let { rep } = rscTableRemove(_jcoResourceRemoveContext, handleTable1, handle);
|
|
2862
|
+
STORE_TRAP.stopped || exports0[0](rep);
|
|
2863
|
+
});
|
|
2864
|
+
HANDLE_TABLES[1] = handleTable1;
|
|
2865
|
+
var renderStaticPlayerParse;
|
|
2866
|
+
var Player = class {
|
|
2867
|
+
constructor() {
|
|
2868
|
+
throw Error('"Player" resource does not define a constructor');
|
|
2869
|
+
}
|
|
2870
|
+
};
|
|
2871
|
+
Player.parse = function parse(arg0) {
|
|
2872
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
2873
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
2874
|
+
componentIdx: 0,
|
|
2875
|
+
isAsync: false,
|
|
2876
|
+
isManualAsync: false,
|
|
2877
|
+
preserveFutureResult: false,
|
|
2878
|
+
entryFnName: "renderStaticPlayerParse",
|
|
2879
|
+
getCallbackFn: () => null,
|
|
2880
|
+
callbackFnName: null,
|
|
2881
|
+
errHandling: "throw-result-err",
|
|
2882
|
+
callingWasmExport: true
|
|
2883
|
+
});
|
|
2884
|
+
task.setCalleeIsAsync(false);
|
|
2885
|
+
task.setFuncTypeIsAsync(false);
|
|
2886
|
+
task.setReturnResultTypeIdx(1);
|
|
2887
|
+
task.enterSync();
|
|
2888
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
2889
|
+
task.setReturnMemoryIdx(0);
|
|
2890
|
+
task.setReturnMemory(memory0);
|
|
2891
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
2892
|
+
taskID: task.id(),
|
|
2893
|
+
threadID,
|
|
2894
|
+
componentIdx: task.componentIdx(),
|
|
2895
|
+
fn: () => {
|
|
2896
|
+
try {
|
|
2897
|
+
var val0 = arg0;
|
|
2898
|
+
var len0 = Array.isArray(val0) ? val0.length : val0.byteLength;
|
|
2899
|
+
var ptr0 = ((...args) => {
|
|
2900
|
+
let state = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
2901
|
+
let previousMayLeave = state.mayLeave;
|
|
2902
|
+
let meta = _getGlobalCurrentThreadMeta(CURRENT_TASK_META, 0);
|
|
2903
|
+
let thread = meta && getCurrentThread(_jcoThreadLookupContext, meta.componentIdx, meta.threadID, meta.taskID)?.thread;
|
|
2904
|
+
let previousStorage = thread?.storage;
|
|
2905
|
+
thread && (thread.storage = [0, 0]);
|
|
2906
|
+
state.mayLeave = false;
|
|
2907
|
+
let restore = () => {
|
|
2908
|
+
state.mayLeave = previousMayLeave;
|
|
2909
|
+
thread && (thread.storage = previousStorage);
|
|
2910
|
+
};
|
|
2911
|
+
let result;
|
|
2912
|
+
try {
|
|
2913
|
+
result = realloc0(...args);
|
|
2914
|
+
} catch (err) {
|
|
2915
|
+
restore();
|
|
2916
|
+
throw err;
|
|
2917
|
+
}
|
|
2918
|
+
if (result && typeof result.then == "function") return Promise.resolve(result).finally(restore);
|
|
2919
|
+
restore();
|
|
2920
|
+
return result;
|
|
2921
|
+
})(0, 0, 1, len0 * 1);
|
|
2922
|
+
ptr0 >>>= 0;
|
|
2923
|
+
if (ptr0 % 1 != 0) throw new WebAssemblyRuntimeError("realloc return: result not aligned");
|
|
2924
|
+
if (ptr0 > memory0.buffer.byteLength || len0 > Math.floor((memory0.buffer.byteLength - ptr0) / 1)) throw new WebAssemblyRuntimeError("realloc return: beyond end of memory");
|
|
2925
|
+
let valData0;
|
|
2926
|
+
let valLenBytes0 = len0 * 1;
|
|
2927
|
+
if (Array.isArray(val0)) {
|
|
2928
|
+
let offset = 0;
|
|
2929
|
+
let dv0 = new DataView(memory0.buffer);
|
|
2930
|
+
for (let v of val0) {
|
|
2931
|
+
_requireValidNumericPrimitive.bind(null, "u8")(v);
|
|
2932
|
+
dv0.setUint8(ptr0 + offset, v, true);
|
|
2933
|
+
offset += 1;
|
|
2934
|
+
}
|
|
2935
|
+
} else {
|
|
2936
|
+
valData0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, valLenBytes0);
|
|
2937
|
+
new Uint8Array(memory0.buffer, ptr0, valLenBytes0).set(valData0);
|
|
2938
|
+
}
|
|
2939
|
+
_debugLog('[iface="aula:render/render", function="[static]player.parse"][Instruction::CallWasm] enter', {
|
|
2940
|
+
funcName: "[static]player.parse",
|
|
2941
|
+
paramCount: 2,
|
|
2942
|
+
async: false,
|
|
2943
|
+
postReturn: true
|
|
2944
|
+
});
|
|
2945
|
+
let ret;
|
|
2946
|
+
try {
|
|
2947
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
2948
|
+
taskID: task.id(),
|
|
2949
|
+
threadID,
|
|
2950
|
+
componentIdx: task.componentIdx(),
|
|
2951
|
+
fn: () => renderStaticPlayerParse(ptr0, len0)
|
|
2952
|
+
});
|
|
2953
|
+
} catch (err) {
|
|
2954
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
2955
|
+
taskID: task.id(),
|
|
2956
|
+
err
|
|
2957
|
+
});
|
|
2958
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
2959
|
+
task.setErrored(err);
|
|
2960
|
+
task.reject(err);
|
|
2961
|
+
task.exit();
|
|
2962
|
+
throw err;
|
|
2963
|
+
}
|
|
2964
|
+
task.endFirstSlice();
|
|
2965
|
+
let variant4;
|
|
2966
|
+
switch (dataView(_jcoDataViewCacheContext, memory0).getUint8((ret >>> 0) + 0, true)) {
|
|
2967
|
+
case 0:
|
|
2968
|
+
var handle2 = dataView(_jcoDataViewCacheContext, memory0).getInt32((ret >>> 0) + 4, true);
|
|
2969
|
+
var rsc1 = new.target === Player ? this : Object.create(Player.prototype);
|
|
2970
|
+
Object.defineProperty(rsc1, symbolRscHandle, {
|
|
2971
|
+
writable: true,
|
|
2972
|
+
value: handle2
|
|
2973
|
+
});
|
|
2974
|
+
finalizationRegistry0.register(rsc1, handle2, rsc1);
|
|
2975
|
+
Object.defineProperty(rsc1, symbolDispose, {
|
|
2976
|
+
writable: true,
|
|
2977
|
+
value: function() {
|
|
2978
|
+
finalizationRegistry0.unregister(rsc1);
|
|
2979
|
+
let handleEntry = rscTableRemove(_jcoResourceRemoveContext, handleTable0, handle2);
|
|
2980
|
+
rsc1[symbolDispose] = emptyFunc;
|
|
2981
|
+
rsc1[symbolRscHandle] = void 0;
|
|
2982
|
+
STORE_TRAP.stopped || exports0[0](handleEntry.rep);
|
|
2983
|
+
}
|
|
2984
|
+
});
|
|
2985
|
+
variant4 = {
|
|
2986
|
+
tag: "ok",
|
|
2987
|
+
val: rsc1
|
|
2988
|
+
};
|
|
2989
|
+
break;
|
|
2990
|
+
case 1:
|
|
2991
|
+
var ptr3 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 4, true) >>> 0;
|
|
2992
|
+
var len3 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 8, true) >>> 0;
|
|
2993
|
+
if (ptr3 > memory0.buffer.byteLength || len3 > Math.floor((memory0.buffer.byteLength - ptr3) / 1)) throw new WebAssemblyRuntimeError("string pointer/length out of bounds of memory");
|
|
2994
|
+
variant4 = {
|
|
2995
|
+
tag: "err",
|
|
2996
|
+
val: _decodeUtf8(WebAssemblyRuntimeError, TEXT_DECODER_UTF8, new Uint8Array(memory0.buffer, ptr3, len3))
|
|
2997
|
+
};
|
|
2998
|
+
break;
|
|
2999
|
+
default:
|
|
3000
|
+
throw TypeError("invalid variant discriminant for expected");
|
|
3001
|
+
}
|
|
3002
|
+
_debugLog('[iface="aula:render/render", function="[static]player.parse"][Instruction::Return]', {
|
|
3003
|
+
funcName: "[static]player.parse",
|
|
3004
|
+
paramCount: 1,
|
|
3005
|
+
async: false,
|
|
3006
|
+
postReturn: true
|
|
3007
|
+
});
|
|
3008
|
+
let retCopy = variant4;
|
|
3009
|
+
task.resolve([retCopy]);
|
|
3010
|
+
let cstate = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3011
|
+
cstate.mayLeave = false;
|
|
3012
|
+
try {
|
|
3013
|
+
postReturn0(ret);
|
|
3014
|
+
} catch (err) {
|
|
3015
|
+
err = _postReturnTrap(_jcoComponentPostReturnTrapContext, 0, err);
|
|
3016
|
+
task.reject(err);
|
|
3017
|
+
throw err;
|
|
3018
|
+
}
|
|
3019
|
+
cstate.mayLeave = true;
|
|
3020
|
+
task.exit();
|
|
3021
|
+
if (typeof retCopy == "object" && retCopy.tag === "err") throw new ComponentError(retCopy.val);
|
|
3022
|
+
return retCopy.val;
|
|
3023
|
+
} catch (err) {
|
|
3024
|
+
if (!task.isResolvedState()) {
|
|
3025
|
+
task.setErrored(err);
|
|
3026
|
+
task.reject(err);
|
|
3027
|
+
}
|
|
3028
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3029
|
+
throw err;
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
});
|
|
3033
|
+
};
|
|
3034
|
+
var renderMethodPlayerFps;
|
|
3035
|
+
Player.prototype.fps = function fps() {
|
|
3036
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
3037
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
3038
|
+
componentIdx: 0,
|
|
3039
|
+
isAsync: false,
|
|
3040
|
+
isManualAsync: false,
|
|
3041
|
+
preserveFutureResult: false,
|
|
3042
|
+
entryFnName: "renderMethodPlayerFps",
|
|
3043
|
+
getCallbackFn: () => null,
|
|
3044
|
+
callbackFnName: null,
|
|
3045
|
+
errHandling: "none",
|
|
3046
|
+
callingWasmExport: true
|
|
3047
|
+
});
|
|
3048
|
+
task.setCalleeIsAsync(false);
|
|
3049
|
+
task.setFuncTypeIsAsync(false);
|
|
3050
|
+
task.setReturnResultTypeIdx(3);
|
|
3051
|
+
task.enterSync();
|
|
3052
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
3053
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3054
|
+
taskID: task.id(),
|
|
3055
|
+
threadID,
|
|
3056
|
+
componentIdx: task.componentIdx(),
|
|
3057
|
+
fn: () => {
|
|
3058
|
+
try {
|
|
3059
|
+
if (!(this instanceof Player)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3060
|
+
var handle1 = this[symbolRscHandle];
|
|
3061
|
+
if (!handle1 || !(handleTable0[(handle1 << 1) + 1] >= T_OWN)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3062
|
+
var handle0 = handleTable0[(handle1 << 1) + 1] - T_OWN;
|
|
3063
|
+
_debugLog('[iface="aula:render/render", function="[method]player.fps"][Instruction::CallWasm] enter', {
|
|
3064
|
+
funcName: "[method]player.fps",
|
|
3065
|
+
paramCount: 1,
|
|
3066
|
+
async: false,
|
|
3067
|
+
postReturn: false
|
|
3068
|
+
});
|
|
3069
|
+
let ret;
|
|
3070
|
+
try {
|
|
3071
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3072
|
+
taskID: task.id(),
|
|
3073
|
+
threadID,
|
|
3074
|
+
componentIdx: task.componentIdx(),
|
|
3075
|
+
fn: () => renderMethodPlayerFps(handle0)
|
|
3076
|
+
});
|
|
3077
|
+
} catch (err) {
|
|
3078
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
3079
|
+
taskID: task.id(),
|
|
3080
|
+
err
|
|
3081
|
+
});
|
|
3082
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
3083
|
+
task.setErrored(err);
|
|
3084
|
+
task.reject(err);
|
|
3085
|
+
task.exit();
|
|
3086
|
+
throw err;
|
|
3087
|
+
}
|
|
3088
|
+
task.endFirstSlice();
|
|
3089
|
+
_debugLog('[iface="aula:render/render", function="[method]player.fps"][Instruction::Return]', {
|
|
3090
|
+
funcName: "[method]player.fps",
|
|
3091
|
+
paramCount: 1,
|
|
3092
|
+
async: false,
|
|
3093
|
+
postReturn: false
|
|
3094
|
+
});
|
|
3095
|
+
task.resolve([ret]);
|
|
3096
|
+
task.exit();
|
|
3097
|
+
return ret;
|
|
3098
|
+
} catch (err) {
|
|
3099
|
+
if (!task.isResolvedState()) {
|
|
3100
|
+
task.setErrored(err);
|
|
3101
|
+
task.reject(err);
|
|
3102
|
+
}
|
|
3103
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3104
|
+
throw err;
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
});
|
|
3108
|
+
};
|
|
3109
|
+
var renderMethodPlayerFrames;
|
|
3110
|
+
Player.prototype.frames = function frames() {
|
|
3111
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
3112
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
3113
|
+
componentIdx: 0,
|
|
3114
|
+
isAsync: false,
|
|
3115
|
+
isManualAsync: false,
|
|
3116
|
+
preserveFutureResult: false,
|
|
3117
|
+
entryFnName: "renderMethodPlayerFrames",
|
|
3118
|
+
getCallbackFn: () => null,
|
|
3119
|
+
callbackFnName: null,
|
|
3120
|
+
errHandling: "none",
|
|
3121
|
+
callingWasmExport: true
|
|
3122
|
+
});
|
|
3123
|
+
task.setCalleeIsAsync(false);
|
|
3124
|
+
task.setFuncTypeIsAsync(false);
|
|
3125
|
+
task.setReturnResultTypeIdx(4);
|
|
3126
|
+
task.enterSync();
|
|
3127
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
3128
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3129
|
+
taskID: task.id(),
|
|
3130
|
+
threadID,
|
|
3131
|
+
componentIdx: task.componentIdx(),
|
|
3132
|
+
fn: () => {
|
|
3133
|
+
try {
|
|
3134
|
+
if (!(this instanceof Player)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3135
|
+
var handle1 = this[symbolRscHandle];
|
|
3136
|
+
if (!handle1 || !(handleTable0[(handle1 << 1) + 1] >= T_OWN)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3137
|
+
var handle0 = handleTable0[(handle1 << 1) + 1] - T_OWN;
|
|
3138
|
+
_debugLog('[iface="aula:render/render", function="[method]player.frames"][Instruction::CallWasm] enter', {
|
|
3139
|
+
funcName: "[method]player.frames",
|
|
3140
|
+
paramCount: 1,
|
|
3141
|
+
async: false,
|
|
3142
|
+
postReturn: false
|
|
3143
|
+
});
|
|
3144
|
+
let ret;
|
|
3145
|
+
try {
|
|
3146
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3147
|
+
taskID: task.id(),
|
|
3148
|
+
threadID,
|
|
3149
|
+
componentIdx: task.componentIdx(),
|
|
3150
|
+
fn: () => renderMethodPlayerFrames(handle0)
|
|
3151
|
+
});
|
|
3152
|
+
} catch (err) {
|
|
3153
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
3154
|
+
taskID: task.id(),
|
|
3155
|
+
err
|
|
3156
|
+
});
|
|
3157
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
3158
|
+
task.setErrored(err);
|
|
3159
|
+
task.reject(err);
|
|
3160
|
+
task.exit();
|
|
3161
|
+
throw err;
|
|
3162
|
+
}
|
|
3163
|
+
task.endFirstSlice();
|
|
3164
|
+
_debugLog('[iface="aula:render/render", function="[method]player.frames"][Instruction::Return]', {
|
|
3165
|
+
funcName: "[method]player.frames",
|
|
3166
|
+
paramCount: 1,
|
|
3167
|
+
async: false,
|
|
3168
|
+
postReturn: false
|
|
3169
|
+
});
|
|
3170
|
+
task.resolve([ret >>> 0]);
|
|
3171
|
+
task.exit();
|
|
3172
|
+
return ret >>> 0;
|
|
3173
|
+
} catch (err) {
|
|
3174
|
+
if (!task.isResolvedState()) {
|
|
3175
|
+
task.setErrored(err);
|
|
3176
|
+
task.reject(err);
|
|
3177
|
+
}
|
|
3178
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3179
|
+
throw err;
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
};
|
|
3184
|
+
var renderMethodPlayerPng;
|
|
3185
|
+
Player.prototype.png = function png(arg1) {
|
|
3186
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
3187
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
3188
|
+
componentIdx: 0,
|
|
3189
|
+
isAsync: false,
|
|
3190
|
+
isManualAsync: false,
|
|
3191
|
+
preserveFutureResult: false,
|
|
3192
|
+
entryFnName: "renderMethodPlayerPng",
|
|
3193
|
+
getCallbackFn: () => null,
|
|
3194
|
+
callbackFnName: null,
|
|
3195
|
+
errHandling: "none",
|
|
3196
|
+
callingWasmExport: true
|
|
3197
|
+
});
|
|
3198
|
+
task.setCalleeIsAsync(false);
|
|
3199
|
+
task.setFuncTypeIsAsync(false);
|
|
3200
|
+
task.setReturnResultTypeIdx(0);
|
|
3201
|
+
task.enterSync();
|
|
3202
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
3203
|
+
task.setReturnMemoryIdx(0);
|
|
3204
|
+
task.setReturnMemory(memory0);
|
|
3205
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3206
|
+
taskID: task.id(),
|
|
3207
|
+
threadID,
|
|
3208
|
+
componentIdx: task.componentIdx(),
|
|
3209
|
+
fn: () => {
|
|
3210
|
+
try {
|
|
3211
|
+
if (!(this instanceof Player)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3212
|
+
var handle1 = this[symbolRscHandle];
|
|
3213
|
+
if (!handle1 || !(handleTable0[(handle1 << 1) + 1] >= T_OWN)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3214
|
+
var handle0 = handleTable0[(handle1 << 1) + 1] - T_OWN;
|
|
3215
|
+
_debugLog('[iface="aula:render/render", function="[method]player.png"][Instruction::CallWasm] enter', {
|
|
3216
|
+
funcName: "[method]player.png",
|
|
3217
|
+
paramCount: 2,
|
|
3218
|
+
async: false,
|
|
3219
|
+
postReturn: true
|
|
3220
|
+
});
|
|
3221
|
+
let ret;
|
|
3222
|
+
try {
|
|
3223
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3224
|
+
taskID: task.id(),
|
|
3225
|
+
threadID,
|
|
3226
|
+
componentIdx: task.componentIdx(),
|
|
3227
|
+
fn: () => renderMethodPlayerPng(handle0, +arg1)
|
|
3228
|
+
});
|
|
3229
|
+
} catch (err) {
|
|
3230
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
3231
|
+
taskID: task.id(),
|
|
3232
|
+
err
|
|
3233
|
+
});
|
|
3234
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
3235
|
+
task.setErrored(err);
|
|
3236
|
+
task.reject(err);
|
|
3237
|
+
task.exit();
|
|
3238
|
+
throw err;
|
|
3239
|
+
}
|
|
3240
|
+
task.endFirstSlice();
|
|
3241
|
+
var ptr2 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 0, true) >>> 0;
|
|
3242
|
+
var len2 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 4, true);
|
|
3243
|
+
if (ptr2 < 0 || len2 < 0 || len2 > 268435455 || ptr2 > memory0.buffer.byteLength || len2 > Math.floor((memory0.buffer.byteLength - ptr2) / 1)) throw new WebAssemblyRuntimeError("wasm trap: out of bounds memory access");
|
|
3244
|
+
if (ptr2 % 1 != 0) throw TypeError(`list pointer [${ptr2}] is not aligned to 1`);
|
|
3245
|
+
var result2 = new Uint8Array(memory0.buffer.slice(ptr2, ptr2 + len2 * 1));
|
|
3246
|
+
_debugLog('[iface="aula:render/render", function="[method]player.png"][Instruction::Return]', {
|
|
3247
|
+
funcName: "[method]player.png",
|
|
3248
|
+
paramCount: 1,
|
|
3249
|
+
async: false,
|
|
3250
|
+
postReturn: true
|
|
3251
|
+
});
|
|
3252
|
+
task.resolve([result2]);
|
|
3253
|
+
let retCopy = result2;
|
|
3254
|
+
let cstate = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3255
|
+
cstate.mayLeave = false;
|
|
3256
|
+
try {
|
|
3257
|
+
postReturn1(ret);
|
|
3258
|
+
} catch (err) {
|
|
3259
|
+
err = _postReturnTrap(_jcoComponentPostReturnTrapContext, 0, err);
|
|
3260
|
+
task.reject(err);
|
|
3261
|
+
throw err;
|
|
3262
|
+
}
|
|
3263
|
+
cstate.mayLeave = true;
|
|
3264
|
+
task.exit();
|
|
3265
|
+
return retCopy;
|
|
3266
|
+
} catch (err) {
|
|
3267
|
+
if (!task.isResolvedState()) {
|
|
3268
|
+
task.setErrored(err);
|
|
3269
|
+
task.reject(err);
|
|
3270
|
+
}
|
|
3271
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3272
|
+
throw err;
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
});
|
|
3276
|
+
};
|
|
3277
|
+
var renderMethodPlayerRgba;
|
|
3278
|
+
Player.prototype.rgba = function rgba(arg1, arg2, arg3) {
|
|
3279
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
3280
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
3281
|
+
componentIdx: 0,
|
|
3282
|
+
isAsync: false,
|
|
3283
|
+
isManualAsync: false,
|
|
3284
|
+
preserveFutureResult: false,
|
|
3285
|
+
entryFnName: "renderMethodPlayerRgba",
|
|
3286
|
+
getCallbackFn: () => null,
|
|
3287
|
+
callbackFnName: null,
|
|
3288
|
+
errHandling: "none",
|
|
3289
|
+
callingWasmExport: true
|
|
3290
|
+
});
|
|
3291
|
+
task.setCalleeIsAsync(false);
|
|
3292
|
+
task.setFuncTypeIsAsync(false);
|
|
3293
|
+
task.setReturnResultTypeIdx(0);
|
|
3294
|
+
task.enterSync();
|
|
3295
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
3296
|
+
task.setReturnMemoryIdx(0);
|
|
3297
|
+
task.setReturnMemory(memory0);
|
|
3298
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3299
|
+
taskID: task.id(),
|
|
3300
|
+
threadID,
|
|
3301
|
+
componentIdx: task.componentIdx(),
|
|
3302
|
+
fn: () => {
|
|
3303
|
+
try {
|
|
3304
|
+
if (!(this instanceof Player)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3305
|
+
var handle1 = this[symbolRscHandle];
|
|
3306
|
+
if (!handle1 || !(handleTable0[(handle1 << 1) + 1] >= T_OWN)) throw TypeError('Resource error: Not a valid "Player" resource.');
|
|
3307
|
+
var handle0 = handleTable0[(handle1 << 1) + 1] - T_OWN;
|
|
3308
|
+
_debugLog('[iface="aula:render/render", function="[method]player.rgba"][Instruction::CallWasm] enter', {
|
|
3309
|
+
funcName: "[method]player.rgba",
|
|
3310
|
+
paramCount: 4,
|
|
3311
|
+
async: false,
|
|
3312
|
+
postReturn: true
|
|
3313
|
+
});
|
|
3314
|
+
let ret;
|
|
3315
|
+
try {
|
|
3316
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3317
|
+
taskID: task.id(),
|
|
3318
|
+
threadID,
|
|
3319
|
+
componentIdx: task.componentIdx(),
|
|
3320
|
+
fn: () => renderMethodPlayerRgba(handle0, +arg1, toUint32(_jcoStrictNumericContext, arg2), toUint32(_jcoStrictNumericContext, arg3))
|
|
3321
|
+
});
|
|
3322
|
+
} catch (err) {
|
|
3323
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
3324
|
+
taskID: task.id(),
|
|
3325
|
+
err
|
|
3326
|
+
});
|
|
3327
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
3328
|
+
task.setErrored(err);
|
|
3329
|
+
task.reject(err);
|
|
3330
|
+
task.exit();
|
|
3331
|
+
throw err;
|
|
3332
|
+
}
|
|
3333
|
+
task.endFirstSlice();
|
|
3334
|
+
var ptr2 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 0, true) >>> 0;
|
|
3335
|
+
var len2 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 4, true);
|
|
3336
|
+
if (ptr2 < 0 || len2 < 0 || len2 > 268435455 || ptr2 > memory0.buffer.byteLength || len2 > Math.floor((memory0.buffer.byteLength - ptr2) / 1)) throw new WebAssemblyRuntimeError("wasm trap: out of bounds memory access");
|
|
3337
|
+
if (ptr2 % 1 != 0) throw TypeError(`list pointer [${ptr2}] is not aligned to 1`);
|
|
3338
|
+
var result2 = new Uint8Array(memory0.buffer.slice(ptr2, ptr2 + len2 * 1));
|
|
3339
|
+
_debugLog('[iface="aula:render/render", function="[method]player.rgba"][Instruction::Return]', {
|
|
3340
|
+
funcName: "[method]player.rgba",
|
|
3341
|
+
paramCount: 1,
|
|
3342
|
+
async: false,
|
|
3343
|
+
postReturn: true
|
|
3344
|
+
});
|
|
3345
|
+
task.resolve([result2]);
|
|
3346
|
+
let retCopy = result2;
|
|
3347
|
+
let cstate = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3348
|
+
cstate.mayLeave = false;
|
|
3349
|
+
try {
|
|
3350
|
+
postReturn1(ret);
|
|
3351
|
+
} catch (err) {
|
|
3352
|
+
err = _postReturnTrap(_jcoComponentPostReturnTrapContext, 0, err);
|
|
3353
|
+
task.reject(err);
|
|
3354
|
+
throw err;
|
|
3355
|
+
}
|
|
3356
|
+
cstate.mayLeave = true;
|
|
3357
|
+
task.exit();
|
|
3358
|
+
return retCopy;
|
|
3359
|
+
} catch (err) {
|
|
3360
|
+
if (!task.isResolvedState()) {
|
|
3361
|
+
task.setErrored(err);
|
|
3362
|
+
task.reject(err);
|
|
3363
|
+
}
|
|
3364
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3365
|
+
throw err;
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
});
|
|
3369
|
+
};
|
|
3370
|
+
var renderSheet;
|
|
3371
|
+
function sheet(arg0, arg1, arg2) {
|
|
3372
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).throwIfTrapped();
|
|
3373
|
+
let { task, threadID } = createNewCurrentImplicitThread(_jcoTaskCreateContext, {
|
|
3374
|
+
componentIdx: 0,
|
|
3375
|
+
isAsync: false,
|
|
3376
|
+
isManualAsync: false,
|
|
3377
|
+
preserveFutureResult: false,
|
|
3378
|
+
entryFnName: "renderSheet",
|
|
3379
|
+
getCallbackFn: () => null,
|
|
3380
|
+
callbackFnName: null,
|
|
3381
|
+
errHandling: "throw-result-err",
|
|
3382
|
+
callingWasmExport: true
|
|
3383
|
+
});
|
|
3384
|
+
task.setCalleeIsAsync(false);
|
|
3385
|
+
task.setFuncTypeIsAsync(false);
|
|
3386
|
+
task.setReturnResultTypeIdx(8);
|
|
3387
|
+
task.enterSync();
|
|
3388
|
+
CURRENT_TASK_MAY_BLOCK.value = +!!task.mayBlock();
|
|
3389
|
+
task.setReturnMemoryIdx(0);
|
|
3390
|
+
task.setReturnMemory(memory0);
|
|
3391
|
+
return _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3392
|
+
taskID: task.id(),
|
|
3393
|
+
threadID,
|
|
3394
|
+
componentIdx: task.componentIdx(),
|
|
3395
|
+
fn: () => {
|
|
3396
|
+
try {
|
|
3397
|
+
var vec3 = arg0;
|
|
3398
|
+
var len3 = vec3.length;
|
|
3399
|
+
var result3 = ((...args) => {
|
|
3400
|
+
let state = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3401
|
+
let previousMayLeave = state.mayLeave;
|
|
3402
|
+
let meta = _getGlobalCurrentThreadMeta(CURRENT_TASK_META, 0);
|
|
3403
|
+
let thread = meta && getCurrentThread(_jcoThreadLookupContext, meta.componentIdx, meta.threadID, meta.taskID)?.thread;
|
|
3404
|
+
let previousStorage = thread?.storage;
|
|
3405
|
+
thread && (thread.storage = [0, 0]);
|
|
3406
|
+
state.mayLeave = false;
|
|
3407
|
+
let restore = () => {
|
|
3408
|
+
state.mayLeave = previousMayLeave;
|
|
3409
|
+
thread && (thread.storage = previousStorage);
|
|
3410
|
+
};
|
|
3411
|
+
let result;
|
|
3412
|
+
try {
|
|
3413
|
+
result = realloc0(...args);
|
|
3414
|
+
} catch (err) {
|
|
3415
|
+
restore();
|
|
3416
|
+
throw err;
|
|
3417
|
+
}
|
|
3418
|
+
if (result && typeof result.then == "function") return Promise.resolve(result).finally(restore);
|
|
3419
|
+
restore();
|
|
3420
|
+
return result;
|
|
3421
|
+
})(0, 0, 4, len3 * 16);
|
|
3422
|
+
result3 >>>= 0;
|
|
3423
|
+
if (result3 % 4 != 0) throw new WebAssemblyRuntimeError("realloc return: result not aligned");
|
|
3424
|
+
if (result3 > memory0.buffer.byteLength || len3 > Math.floor((memory0.buffer.byteLength - result3) / 16)) throw new WebAssemblyRuntimeError("realloc return: beyond end of memory");
|
|
3425
|
+
if (result3 < 0 || len3 < 0 || len3 > 16777215 || result3 > memory0.buffer.byteLength || len3 > Math.floor((memory0.buffer.byteLength - result3) / 16)) throw new WebAssemblyRuntimeError("wasm trap: out of bounds memory access");
|
|
3426
|
+
for (let i = 0; i < vec3.length; i++) {
|
|
3427
|
+
let e = vec3[i];
|
|
3428
|
+
let base = result3 + i * 16;
|
|
3429
|
+
var { name: v0_0, png: v0_1 } = e;
|
|
3430
|
+
var encodeRes = _utf8AllocateAndEncode(TEXT_ENCODER_UTF8, v0_0, ((...args) => {
|
|
3431
|
+
let state = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3432
|
+
let previousMayLeave = state.mayLeave;
|
|
3433
|
+
let meta = _getGlobalCurrentThreadMeta(CURRENT_TASK_META, 0);
|
|
3434
|
+
let thread = meta && getCurrentThread(_jcoThreadLookupContext, meta.componentIdx, meta.threadID, meta.taskID)?.thread;
|
|
3435
|
+
let previousStorage = thread?.storage;
|
|
3436
|
+
thread && (thread.storage = [0, 0]);
|
|
3437
|
+
state.mayLeave = false;
|
|
3438
|
+
let restore = () => {
|
|
3439
|
+
state.mayLeave = previousMayLeave;
|
|
3440
|
+
thread && (thread.storage = previousStorage);
|
|
3441
|
+
};
|
|
3442
|
+
let result;
|
|
3443
|
+
try {
|
|
3444
|
+
result = realloc0(...args);
|
|
3445
|
+
} catch (err) {
|
|
3446
|
+
restore();
|
|
3447
|
+
throw err;
|
|
3448
|
+
}
|
|
3449
|
+
if (result && typeof result.then == "function") return Promise.resolve(result).finally(restore);
|
|
3450
|
+
restore();
|
|
3451
|
+
return result;
|
|
3452
|
+
}), memory0);
|
|
3453
|
+
var ptr1 = encodeRes.ptr;
|
|
3454
|
+
var len1 = encodeRes.len;
|
|
3455
|
+
dataView(_jcoDataViewCacheContext, memory0).setUint32(base + 4, len1, true);
|
|
3456
|
+
dataView(_jcoDataViewCacheContext, memory0).setUint32(base + 0, ptr1, true);
|
|
3457
|
+
var val2 = v0_1;
|
|
3458
|
+
var len2 = Array.isArray(val2) ? val2.length : val2.byteLength;
|
|
3459
|
+
var ptr2 = ((...args) => {
|
|
3460
|
+
let state = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3461
|
+
let previousMayLeave = state.mayLeave;
|
|
3462
|
+
let meta = _getGlobalCurrentThreadMeta(CURRENT_TASK_META, 0);
|
|
3463
|
+
let thread = meta && getCurrentThread(_jcoThreadLookupContext, meta.componentIdx, meta.threadID, meta.taskID)?.thread;
|
|
3464
|
+
let previousStorage = thread?.storage;
|
|
3465
|
+
thread && (thread.storage = [0, 0]);
|
|
3466
|
+
state.mayLeave = false;
|
|
3467
|
+
let restore = () => {
|
|
3468
|
+
state.mayLeave = previousMayLeave;
|
|
3469
|
+
thread && (thread.storage = previousStorage);
|
|
3470
|
+
};
|
|
3471
|
+
let result;
|
|
3472
|
+
try {
|
|
3473
|
+
result = realloc0(...args);
|
|
3474
|
+
} catch (err) {
|
|
3475
|
+
restore();
|
|
3476
|
+
throw err;
|
|
3477
|
+
}
|
|
3478
|
+
if (result && typeof result.then == "function") return Promise.resolve(result).finally(restore);
|
|
3479
|
+
restore();
|
|
3480
|
+
return result;
|
|
3481
|
+
})(0, 0, 1, len2 * 1);
|
|
3482
|
+
ptr2 >>>= 0;
|
|
3483
|
+
if (ptr2 % 1 != 0) throw new WebAssemblyRuntimeError("realloc return: result not aligned");
|
|
3484
|
+
if (ptr2 > memory0.buffer.byteLength || len2 > Math.floor((memory0.buffer.byteLength - ptr2) / 1)) throw new WebAssemblyRuntimeError("realloc return: beyond end of memory");
|
|
3485
|
+
let valData2;
|
|
3486
|
+
let valLenBytes2 = len2 * 1;
|
|
3487
|
+
if (Array.isArray(val2)) {
|
|
3488
|
+
let offset = 0;
|
|
3489
|
+
let dv2 = new DataView(memory0.buffer);
|
|
3490
|
+
for (let v of val2) {
|
|
3491
|
+
_requireValidNumericPrimitive.bind(null, "u8")(v);
|
|
3492
|
+
dv2.setUint8(ptr2 + offset, v, true);
|
|
3493
|
+
offset += 1;
|
|
3494
|
+
}
|
|
3495
|
+
} else {
|
|
3496
|
+
valData2 = new Uint8Array(val2.buffer || val2, val2.byteOffset, valLenBytes2);
|
|
3497
|
+
new Uint8Array(memory0.buffer, ptr2, valLenBytes2).set(valData2);
|
|
3498
|
+
}
|
|
3499
|
+
dataView(_jcoDataViewCacheContext, memory0).setUint32(base + 12, len2, true);
|
|
3500
|
+
dataView(_jcoDataViewCacheContext, memory0).setUint32(base + 8, ptr2, true);
|
|
3501
|
+
}
|
|
3502
|
+
_debugLog('[iface="aula:render/render", function="sheet"][Instruction::CallWasm] enter', {
|
|
3503
|
+
funcName: "sheet",
|
|
3504
|
+
paramCount: 4,
|
|
3505
|
+
async: false,
|
|
3506
|
+
postReturn: true
|
|
3507
|
+
});
|
|
3508
|
+
let ret;
|
|
3509
|
+
try {
|
|
3510
|
+
ret = _withGlobalCurrentThreadMeta(CURRENT_TASK_META, {
|
|
3511
|
+
taskID: task.id(),
|
|
3512
|
+
threadID,
|
|
3513
|
+
componentIdx: task.componentIdx(),
|
|
3514
|
+
fn: () => renderSheet(result3, len3, toUint32(_jcoStrictNumericContext, arg1), toUint32(_jcoStrictNumericContext, arg2))
|
|
3515
|
+
});
|
|
3516
|
+
} catch (err) {
|
|
3517
|
+
_debugLog("[Instruction::CallWasm] error during sync call", {
|
|
3518
|
+
taskID: task.id(),
|
|
3519
|
+
err
|
|
3520
|
+
});
|
|
3521
|
+
getOrCreateAsyncState(_jcoComponentStateLookupContext, 0).markTrapped(err);
|
|
3522
|
+
task.setErrored(err);
|
|
3523
|
+
task.reject(err);
|
|
3524
|
+
task.exit();
|
|
3525
|
+
throw err;
|
|
3526
|
+
}
|
|
3527
|
+
task.endFirstSlice();
|
|
3528
|
+
let variant6;
|
|
3529
|
+
switch (dataView(_jcoDataViewCacheContext, memory0).getUint8((ret >>> 0) + 0, true)) {
|
|
3530
|
+
case 0:
|
|
3531
|
+
var ptr4 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 4, true) >>> 0;
|
|
3532
|
+
var len4 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 8, true);
|
|
3533
|
+
if (ptr4 < 0 || len4 < 0 || len4 > 268435455 || ptr4 > memory0.buffer.byteLength || len4 > Math.floor((memory0.buffer.byteLength - ptr4) / 1)) throw new WebAssemblyRuntimeError("wasm trap: out of bounds memory access");
|
|
3534
|
+
if (ptr4 % 1 != 0) throw TypeError(`list pointer [${ptr4}] is not aligned to 1`);
|
|
3535
|
+
variant6 = {
|
|
3536
|
+
tag: "ok",
|
|
3537
|
+
val: new Uint8Array(memory0.buffer.slice(ptr4, ptr4 + len4 * 1))
|
|
3538
|
+
};
|
|
3539
|
+
break;
|
|
3540
|
+
case 1:
|
|
3541
|
+
var ptr5 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 4, true) >>> 0;
|
|
3542
|
+
var len5 = dataView(_jcoDataViewCacheContext, memory0).getUint32((ret >>> 0) + 8, true) >>> 0;
|
|
3543
|
+
if (ptr5 > memory0.buffer.byteLength || len5 > Math.floor((memory0.buffer.byteLength - ptr5) / 1)) throw new WebAssemblyRuntimeError("string pointer/length out of bounds of memory");
|
|
3544
|
+
variant6 = {
|
|
3545
|
+
tag: "err",
|
|
3546
|
+
val: _decodeUtf8(WebAssemblyRuntimeError, TEXT_DECODER_UTF8, new Uint8Array(memory0.buffer, ptr5, len5))
|
|
3547
|
+
};
|
|
3548
|
+
break;
|
|
3549
|
+
default:
|
|
3550
|
+
throw TypeError("invalid variant discriminant for expected");
|
|
3551
|
+
}
|
|
3552
|
+
_debugLog('[iface="aula:render/render", function="sheet"][Instruction::Return]', {
|
|
3553
|
+
funcName: "sheet",
|
|
3554
|
+
paramCount: 1,
|
|
3555
|
+
async: false,
|
|
3556
|
+
postReturn: true
|
|
3557
|
+
});
|
|
3558
|
+
let retCopy = variant6;
|
|
3559
|
+
task.resolve([retCopy]);
|
|
3560
|
+
let cstate = getOrCreateAsyncState(_jcoComponentStateLookupContext, 0);
|
|
3561
|
+
cstate.mayLeave = false;
|
|
3562
|
+
try {
|
|
3563
|
+
postReturn2(ret);
|
|
3564
|
+
} catch (err) {
|
|
3565
|
+
err = _postReturnTrap(_jcoComponentPostReturnTrapContext, 0, err);
|
|
3566
|
+
task.reject(err);
|
|
3567
|
+
throw err;
|
|
3568
|
+
}
|
|
3569
|
+
cstate.mayLeave = true;
|
|
3570
|
+
task.exit();
|
|
3571
|
+
if (typeof retCopy == "object" && retCopy.tag === "err") throw new ComponentError(retCopy.val);
|
|
3572
|
+
return retCopy.val;
|
|
3573
|
+
} catch (err) {
|
|
3574
|
+
if (!task.isResolvedState()) {
|
|
3575
|
+
task.setErrored(err);
|
|
3576
|
+
task.reject(err);
|
|
3577
|
+
}
|
|
3578
|
+
task.isExited() || task.exit({ skipExclusiveLockCheck: true });
|
|
3579
|
+
throw err;
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
var trampoline0 = (rep) => rscTableCreateOwn(HANDLE_INDEX_SPACES, handleTable0, rep);
|
|
3585
|
+
function trampoline1(handle) {
|
|
3586
|
+
let handleEntry = rscTableRemove(_jcoResourceRemoveContext, handleTable0, handle);
|
|
3587
|
+
handleEntry.own && exports0[0](handleEntry.rep);
|
|
3588
|
+
}
|
|
3589
|
+
await (() => {
|
|
3590
|
+
let gen = (function* _initGenerator() {
|
|
3591
|
+
let module0 = fetchCompile(_jcoFetchCompileContext, new URL("./aula-render.core.wasm", import.meta.url));
|
|
3592
|
+
Promise.resolve(module0).catch(() => {
|
|
3593
|
+
});
|
|
3594
|
+
let module1 = base64Compile(_jcoBase64CompileContext, "AGFzbQEAAAABBQFgAX8AAwIBAAQFAXABAQEHEAIBMAAACCRpbXBvcnRzAQAKCwEJACAAQQARAAALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yNTkuMA");
|
|
3595
|
+
Promise.resolve(module1).catch(() => {
|
|
3596
|
+
});
|
|
3597
|
+
let module2 = base64Compile(_jcoBase64CompileContext, "AGFzbQEAAAABBQFgAX8AAh8CBmFjdHVhbAEwAAAEc2hpbQgkaW1wb3J0cwFwAQEBCQcBAEEACwEAAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yNTkuMA");
|
|
3598
|
+
Promise.resolve(module2).catch(() => {
|
|
3599
|
+
});
|
|
3600
|
+
let instanceFlags0 = new WebAssembly.Global({
|
|
3601
|
+
value: "i32",
|
|
3602
|
+
mutable: true
|
|
3603
|
+
}, 1);
|
|
3604
|
+
INSTANCE_FLAGS.set(0, instanceFlags0);
|
|
3605
|
+
({ exports: exports0 } = yield instantiateCore(WebAssembly, yield module1));
|
|
3606
|
+
({ exports: exports1 } = yield instantiateCore(WebAssembly, yield module0, { "[export]aula:render/render": {
|
|
3607
|
+
"[resource-drop]player": Object.assign(_guardTrap(_jcoComponentRecordTrapContext, 0, _guardMayLeave(_jcoComponentMayLeaveContext, 0, trampoline1), true), { _jcoMaySuspend: false }),
|
|
3608
|
+
"[resource-new]player": Object.assign(_guardTrap(_jcoComponentRecordTrapContext, 0, _guardMayLeave(_jcoComponentMayLeaveContext, 0, trampoline0), true), { _jcoMaySuspend: false })
|
|
3609
|
+
} }));
|
|
3610
|
+
({ exports: exports2 } = yield instantiateCore(WebAssembly, yield module2, {
|
|
3611
|
+
actual: { 0: Object.assign(exports1["aula:render/render#[dtor]player"], { _jcoMaySuspend: false }) },
|
|
3612
|
+
shim: { $imports: exports0.$imports }
|
|
3613
|
+
}));
|
|
3614
|
+
memory0 = exports1.memory;
|
|
3615
|
+
realloc0 = (oldPtr, oldSize, align, newSize) => exports1.cabi_realloc(oldPtr, oldSize, align, newSize) >>> 0;
|
|
3616
|
+
try {
|
|
3617
|
+
WebAssembly.promising(exports1.cabi_realloc);
|
|
3618
|
+
} catch {
|
|
3619
|
+
}
|
|
3620
|
+
postReturn0 = exports1["cabi_post_aula:render/render#[static]player.parse"];
|
|
3621
|
+
try {
|
|
3622
|
+
WebAssembly.promising(exports1["cabi_post_aula:render/render#[static]player.parse"]);
|
|
3623
|
+
} catch {
|
|
3624
|
+
exports1["cabi_post_aula:render/render#[static]player.parse"];
|
|
3625
|
+
}
|
|
3626
|
+
postReturn1 = exports1["cabi_post_aula:render/render#[method]player.png"];
|
|
3627
|
+
try {
|
|
3628
|
+
WebAssembly.promising(exports1["cabi_post_aula:render/render#[method]player.png"]);
|
|
3629
|
+
} catch {
|
|
3630
|
+
exports1["cabi_post_aula:render/render#[method]player.png"];
|
|
3631
|
+
}
|
|
3632
|
+
postReturn2 = exports1["cabi_post_aula:render/render#sheet"];
|
|
3633
|
+
try {
|
|
3634
|
+
WebAssembly.promising(exports1["cabi_post_aula:render/render#sheet"]);
|
|
3635
|
+
} catch {
|
|
3636
|
+
exports1["cabi_post_aula:render/render#sheet"];
|
|
3637
|
+
}
|
|
3638
|
+
renderStaticPlayerParse = exports1["aula:render/render#[static]player.parse"];
|
|
3639
|
+
renderMethodPlayerFps = exports1["aula:render/render#[method]player.fps"];
|
|
3640
|
+
renderMethodPlayerFrames = exports1["aula:render/render#[method]player.frames"];
|
|
3641
|
+
renderMethodPlayerPng = exports1["aula:render/render#[method]player.png"];
|
|
3642
|
+
renderMethodPlayerRgba = exports1["aula:render/render#[method]player.rgba"];
|
|
3643
|
+
renderSheet = exports1["aula:render/render#sheet"];
|
|
3644
|
+
})();
|
|
3645
|
+
let promise, resolve, reject;
|
|
3646
|
+
function normalizeInstantiationError(e) {
|
|
3647
|
+
if (typeof WebAssembly < "u" && typeof WebAssembly.SuspendError == "function" && e instanceof WebAssembly.SuspendError) return new WebAssembly.RuntimeError("cannot block a synchronous task before returning");
|
|
3648
|
+
return e;
|
|
3649
|
+
}
|
|
3650
|
+
function runNext(value) {
|
|
3651
|
+
try {
|
|
3652
|
+
let done;
|
|
3653
|
+
do
|
|
3654
|
+
({ value, done } = gen.next(value));
|
|
3655
|
+
while (!(value instanceof Promise) && !done);
|
|
3656
|
+
if (done) {
|
|
3657
|
+
if (resolve) resolve(value);
|
|
3658
|
+
else return value;
|
|
3659
|
+
}
|
|
3660
|
+
promise ||= new Promise((_resolve, _reject) => (resolve = _resolve, reject = _reject));
|
|
3661
|
+
value.then(runNext, (e) => reject(normalizeInstantiationError(e)));
|
|
3662
|
+
} catch (e) {
|
|
3663
|
+
e = normalizeInstantiationError(e);
|
|
3664
|
+
if (reject) reject(e);
|
|
3665
|
+
else throw e;
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
let maybeSyncReturn = runNext(null);
|
|
3669
|
+
return promise || maybeSyncReturn;
|
|
3670
|
+
})();
|
|
3671
|
+
var render = {
|
|
3672
|
+
Player,
|
|
3673
|
+
sheet
|
|
3674
|
+
};
|
|
3675
|
+
var _util = {
|
|
3676
|
+
stop: _stopInstance.bind(void 0, _jcoComponentStopContext),
|
|
3677
|
+
whenIdle: _whenIdle.bind(void 0, _jcoComponentIdleContext),
|
|
3678
|
+
isComponentError: (value) => value instanceof ComponentError
|
|
3679
|
+
};
|
|
3680
|
+
|
|
3681
|
+
// src/render-child.ts
|
|
3682
|
+
function payload(e) {
|
|
3683
|
+
if (e instanceof Error && "payload" in e && typeof e.payload === "string") return e.payload;
|
|
3684
|
+
return e instanceof Error ? e.message : String(e);
|
|
3685
|
+
}
|
|
3686
|
+
async function pictures(job) {
|
|
3687
|
+
const player = render.Player.parse(await readFile(job.lottie));
|
|
3688
|
+
const sheets = [];
|
|
3689
|
+
for (const group of job.groups) {
|
|
3690
|
+
const folder = path.join(job.out, group.folder);
|
|
3691
|
+
const tiles = group.tiles.map((t) => ({ name: t.name, png: player.png(t.frame) }));
|
|
3692
|
+
await mkdir(folder, { recursive: true });
|
|
3693
|
+
for (const tile of tiles) await writeFile(path.join(folder, `${tile.name}.png`), tile.png);
|
|
3694
|
+
const per = group.cols * group.rows;
|
|
3695
|
+
for (let page = 0; page * per < tiles.length; page++) {
|
|
3696
|
+
const out = path.join(folder, `sheet-${String(page).padStart(2, "0")}.png`);
|
|
3697
|
+
await writeFile(out, render.sheet(tiles.slice(page * per, (page + 1) * per), group.cols, group.rows));
|
|
3698
|
+
sheets.push(out);
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
return sheets;
|
|
3702
|
+
}
|
|
3703
|
+
async function ffmpeg(args, input) {
|
|
3704
|
+
const child = spawn("ffmpeg", ["-hide_banner", "-loglevel", "error", "-nostdin", "-y", ...args], {
|
|
3705
|
+
stdio: ["pipe", "ignore", "pipe"]
|
|
3706
|
+
});
|
|
3707
|
+
let stderr = "";
|
|
3708
|
+
child.stderr.setEncoding("utf8");
|
|
3709
|
+
child.stderr.on("data", (d) => stderr += d);
|
|
3710
|
+
const exited = new Promise((resolve, reject) => {
|
|
3711
|
+
child.on("error", (e) => {
|
|
3712
|
+
const missing = "code" in e && e.code === "ENOENT";
|
|
3713
|
+
reject(new Error(missing ? "ffmpeg is not on the PATH: install ffmpeg" : `cannot run ffmpeg: ${e.message}`));
|
|
3714
|
+
});
|
|
3715
|
+
child.on("close", (code, signal) => {
|
|
3716
|
+
if (code === 0) resolve();
|
|
3717
|
+
else reject(new Error(`ffmpeg failed: ${stderr.trim() || (signal ?? `exit status: ${String(code)}`)}`));
|
|
3718
|
+
});
|
|
3719
|
+
});
|
|
3720
|
+
child.stdin.on("error", () => void 0);
|
|
3721
|
+
await input(child.stdin);
|
|
3722
|
+
child.stdin.end();
|
|
3723
|
+
await exited;
|
|
3724
|
+
}
|
|
3725
|
+
async function write(stdin, chunk) {
|
|
3726
|
+
if (stdin.write(chunk)) return true;
|
|
3727
|
+
return new Promise((resolve) => {
|
|
3728
|
+
const drained = () => {
|
|
3729
|
+
stdin.off("close", closed);
|
|
3730
|
+
resolve(true);
|
|
3731
|
+
};
|
|
3732
|
+
const closed = () => {
|
|
3733
|
+
stdin.off("drain", drained);
|
|
3734
|
+
resolve(false);
|
|
3735
|
+
};
|
|
3736
|
+
stdin.once("drain", drained);
|
|
3737
|
+
stdin.once("close", closed);
|
|
3738
|
+
});
|
|
3739
|
+
}
|
|
3740
|
+
async function clip(job) {
|
|
3741
|
+
const player = render.Player.parse(await readFile(job.lottie));
|
|
3742
|
+
await mkdir(path.dirname(job.out), { recursive: true });
|
|
3743
|
+
const { width, height, fps: fps2 } = VIDEO;
|
|
3744
|
+
const last = player.frames() - 1;
|
|
3745
|
+
const input = ["-f", "rawvideo", "-pix_fmt", "rgba", "-s", `${String(width)}x${String(height)}`, "-r", String(fps2)];
|
|
3746
|
+
const output = ["-c:v", "libx264", "-pix_fmt", "yuv420p", "-crf", "20", job.out];
|
|
3747
|
+
await ffmpeg([...input, "-i", "-", ...output], async (stdin) => {
|
|
3748
|
+
for (let k = 0; k < job.frames; k++) {
|
|
3749
|
+
const frame = Math.min(Math.max((job.from + k / fps2) * player.fps(), 0), last);
|
|
3750
|
+
if (!await write(stdin, player.rgba(frame, width, height))) return;
|
|
3751
|
+
}
|
|
3752
|
+
});
|
|
3753
|
+
}
|
|
3754
|
+
try {
|
|
3755
|
+
const [kind, job, ...rest] = process.argv.slice(2);
|
|
3756
|
+
if (job === void 0 || rest.length > 0) throw new Error("usage: render-child.ts pictures|clip <job JSON>");
|
|
3757
|
+
if (kind === "pictures") {
|
|
3758
|
+
const parsed = JSON.parse(job);
|
|
3759
|
+
for (const out of await pictures(parsed)) process.stdout.write(`${out}
|
|
3760
|
+
`);
|
|
3761
|
+
} else if (kind === "clip") {
|
|
3762
|
+
const parsed = JSON.parse(job);
|
|
3763
|
+
await clip(parsed);
|
|
3764
|
+
} else {
|
|
3765
|
+
throw new Error(`unknown render job ${String(kind)}`);
|
|
3766
|
+
}
|
|
3767
|
+
} catch (e) {
|
|
3768
|
+
process.stderr.write(`${payload(e)}
|
|
3769
|
+
`);
|
|
3770
|
+
process.exitCode = 1;
|
|
3771
|
+
}
|