Files
pyscript/pyscript.core/esm/worker/hooks.js
2023-06-27 16:53:19 +02:00

25 lines
704 B
JavaScript

// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const workerHooks = [
["beforeRun", "codeBeforeRunWorker"],
["beforeRunAsync", "codeBeforeRunWorkerAsync"],
["afterRun", "codeAfterRunWorker"],
["afterRunAsync", "codeAfterRunWorkerAsync"],
];
export class Hook {
constructor(interpreter, options) {
this.interpreter = interpreter;
this.onWorkerReady = options.onWorkerReady;
for (const [key, value] of workerHooks) this[key] = options[value]?.();
}
get stringHooks() {
const hooks = {};
for (const [key] of workerHooks) {
if (this[key]) hooks[key] = this[key];
}
return hooks;
}
}
/* c8 ignore stop */