diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-10-04 22:34:58 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-10-04 22:34:58 +0200 |
commit | 03b9ad307bd4313adc974982fc008f4c58337c11 (patch) | |
tree | 9d30312498ab63430fbb1136cd5c345a9b5bbf58 /tests | |
parent | 2c3e8f8e38fa2bb07519ca60d5b5efdf234aef32 (diff) |
treewide: rework function scoping
- Implement proper closure scoping for function
- Avoid circular references when managing scopes pointers
- Eliminate ut_putval() in favor to json_object_put()
- Fix function return value handling
- Change internal function structure
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/02_runtime/05_closure_scope | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/02_runtime/05_closure_scope b/tests/02_runtime/05_closure_scope new file mode 100644 index 0000000..40f9245 --- /dev/null +++ b/tests/02_runtime/05_closure_scope @@ -0,0 +1,35 @@ +Testing closure scopes. + + +1. Ensure that the declaring scope is retained in functions. + +-- Expect stdout -- +Make function with x=1 +Make function with x=2 +Make function with x=3 +x is 1 +x is 2 +x is 3 +-- End -- + +-- Testcase -- +{% + local count=0; + + function a() { + local x = ++count; + print("Make function with x=", x, "\n"); + return function() { + print("x is ", x, "\n"); + }; + } + + local fn1 = a(); + local fn2 = a(); + local fn3 = a(); + + fn1(); + fn2(); + fn3(); +%} +-- End -- |