HS tests: stringify DOM properties (innerHTML, textContent, value)

In a real browser, innerHTML/textContent/value are always strings.
The mock was storing raw SX values (Number, Bool, Nil), causing type
mismatches like "Expected 1, got 1" where the value was correct but
Number 1.0 != String "1".

Now coerces to string on host-set! for innerHTML, textContent, value,
outerHTML, innerText. Fixes 10 increment tests that were doing
`put value into me` with numeric results.

367 → 375/831 HS tests (+8 net, +10 new passes, -2 regressions).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-14 12:38:33 +00:00
parent e3eb46d0dc
commit a6eb125dcc

View File

@@ -1639,11 +1639,29 @@ let run_spec_tests env test_files =
| _ -> (match Hashtbl.find_opt d (string_of_int i) with Some v -> v | None -> Nil))
| _ -> Nil);
(* Stringify a value for DOM string properties *)
let dom_stringify = function
| String s -> String s
| Number n ->
let i = int_of_float n in
if float_of_int i = n then String (string_of_int i) else String (string_of_float n)
| Bool true -> String "true"
| Bool false -> String "false"
| Nil -> String ""
| v -> String (Sx_types.inspect v)
in
reg "host-set!" (fun args ->
match args with
| [Nil; _; _] -> Nil
| [Dict d; String key; value] ->
Hashtbl.replace d key value;
(* DOM string properties: coerce to string like a browser *)
let stored = match key with
| "innerHTML" | "textContent" | "outerHTML" | "value" | "innerText" ->
dom_stringify value
| _ -> value
in
Hashtbl.replace d key stored;
(* Side effects for special keys *)
(if key = "className" then
match Hashtbl.find_opt d "classList" with
@@ -1651,7 +1669,7 @@ let run_spec_tests env test_files =
(* classList sub-dict doesn't store classes — they live in className *)
ignore cl
| _ -> ());
value
stored
| _ -> Nil);
reg "host-call" (fun args ->