Skip to content

Instantly share code, notes, and snippets.

@dbuenzli
Created August 26, 2014 18:34
Show Gist options
  • Select an option

  • Save dbuenzli/e6f6b226b165243f51d1 to your computer and use it in GitHub Desktop.

Select an option

Save dbuenzli/e6f6b226b165243f51d1 to your computer and use it in GitHub Desktop.
Hashtbl values disappearing in Safari
<!DOCTYPE html>
<!--
This code is in the public domain.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" defer="defer" src="min.js"></script>
<title>Vgr_htmlc minimal example</title>
</head>
<body>
</body>
</html>
(* This code is in the public domain.
Compile with:
ocamlfind ocamlc \
-package js_of_ocaml,js_of_ocaml.syntax \
-syntax camlp4o -linkpkg -o min.byte min.ml && \
js_of_ocaml min.byte && \
reload-browser file://`pwd`/min.html
*)
let now () = (jsnew Js.date_now () ## getTime ()) /. 1000.
let setup_log () =
let log = Dom_html.(createDiv document) in
let add_entry s =
let e = Dom_html.(createP document) in
e ## innerHTML <- Js.string s;
Dom.insertBefore log e (log ## firstChild)
in
Dom.appendChild (Dom_html.document ## body) log;
Sys_js.set_channel_flusher stdout add_entry;
Sys_js.set_channel_flusher stderr add_entry;
()
let h : (string, int) Hashtbl.t = Hashtbl.create 47
let () = Hashtbl.add h "key" 3
let down _ e =
Printf.printf "%f: Looking up... " (now ());
begin try ignore (Hashtbl.find h "key"); Printf.printf "found\n%!"; with
| Not_found -> Printf.printf "NOT FOUND\n%!"
end;
Js._false
let main _ =
let t = (Dom_html.window :> Dom_html.eventTarget Js.t) in
let e = Dom_html.Event.keydown in
ignore (Dom.addEventListener t e (Dom.full_handler down) Js._false);
setup_log ();
Js._false
let () = Dom_html.window ## onload <- Dom_html.handler main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment