From 1a1a98dc7ee9c87ef8e4891974d350b46f670254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Fri, 20 Sep 2024 11:26:23 +0200 Subject: [PATCH 1/3] Bump js_of_ocaml version dependency --- opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opam b/opam index 3c4c1141..5854f032 100644 --- a/opam +++ b/opam @@ -13,7 +13,7 @@ build: [ make "-j%{jobs}%" ] install: [ make "install" ] depends: [ "ocaml" {>= "4.08.0"} - "js_of_ocaml" {>= "4.1.0"} + "js_of_ocaml" {>= "5.5.0"} "eliom" {>= "11.0.0"} "calendar" {>= "2.0.0"} ] From 0006c15f442d648407aace25fa4fe2e9f2588588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 3 Oct 2023 14:26:26 +0200 Subject: [PATCH 2/3] Explicit float conversions --- src/widgets/ot_carousel.eliom | 2 +- src/widgets/ot_picture_uploader.eliom | 4 ++-- src/widgets/ot_pulltorefresh.eliom | 6 +++--- src/widgets/ot_size.eliom | 8 ++++---- src/widgets/ot_time_picker.eliom | 13 ++++++++----- src/widgets/ot_tip.eliom | 8 ++++---- src/widgets/ot_tongue.eliom | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/widgets/ot_carousel.eliom b/src/widgets/ot_carousel.eliom index 520a03e0..222972e6 100644 --- a/src/widgets/ot_carousel.eliom +++ b/src/widgets/ot_carousel.eliom @@ -64,7 +64,7 @@ let%shared default_make_transform ~vertical ?(delta = 0) pos = let%client ot_swiping = "ot-swiping" [%%client -let now () = (new%js Js.date_now)##getTime /. 1000. +let now () = Js.to_float (new%js Js.date_now)##getTime /. 1000. let average_time = 0.1 (* the time, in seconds, diff --git a/src/widgets/ot_picture_uploader.eliom b/src/widgets/ot_picture_uploader.eliom index 38cc5621..2e0ac921 100644 --- a/src/widgets/ot_picture_uploader.eliom +++ b/src/widgets/ot_picture_uploader.eliom @@ -367,8 +367,8 @@ let%shared cropper ~(image : Dom_html.element Js.t Eliom_client_value.t) [%client (fun () -> let bb = ~%image##getBoundingClientRect in - let bb_w = bb##.right -. bb##.left in - let bb_h = bb##.bottom -. bb##.top in + let bb_w = Js.to_float bb##.right -. Js.to_float bb##.left in + let bb_h = Js.to_float bb##.bottom -. Js.to_float bb##.top in let w, h = match ~%ratio with | Some ratio -> diff --git a/src/widgets/ot_pulltorefresh.eliom b/src/widgets/ot_pulltorefresh.eliom index dce2948f..ade02fbf 100644 --- a/src/widgets/ot_pulltorefresh.eliom +++ b/src/widgets/ot_pulltorefresh.eliom @@ -113,7 +113,7 @@ module Make (Conf : CONF) = struct Conf.set_state @@ Some Succeeded; js_container##.style##.transform := Js.string "translateY(0)"; refreshFlag := false)) - 700.) + (Js.float 700.)) (*if the page refreshing finishes instantaneously, setTimeout is used to show the animation*) else ( @@ -123,7 +123,7 @@ module Make (Conf : CONF) = struct ignore (Dom_html.window##setTimeout (Js.wrap_callback (fun () -> refreshFlag := false)) - 500.)); + (Js.float 500.))); Lwt.return_unit) let scroll_back () = @@ -136,7 +136,7 @@ module Make (Conf : CONF) = struct ignore (Dom_html.window##setTimeout (Js.wrap_callback (fun () -> refreshFlag := false)) - 500.)) + (Js.float 500.))) let touchend_handler ev _ = if !top && !distance > 0. && !dragStart >= 0 diff --git a/src/widgets/ot_size.eliom b/src/widgets/ot_size.eliom index cac89ba6..767b25cb 100644 --- a/src/widgets/ot_size.eliom +++ b/src/widgets/ot_size.eliom @@ -117,18 +117,18 @@ let client_width ?(with_margin = false) elt = let client_page_top ?with_margin elt = client_top ?with_margin elt - -. Dom_html.document##.body##getBoundingClientRect##.top + -. Js.to_float Dom_html.document##.body##getBoundingClientRect##.top let client_page_left ?with_margin elt = client_left elt ?with_margin - -. Dom_html.document##.body##getBoundingClientRect##.left + -. Js.to_float Dom_html.document##.body##getBoundingClientRect##.left let client_page_bottom ?with_margin elt = - Dom_html.document##.body##getBoundingClientRect##.bottom + Js.to_float Dom_html.document##.body##getBoundingClientRect##.bottom -. client_bottom ?with_margin elt let client_page_right ?with_margin elt = - Dom_html.document##.body##getBoundingClientRect##.left + Js.to_float Dom_html.document##.body##getBoundingClientRect##.left -. client_right elt ?with_margin let pageYOffset () = diff --git a/src/widgets/ot_time_picker.eliom b/src/widgets/ot_time_picker.eliom index aef06655..63ff6be7 100644 --- a/src/widgets/ot_time_picker.eliom +++ b/src/widgets/ot_time_picker.eliom @@ -207,7 +207,10 @@ let%client ( >>! ) = Js.Opt.iter let%client wrap_touch_aux ev f = ev##.currentTarget >>! fun a -> let r = a##getBoundingClientRect in - let ox = r##.left and ox' = r##.right and oy = r##.top and oy' = r##.bottom in + let ox = Js.to_float r##.left + and ox' = Js.to_float r##.right + and oy = Js.to_float r##.top + and oy' = Js.to_float r##.bottom in assert (ox' >= ox); assert (oy' >= oy); Js.Optdef.iter ev ##. changedTouches ## (item 0) @@ fun touch0 -> @@ -231,10 +234,10 @@ let%client wrap_touch_24h ~ends ev f_e f_b = let%client wrap_click_aux ev f = ev##.currentTarget >>! fun a -> let r = a##getBoundingClientRect in - let ox = r##.left - and ox' = r##.right - and oy = r##.top - and oy' = r##.bottom + let ox = Js.to_float r##.left + and ox' = Js.to_float r##.right + and oy = Js.to_float r##.top + and oy' = Js.to_float r##.bottom and x = ev##.clientX and y = ev##.clientY in assert (ox' > ox); diff --git a/src/widgets/ot_tip.eliom b/src/widgets/ot_tip.eliom index 9d07b0a1..56cc74b4 100644 --- a/src/widgets/ot_tip.eliom +++ b/src/widgets/ot_tip.eliom @@ -44,12 +44,12 @@ let%client display ?(container_a = [a_class ["ot-tip-container"]]) let d_height = float @@ Dom_html.window##.innerHeight in let d_width = float Dom_html.document##.documentElement##.clientWidth in let o_bounds = origin##getBoundingClientRect in - let o_left = o_bounds##.left in - let o_right = o_bounds##.right in + let o_left = Js.to_float o_bounds##.left in + let o_right = Js.to_float o_bounds##.right in let o_to_right = d_width -. o_right in - let o_top = o_bounds##.top in + let o_top = Js.to_float o_bounds##.top in let o_to_top = d_height -. o_top in - let o_bottom = o_bounds##.bottom in + let o_bottom = Js.to_float o_bounds##.bottom in let o_to_bottom = d_height -. o_bottom in let o_width = o_right -. o_left in let o_center_to_left = (o_right +. o_left) /. 2. in diff --git a/src/widgets/ot_tongue.eliom b/src/widgets/ot_tongue.eliom index c97dbc32..23afa509 100644 --- a/src/widgets/ot_tongue.eliom +++ b/src/widgets/ot_tongue.eliom @@ -51,7 +51,7 @@ type%shared tongue = ; px_signal_before : int React.S.t Eliom_client_value.t ; px_signal_after : int React.S.t Eliom_client_value.t } -let%client now () = (new%js Js.date_now)##getTime /. 1000. +let%client now () = Js.to_float (new%js Js.date_now)##getTime /. 1000. let%client clX ev = Js.Optdef.case From ad94b746bfb7c8db13d870f25b593548fb443b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 3 Oct 2023 23:37:09 +0200 Subject: [PATCH 3/3] Do not use physical equality on JavaScript values --- src/widgets/ot_carousel.eliom | 5 +++-- src/widgets/ot_lib.eliom | 4 ++-- src/widgets/ot_nodeready.eliom | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/widgets/ot_carousel.eliom b/src/widgets/ot_carousel.eliom index 222972e6..44a65932 100644 --- a/src/widgets/ot_carousel.eliom +++ b/src/widgets/ot_carousel.eliom @@ -284,8 +284,9 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0) (Js.Unsafe.coerce d2'##.style)##.webkitTransform := s; let move = not - (before == (Js.Unsafe.coerce d2'##.style)##.transform - || before == (Js.Unsafe.coerce d2'##.style)##.webkitTransform) + (Js.strict_equals before (Js.Unsafe.coerce d2'##.style)##.transform + || Js.strict_equals before + (Js.Unsafe.coerce d2'##.style)##.webkitTransform) in let step = React.Step.create () in pos_set ~step pos; diff --git a/src/widgets/ot_lib.eliom b/src/widgets/ot_lib.eliom index 489903b0..69c8e2e0 100644 --- a/src/widgets/ot_lib.eliom +++ b/src/widgets/ot_lib.eliom @@ -78,8 +78,8 @@ let%client window_scrolls ?(ios_html_scroll_hack = false) ?use_capture handler = (fun () -> stop_thread (); Lwt.cancel !cur; Lwt.return_unit) let%client rec in_ancestors ~elt ~ancestor = - elt == (ancestor : Dom_html.element Js.t) - || (not (elt == Dom_html.document##.body)) + Js.strict_equals elt (ancestor : Dom_html.element Js.t) + || (not (Js.strict_equals elt Dom_html.document##.body)) && Js.Opt.case elt##.parentNode (fun () -> false) (fun parent -> diff --git a/src/widgets/ot_nodeready.eliom b/src/widgets/ot_nodeready.eliom index 15e55a5a..704dfc5c 100644 --- a/src/widgets/ot_nodeready.eliom +++ b/src/widgets/ot_nodeready.eliom @@ -25,7 +25,7 @@ open Js_of_ocaml let debug = false let rec node_in_document node = - node == (Dom_html.document :> Dom.node Js.t) + Js.strict_equals node (Dom_html.document :> Dom.node Js.t) || Js.Opt.case node##.parentNode (fun () -> false) node_in_document type t = @@ -81,7 +81,9 @@ let nodeready n = else ( if !watched = [] then observer##observe Dom_html.document config; try - let {thread} = List.find (fun {node} -> n == node) !watched in + let {thread} = + List.find (fun {node} -> Js.strict_equals n node) !watched + in log ~n "already being watched"; thread with Not_found -> @@ -93,7 +95,7 @@ let nodeready n = in Eliom_client.Page_status.ondead ~stop (fun () -> let instances_of_node, rest = - List.partition (fun {node} -> n == node) !watched + List.partition (fun {node} -> Js.strict_equals n node) !watched in watched := rest; instances_of_node