Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put Ojs_exn inside Ojs module (breaking change !) #126

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(public_name ojs)
(synopsis "Runtime support for gen_js_api")
(libraries)
(wrapped false)
(foreign_stubs (language c) (names ojs_runtime_stubs))
(modes byte)
(js_of_ocaml (javascript_files ojs_runtime.js)))
25 changes: 24 additions & 1 deletion lib/ojs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,33 @@ let is_null x =

let obj_type x =
string_of_js (call (pure_js_expr "Object.prototype.toString") "call" [|x|])

module type T = sig
type js := t
type t
val t_to_js : t -> js
val t_of_js : js -> t
end

module Exn = struct
type nonrec t = t

let name x = string_of_js (get x "name")
let message x = string_of_js (get x "message")
let stack x = option_of_js string_of_js (get x "stack")
let to_string x = string_of_js (call x "toString" [||])

exception Error of t

let () = Callback.register_exception "jsError" (Error (obj [||]))

(* The js_of_ocaml runtime expects to have this registered.
So it's probably a bad idea to use both this Ojs.Exn module
and the js_of_ocaml standard library. *)

let () =
Printexc.register_printer (function
| Error x -> Some (to_string x)
| _ -> None
)
end
14 changes: 14 additions & 0 deletions lib/ojs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ module type T =
val t_to_js : t -> js
val t_of_js : js -> t
end

module Exn : sig
(** OCaml view on JS exceptions *)

type t

val name: t -> string
val message: t -> string
val stack: t -> string option
val to_string: t -> string

exception Error of t

end
24 changes: 0 additions & 24 deletions lib/ojs_exn.ml

This file was deleted.

14 changes: 0 additions & 14 deletions lib/ojs_exn.mli

This file was deleted.