diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-12 00:12:09 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-12 00:12:39 +0200 |
commit | 0329d7d1708f37396d63eb1801b671f16999390f (patch) | |
tree | b6bf314c4f93d944b160962b673dadddbbc3b818 | |
parent | 79579e819c289ef1b41b6ba0a643c2fc4d1858cf (diff) |
eval: keep references to function contexts
Otherwise the "this" context might be gc'ed before the function can access it.
This bug manifested itself with long chained expressions such as:
require("fs").open("file.txt").read(10)
The file handle produced by open() was gc'ed before invoking read() on it due
to the evaluation not increasing its refcount.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | eval.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -1326,7 +1326,9 @@ ut_execute_op(struct ut_state *state, uint32_t off) case T_LABEL: scope = ut_getref(state, off, &key); - state->ctx = scope; + + ut_putval(state->ctx); + state->ctx = json_object_get(scope); val = ut_getval(scope, key); ut_putval(scope); @@ -1335,7 +1337,9 @@ ut_execute_op(struct ut_state *state, uint32_t off) case T_DOT: scope = ut_getref_required(state, off, &key); - state->ctx = scope; + + ut_putval(state->ctx); + state->ctx = json_object_get(scope); if (!key) return scope; @@ -1349,7 +1353,9 @@ ut_execute_op(struct ut_state *state, uint32_t off) /* postfix access */ if (op->is_postfix) { scope = ut_getref_required(state, off, &key); - state->ctx = scope; + + ut_putval(state->ctx); + state->ctx = json_object_get(scope); if (!key) return scope; |