| 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"; |
| 11 import 'dart:_internal' as internal; | 11 import 'dart:_internal' as internal; |
| 12 | 12 |
| 13 // Equivalent of calling FATAL from C++ code. | 13 // Equivalent of calling FATAL from C++ code. |
| 14 _fatal(msg) native "DartCore_fatal"; | 14 _fatal(msg) native "DartCore_fatal"; |
| 15 | 15 |
| 16 // The members of this class are cloned and added to each class that | 16 // The members of this class are cloned and added to each class that |
| 17 // represents an enum type. | 17 // represents an enum type. |
| 18 class _EnumHelper { | 18 class _EnumHelper { |
| 19 String _name; | 19 String _name; |
| 20 String toString() => _name; | 20 String toString() => _name; |
| 21 int get hashCode => _name.hashCode; | 21 int get hashCode => _name.hashCode; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // _SyncIterable and _syncIterator are used by the compiler to | 24 // _SyncIterable and _syncIterator are used by the compiler to |
| 25 // implement sync* generator functions. A sync* generator allocates | 25 // implement sync* generator functions. A sync* generator allocates |
| 26 // and returns a new _SyncIterable object. | 26 // and returns a new _SyncIterable object. |
| 27 | 27 |
| 28 typedef bool SyncGeneratorCallback(Iterator iterator); | 28 typedef bool _SyncGeneratorCallback(Iterator iterator); |
| 29 | 29 |
| 30 class _SyncIterable extends IterableBase { | 30 class _SyncIterable extends IterableBase { |
| 31 // moveNextFn is the closurized body of the generator function. | 31 // _moveNextFn is the closurized body of the generator function. |
| 32 final SyncGeneratorCallback moveNextFn; | 32 final _SyncGeneratorCallback _moveNextFn; |
| 33 | 33 |
| 34 const _SyncIterable(this.moveNextFn); | 34 const _SyncIterable(this._moveNextFn); |
| 35 | 35 |
| 36 get iterator { | 36 get iterator { |
| 37 return new _SyncIterator(moveNextFn._clone()); | 37 return new _SyncIterator(_moveNextFn._clone()); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 class _SyncIterator implements Iterator { | 41 class _SyncIterator implements Iterator { |
| 42 bool isYieldEach; // Set by generated code for the yield* statement. | 42 bool isYieldEach; // Set by generated code for the yield* statement. |
| 43 Iterator yieldEachIterator; | 43 Iterator yieldEachIterator; |
| 44 var _current; // Set by generated code for the yield and yield* statement. | 44 var _current; // Set by generated code for the yield and yield* statement. |
| 45 SyncGeneratorCallback moveNextFn; | 45 _SyncGeneratorCallback _moveNextFn; |
| 46 | 46 |
| 47 get current => yieldEachIterator != null | 47 get current => yieldEachIterator != null |
| 48 ? yieldEachIterator.current | 48 ? yieldEachIterator.current |
| 49 : _current; | 49 : _current; |
| 50 | 50 |
| 51 _SyncIterator(this.moveNextFn); | 51 _SyncIterator(this._moveNextFn); |
| 52 | 52 |
| 53 bool moveNext() { | 53 bool moveNext() { |
| 54 if (moveNextFn == null) { | 54 if (_moveNextFn == null) { |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 while(true) { | 57 while(true) { |
| 58 if (yieldEachIterator != null) { | 58 if (yieldEachIterator != null) { |
| 59 if (yieldEachIterator.moveNext()) { | 59 if (yieldEachIterator.moveNext()) { |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 yieldEachIterator = null; | 62 yieldEachIterator = null; |
| 63 } | 63 } |
| 64 isYieldEach = false; | 64 isYieldEach = false; |
| 65 // moveNextFn() will update the values of isYieldEach and _current. | 65 // _moveNextFn() will update the values of isYieldEach and _current. |
| 66 if (!moveNextFn(this)) { | 66 if (!_moveNextFn(this)) { |
| 67 moveNextFn = null; | 67 _moveNextFn = null; |
| 68 _current = null; | 68 _current = null; |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 if (isYieldEach) { | 71 if (isYieldEach) { |
| 72 // Spec mandates: it is a dynamic error if the class of [the object | 72 // Spec mandates: it is a dynamic error if the class of [the object |
| 73 // returned by yield*] does not implement Iterable. | 73 // returned by yield*] does not implement Iterable. |
| 74 yieldEachIterator = (_current as Iterable).iterator; | 74 yieldEachIterator = (_current as Iterable).iterator; |
| 75 _current = null; | 75 _current = null; |
| 76 continue; | 76 continue; |
| 77 } | 77 } |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 @patch class StackTrace { | 83 @patch class StackTrace { |
| 84 @patch static StackTrace get current native "StackTrace_current"; | 84 @patch static StackTrace get current native "StackTrace_current"; |
| 85 } | 85 } |
| OLD | NEW |