summaryrefslogtreecommitdiffhomepage
path: root/eval.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-05 16:28:37 +0200
committerJo-Philipp Wich <jo@mein.io>2020-10-05 16:28:37 +0200
commitbae96955c502350a6ec90e47b60e1f5d7f460477 (patch)
tree61ce5596b7fbfaef1325936a7400d1ae31ec13ce /eval.c
parent6850df5cafb5766a0511cc9a194b05e59816ecde (diff)
eval: restore correct scope after leaving function
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c5
1 files changed, 3 insertions, 2 deletions
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);