feat: Add bindings for exception handling (try/catch/throw/rethrow)#197
feat: Add bindings for exception handling (try/catch/throw/rethrow)#197
Conversation
ospencer
left a comment
There was a problem hiding this comment.
Nice work!
We generally try to keep the C bindings to match the C API as closely as possible—would you mind updating this to just have a caml_binaryen_try and then implement the other APIs in OCaml, just calling that one function? That way we get the same interface but less binding code (and guarantees the same behavior across JS and OCaml).
|
@ospencer Good call. Fixed 👍 |
|
|
||
| // Exception handling operations | ||
| CAMLprim value | ||
| caml_binaryen_try_native(value _module, value _name, value _body, value _catchTags, value _catchBodies, value _delegateTarget) { |
There was a problem hiding this comment.
Could we name this just caml_binaryen_try?
| //Provides: caml_binaryen_try_get_name | ||
| //Requires: Binaryen, caml_string_of_jsstring | ||
| function caml_binaryen_try_get_name(expr) { | ||
| return caml_string_of_jsstring(Binaryen['_BinaryenTryGetName'](expr)); |
There was a problem hiding this comment.
Were you able to verify that this works? I don't know if this actually returns a JS string or if it's just a pointer or something.
There was a problem hiding this comment.
I don't think any of the raw _Binaryen functions actually return strings, as those would be operating in Asm.js memory space
|
Completed in #264 |
Closes #189 .
One note about this API: the Binaryen constructor for
tryaccepts either a list of catch expressions or a delegate tag. Keeping in line with the other bindings, we expose this API throughBinaryen.Try.make, but we additionally defineBinaryen.Try_Catch.makeandBinaryen.Try_Delegate.makeexpressions which are more safe to use (since users don't need to worry about passingNonetoTry.make)