Platform FFI reduction: remove 99 redundant PRIMITIVES registrations

Move DOM/browser operations to SX library wrappers (dom.sx, browser.sx)
using the 8 FFI primitives, eliminating duplicate native implementations.
Add scope-emitted transpiler rename — fixes 199 pre-existing test failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 11:25:51 +00:00
parent efb2d92b99
commit bc7da977a0
5 changed files with 78 additions and 277 deletions

View File

@@ -169,3 +169,43 @@
(define now-ms
(fn ()
(host-call (host-global "Date") "now")))
;; --------------------------------------------------------------------------
;; Scheduling
;; --------------------------------------------------------------------------
(define schedule-idle
(fn (f)
(let ((cb (host-callback f)))
(if (host-get (dom-window) "requestIdleCallback")
(host-call (dom-window) "requestIdleCallback" cb)
(set-timeout cb 0)))))
;; --------------------------------------------------------------------------
;; Cookies
;; --------------------------------------------------------------------------
(define set-cookie
(fn (name value days)
(let ((d (or days 365))
(expires (host-call
(host-new "Date"
(+ (host-call (host-global "Date") "now")
(* d 864e5)))
"toUTCString")))
(host-set! (dom-document) "cookie"
(str name "="
(host-call nil "encodeURIComponent" value)
";expires=" expires ";path=/;SameSite=Lax")))))
(define get-cookie
(fn (name)
(let ((cookies (host-get (dom-document) "cookie"))
(match (host-call cookies "match"
(host-new "RegExp"
(str "(?:^|;\\s*)" name "=([^;]*)")))))
(if match
(host-call nil "decodeURIComponent" (host-get match 1))
nil))))

View File

@@ -263,6 +263,29 @@
(define event-detail
(fn (evt) (host-get evt "detail")))
(define prevent-default
(fn (e) (when e (host-call e "preventDefault"))))
(define stop-propagation
(fn (e) (when e (host-call e "stopPropagation"))))
(define event-modifier-key?
(fn (e)
(and e (or (host-get e "ctrlKey") (host-get e "metaKey")
(host-get e "shiftKey") (host-get e "altKey")))))
(define element-value
(fn (el)
(if (and el (not (nil? (host-get el "value"))))
(host-get el "value")
nil)))
(define error-message
(fn (e)
(if (and e (host-get e "message"))
(host-get e "message")
(str e))))
;; --------------------------------------------------------------------------
;; DOM data storage