Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files": {
"ignore": ["**"]
}
}
1 change: 1 addition & 0 deletions build.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const extEntries = [
'src/ext/worker.js',
'src/ext/eventsource.js',
'src/ext/tailwind.js',
'src/ext/ttd.js',
]

const shared = {
Expand Down
29 changes: 29 additions & 0 deletions src/core/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,28 @@ export class Runtime {

unifiedExec(command, ctx) {
while (true) {
const target = ctx.meta.owner || ctx.me;
const eventResult = this.triggerEvent(
target,
"hyperscript:beforeEval",
{ command: command, ctx: ctx },
);
if (!eventResult) {
if (ctx.meta.onHalt) ctx.meta.onHalt();
return;
}
let afterFired = false;

try {
var next = this.unifiedEval(command, ctx);
} catch (e) {
this.triggerEvent(target, "hyperscript:afterEval", {
command: command,
ctx: ctx,
error: e,
});
afterFired = true;

if (ctx.meta.handlingFinally) {
console.error(" Exception in finally block: ", e);
next = Runtime.HALT;
Expand All @@ -113,6 +132,16 @@ export class Runtime {
}
}
}

// afterEval should only fire once per unifiedEval invocation. if unifiedEval threw, don't fire the event again
if (!afterFired) {
this.triggerEvent(target, "hyperscript:afterEval", {
command: command,
ctx: ctx,
next: next,
});
}

if (next == null) {
throw new Error("Command " + (command.type || "unknown") + " did not return a next element to execute");
} else if (next.then) {
Expand Down
Loading