Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "dart:math"; | 5 import "dart:math"; |
| 6 import "dart:typed_data"; | 6 import "dart:typed_data"; |
| 7 | 7 |
| 8 // We need to pass the exception object as second parameter to the continuation. | 8 // We need to pass the exception object as second parameter to the continuation. |
| 9 // See vm/ast_transformer.cc for usage. | 9 // See vm/ast_transformer.cc for usage. |
| 10 void _asyncCatchHelper(catchFunction, continuation) { | 10 void _asyncCatchHelper(catchFunction, continuation) { |
| 11 catchFunction((e) => continuation(null, e)); | 11 catchFunction((e) => continuation(null, e)); |
| 12 } | 12 } |
| 13 | 13 |
| 14 // The members of this class are cloned and added to each class that | 14 // The members of this class are cloned and added to each class that |
| 15 // represents an enum type. | 15 // represents an enum type. |
| 16 class _EnumHelper { | 16 class _EnumHelper { |
| 17 // Declare the list of enum value names private. When this field is | 17 // Declare the list of enum value names private. When this field is |
| 18 // cloned into a user-defined enum class, the field will be inaccessible | 18 // cloned into a user-defined enum class, the field will be inaccessible |
| 19 // because of the library-specific name suffix. The toString() function | 19 // because of the library-specific name suffix. The toString() function |
| 20 // below can access it because it uses the same name suffix. | 20 // below can access it because it uses the same name suffix. |
| 21 static const List<String> _enum_names = null; | 21 static const List<String> _enum_names = null; |
| 22 String toString() => _enum_names[index]; | 22 String toString() => _enum_names[index]; |
| 23 } | 23 } |
| 24 | |
| 25 | |
| 26 class _SyncIterable extends IterableBase { | |
| 27 final moveNextFn; | |
| 28 | |
| 29 const _SyncIterable(this.moveNextFn); | |
| 30 | |
| 31 get iterator { | |
| 32 return new _SyncIterator(moveNextFn._clone()); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 class _SyncIterator implements Iterator { | |
| 37 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.
| |
| 38 var yieldEachIterator = null; | |
| 39 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.
| |
| 40 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
| |
| 41 | |
| 42 _SyncIterator(this.moveNextFn); | |
| 43 | |
| 44 moveNext() { | |
|
srdjan
2015/02/04 19:29:12
bool moveNext() {
hausner
2015/02/04 22:09:24
Done.
| |
| 45 if (moveNextFn == null) { | |
| 46 return false; | |
| 47 } | |
| 48 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.
| |
| 49 if (yieldEachIterator != null) { | |
| 50 if (yieldEachIterator.moveNext()) { | |
| 51 current = yieldEachIterator.current; | |
| 52 return true; | |
| 53 } | |
| 54 yieldEachIterator = null; | |
| 55 } | |
| 56 isYieldEach = false; | |
| 57 if (!moveNextFn(this)) { | |
| 58 moveNextFn = null; | |
| 59 current = null; | |
| 60 return false; | |
| 61 } | |
| 62 if (isYieldEach && (current is Iterable)) { | |
| 63 yieldEachIterator = current.iterator; | |
| 64 continue; | |
| 65 } | |
| 66 return true; | |
| 67 } | |
| 68 } | |
| 69 } | |
| OLD | NEW |