diff options
-rw-r--r-- | eval.c | 9 | ||||
-rw-r--r-- | tests/02_runtime/02_this | 22 |
2 files changed, 31 insertions, 0 deletions
@@ -746,6 +746,7 @@ ut_cmp(int how, struct json_object *v1, struct json_object *v2) static struct json_object * _ut_get_operands(struct ut_state *state, struct ut_op *op, size_t n, struct json_object **v) { + struct json_object *ctx = NULL; struct ut_op *child; size_t i, j; @@ -759,7 +760,12 @@ _ut_get_operands(struct ut_state *state, struct ut_op *op, size_t n, struct json else v[i] = NULL; + if (i == 0) + ctx = json_object_get(state->ctx); + if (ut_is_type(v[i], T_EXCEPTION)) { + json_object_put(ctx); + for (j = 0; j < i; j++) json_object_put(v[j]); @@ -767,6 +773,9 @@ _ut_get_operands(struct ut_state *state, struct ut_op *op, size_t n, struct json } } + json_object_put(state->ctx); + state->ctx = ctx; + return NULL; } diff --git a/tests/02_runtime/02_this b/tests/02_runtime/02_this index d41be7f..e1efd80 100644 --- a/tests/02_runtime/02_this +++ b/tests/02_runtime/02_this @@ -23,3 +23,25 @@ true print(o.test(), "\n"); %} -- End -- + +Test that the context is properly restored if function call arguments are +dot or bracket expressions as well. + +-- Expect stdout -- +true +true +-- End -- + +-- Testcase -- +{% + local o = { + test: function() { + return (this === o); + } + }; + + local dummy = { foo: true, bar: false }; + + print(o.test(dummy.foo, dummy.bar), "\n"); + print(o.test(dummy.foo, o.test(dummy.foo, dummy.bar)), "\n"); +%} |