diff --git a/lib/js_of_ocaml/js.ml b/lib/js_of_ocaml/js.ml index 3349b04ec..481622854 100644 --- a/lib/js_of_ocaml/js.ml +++ b/lib/js_of_ocaml/js.ml @@ -838,9 +838,12 @@ let export_js (field : js_string t) x = Unsafe.set (Unsafe.pure_js_expr "jsoo_exports") field - (if String.equal (Js.to_string (typeof (Obj.magic x))) "function" - (* function with arity/length equal to zero are already wrapped *) - && Unsafe.get (Obj.magic x) (Js.string "length") > 0 + (if match Sys.backend_type with + | Other "wasm_of_ocaml" -> Obj.tag (Obj.repr x) = Obj.closure_tag + | _ -> + String.equal (Js.to_string (typeof (Obj.magic x))) "function" + (* function with arity/length equal to zero are already wrapped *) + && Unsafe.get (Obj.magic x) (Js.string "length") > 0 then Obj.magic (wrap_callback (Obj.magic x)) else x) diff --git a/lib/tests/test_fun_call.ml b/lib/tests/test_fun_call.ml index 70c109851..f36b0b871 100644 --- a/lib/tests/test_fun_call.ml +++ b/lib/tests/test_fun_call.ml @@ -409,16 +409,14 @@ let%expect_test _ = [%expect {| Result: other |}] -(*ZZZ - let%expect_test _ = - let open Js_of_ocaml in - let f = Js.wrap_callback (fun s -> print_endline s) in - Js.export "f" f; - let () = - Js.Unsafe.fun_call - (Js.Unsafe.pure_js_expr "jsoo_exports")##.f - [| Js.Unsafe.coerce (Js.string "hello") |] - in - (); - [%expect {| hello |}] -*) +let%expect_test _ = + let open Js_of_ocaml in + let f = Js.wrap_callback (fun s -> print_endline (Js.to_string s)) in + Js.export "f" f; + let () = + Js.Unsafe.fun_call + (Js.Unsafe.pure_js_expr "jsoo_exports")##.f + [| Js.Unsafe.coerce (Js.string "hello") |] + in + (); + [%expect {| hello |}] diff --git a/runtime/wasm/runtime.js b/runtime/wasm/runtime.js index ed8a609ec..31ba054a3 100644 --- a/runtime/wasm/runtime.js +++ b/runtime/wasm/runtime.js @@ -376,5 +376,5 @@ event.error&&caml_handle_uncaught_exception(event.error)) } await _initialize(); -})(((joo_global_object,globalThis)=>(x)=>eval(x))(globalThis,globalThis), +})(((joo_global_object,jsoo_exports,globalThis)=>(x)=>eval(x))(globalThis,globalThis?.module?.exports||globalThis,globalThis), PRIMITIVES);