Skip to content

Commit 531449b

Browse files
committed
Toplevel: restore the ability to use js globals as externals
1 parent af463b6 commit 531449b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

runtime/dynlink.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ function caml_dynlink_close_lib (idx) {
4242
//Requires: caml_jsstring_of_string
4343
function caml_dynlink_lookup_symbol (idx, fun_name) {
4444
var name = caml_jsstring_of_string(fun_name);
45-
console.log("Dynlink: look for symbol ", name);
45+
console.log("Dynlink: looking for symbol", name);
4646
if(current_libs[idx] && current_libs[idx][name])
47-
return current_libs[idx][name];
47+
return {name: name, symbol: current_libs[idx][name]};
4848
return 0;
4949
}
5050

5151
//Provides: caml_dynlink_add_primitive
5252
//Requires: caml_global_data
5353
function caml_dynlink_add_primitive (dll_addr) {
54+
globalThis.jsoo_runtime[dll_addr.name] = dll_addr.symbol;
5455
return caml_global_data.prim_count++;
5556
}
5657

toplevel/test/test_toplevel.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ let fmt = Format.std_formatter
55
let () =
66
Js_of_ocaml.Sys_js.set_channel_flusher stderr (fun str -> Printf.printf "<ERR>: %s" str)
77

8+
let () =
9+
Js_of_ocaml_toplevel.JsooTop.execute
10+
true
11+
~pp_code:fmt
12+
~highlight_location:(fun _ -> ())
13+
fmt
14+
{|
15+
external parseInt : float -> int = "parseInt"
16+
let f = 3.14
17+
let () = Printf.printf "parseInt(%f) = %d\n" f (parseInt f);;
18+
|}
19+
820
let () =
921
Js_of_ocaml_toplevel.JsooTop.execute
1022
true

toplevel/test/test_toplevel.reference

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
external parseInt : float -> int = "parseInt"
3+
let f = 3.14
4+
let () = Printf.printf "parseInt(%f) = %d\n" f (parseInt f);;
5+
Dynlink: looking for symbol parseInt
6+
parseInt(3.140000) = 3
7+
external parseInt : float -> int = "parseInt"
8+
val f : float = 3.14
9+
210
let () = print_endline "hello";;
311
hello
412
1+;;

0 commit comments

Comments
 (0)