Skip to content

Commit 8848116

Browse files
committed
use JsError to encode Js.Exn
1 parent 7409a06 commit 8848116

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

jscomp/others/js_exn.ml

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
type t = Caml_js_exceptions.t
26+
type t = unknown
2727

2828
[@@@warning "-38"] (* unused extension constructor*)
29-
exception Error = Caml_js_exceptions.Error
29+
exception Error = JsError
3030

3131
external asJsExn : exn -> t option =
3232
"?as_js_exn"
@@ -45,8 +45,7 @@ external makeError : string -> error = "Error" [@@bs.new]
4545
external isCamlExceptionOrOpenVariant :
4646
'a -> bool = "?is_extension"
4747

48-
let anyToExnInternal x =
49-
Caml_js_exceptions.internalToOCamlException (Obj.repr x)
48+
external anyToExnInternal : 'a -> exn = "#wrap_exn"
5049

5150

5251
let raiseError str =

jscomp/others/js_exn.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ external isCamlExceptionOrOpenVariant:
4343
'a -> bool = "?is_extension"
4444
(** internal use only *)
4545

46-
val anyToExnInternal: 'a -> exn
46+
external anyToExnInternal : 'a -> exn = "#wrap_exn"
4747
(**
4848
`anyToExnInternal obj` will take any value `obj` and wrap it
4949
in a Js.Exn.Error if given value is not an exn already. If

jscomp/runtime/caml_js_exceptions.ml

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1+
(* Copyright (C) 2015- Hongbo Zhang, Authors of ReScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
124

225

3-
type t =
4-
| Any : 'a -> t [@@unboxed]
526

6-
exception Error of t
27+
exception Error = JsError
728

829

930
(**
1031
This function has to be in this module Since
1132
[Error] is defined here
1233
*)
13-
let internalToOCamlException (e : Obj.t) =
34+
let internalToOCamlException (e : unknown) =
1435
if Caml_exceptions.is_extension e then
1536
(Obj.magic e : exn)
16-
else Error (Any e)
37+
else JsError ( e)
1738

1839
let as_js_exn exn =
1940
match exn with

0 commit comments

Comments
 (0)