-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
5 changed files
with
195 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters