Skip to content

Commit 5f0bfaf

Browse files
committed
toplevel: clean
1 parent 7e62be2 commit 5f0bfaf

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

toplevel/toplevel.ml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
open Lwt
2222
open Compiler
2323
module Html = Dom_html
24-
module type Dummy = module type of Html5_types
2524

2625
module H = struct
2726
type 'a t = {
@@ -96,34 +95,16 @@ module H = struct
9695

9796
end
9897

99-
(* load (binary) file from server using a synchronous XMLHttpRequest *)
100-
let load_from_server (_,suffix) =
101-
try
102-
let xml = XmlHttpRequest.create () in
103-
xml##_open(Js.string "GET", Js.string ("filesys/" ^ suffix), Js._false);
104-
xml##send(Js.null);
105-
if xml##status = 200 then
106-
let resp = xml##responseText in
107-
let len = resp##length in
108-
let str = String.create len in
109-
for i=0 to len-1 do
110-
str.[i] <- Char.chr (int_of_float resp##charCodeAt(i) land 0xff)
111-
done;
112-
Some(str)
113-
else
114-
None
115-
with _ ->
116-
None
11798
#let_default metaocaml = false
11899
#if metaocaml
119100
let compiler_name = "MetaOCaml"
120101
#else
121102
let compiler_name = "OCaml"
122103
#endif
123104

124-
let load_resource scheme (_,suffix) =
105+
(* load file using a synchronous XMLHttpRequest *)
106+
let load_resource_aux url =
125107
try
126-
let url = Printf.sprintf "%s://%s" scheme suffix in
127108
let xml = XmlHttpRequest.create () in
128109
xml##_open(Js.string "GET", Js.string url, Js._false);
129110
xml##send(Js.null);
@@ -140,9 +121,13 @@ let load_resource scheme (_,suffix) =
140121
with _ ->
141122
None
142123

124+
let load_resource scheme (_,suffix) =
125+
let url = Printf.sprintf "%s://%s" scheme suffix in
126+
load_resource_aux url
127+
143128
let initialize () =
144129
Sys_js.register_autoload "/dev/" (fun s -> Some "");
145-
Sys_js.register_autoload "/" (fun s -> load_from_server s);
130+
Sys_js.register_autoload "/" (fun (_,s) -> load_resource_aux ("filesys/" ^ s));
146131
Sys_js.register_autoload "/http/" (fun s -> load_resource "http" s);
147132
Sys_js.register_autoload "/https/" (fun s -> load_resource "https" s);
148133
Sys_js.register_autoload "/ftp/" (fun s -> load_resource "ftp" s);

0 commit comments

Comments
 (0)