From c3b0aef1f8b16d0d1eee14c15b730f9c7effaf42 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 24 Apr 2026 09:56:54 +0000 Subject: [PATCH] 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) --- lib/js/runtime.sx | 56 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index d33bf4a5..0a43f8e4 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -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)))