diff --git a/CHANGES.md b/CHANGES.md index e0d314ad2c..2e8ad43b60 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,15 @@ +# dev + +## Features/Changes +* Lib: fix the type of some DOM properties and methods (#1747) +* Test: use dune test stanzas (#1631) + +# 5.9.1 (02-12-2024) - Lille + +## Features/Changes +* Compiler: add mechanism to deprecate runtime promitives +* Runtime: re-introduce caml_new_string, marked as deprecated + # 5.9.0 (2024-11-22) - Lille ## Features/Changes diff --git a/VERSION b/VERSION index b3d91f9cfc..450ad1e283 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.9.0 +5.9.1 diff --git a/compiler/bin-js_of_ocaml/check_runtime.ml b/compiler/bin-js_of_ocaml/check_runtime.ml index 29b541914a..5868fdad53 100644 --- a/compiler/bin-js_of_ocaml/check_runtime.ml +++ b/compiler/bin-js_of_ocaml/check_runtime.ml @@ -101,11 +101,11 @@ let f (runtime_files, bytecode, target_env) = StringSet.of_list (Linker.all state), missing in assert (StringSet.equal missing missing'); + let extra = StringSet.diff from_runtime1 all_used |> StringSet.elements in let extra = - StringSet.diff from_runtime1 all_used - |> StringSet.elements + extra |> List.map ~f:(fun name -> - ( name + ( (name ^ if Linker.deprecated ~name then " (deprecated)" else "") , match Linker.origin ~name with | None -> [] | Some x -> [ x ] )) diff --git a/compiler/lib/annot_lexer.mll b/compiler/lib/annot_lexer.mll index 7f4a54862a..10e1292cdc 100644 --- a/compiler/lib/annot_lexer.mll +++ b/compiler/lib/annot_lexer.mll @@ -28,6 +28,7 @@ rule main = parse | "Always" {TAlways} | "If" {TIf} | "Alias" {TAlias} + | "Deprecated: " ([^'\n']* as txt) {TDeprecated txt} | "pure" {TA_Pure } | "const" {TA_Const } | "mutable" {TA_Mutable } diff --git a/compiler/lib/annot_parser.mly b/compiler/lib/annot_parser.mly index 1e67629828..776264c7e1 100644 --- a/compiler/lib/annot_parser.mly +++ b/compiler/lib/annot_parser.mly @@ -22,6 +22,7 @@ %token TIdent TVNum %token TComma TColon EOF EOL LE LT GE GT EQ LPARENT RPARENT %token TOTHER +%token TDeprecated %token TBang %start annot @@ -40,6 +41,7 @@ annot: { `Version (l) } | TWeakdef endline { `Weakdef } | TAlways endline { `Always } + | TDeprecated endline { `Deprecated $1 } | TAlias TColon name=TIdent endline { `Alias (name) } | TIf TColon name=TIdent endline { `If (name) } | TIf TColon TBang name=TIdent endline { `Ifnot (name) } diff --git a/compiler/lib/linker.ml b/compiler/lib/linker.ml index 69be7e08f8..416376ec3e 100644 --- a/compiler/lib/linker.ml +++ b/compiler/lib/linker.ml @@ -177,6 +177,7 @@ module Fragment = struct ; conditions : bool StringMap.t ; fragment_target : Target_env.t option ; aliases : StringSet.t + ; deprecated : string option } let allowed_flags = @@ -259,6 +260,7 @@ module Fragment = struct ; conditions = StringMap.empty ; fragment_target = None ; aliases = StringSet.empty + ; deprecated = None } in let fragment = @@ -289,6 +291,7 @@ module Fragment = struct | `Always -> { fragment with always = true } | `Alias name -> { fragment with aliases = StringSet.add name fragment.aliases } + | `Deprecated txt -> { fragment with deprecated = Some txt } | `If name when Option.is_some (Target_env.of_string name) -> if Option.is_some fragment.fragment_target then Format.eprintf "Duplicated target_env in %s\n" (loc pi); @@ -394,6 +397,7 @@ type state = { ids : IntSet.t ; always_required_codes : always_required list ; codes : (Javascript.program pack * bool) list + ; deprecation : (int list * string) list ; missing : StringSet.t ; include_ : string -> bool } @@ -456,6 +460,7 @@ let load_fragment ~target_env ~filename (f : Fragment.t) = ; aliases ; has_macro ; conditions + ; deprecated } -> ( let should_ignore = StringMap.exists @@ -543,14 +548,14 @@ let load_fragment ~target_env ~filename (f : Fragment.t) = name { id; pi; filename; weakdef; target_env = fragment_target }; Hashtbl.add provided_rev id (name, pi); - Hashtbl.add code_pieces id (code, has_macro, requires); + Hashtbl.add code_pieces id (code, has_macro, requires, deprecated); StringSet.iter (fun alias -> Primitive.alias alias name) aliases; `Ok) let check_deps () = let provided = list_all () in Hashtbl.iter - (fun id (code, _has_macro, requires) -> + (fun id (code, _has_macro, requires, _deprecated) -> match code with | Ok code -> ( let traverse = new Js_traverse.free in @@ -617,13 +622,18 @@ and resolve_dep_id_rev state path id = state) else let path = id :: path in - let code, has_macro, req = Hashtbl.find code_pieces id in + let code, has_macro, req, deprecated = Hashtbl.find code_pieces id in let state = { state with ids = IntSet.add id state.ids } in let state = List.fold_left req ~init:state ~f:(fun state nm -> resolve_dep_name_rev state path nm) in - let state = { state with codes = (code, has_macro) :: state.codes } in + let deprecation = + match deprecated with + | None -> state.deprecation + | Some txt -> (path, txt) :: state.deprecation + in + let state = { state with codes = (code, has_macro) :: state.codes; deprecation } in state let proj_always_required { ar_filename; ar_requires; ar_program } = @@ -640,6 +650,7 @@ let init ?from () = List.rev (List.filter_map !always_included ~f:(fun x -> if include_ x.ar_filename then Some (proj_always_required x) else None)) + ; deprecation = [] ; codes = [] ; include_ ; missing = StringSet.empty @@ -681,6 +692,29 @@ let link ?(check_missing = true) program (state : state) = { state with codes = (Ok always.program, false) :: state.codes }) in if check_missing then do_check_missing state; + List.iter state.deprecation ~f:(fun (path, txt) -> + match path with + | [] -> assert false + | [ x ] -> + if false + then + let name = fst (Hashtbl.find provided_rev x) in + warn "The runtime primitive [%s] is deprecated. %s\n" name txt + | x :: path -> + let name = fst (Hashtbl.find provided_rev x) in + let path = + String.concat + ~sep:"\n" + (List.map path ~f:(fun id -> + let nm, loc = Hashtbl.find provided_rev id in + Printf.sprintf "-> %s:%s" nm (Parse_info.to_string loc))) + in + warn + "The runtime primitive [%s] is deprecated. %s. Used by:\n%s\n" + name + txt + path); + let codes = List.map state.codes ~f:(fun (x, has_macro) -> let c = unpack x in @@ -710,3 +744,10 @@ let origin ~name = let x = Hashtbl.find provided name in x.pi.Parse_info.src with Not_found -> None + +let deprecated ~name = + try + let x = Hashtbl.find provided name in + let _, _, _, deprecated = Hashtbl.find code_pieces x.id in + Option.is_some deprecated + with Not_found -> false diff --git a/compiler/lib/linker.mli b/compiler/lib/linker.mli index b7d49194c7..00ce9b902f 100644 --- a/compiler/lib/linker.mli +++ b/compiler/lib/linker.mli @@ -68,3 +68,5 @@ val all : state -> string list val missing : state -> string list val origin : name:string -> string option + +val deprecated : name:string -> bool diff --git a/compiler/lib/primitive.ml b/compiler/lib/primitive.ml index 9ccfd71df3..57abd19e60 100644 --- a/compiler/lib/primitive.ml +++ b/compiler/lib/primitive.ml @@ -50,6 +50,7 @@ type t = | `Weakdef | `Always | `Alias of string + | `Deprecated of string | condition ] diff --git a/compiler/lib/primitive.mli b/compiler/lib/primitive.mli index 08888360b9..59613b796c 100644 --- a/compiler/lib/primitive.mli +++ b/compiler/lib/primitive.mli @@ -48,6 +48,7 @@ type t = | `Weakdef | `Always | `Alias of string + | `Deprecated of string | condition ] diff --git a/compiler/tests-check-prim/main.output b/compiler/tests-check-prim/main.output index 3051f6b6ec..139954b7ee 100644 --- a/compiler/tests-check-prim/main.output +++ b/compiler/tests-check-prim/main.output @@ -108,11 +108,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +stdlib.js: caml_build_symbols diff --git a/compiler/tests-check-prim/main.output5 b/compiler/tests-check-prim/main.output5 index f685d9f19d..3c5ba47eab 100644 --- a/compiler/tests-check-prim/main.output5 +++ b/compiler/tests-check-prim/main.output5 @@ -101,11 +101,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +runtime_events.js: caml_runtime_events_create_cursor diff --git a/compiler/tests-check-prim/unix-unix.output b/compiler/tests-check-prim/unix-unix.output index a5b4b7b999..21af5e2974 100644 --- a/compiler/tests-check-prim/unix-unix.output +++ b/compiler/tests-check-prim/unix-unix.output @@ -217,11 +217,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +stdlib.js: caml_build_symbols diff --git a/compiler/tests-check-prim/unix-unix.output5 b/compiler/tests-check-prim/unix-unix.output5 index 7902a823df..630bcaf2fd 100644 --- a/compiler/tests-check-prim/unix-unix.output5 +++ b/compiler/tests-check-prim/unix-unix.output5 @@ -212,11 +212,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +runtime_events.js: caml_runtime_events_create_cursor diff --git a/compiler/tests-check-prim/unix-win32.output b/compiler/tests-check-prim/unix-win32.output index 284f7eb510..f49ad3383a 100644 --- a/compiler/tests-check-prim/unix-win32.output +++ b/compiler/tests-check-prim/unix-win32.output @@ -182,11 +182,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +stdlib.js: caml_build_symbols diff --git a/compiler/tests-check-prim/unix-win32.output5 b/compiler/tests-check-prim/unix-win32.output5 index b45443271c..f2c49c3ded 100644 --- a/compiler/tests-check-prim/unix-win32.output5 +++ b/compiler/tests-check-prim/unix-win32.output5 @@ -178,11 +178,12 @@ BigStringReader caml_marshal_constants From +mlBytes.js: -caml_array_of_bytes -caml_array_of_string +caml_array_of_bytes (deprecated) +caml_array_of_string (deprecated) caml_bytes_of_utf16_jsstring +caml_new_string (deprecated) caml_string_concat -caml_to_js_string +caml_to_js_string (deprecated) From +runtime_events.js: caml_runtime_events_create_cursor diff --git a/compiler/tests-dynlink-js/dune b/compiler/tests-dynlink-js/dune index da871999b7..52df5f5de0 100644 --- a/compiler/tests-dynlink-js/dune +++ b/compiler/tests-dynlink-js/dune @@ -5,11 +5,9 @@ (libraries js_of_ocaml) (link_flags (:standard -linkall)) - ;; Until dune is fixed https://github.com/ocaml/dune/pull/10935 (js_of_ocaml (flags (:standard) - --linkall (:include effects_flags.sexp)) (build_runtime_flags (:standard) diff --git a/compiler/tests-sourcemap/dune b/compiler/tests-sourcemap/dune index 76618354b5..2582f218bc 100644 --- a/compiler/tests-sourcemap/dune +++ b/compiler/tests-sourcemap/dune @@ -6,6 +6,8 @@ (executable (name test) (modules test) + (enabled_if + (<> %{profile} using-effects)) (modes js) (js_of_ocaml (link_flags diff --git a/compiler/tests-toplevel/dune b/compiler/tests-toplevel/dune index 0fba2cc55f..650ac90c16 100644 --- a/compiler/tests-toplevel/dune +++ b/compiler/tests-toplevel/dune @@ -16,7 +16,10 @@ (rule (target test_toplevel.bc.js.actual) - (enabled_if %{env:js-enabled=}) + (enabled_if + (and + (>= %{ocaml_version} 5.2) + %{env:js-enabled=})) (action (with-stdout-to %{target} diff --git a/examples/graph_viewer/viewer_js.ml b/examples/graph_viewer/viewer_js.ml index 0e37cdff64..2820bd543e 100644 --- a/examples/graph_viewer/viewer_js.ml +++ b/examples/graph_viewer/viewer_js.ml @@ -231,23 +231,23 @@ class adjustment end let handle_drag element f = - let mx = ref 0 in - let my = ref 0 in + let mx = ref 0. in + let my = ref 0. in element##.onmousedown := Html.handler (fun ev -> - mx := ev##.clientX; - my := ev##.clientY; + mx := Js.to_float ev##.clientX; + my := Js.to_float ev##.clientY; element##.style##.cursor := Js.string "move"; let c1 = Html.addEventListener Html.document Html.Event.mousemove (Html.handler (fun ev -> - let x = ev##.clientX and y = ev##.clientY in + let x = Js.to_float ev##.clientX and y = Js.to_float ev##.clientY in let x' = !mx and y' = !my in mx := x; my := y; - f (x - x') (y - y'); + f (x -. x') (y -. y'); Js._true)) Js._true in @@ -443,12 +443,13 @@ Firebug.console##log(Js.string "sleep"); sadj#set_value (float (height - pos') *. sadj#upper /. float height); rescale 0.5 0.5) in - handle_drag thumb (fun _dx dy -> set_slider_position (min height (max 0 (!pos + dy)))); + handle_drag thumb (fun _dx dy -> + set_slider_position (min height (max 0 (!pos + int_of_float dy)))); slider##.onmousedown := Html.handler (fun ev -> - let ey = ev##.clientY in + let ey = Js.to_float ev##.clientY in let _, sy = Dom_html.elementClientPosition slider in - set_slider_position (max 0 (min height (ey - sy - (size / 2)))); + set_slider_position (max 0 (min height (int_of_float ey - sy - (size / 2)))); Js._false); let adjust_slider () = let pos' = height - truncate ((sadj#value *. float height /. sadj#upper) +. 0.5) in @@ -466,7 +467,7 @@ Firebug.console##log(Js.string "sleep"); handle_drag canvas (fun dx dy -> let scale = get_scale () in let offset a d = - a#set_value (min (a#value -. (float d /. scale)) (a#upper -. a#page_size)) + a#set_value (min (a#value -. (d /. scale)) (a#upper -. a#page_size)) in offset hadj dx; offset vadj dy; @@ -490,8 +491,8 @@ Firebug.console##log(Js.string "sleep"); canvas (fun ev ~dx:_ ~dy -> let ex, ey = Dom_html.elementClientPosition canvas in - let x = float (ev##.clientX - ex) in - let y = float (ev##.clientY - ey) in + let x = Js.to_float ev##.clientX -. float ex in + let y = Js.to_float ev##.clientY -. float ey in if dy < 0 then bump_scale x y 1. else if dy > 0 diff --git a/examples/hyperbolic/hypertree.ml b/examples/hyperbolic/hypertree.ml index b6d55991be..047866de6b 100644 --- a/examples/hyperbolic/hypertree.ml +++ b/examples/hyperbolic/hypertree.ml @@ -294,10 +294,10 @@ let _debug_msg _s = () *) let handle_drag element move stop click = - let fuzz = 4 in + let fuzz = 4. in element##.onmousedown := Html.handler (fun ev -> - let x0 = ev##.clientX and y0 = ev##.clientY in + let x0 = Js.to_float ev##.clientX and y0 = Js.to_float ev##.clientY in (* debug_msg (Format.sprintf "Mouse down %d %d" x0 y0); *) @@ -307,11 +307,12 @@ debug_msg (Format.sprintf "Mouse down %d %d" x0 y0); Html.document Html.Event.mousemove (Html.handler (fun ev -> - let x = ev##.clientX and y = ev##.clientY in + let x = Js.to_float ev##.clientX and y = Js.to_float ev##.clientY in (* debug_msg (Format.sprintf "Mouse move %d %d %d %d" x0 y0 x y); *) - if (not !started) && (abs (x - x0) > fuzz || abs (y - y0) > fuzz) + if (not !started) + && (abs_float (x -. x0) > fuzz || abs_float (y -. y0) > fuzz) then ( started := true; element##.style##.cursor := Js.string "move"); @@ -335,14 +336,14 @@ debug_msg (Format.sprintf "Mouse up %d %d %d %d" x0 y0 ev##clientX ev##clientY); if !started then ( element##.style##.cursor := Js.string ""; - stop ev##.clientX ev##.clientY) - else click ev##.clientX ev##.clientY; + stop (Js.to_float ev##.clientX) (Js.to_float ev##.clientY)) + else click (Js.to_float ev##.clientX) (Js.to_float ev##.clientY); Js._true)) Js._true); Js._true) let handle_touch_events element move stop cancel click = - let fuzz = 4 in + let fuzz = 4. in ignore (Html.addEventListener element @@ -352,7 +353,8 @@ let handle_touch_events element move stop cancel click = (ev##.changedTouches##item 0) (fun touch -> let id = touch##.identifier in - let x0 = touch##.clientX and y0 = touch##.clientY in + let x0 = Js.to_float touch##.clientX + and y0 = Js.to_float touch##.clientY in (* debug_msg (Format.sprintf "Touch start %d %d" x0 y0); *) @@ -368,12 +370,14 @@ debug_msg (Format.sprintf "Touch start %d %d" x0 y0); (fun touch -> if touch##.identifier = id then ( - let x = touch##.clientX and y = touch##.clientY in + let x = Js.to_float touch##.clientX + and y = Js.to_float touch##.clientY in (* debug_msg (Format.sprintf "Touch move %d %d %d %d" x0 y0 x y); *) if (not !started) - && (abs (x - x0) > fuzz || abs (y - y0) > fuzz) + && (abs_float (x -. x0) > fuzz + || abs_float (y -. y0) > fuzz) then ( started := true; element##.style##.cursor := Js.string "move"); @@ -397,7 +401,8 @@ debug_msg (Format.sprintf "Touch start %d %d" x0 y0); (fun touch -> if touch##.identifier = id then ( - let x = touch##.clientX and y = touch##.clientY in + let x = Js.to_float touch##.clientX + and y = Js.to_float touch##.clientY in (* debug_msg (Format.sprintf "Touch end %d %d %d %d" x0 y0 x y); *) @@ -582,7 +587,7 @@ let to_screen z = ((z.x +. 1.) *. r, (z.y +. 1.) *. r) *) let from_screen canvas x y = let rx, ry, dx, dy = screen_transform canvas in - let z = { x = (float x -. dx) /. rx; y = (float y -. dy) /. ry } in + let z = { x = (x -. dx) /. rx; y = (y -. dy) /. ry } in let n = norm z in if n <= 1. -. eps then z else sdiv z (n /. (1. -. eps)) @@ -1631,10 +1636,8 @@ debug_msg (Format.sprintf "Resize %d %d" w h); let p = ref (-1) in for i = 0 to Array.length boxes.bw - 1 do if Array.unsafe_get boxes.bw i > 0. - && abs_float (float x -. Array.unsafe_get boxes.bx i) - < Array.unsafe_get boxes.bw i - && abs_float (float y -. Array.unsafe_get boxes.by i) - < Array.unsafe_get boxes.bh i + && abs_float (x -. Array.unsafe_get boxes.bx i) < Array.unsafe_get boxes.bw i + && abs_float (y -. Array.unsafe_get boxes.by i) < Array.unsafe_get boxes.bh i then p := i done; !p @@ -1655,7 +1658,7 @@ debug_msg (Format.sprintf "Resize %d %d" w h); in canvas##.onmousemove := Html.handler (fun ev -> - update_cursor ev##.clientX ev##.clientY; + update_cursor (Js.to_float ev##.clientX) (Js.to_float ev##.clientY); Js._false); handle_drag canvas diff --git a/examples/planet/planet.ml b/examples/planet/planet.ml index 25d0f4a724..1ab5f87472 100644 --- a/examples/planet/planet.ml +++ b/examples/planet/planet.ml @@ -683,23 +683,23 @@ let () = p##.innerHTML := Js.string "Credit: Visual Earth, Nasa"; add doc##.body p; - let mx = ref 0 in - let my = ref 0 in + let mx = ref 0. in + let my = ref 0. in canvas##.onmousedown := Dom_html.handler (fun ev -> - mx := ev##.clientX; - my := ev##.clientY; + mx := Js.to_float ev##.clientX; + my := Js.to_float ev##.clientY; let c1 = Html.addEventListener Html.document Html.Event.mousemove (Dom_html.handler (fun ev -> - let x = ev##.clientX and y = ev##.clientY in - let dx = x - !mx and dy = y - !my in - if dy != 0 - then m := matrix_mul (yz_rotation (2. *. float dy /. float width)) !m; - if dx != 0 - then m := matrix_mul (xz_rotation (2. *. float dx /. float width)) !m; + let x = Js.to_float ev##.clientX and y = Js.to_float ev##.clientY in + let dx = x -. !mx and dy = y -. !my in + if dy != 0. + then m := matrix_mul (yz_rotation (2. *. dy /. float width)) !m; + if dx != 0. + then m := matrix_mul (xz_rotation (2. *. dx /. float width)) !m; mx := x; my := y; Js._true)) diff --git a/lib/js_of_ocaml/dom_html.ml b/lib/js_of_ocaml/dom_html.ml index ed556ee037..958d91e877 100644 --- a/lib/js_of_ocaml/dom_html.ml +++ b/lib/js_of_ocaml/dom_html.ml @@ -297,17 +297,17 @@ and mouseEvent = object method relatedTarget : element t opt optdef readonly_prop - method clientX : int readonly_prop + method clientX : number_t readonly_prop - method clientY : int readonly_prop + method clientY : number_t readonly_prop - method screenX : int readonly_prop + method screenX : number_t readonly_prop - method screenY : int readonly_prop + method screenY : number_t readonly_prop - method offsetX : int readonly_prop + method offsetX : number_t readonly_prop - method offsetY : int readonly_prop + method offsetY : number_t readonly_prop method ctrlKey : bool t readonly_prop @@ -325,9 +325,9 @@ and mouseEvent = object method toElement : element t opt optdef readonly_prop - method pageX : int optdef readonly_prop + method pageX : number_t optdef readonly_prop - method pageY : int optdef readonly_prop + method pageY : number_t optdef readonly_prop end and keyboardEvent = object @@ -421,17 +421,17 @@ and touch = object method target : element t optdef readonly_prop - method screenX : int readonly_prop + method screenX : number_t readonly_prop - method screenY : int readonly_prop + method screenY : number_t readonly_prop - method clientX : int readonly_prop + method clientX : number_t readonly_prop - method clientY : int readonly_prop + method clientY : number_t readonly_prop - method pageX : int readonly_prop + method pageX : number_t readonly_prop - method pageY : int readonly_prop + method pageY : number_t readonly_prop end and submitEvent = object @@ -727,9 +727,9 @@ and element = object method offsetHeight : int readonly_prop - method scrollLeft : int prop + method scrollLeft : number_t prop - method scrollTop : int prop + method scrollTop : number_t prop method scrollWidth : int prop @@ -2321,9 +2321,15 @@ class type window = object method blur : unit meth - method scroll : int -> int -> unit meth + method scrollX : number_t readonly_prop - method scrollBy : int -> int -> unit meth + method scrollY : number_t readonly_prop + + method scroll : number_t -> number_t -> unit meth + + method scrollTo : number_t -> number_t -> unit meth + + method scrollBy : number_t -> number_t -> unit meth method sessionStorage : storage t optdef readonly_prop @@ -2888,14 +2894,22 @@ let eventRelatedTarget (e : #mouseEvent t) = let eventAbsolutePosition' (e : #mouseEvent t) = let body = document##.body in let html = document##.documentElement in - ( e##.clientX + body##.scrollLeft + html##.scrollLeft - , e##.clientY + body##.scrollTop + html##.scrollTop ) + ( Js.to_float e##.clientX + +. Js.to_float body##.scrollLeft + +. Js.to_float html##.scrollLeft + , Js.to_float e##.clientY + +. Js.to_float body##.scrollTop + +. Js.to_float html##.scrollTop ) let eventAbsolutePosition (e : #mouseEvent t) = Optdef.case e##.pageX (fun () -> eventAbsolutePosition' e) - (fun x -> Optdef.case e##.pageY (fun () -> eventAbsolutePosition' e) (fun y -> x, y)) + (fun x -> + Optdef.case + e##.pageY + (fun () -> eventAbsolutePosition' e) + (fun y -> Js.to_float x, Js.to_float y)) let elementClientPosition (e : #element t) = let r = e##getBoundingClientRect in @@ -2907,7 +2921,8 @@ let elementClientPosition (e : #element t) = let getDocumentScroll () = let body = document##.body in let html = document##.documentElement in - body##.scrollLeft + html##.scrollLeft, body##.scrollTop + html##.scrollTop + ( Js.to_float body##.scrollLeft +. Js.to_float html##.scrollLeft + , Js.to_float body##.scrollTop +. Js.to_float html##.scrollTop ) let buttonPressed (ev : #mouseEvent Js.t) = Js.Optdef.case diff --git a/lib/js_of_ocaml/dom_html.mli b/lib/js_of_ocaml/dom_html.mli index 5e00793cd0..7b5f2f7793 100644 --- a/lib/js_of_ocaml/dom_html.mli +++ b/lib/js_of_ocaml/dom_html.mli @@ -299,18 +299,18 @@ and mouseEvent = object method relatedTarget : element t opt optdef readonly_prop (* Relative to viewport *) - method clientX : int readonly_prop + method clientX : number_t readonly_prop - method clientY : int readonly_prop + method clientY : number_t readonly_prop (* Relative to the edge of the screen *) - method screenX : int readonly_prop + method screenX : number_t readonly_prop - method screenY : int readonly_prop + method screenY : number_t readonly_prop - method offsetX : int readonly_prop + method offsetX : number_t readonly_prop - method offsetY : int readonly_prop + method offsetY : number_t readonly_prop method ctrlKey : bool t readonly_prop @@ -329,9 +329,9 @@ and mouseEvent = object method toElement : element t opt optdef readonly_prop - method pageX : int optdef readonly_prop + method pageX : number_t optdef readonly_prop - method pageY : int optdef readonly_prop + method pageY : number_t optdef readonly_prop end and keyboardEvent = object @@ -427,17 +427,17 @@ and touch = object method target : element t optdef readonly_prop - method screenX : int readonly_prop + method screenX : number_t readonly_prop - method screenY : int readonly_prop + method screenY : number_t readonly_prop - method clientX : int readonly_prop + method clientX : number_t readonly_prop - method clientY : int readonly_prop + method clientY : number_t readonly_prop - method pageX : int readonly_prop + method pageX : number_t readonly_prop - method pageY : int readonly_prop + method pageY : number_t readonly_prop end and submitEvent = object @@ -740,9 +740,9 @@ and element = object method offsetHeight : int readonly_prop - method scrollLeft : int prop + method scrollLeft : number_t prop - method scrollTop : int prop + method scrollTop : number_t prop method scrollWidth : int prop @@ -2165,9 +2165,15 @@ class type window = object method blur : unit meth - method scroll : int -> int -> unit meth + method scrollX : number_t readonly_prop - method scrollBy : int -> int -> unit meth + method scrollY : number_t readonly_prop + + method scroll : number_t -> number_t -> unit meth + + method scrollTo : number_t -> number_t -> unit meth + + method scrollBy : number_t -> number_t -> unit meth method sessionStorage : storage t optdef readonly_prop @@ -2591,13 +2597,13 @@ val buttonPressed : #mouseEvent Js.t -> mouse_button (** {2 Position helper functions} *) -val eventAbsolutePosition : #mouseEvent t -> int * int +val eventAbsolutePosition : #mouseEvent t -> float * float (** Returns the absolute position of the mouse pointer. *) val elementClientPosition : #element t -> int * int (** Position of an element relative to the viewport *) -val getDocumentScroll : unit -> int * int +val getDocumentScroll : unit -> float * float (** Viewport top/left position *) (** {2 Key event helper functions} *) diff --git a/lib/lwt/graphics/graphics_js.ml b/lib/lwt/graphics/graphics_js.ml index 588a329300..516099a576 100644 --- a/lib/lwt/graphics/graphics_js.ml +++ b/lib/lwt/graphics/graphics_js.ml @@ -48,12 +48,12 @@ let open_canvas x = let compute_real_pos (elt : #Dom_html.element Js.t) ev = let r = elt##getBoundingClientRect in let x = - (float_of_int ev##.clientX -. Js.to_float r##.left) + (Js.to_float ev##.clientX -. Js.to_float r##.left) /. (Js.to_float r##.right -. Js.to_float r##.left) *. float_of_int elt##.width in let y = - (float_of_int ev##.clientY -. Js.to_float r##.top) + (Js.to_float ev##.clientY -. Js.to_float r##.top) /. (Js.to_float r##.bottom -. Js.to_float r##.top) *. float_of_int elt##.height in diff --git a/runtime/js/mlBytes.js b/runtime/js/mlBytes.js index a39ae3a101..8566487548 100644 --- a/runtime/js/mlBytes.js +++ b/runtime/js/mlBytes.js @@ -879,36 +879,49 @@ function caml_is_ml_string(s) { //Provides: caml_js_to_byte_string const //Requires: caml_string_of_jsbytes +//Deprecated: Use [caml_string_of_jsbytes] instead function caml_js_to_byte_string(s) { return caml_string_of_jsbytes(s); } //Provides: caml_js_from_string mutable (const) //Requires: caml_jsstring_of_string +//Deprecated: Use [caml_jsstring_of_string] instead function caml_js_from_string(s) { return caml_jsstring_of_string(s); } //Provides: caml_to_js_string mutable (const) //Requires: caml_jsstring_of_string +//Deprecated: Use [caml_jsstring_of_string] instead function caml_to_js_string(s) { return caml_jsstring_of_string(s); } //Provides: caml_js_to_string const //Requires: caml_string_of_jsstring +//Deprecated: Use [caml_string_of_jsstring] instead function caml_js_to_string(s) { return caml_string_of_jsstring(s); } //Provides: caml_array_of_string //Requires: caml_uint8_array_of_string +//Deprecated: Use [caml_uint8_array_of_string] instead function caml_array_of_string(x) { return caml_uint8_array_of_string(x); } //Provides: caml_array_of_bytes //Requires: caml_uint8_array_of_bytes +//Deprecated: Use [caml_uint8_array_of_bytes] instead function caml_array_of_bytes(x) { return caml_uint8_array_of_bytes(x); } + +//Provides: caml_new_string +//Requires: caml_string_of_jsbytes +//Deprecated: Use [caml_string_of_jsbytes] instead +function caml_new_string(s) { + return caml_string_of_jsbytes(s); +} diff --git a/toplevel/examples/lwt_toplevel/toplevel.ml b/toplevel/examples/lwt_toplevel/toplevel.ml index acf49a4aa7..c3b815ec94 100644 --- a/toplevel/examples/lwt_toplevel/toplevel.ml +++ b/toplevel/examples/lwt_toplevel/toplevel.ml @@ -145,7 +145,7 @@ let resize ~container ~textbox () = textbox##.style##.height := Js.string "auto"; textbox##.style##.height := Js.string (Printf.sprintf "%dpx" (max 18 textbox##.scrollHeight)); - container##.scrollTop := container##.scrollHeight; + container##.scrollTop := Js.float (float container##.scrollHeight); Lwt.return () let setup_printers () = @@ -376,7 +376,7 @@ let run _ = JsooTop.execute true ~pp_code:sharp_ppf ~highlight_location caml_ppf content'; resize ~container ~textbox () >>= fun () -> - container##.scrollTop := container##.scrollHeight; + container##.scrollTop := Js.float (float container##.scrollHeight); textbox##focus; Lwt.return_unit in