OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // part of dart.async; | 5 // part of dart.async; |
6 | 6 |
7 // States shared by single/multi stream implementations. | 7 // States shared by single/multi stream implementations. |
8 | 8 |
9 /// Initial and default state where the stream can receive and send events. | 9 /// Initial and default state where the stream can receive and send events. |
10 const int _STREAM_OPEN = 0; | 10 const int _STREAM_OPEN = 0; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 /** Record a decrease in the number of times the listener has paused. */ | 173 /** Record a decrease in the number of times the listener has paused. */ |
174 void _decrementPauseCount(_StreamListener<T> listener) { | 174 void _decrementPauseCount(_StreamListener<T> listener) { |
175 assert(_isPaused); | 175 assert(_isPaused); |
176 listener._decrementPauseCount(); | 176 listener._decrementPauseCount(); |
177 _updatePauseCount(-1); | 177 _updatePauseCount(-1); |
178 } | 178 } |
179 | 179 |
180 /** Update the stream's own pause count only. */ | 180 /** Update the stream's own pause count only. */ |
181 void _updatePauseCount(int by) { | 181 void _updatePauseCount(int by) { |
182 _state += by << _STREAM_PAUSE_COUNT_SHIFT; | 182 int oldState = _state; |
| 183 // We can't just _state += by << _STREAM_PAUSE_COUNT_SHIFT, since dart2js |
| 184 // converts the result of the left-shift to a positive number. |
| 185 if (by >= 0) { |
| 186 _state = oldState + (by << _STREAM_PAUSE_COUNT_SHIFT); |
| 187 } else { |
| 188 _state = oldState - ((-by) << _STREAM_PAUSE_COUNT_SHIFT); |
| 189 } |
183 assert(_state >= 0); | 190 assert(_state >= 0); |
| 191 assert((_state >> _STREAM_PAUSE_COUNT_SHIFT) == |
| 192 (oldState >> _STREAM_PAUSE_COUNT_SHIFT) + by); |
184 } | 193 } |
185 | 194 |
186 void _setClosed() { | 195 void _setClosed() { |
187 assert(!_isClosed); | 196 assert(!_isClosed); |
188 _state |= _STREAM_CLOSED; | 197 _state |= _STREAM_CLOSED; |
189 } | 198 } |
190 | 199 |
191 void _setComplete() { | 200 void _setComplete() { |
192 assert(_isClosed); | 201 assert(_isClosed); |
193 _state = _state |_STREAM_COMPLETE; | 202 _state = _state |_STREAM_COMPLETE; |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 if (_isComplete) { | 1019 if (_isComplete) { |
1011 throw new StateError("Subscription has been canceled."); | 1020 throw new StateError("Subscription has been canceled."); |
1012 } | 1021 } |
1013 if (_timer != null) { | 1022 if (_timer != null) { |
1014 _timer.cancel(); | 1023 _timer.cancel(); |
1015 _timer = null; | 1024 _timer = null; |
1016 } | 1025 } |
1017 _pauseCount = 0; | 1026 _pauseCount = 0; |
1018 } | 1027 } |
1019 } | 1028 } |
OLD | NEW |