From bae96955c502350a6ec90e47b60e1f5d7f460477 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich <jo@mein.io> Date: Mon, 5 Oct 2020 16:28:37 +0200 Subject: eval: restore correct scope after leaving function Signed-off-by: Jo-Philipp Wich <jo@mein.io> --- eval.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 7052749..e9c797b 100644 --- a/eval.c +++ b/eval.c @@ -1003,6 +1003,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, struct ut_op *tag = json_object_get_userdata(func); struct json_object *rv = NULL; struct ut_function *fn; + struct ut_scope *sc; size_t arridx; ut_c_fn *cfn; @@ -1020,7 +1021,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, fn->scope = ut_new_scope(state, fn->parent_scope); fn->scope->ctx = json_object_get(this ? this : state->ctx); - ut_release_scope(state->scope); + sc = state->scope; state->scope = ut_acquire_scope(fn->scope); if (fn->args) @@ -1048,7 +1049,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, /* we left the function, pop the function scope... */ ut_release_scope(state->scope); - state->scope = ut_acquire_scope(ut_parent_scope(fn->scope)); + state->scope = sc; /* ... and remove the "this" context... */ json_object_put(fn->scope->ctx); -- cgit v1.2.3