diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index 8f770e4a..24ec68b1 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -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 ->