Merge branch 'loops/host' into merge/host-arch
# Conflicts: # lib/erlang/runtime.sx
This commit is contained in:
@@ -2812,10 +2812,13 @@ let run_spec_tests env test_files =
|
||||
| "insertAdjacentHTML" | "prepend" | "showModal" | "show" | "close"
|
||||
| "getBoundingClientRect" | "getAnimations" | "scrollIntoView"
|
||||
| "scrollTo" | "scroll" | "reset" -> Bool true
|
||||
| "firstElementChild" ->
|
||||
| "firstElementChild" | "firstChild" ->
|
||||
(* the mock treats element children and child nodes alike, so
|
||||
firstChild == firstElementChild — children-to-fragment walks
|
||||
firstChild to drain a parsed fragment into a swap target. *)
|
||||
let kids = match Hashtbl.find_opt d "children" with Some (List l) -> l | _ -> [] in
|
||||
(match kids with c :: _ -> c | [] -> Nil)
|
||||
| "lastElementChild" ->
|
||||
| "lastElementChild" | "lastChild" ->
|
||||
let kids = match Hashtbl.find_opt d "children" with Some (List l) -> l | _ -> [] in
|
||||
(match List.rev kids with c :: _ -> c | [] -> Nil)
|
||||
| "nextElementSibling" | "nextSibling" ->
|
||||
@@ -2961,6 +2964,15 @@ let run_spec_tests env test_files =
|
||||
| "setTimeout" -> (match rest with fn :: _ -> ignore (Sx_ref.cek_call fn (List [])); Nil | _ -> Nil)
|
||||
| "clearTimeout" -> Nil
|
||||
| _ -> Nil)
|
||||
(* NodeList.item(i) — dom-query-all iterates the querySelectorAll result
|
||||
(a bare List) via this method, exactly like a browser NodeList. *)
|
||||
| (List _ | ListRef _) :: String "item" :: [idx] ->
|
||||
let items = match args with
|
||||
| List l :: _ -> l
|
||||
| ListRef { contents = l } :: _ -> l
|
||||
| _ -> [] in
|
||||
let i = match idx with Number n -> int_of_float n | Integer n -> n | _ -> -1 in
|
||||
if i >= 0 && i < List.length items then List.nth items i else Nil
|
||||
| Dict d :: String "hasOwnProperty" :: [String k] ->
|
||||
Bool (Hashtbl.mem d k)
|
||||
| Dict d :: String m :: rest ->
|
||||
@@ -3070,6 +3082,26 @@ let run_spec_tests env test_files =
|
||||
(* console.log/debug/error — no-op in tests *)
|
||||
Nil
|
||||
|
||||
else if mt = "domparser" then
|
||||
(* DOMParser.parseFromString(text, "text/html") — returns a mock
|
||||
document whose <body> is parsed from `text`. An empty string yields
|
||||
a valid empty document (truthy), matching the browser: that's what
|
||||
the engine's handle-html-response relies on for an empty-body
|
||||
sx-swap="delete" response. *)
|
||||
(match m with
|
||||
| "parseFromString" ->
|
||||
let text = match rest with String t :: _ -> t | _ -> "" in
|
||||
let bd = match make_mock_element "body" with Dict d -> d | _ -> Hashtbl.create 0 in
|
||||
Hashtbl.replace bd "tagName" (String "BODY");
|
||||
Hashtbl.replace bd "nodeName" (String "BODY");
|
||||
parse_html_into bd text;
|
||||
Hashtbl.replace bd "innerHTML" (String text);
|
||||
let doc = Hashtbl.create 4 in
|
||||
Hashtbl.replace doc "__mock_type" (String "document");
|
||||
Hashtbl.replace doc "body" (Dict bd);
|
||||
Dict doc
|
||||
| _ -> Nil)
|
||||
|
||||
else
|
||||
(* Element methods *)
|
||||
(match m with
|
||||
@@ -3483,6 +3515,10 @@ let run_spec_tests env test_files =
|
||||
Dict ev
|
||||
| [String "Object"] ->
|
||||
Dict (Hashtbl.create 4)
|
||||
| [String "DOMParser"] ->
|
||||
let d = Hashtbl.create 4 in
|
||||
Hashtbl.replace d "__mock_type" (String "domparser");
|
||||
Dict d
|
||||
| _ -> Nil);
|
||||
|
||||
reg "host-callback" (fun args ->
|
||||
@@ -3686,6 +3722,7 @@ let run_spec_tests env test_files =
|
||||
load_module "router.sx" web_dir;
|
||||
load_module "deps.sx" web_dir;
|
||||
load_module "orchestration.sx" web_dir;
|
||||
load_module "console-render.sx" web_dir;
|
||||
(* Library modules for lib/tests/ *)
|
||||
load_module "bytecode.sx" lib_dir;
|
||||
load_module "compiler.sx" lib_dir;
|
||||
|
||||
Reference in New Issue
Block a user