Caml_js_expr: fallback to runtime evaluation

I am running some OCaml/js_of_ocaml code in Chrome, and at runtime, in bright red, it prints to dev console:

caml_js_expr: fallback to runtime evaluation

I am trying to understand what is going on here (and why it is important).

Is the issue that Js.Unsafe.js_expr expects a CONSTANT string … and is unhappy when we pass it a string that is constructed at runtime ? If so, why does this matter ? Is there some runtime penalty associated with this ?

According to the JSOO docs:

js_expr e will parse the JavaScript expression e if e is available at compile time or will fallback to a runtime evaluation.

So yes, it works best if the string is available at compile time, i.e. is constant.

For an explanation of the problems with runtime evaluation, see eval() on MDN.

1 Like