js-on-sx: raise JS TypeError for non-callable callee, undefined()
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 59s

Calling a non-callable raised an OCaml-level Eval_error "Not callable"
that JS try/catch couldn't intercept. Added a (js-function? callable)
precheck in js-apply-fn that raises a TypeError instance via
(js-new-call TypeError (list msg)) so e instanceof TypeError is
true. Same swap for the undefined() branch in js-call-plain (was
raising a bare string). built-ins/String: 71/99 → 73/99 (canonical),
74/99 → 75/99 (isolated). conformance.sh: 148/148.
This commit is contained in:
2026-05-07 15:58:16 +00:00
parent cf0ba8a02a
commit 843c3a7e5e
4 changed files with 56 additions and 45 deletions

View File

@@ -425,30 +425,44 @@
(fn-val args)
(let
((callable (if (and (dict? fn-val) (contains? (keys fn-val) "__callable__")) (get fn-val "__callable__") fn-val)))
(cond
((= (len args) 0) (callable))
((= (len args) 1) (callable (nth args 0)))
((= (len args) 2) (callable (nth args 0) (nth args 1)))
((= (len args) 3)
(callable (nth args 0) (nth args 1) (nth args 2)))
((= (len args) 4)
(callable (nth args 0) (nth args 1) (nth args 2) (nth args 3)))
((= (len args) 5)
(callable
(nth args 0)
(nth args 1)
(nth args 2)
(nth args 3)
(nth args 4)))
((= (len args) 6)
(callable
(nth args 0)
(nth args 1)
(nth args 2)
(nth args 3)
(nth args 4)
(nth args 5)))
(else (apply callable args))))))
(if
(not (js-function? callable))
(raise
(js-new-call
TypeError
(list (str (str fn-val) " is not a function"))))
(cond
((= (len args) 0) (callable))
((= (len args) 1) (callable (nth args 0)))
((= (len args) 2)
(callable (nth args 0) (nth args 1)))
((= (len args) 3)
(callable
(nth args 0)
(nth args 1)
(nth args 2)))
((= (len args) 4)
(callable
(nth args 0)
(nth args 1)
(nth args 2)
(nth args 3)))
((= (len args) 5)
(callable
(nth args 0)
(nth args 1)
(nth args 2)
(nth args 3)
(nth args 4)))
((= (len args) 6)
(callable
(nth args 0)
(nth args 1)
(nth args 2)
(nth args 3)
(nth args 4)
(nth args 5)))
(else (apply callable args)))))))
;; ── Relational comparisons ────────────────────────────────────────
@@ -608,7 +622,7 @@
(fn-val args)
(cond
((js-undefined? fn-val)
(error "TypeError: undefined is not a function"))
(raise (js-new-call TypeError (list "undefined is not a function"))))
((and (dict? fn-val) (contains? (keys fn-val) "__callable__"))
(js-call-with-this :js-undefined (get fn-val "__callable__") args))
(else (js-call-with-this :js-undefined fn-val args)))))