From 84d6c64f74a89745444253a396f5a024a53c01f2 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Tue, 22 Dec 2020 17:11:57 +0100 Subject: [PATCH] Break compatibility to wrap modules This module does not seem to be used by public libraries on opam. I don't think this will break a lot of foreign code. --- lib/dune | 1 - lib/ojs.ml | 23 +++++++++++++++++++++++ lib/ojs.mli | 14 ++++++++++++++ lib/ojs_exn.ml | 24 ------------------------ lib/ojs_exn.mli | 14 -------------- 5 files changed, 37 insertions(+), 39 deletions(-) delete mode 100644 lib/ojs_exn.ml delete mode 100644 lib/ojs_exn.mli diff --git a/lib/dune b/lib/dune index 615f2e3..1cc9911 100644 --- a/lib/dune +++ b/lib/dune @@ -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))) diff --git a/lib/ojs.ml b/lib/ojs.ml index 56917c9..a8b6fbb 100644 --- a/lib/ojs.ml +++ b/lib/ojs.ml @@ -116,3 +116,26 @@ let is_null x = let obj_type x = string_of_js (call (pure_js_expr "Object.prototype.toString") "call" [|x|]) + +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 diff --git a/lib/ojs.mli b/lib/ojs.mli index 16054df..74b9fa4 100644 --- a/lib/ojs.mli +++ b/lib/ojs.mli @@ -126,3 +126,17 @@ val obj_type: t -> string "[object Null]" "[object Boolean]" *) + +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 diff --git a/lib/ojs_exn.ml b/lib/ojs_exn.ml deleted file mode 100644 index 4a539ff..0000000 --- a/lib/ojs_exn.ml +++ /dev/null @@ -1,24 +0,0 @@ -(* The gen_js_api is released under the terms of an MIT-like license. *) -(* See the attached LICENSE file. *) -(* Copyright 2015 by LexiFi. *) - -type t = Ojs.t - -let name x = Ojs.string_of_js (Ojs.get x "name") -let message x = Ojs.string_of_js (Ojs.get x "message") -let stack x = Ojs.option_of_js Ojs.string_of_js (Ojs.get x "stack") -let to_string x = Ojs.string_of_js (Ojs.call x "toString" [||]) - -exception Error of t - -let () = Callback.register_exception "jsError" (Error (Ojs.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 - ) diff --git a/lib/ojs_exn.mli b/lib/ojs_exn.mli deleted file mode 100644 index 8d41fe9..0000000 --- a/lib/ojs_exn.mli +++ /dev/null @@ -1,14 +0,0 @@ -(* The gen_js_api is released under the terms of an MIT-like license. *) -(* See the attached LICENSE file. *) -(* Copyright 2015 by LexiFi. *) - -(** 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