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 // Equivalent of calling FATAL from C++ code. | 8 // Equivalent of calling FATAL from C++ code. |
| 9 _fatal(msg) native "DartCore_fatal"; | 9 _fatal(msg) native "DartCore_fatal"; |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 const _SyncIterable(this.moveNextFn); | 33 const _SyncIterable(this.moveNextFn); |
| 34 | 34 |
| 35 get iterator { | 35 get iterator { |
| 36 return new _SyncIterator(moveNextFn._clone()); | 36 return new _SyncIterator(moveNextFn._clone()); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 class _SyncIterator implements Iterator { | 40 class _SyncIterator implements Iterator { |
| 41 bool isYieldEach; // Set by generated code for the yield* statement. | 41 bool isYieldEach; // Set by generated code for the yield* statement. |
| 42 Iterator yieldEachIterator; | 42 Iterator yieldEachIterator; |
| 43 var current; // Set by generated code for the yield and yield* statement. | 43 var _current; // Set by generated code for the yield and yield* statement. |
| 44 SyncGeneratorCallback moveNextFn; | 44 SyncGeneratorCallback moveNextFn; |
| 45 | 45 |
| 46 get current => yieldEachIterator != null | |
| 47 ? yieldEachIterator.current | |
| 48 : _current; | |
| 49 | |
| 46 _SyncIterator(this.moveNextFn); | 50 _SyncIterator(this.moveNextFn); |
| 47 | 51 |
| 48 bool moveNext() { | 52 bool moveNext() { |
| 49 if (moveNextFn == null) { | 53 if (moveNextFn == null) { |
| 50 return false; | 54 return false; |
| 51 } | 55 } |
| 52 while(true) { | 56 while(true) { |
| 53 if (yieldEachIterator != null) { | 57 if (yieldEachIterator != null) { |
| 54 if (yieldEachIterator.moveNext()) { | 58 if (yieldEachIterator.moveNext()) { |
| 55 current = yieldEachIterator.current; | |
| 56 return true; | 59 return true; |
| 57 } | 60 } |
| 58 yieldEachIterator = null; | 61 yieldEachIterator = null; |
| 59 } | 62 } |
| 60 isYieldEach = false; | 63 isYieldEach = false; |
| 61 if (!moveNextFn(this)) { | 64 if (!moveNextFn(this)) { |
| 62 moveNextFn = null; | 65 moveNextFn = null; |
| 63 current = null; | 66 _current = null; |
| 64 return false; | 67 return false; |
| 65 } | 68 } |
| 66 if (isYieldEach) { | 69 if (isYieldEach) { |
| 67 // Spec mandates: it is a dynamic error if the class of [the object | 70 // Spec mandates: it is a dynamic error if the class of [the object |
| 68 // returned by yield*] does not implement Iterable. | 71 // returned by yield*] does not implement Iterable. |
| 69 yieldEachIterator = (current as Iterable).iterator; | 72 yieldEachIterator = (_current as Iterable).iterator; |
|
floitsch
2016/02/12 21:01:54
You could GC the _current here.
(_current = null)
hausner
2016/02/12 21:27:16
Done.
| |
| 70 continue; | 73 continue; |
| 71 } | 74 } |
| 72 return true; | 75 return true; |
| 73 } | 76 } |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 patch class StackTrace { | 80 patch class StackTrace { |
| 78 /* patch */ static StackTrace get current native "StackTrace_current"; | 81 /* patch */ static StackTrace get current native "StackTrace_current"; |
| 79 } | 82 } |
| OLD | NEW |