Chromium Code Reviews| Index: runtime/lib/core_patch.dart |
| =================================================================== |
| --- runtime/lib/core_patch.dart (revision 43415) |
| +++ runtime/lib/core_patch.dart (working copy) |
| @@ -21,3 +21,49 @@ |
| static const List<String> _enum_names = null; |
| String toString() => _enum_names[index]; |
| } |
| + |
| + |
| +class _SyncIterable extends IterableBase { |
| + final moveNextFn; |
| + |
| + const _SyncIterable(this.moveNextFn); |
| + |
| + get iterator { |
| + return new _SyncIterator(moveNextFn._clone()); |
| + } |
| +} |
| + |
| +class _SyncIterator implements Iterator { |
| + var isYieldEach; |
|
srdjan
2015/02/04 19:29:12
Please add comment who sets isYieldEach. Also mayb
hausner
2015/02/04 22:09:23
Done.
|
| + var yieldEachIterator = null; |
| + var current = null; |
|
srdjan
2015/02/04 19:29:12
I think null is the default initialization for all
hausner
2015/02/04 22:09:23
Done.
|
| + var moveNextFn; |
|
srdjan
2015/02/04 19:29:12
Does the spec say anything about the type of moveN
hausner
2015/02/04 22:09:23
I don't want to use types. The type checks are unn
|
| + |
| + _SyncIterator(this.moveNextFn); |
| + |
| + moveNext() { |
|
srdjan
2015/02/04 19:29:12
bool moveNext() {
hausner
2015/02/04 22:09:24
Done.
|
| + if (moveNextFn == null) { |
| + return false; |
| + } |
| + for(;;) { |
|
srdjan
2015/02/04 19:29:12
What is the advantage of "for(;;)" vs "while(true)
hausner
2015/02/04 22:09:23
Done.
|
| + if (yieldEachIterator != null) { |
| + if (yieldEachIterator.moveNext()) { |
| + current = yieldEachIterator.current; |
| + return true; |
| + } |
| + yieldEachIterator = null; |
| + } |
| + isYieldEach = false; |
| + if (!moveNextFn(this)) { |
| + moveNextFn = null; |
| + current = null; |
| + return false; |
| + } |
| + if (isYieldEach && (current is Iterable)) { |
| + yieldEachIterator = current.iterator; |
| + continue; |
| + } |
| + return true; |
| + } |
| + } |
| +} |