truncateLoopStacks method
Restores every loop stack to depths, forgetting the loops that are
removed — so a loop entered again later starts from scratch instead of
resuming a stale iterator or list.
Implementation
void truncateLoopStacks(LoopStackDepths depths) {
for (final node in loopNodeStack.skip(depths.nodes)) {
forInIteratorMap.remove(node);
loopEntryDepths.remove(node);
}
for (final node in awaitForNodeStack.skip(depths.awaitFor)) {
loopEntryDepths.remove(node);
}
_shrink(loopNodeStack, depths.nodes);
_shrink(loopEnvironmentStack, depths.environments);
_shrink(loopInitializedStack, depths.initialized);
_shrink(awaitForNodeStack, depths.awaitFor);
_shrink(awaitForListStack, depths.awaitFor);
_shrink(awaitForIndexStack, depths.awaitFor);
if (awaitForNodeStack.isEmpty) {
currentAwaitForList = null;
currentAwaitForIndex = null;
}
}