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:
@@ -683,6 +683,44 @@
|
|||||||
;; ── console.log ───────────────────────────────────────────────────
|
;; ── console.log ───────────────────────────────────────────────────
|
||||||
|
|
||||||
;; Trivial bridge. `log-info` is available on OCaml; fall back to print.
|
;; 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
|
(define
|
||||||
js-function?
|
js-function?
|
||||||
(fn
|
(fn
|
||||||
@@ -694,11 +732,7 @@
|
|||||||
(= t "function")
|
(= t "function")
|
||||||
(= t "component")
|
(= t "component")
|
||||||
(and (= t "dict") (contains? (keys v) "__callable__"))))))
|
(and (= t "dict") (contains? (keys v) "__callable__"))))))
|
||||||
|
|
||||||
(define __js_proto_table__ (dict))
|
(define __js_proto_table__ (dict))
|
||||||
|
|
||||||
;; ── Math object ───────────────────────────────────────────────────
|
|
||||||
|
|
||||||
(define __js_next_id__ (dict))
|
(define __js_next_id__ (dict))
|
||||||
(dict-set! __js_next_id__ "n" 0)
|
(dict-set! __js_next_id__ "n" 0)
|
||||||
(define
|
(define
|
||||||
@@ -746,7 +780,8 @@
|
|||||||
((= (type-of v) "component") "function")
|
((= (type-of v) "component") "function")
|
||||||
((and (= (type-of v) "dict") (contains? (keys v) "__callable__"))
|
((and (= (type-of v) "dict") (contains? (keys v) "__callable__"))
|
||||||
"function")
|
"function")
|
||||||
(else "object"))))
|
(else "object")))) ; deterministic placeholder for tests
|
||||||
|
|
||||||
(define
|
(define
|
||||||
js-to-boolean
|
js-to-boolean
|
||||||
(fn
|
(fn
|
||||||
@@ -758,6 +793,11 @@
|
|||||||
((= v 0) false)
|
((= v 0) false)
|
||||||
((= v "") false)
|
((= v "") false)
|
||||||
(else true))))
|
(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
|
(define
|
||||||
js-to-number
|
js-to-number
|
||||||
(fn
|
(fn
|
||||||
@@ -769,7 +809,7 @@
|
|||||||
((= v false) 0)
|
((= v false) 0)
|
||||||
((= (type-of v) "number") v)
|
((= (type-of v) "number") v)
|
||||||
((= (type-of v) "string") (js-string-to-number v))
|
((= (type-of v) "string") (js-string-to-number v))
|
||||||
(else 0)))) ; deterministic placeholder for tests
|
(else 0))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
js-string-to-number
|
js-string-to-number
|
||||||
@@ -785,10 +825,6 @@
|
|||||||
((js-is-numeric-string? trimmed) (js-parse-num-safe trimmed))
|
((js-is-numeric-string? trimmed) (js-parse-num-safe trimmed))
|
||||||
(else (js-nan-value))))))
|
(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
|
(define
|
||||||
js-is-numeric-string?
|
js-is-numeric-string?
|
||||||
(fn (s) (js-is-numeric-loop s 0 false false false)))
|
(fn (s) (js-is-numeric-loop s 0 false false false)))
|
||||||
|
|||||||
Reference in New Issue
Block a user