HS: socket namespaced names + timeout plumbing (+2)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 17s

Native JS wrapper: replace SX dict with (host-new "Object") so
host-set! mutations persist for rpc and closed? updates. bind-path!
uses (host-new "Object") for intermediate namespace nodes so dotted
paths like MyApp.chat bind correctly. Fix _hs_make_rpc_proxy call
wrapper to strip the nil this-arg. Land tests 4+16: namespaced sockets
work, with timeout parses and uses the configured timeout. 5/16 total.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 10:22:09 +00:00
parent a20c9c4625
commit ce39a35c6b
5 changed files with 71 additions and 56 deletions

View File

@@ -2532,36 +2532,27 @@
hs-socket-register!
(fn
(name-path url timeout-ms handler json?)
;; 1. Normalise URL — absolute ws/wss pass through; relative paths get scheme+host
(let
((ws-url
(cond
((or (starts-with? url "ws://") (starts-with? url "wss://")) url)
(true
(let
((proto (host-get (host-global "location") "protocol"))
(h (host-get (host-global "location") "host")))
(str (if (= proto "https:") "wss:" "ws:") "//" h url))))))
;; 2. Construct WebSocket
((ws-url (cond ((or (starts-with? url "ws://") (starts-with? url "wss://")) url) (true (let ((proto (host-get (host-global "location") "protocol")) (h (host-get (host-global "location") "host"))) (str (if (= proto "https:") "wss:" "ws:") "//" h url))))))
(let
((ws (host-new "WebSocket" ws-url)))
;; 3. Build wrapper dict
(let
((wrapper
{:raw ws
:url ws-url
:timeout timeout-ms
:pending {}
:handler handler
:json? json?
:closed? false}))
;; 4. Wire RPC proxy via JS factory (if available)
((wrapper (host-new "Object")))
(host-set! wrapper "raw" ws)
(host-set! wrapper "url" ws-url)
(host-set! wrapper "timeout" timeout-ms)
(host-set! wrapper "pending" (host-new "Object"))
(host-set! wrapper "handler" handler)
(host-set! wrapper "json?" json?)
(host-set! wrapper "closed?" false)
(let
((proxy-factory (host-global "_hs_make_rpc_proxy")))
(when proxy-factory
(host-set! wrapper "rpc"
(when
proxy-factory
(host-set!
wrapper
"rpc"
(host-call proxy-factory "call" nil wrapper))))
;; 5. Bind wrapper on window, walking name-path
(define
bind-path!
(fn
@@ -2570,10 +2561,9 @@
(= (len path) 1)
(host-set! obj (first path) wrapper)
(let
((key (first path))
(rest-path (rest path)))
((key (first path)) (rest-path (rest path)))
(let
((next (or (host-get obj key) {})))
((next (or (host-get obj key) (host-new "Object"))))
(host-set! obj key next)
(bind-path! next rest-path))))))
(bind-path! (host-global "window") name-path)