Skip to content

Commit 3204c33

Browse files
Lib: Dom_html.html_entities: move error handling to the ML side (#1653)
Co-authored-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
1 parent 3a082a7 commit 3204c33

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/js_of_ocaml/dom_html.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ let onIE = Js.to_bool (caml_js_on_ie ())
2727

2828
external html_escape : js_string t -> js_string t = "caml_js_html_escape"
2929

30-
external decode_html_entities : js_string t -> js_string t = "caml_js_html_entities"
30+
external html_entities : js_string t -> js_string t opt = "caml_js_html_entities"
31+
32+
let decode_html_entities s =
33+
Js.Opt.get (html_entities s) (fun () -> failwith ("Invalid entity " ^ Js.to_string s))
3134

3235
class type cssStyleDeclaration = object
3336
method setProperty :

runtime/jslib_js_of_ocaml.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function caml_js_html_escape (s) {
3737
}
3838

3939
//Provides: caml_js_html_entities
40-
//Requires: caml_failwith
4140
function caml_js_html_entities(s) {
4241
var entity = /^&#?[0-9a-zA-Z]+;$/
4342
if(s.match(entity))
@@ -49,7 +48,7 @@ function caml_js_html_entities(s) {
4948
return str;
5049
}
5150
else {
52-
caml_failwith("Invalid entity " + s);
51+
return null;
5352
}
5453
}
5554

0 commit comments

Comments
 (0)