summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2024-02-20 17:30:38 +0100
committerJo-Philipp Wich <jo@mein.io>2024-02-21 11:02:43 +0100
commitee4af9b55cb4591e63c596af592abc33a8a8f315 (patch)
treec38739676757c60b8caa0c1f0401022e8aa9b44c /tests
parent3f9811d2f7b730f1f1d030872ae1def7e8349be6 (diff)
vm: rework object iteration
Ensure that deleting object keys during iteration is safe by keeping a global chain of per-object iterators which are advanced to the next key when the entry that is about to be iterated is deleted. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/custom/02_runtime/08_object_iteration51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/custom/02_runtime/08_object_iteration b/tests/custom/02_runtime/08_object_iteration
new file mode 100644
index 0000000..2e58cdf
--- /dev/null
+++ b/tests/custom/02_runtime/08_object_iteration
@@ -0,0 +1,51 @@
+Testing object iteration behavior.
+
+
+1. Testing that deleting properties during iteration is safe.
+
+-- Expect stdout --
+a
+w
+z
+-- End --
+
+-- Testcase --
+{%
+ o1 = { a: 1, b: 2, c: 3 };
+
+ for (k in o1) {
+ delete o1.a;
+ delete o1.b;
+ delete o1.c;
+ print(k, "\n");
+ }
+
+ o2 = { w: 1, x: 2, y: 3, z: 4 };
+
+ for (k in o2) {
+ delete o2.x;
+ delete o2.y;
+ print(k, "\n");
+ }
+%}
+-- End --
+
+
+2. Test that reordering object properties during iteration is safe.
+
+-- Expect stdout --
+c
+b
+c
+-- End --
+
+-- Testcase --
+{%
+ o = { c: 1, b: 2, a: 3 };
+
+ for (k in o) {
+ sort(o);
+ print(k, "\n");
+ }
+%}
+-- End --