HS: step limit + meta.caller (+4 tests)

- _NO_STEP_LIMIT set exempts hypertrace tests from the 200k step cap
- globalThis.__hs_deadline exposed so cek_step_loop wall-clock check
  (every 10k steps) can terminate runaway async loops without needing
  to go through host-call or _driveAsync
- meta + _hs-on-caller added to hs-runtime.sx (both lib and bundled):
  on-event handlers now set meta.caller to an object with
  meta.feature.type = "onFeature" before calling the handler

Tests 196 (async hypertrace), 198 (meta.caller), 199, 200 now pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 12:29:23 +00:00
parent e989ff3865
commit 6a1cbdcbdb
4 changed files with 147 additions and 103 deletions

View File

@@ -43,12 +43,26 @@
;; Run an initializer function immediately.
;; (hs-init thunk) — called at element boot time
(define meta (host-new "Object"))
(define
_hs-on-caller
(let
((_ctx (host-new "Object"))
(_m (host-new "Object"))
(_f (host-new "Object")))
(do
(host-set! _f "type" "onFeature")
(host-set! _m "feature" _f)
(host-set! _ctx "meta" _m)
_ctx)))
(define
hs-on
(fn
(target event-name handler)
(let
((wrapped (fn (event) (guard (e ((and (not (= event-name "exception")) (not (= event-name "error"))) (dom-dispatch target "exception" {:error e})) (true (raise e))) (handler event)))))
((wrapped (fn (event) (do (host-set! meta "caller" _hs-on-caller) (guard (e ((and (not (= event-name "exception")) (not (= event-name "error"))) (dom-dispatch target "exception" {:error e})) (true (raise e))) (handler event))))))
(let
((unlisten (dom-listen target event-name wrapped))
(prev (or (dom-get-data target "hs-unlisteners") (list))))

View File

@@ -46045,7 +46045,7 @@ d2=133,bi=102,bh="Re__Hash_set",cA="Stdlib__Type",cB=114,fF="Stdlib__Buffer",dX=
}
return trampoline(eval_expr(Sx_types[75].call(null, mac), local));
}
var step_limit = [0, 0], step_count = [0, 0];
var step_limit = [0, 0], step_count = [0, 0], _wc_check = 0;
function cek_step_loop(state$0){
var state = state$0;
for(;;){
@@ -46055,6 +46055,11 @@ d2=133,bi=102,bh="Re__Hash_set",cA="Stdlib__Type",cB=114,fF="Stdlib__Buffer",dX=
throw caml_maybe_attach_backtrace
([0, Sx_types[9], "TIMEOUT: step limit exceeded"], 1);
}
if(++_wc_check >= 10000){ _wc_check = 0;
if(globalThis.__hs_deadline && Date.now() > globalThis.__hs_deadline)
throw caml_maybe_attach_backtrace
([0, Sx_types[9], "TIMEOUT: wall clock exceeded"], 1);
}
var
or = cek_terminal_p(state),
or$0 = Sx_types[56].call(null, or) ? or : cek_suspended_p(state);