Skip to content

Commit c4559c2

Browse files
committed
Runtimes: add primitive caml_throw_js_exception
To remove any dependency of Jsoo_runtime on JavaScript.
1 parent 0358924 commit c4559c2

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

lib/runtime/js_of_ocaml_runtime_stubs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ void caml_string_of_uint8_array () {
272272
caml_fatal_error("Unimplemented Javascript primitive caml_string_of_uint8_array!");
273273
}
274274

275+
void caml_throw_js_exception () {
276+
caml_fatal_error("Unimplemented Javascript primitive caml_throw_js_exception!");
277+
}
278+
275279
void caml_unmount () {
276280
caml_fatal_error("Unimplemented Javascript primitive caml_unmount!");
277281
}

lib/runtime/jsoo_runtime.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ end = struct
177177

178178
let _ = Callback.register_exception "jsError" (Exn (Obj.magic [||]))
179179

180-
let raise_ : t -> 'a = Js.js_expr "(function (exn) { throw exn })"
180+
external raise_ : t -> 'a = "caml_throw_js_exception"
181181

182182
external of_exn : exn -> t option = "caml_js_error_option_of_exception"
183183

runtime/js/jslib.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ function caml_js_error_option_of_exception(exn) {
203203
return 0;
204204
}
205205

206+
//Provides: caml_throw_js_exception
207+
function caml_throw_js_exception(exn) {
208+
throw exn;
209+
}
210+
206211
//Provides: caml_js_from_bool const (const)
207212
function caml_js_from_bool(x) {
208213
return !!x;

runtime/wasm/jslib.wat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
(func $wrap_fun_arguments (param anyref) (result anyref)))
7676
(import "fail" "caml_failwith_tag"
7777
(func $caml_failwith_tag (result (ref eq))))
78+
(import "fail" "javascript_exception"
79+
(tag $javascript_exception (param externref)))
7880
(import "stdlib" "caml_named_value"
7981
(func $caml_named_value (param (ref eq)) (result (ref null eq))))
8082
(import "obj" "caml_callback_1"
@@ -666,6 +668,11 @@
666668
(array.get $block (local.get $exn) (i32.const 2))))))))
667669
(ref.i31 (i32.const 0)))
668670

671+
(func (export "caml_throw_js_exception")
672+
(param $exn (ref eq)) (result (ref eq))
673+
(throw $javascript_exception
674+
(extern.convert_any (call $unwrap (local.get $exn)))))
675+
669676
(func (export "caml_js_error_of_exception")
670677
(param (ref eq)) (result (ref eq))
671678
(local $exn (ref $block))

0 commit comments

Comments
 (0)