diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-10-13 19:59:22 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-10-14 12:23:08 +0200 |
commit | a71ebe62e75db9402d89c6af1ab69051440bf892 (patch) | |
tree | 6e320234ee5b72dec99235f9a03c8b4d99d9744f | |
parent | b7dba4bde1d60162b8430c29be8271f8625888ed (diff) |
eval: expose complete exception object in catch {} blocks
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | eval.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -1374,15 +1374,21 @@ ut_execute_this(struct ut_state *state, uint32_t off) static struct json_object * ut_execute_try_catch(struct ut_state *state, uint32_t off) { - struct ut_op *op = ut_get_op(state, off); + struct ut_op *tag, *op = ut_get_op(state, off); struct json_object *rv; rv = ut_execute_op_sequence(state, op->tree.operand[0]); if (ut_is_type(rv, T_EXCEPTION)) { - if (op->tree.operand[1]) + if (op->tree.operand[1]) { + /* remove the T_EXCEPTION type from the object to avoid handling + * it as a new exception in the catch block */ + tag = json_object_get_userdata(rv); + tag->type = T_LBRACE; + json_object_put(ut_setval(state->scope->scope, ut_get_child(state, off, 1)->val, - xjs_new_string(json_object_get_string(rv)))); + json_object_get(rv))); + } json_object_put(state->exception); state->exception = NULL; |