this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Many fixes

+87 -24
+5 -1
js_top_worker.opam
··· 7 7 "ocaml" 8 8 "js_of_ocaml" {>= "3.11.0"} 9 9 "rresult" 10 + "astring" 11 + "js_of_ocaml-toplevel" 10 12 ] 11 13 build : [ 12 14 ["dune" "subst"] {pinned} ··· 16 18 description: """ 17 19 An OCaml toplevel designed to run as a web worker 18 20 """ 19 - 21 + pin-depends: [ 22 + ["js_of_ocaml.3.11.0" "git+https://github.com/jonludlam/js_of_ocaml#lazy_files"] 23 + ]
+82 -23
lib/worker.ml
··· 55 55 let res : bool = JsooTop.use Format.std_formatter s in 56 56 if not res then Format.eprintf "error while evaluating %s@." s 57 57 58 - let setup () = 58 + let setup functions () = 59 59 JsooTop.initialize (); 60 + List.iter (fun f -> f ()) functions; 60 61 Sys.interactive := false; 61 62 if Version.compare Version.current [ 4; 07 ] >= 0 then exec' "open Stdlib"; 62 63 let header1 = Printf.sprintf " %s version %%s" "OCaml" in ··· 129 130 ; highlight = !highlighted 130 131 } 131 132 132 - let setup () = 133 - Js_of_ocaml.Sys_js.set_channel_flusher stdout (Buffer.add_string stdout_buff); 134 - Js_of_ocaml.Sys_js.set_channel_flusher stderr (Buffer.add_string stderr_buff); 135 - setup (); 136 - setup_printers (); 137 - IdlM.ErrM.return 138 - Toplevel_api_gen. 139 - { stdout = buff_opt stdout_buff 140 - ; stderr = buff_opt stderr_buff 141 - ; sharp_ppf = None 142 - ; caml_ppf = None 143 - ; highlight = None 144 - } 133 + let setup functions () = 134 + try 135 + Js_of_ocaml.Sys_js.set_channel_flusher stdout (Buffer.add_string stdout_buff); 136 + Js_of_ocaml.Sys_js.set_channel_flusher stderr (Buffer.add_string stderr_buff); 137 + setup functions (); 138 + setup_printers (); 139 + IdlM.ErrM.return 140 + Toplevel_api_gen. 141 + { stdout = buff_opt stdout_buff 142 + ; stderr = buff_opt stderr_buff 143 + ; sharp_ppf = None 144 + ; caml_ppf = None 145 + ; highlight = None 146 + } 147 + with e -> 148 + IdlM.ErrM.return_err (Toplevel_api_gen.InternalError (Printexc.to_string e)) 145 149 146 150 let complete phrase = 147 151 let contains_double_underscore s = ··· 168 172 M.bind (process call) (fun response -> Js_of_ocaml.Worker.post_message (Marshal.to_string response [])); 169 173 () 170 174 171 - let run files = 175 + let sync_get url = 176 + let open Js_of_ocaml in 177 + let x = XmlHttpRequest.create () in 178 + x##.responseType := (Js.string "arraybuffer"); 179 + x##_open (Js.string "GET") (Js.string url) Js._false; 180 + x##send Js.null; 181 + match x##.status with 182 + | 200 -> 183 + Js.Opt.case 184 + (File.CoerceTo.arrayBuffer x##.response) 185 + (fun () -> 186 + Firebug.console##log (Js.string "Failed to receive file"); 187 + None) 188 + (fun b -> 189 + Some (Typed_array.String.of_arrayBuffer b)) 190 + | _ -> 191 + None 192 + 193 + let load_resource files = 194 + let open Js_of_ocaml in 195 + fun ~prefix ~path -> 196 + Firebug.console##log (Js.string (Printf.sprintf "here we are, loading prefix=%s path=%s" prefix path)); 197 + (* let abs_filename = Filename.concat prefix path in *) 198 + if List.mem_assoc path files 199 + then begin 200 + Firebug.console##log (Js.string "path is in files"); 201 + let f = sync_get (List.assoc path files) in 202 + match f with 203 + | Some content -> 204 + Firebug.console##log (Js.string (Printf.sprintf "Got result (length=%d)" (String.length content))); 205 + (* Sys_js.update_file ~name:abs_filename ~content; *) 206 + Some content 207 + | None -> 208 + None 209 + end 210 + else 211 + (Firebug.console##log (Js.string "path is NOT in files"); 212 + None) 213 + 214 + let run files cmis functions = 172 215 (* Here we bind the server stub functions to the implementations *) 173 - Js_top_worker_rpc.Idl.logfn := (fun s -> Js_of_ocaml.(Firebug.console##log ( s))); 174 - Clflags.no_check_prims := true; 175 - Server.complete complete; 176 - Server.exec execute; 177 - Server.setup setup; 178 - let rpc_fn = IdlM.server Server.implementation in 179 - Js_of_ocaml.Worker.import_scripts files; 180 - Js_of_ocaml.Worker.set_onmessage (server rpc_fn) 216 + let open Js_of_ocaml in 217 + try 218 + Js_top_worker_rpc.Idl.logfn := (fun s -> Js_of_ocaml.(Firebug.console##log ( s))); 219 + ignore cmis; 220 + Clflags.no_check_prims := true; 221 + let cmi_files = List.map (fun cmi -> 222 + (Filename.basename cmi, cmi)) cmis in 223 + Sys_js.mount ~path:"/dynamic/cmis" (load_resource cmi_files); 224 + List.iter (fun (path, _) -> Sys_js.register_lazy ("/dynamic/cmis/" ^ path)) cmi_files; 225 + Topdirs.dir_directory "/dynamic/cmis"; 226 + Js_of_ocaml.Worker.import_scripts files; 227 + let functions = List.map (fun func_name -> 228 + Firebug.console##log (Js.string ("Function: " ^ func_name )); 229 + let func = Js.Unsafe.js_expr func_name in 230 + fun () -> Js.Unsafe.fun_call func [| Js.Unsafe.inject Dom_html.window |]) 231 + functions in 232 + Server.complete complete; 233 + Server.exec execute; 234 + Server.setup (setup functions); 235 + let rpc_fn = IdlM.server Server.implementation in 236 + Js_of_ocaml.Worker.set_onmessage (server rpc_fn); 237 + Firebug.console##log (Js.string "All finished"); 238 + with e -> 239 + Firebug.console##log (Js.string ("Exception: " ^ Printexc.to_string e))