js-on-sx: URIError and EvalError constructors

Mirrors the existing Error/TypeError/RangeError/SyntaxError/ReferenceError
shims. Each sets .message and .name on the new object. Unblocks tests
that use these error types in type-check assertions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 09:56:54 +00:00
parent 38e9376573
commit c3b0aef1f8

View File

@@ -683,6 +683,44 @@
;; ── console.log ───────────────────────────────────────────────────
;; Trivial bridge. `log-info` is available on OCaml; fall back to print.
(define
URIError
(fn
(&rest args)
(let
((this (js-this)))
(begin
(if
(= this :js-undefined)
nil
(do
(dict-set!
this
"message"
(if (empty? args) "" (js-to-string (nth args 0))))
(dict-set! this "name" "URIError")))
this))))
(define
EvalError
(fn
(&rest args)
(let
((this (js-this)))
(begin
(if
(= this :js-undefined)
nil
(do
(dict-set!
this
"message"
(if (empty? args) "" (js-to-string (nth args 0))))
(dict-set! this "name" "EvalError")))
this))))
;; ── Math object ───────────────────────────────────────────────────
(define
js-function?
(fn
@@ -694,11 +732,7 @@
(= t "function")
(= t "component")
(and (= t "dict") (contains? (keys v) "__callable__"))))))
(define __js_proto_table__ (dict))
;; ── Math object ───────────────────────────────────────────────────
(define __js_next_id__ (dict))
(dict-set! __js_next_id__ "n" 0)
(define
@@ -746,7 +780,8 @@
((= (type-of v) "component") "function")
((and (= (type-of v) "dict") (contains? (keys v) "__callable__"))
"function")
(else "object"))))
(else "object")))) ; deterministic placeholder for tests
(define
js-to-boolean
(fn
@@ -758,6 +793,11 @@
((= v 0) false)
((= v "") false)
(else true))))
;; The global object — lookup table for JS names that aren't in the
;; SX env. Transpiled idents look up locally first; globals here are a
;; fallback, but most slice programs reference `console`, `Math`,
;; `undefined` as plain symbols, which we bind as defines above.
(define
js-to-number
(fn
@@ -769,7 +809,7 @@
((= v false) 0)
((= (type-of v) "number") v)
((= (type-of v) "string") (js-string-to-number v))
(else 0)))) ; deterministic placeholder for tests
(else 0))))
(define
js-string-to-number
@@ -785,10 +825,6 @@
((js-is-numeric-string? trimmed) (js-parse-num-safe trimmed))
(else (js-nan-value))))))
;; The global object — lookup table for JS names that aren't in the
;; SX env. Transpiled idents look up locally first; globals here are a
;; fallback, but most slice programs reference `console`, `Math`,
;; `undefined` as plain symbols, which we bind as defines above.
(define
js-is-numeric-string?
(fn (s) (js-is-numeric-loop s 0 false false false)))