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:async"; | 5 import "dart:async"; |
6 import "dart:collection" show LinkedList, LinkedListEntry; | 6 import "dart:collection" show LinkedList, LinkedListEntry; |
7 import 'dart:convert' show ASCII, JSON; | 7 import 'dart:convert' show ASCII, JSON; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 import "dart:math"; | 9 import "dart:math"; |
10 import "dart:typed_data"; | 10 import "dart:typed_data"; |
(...skipping 18 matching lines...) Expand all Loading... |
29 final _SyncGeneratorCallback _moveNextFn; | 29 final _SyncGeneratorCallback _moveNextFn; |
30 | 30 |
31 const _SyncIterable(this._moveNextFn); | 31 const _SyncIterable(this._moveNextFn); |
32 | 32 |
33 get iterator { | 33 get iterator { |
34 return new _SyncIterator(_moveNextFn._clone()); | 34 return new _SyncIterator(_moveNextFn._clone()); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 class _SyncIterator implements Iterator { | 38 class _SyncIterator implements Iterator { |
39 bool isYieldEach; // Set by generated code for the yield* statement. | 39 bool isYieldEach; // Set by generated code for the yield* statement. |
40 Iterator yieldEachIterator; | 40 Iterator yieldEachIterator; |
41 var _current; // Set by generated code for the yield and yield* statement. | 41 var _current; // Set by generated code for the yield and yield* statement. |
42 _SyncGeneratorCallback _moveNextFn; | 42 _SyncGeneratorCallback _moveNextFn; |
43 | 43 |
44 get current => | 44 get current => yieldEachIterator != null |
45 yieldEachIterator != null ? yieldEachIterator.current : _current; | 45 ? yieldEachIterator.current |
| 46 : _current; |
46 | 47 |
47 _SyncIterator(this._moveNextFn); | 48 _SyncIterator(this._moveNextFn); |
48 | 49 |
49 bool moveNext() { | 50 bool moveNext() { |
50 if (_moveNextFn == null) { | 51 if (_moveNextFn == null) { |
51 return false; | 52 return false; |
52 } | 53 } |
53 while (true) { | 54 while(true) { |
54 if (yieldEachIterator != null) { | 55 if (yieldEachIterator != null) { |
55 if (yieldEachIterator.moveNext()) { | 56 if (yieldEachIterator.moveNext()) { |
56 return true; | 57 return true; |
57 } | 58 } |
58 yieldEachIterator = null; | 59 yieldEachIterator = null; |
59 } | 60 } |
60 isYieldEach = false; | 61 isYieldEach = false; |
61 // _moveNextFn() will update the values of isYieldEach and _current. | 62 // _moveNextFn() will update the values of isYieldEach and _current. |
62 if (!_moveNextFn(this)) { | 63 if (!_moveNextFn(this)) { |
63 _moveNextFn = null; | 64 _moveNextFn = null; |
64 _current = null; | 65 _current = null; |
65 return false; | 66 return false; |
66 } | 67 } |
67 if (isYieldEach) { | 68 if (isYieldEach) { |
68 // Spec mandates: it is a dynamic error if the class of [the object | 69 // Spec mandates: it is a dynamic error if the class of [the object |
69 // returned by yield*] does not implement Iterable. | 70 // returned by yield*] does not implement Iterable. |
70 yieldEachIterator = (_current as Iterable).iterator; | 71 yieldEachIterator = (_current as Iterable).iterator; |
71 _current = null; | 72 _current = null; |
72 continue; | 73 continue; |
73 } | 74 } |
74 return true; | 75 return true; |
75 } | 76 } |
76 } | 77 } |
77 } | 78 } |
78 | 79 |
79 @patch | 80 @patch class StackTrace { |
80 class StackTrace { | 81 @patch static StackTrace get current native "StackTrace_current"; |
81 @patch | |
82 static StackTrace get current native "StackTrace_current"; | |
83 } | 82 } |
OLD | NEW |