Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: runtime/lib/async_patch.dart

Issue 2718353002: Revert "Track the 'awaiter return' call stack..." (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/observatory/tests/service/pause_on_unhandled_async_exceptions2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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:_internal" hide Symbol; 5 import "dart:_internal" hide Symbol;
6 6
7 // Equivalent of calling FATAL from C++ code. 7 // Equivalent of calling FATAL from C++ code.
8 _fatal(msg) native "DartAsync_fatal"; 8 _fatal(msg) native "DartAsync_fatal";
9 9
10 // We need to pass the value as first argument and leave the second and third 10 // We need to pass the value as first argument and leave the second and third
(...skipping 27 matching lines...) Expand all
38 if (Zone.current == Zone.ROOT) return errorCallback; 38 if (Zone.current == Zone.ROOT) return errorCallback;
39 return Zone.current.registerBinaryCallback(errorCallback); 39 return Zone.current.registerBinaryCallback(errorCallback);
40 } 40 }
41 41
42 /// Registers the [thenCallback] and [errorCallback] on the given [object]. 42 /// Registers the [thenCallback] and [errorCallback] on the given [object].
43 /// 43 ///
44 /// If [object] is not a future, then it is wrapped into one. 44 /// If [object] is not a future, then it is wrapped into one.
45 /// 45 ///
46 /// Returns the result of registering with `.then`. 46 /// Returns the result of registering with `.then`.
47 Future _awaitHelper( 47 Future _awaitHelper(
48 var object, 48 var object, Function thenCallback, Function errorCallback) {
49 Function thenCallback,
50 Function errorCallback,
51 var awaiter) {
52 if (object is! Future) { 49 if (object is! Future) {
53 object = new _Future().._setValue(object); 50 object = new _Future().._setValue(object);
54 } else if (object is! _Future) { 51 } else if (object is! _Future) {
55 return object.then(thenCallback, onError: errorCallback); 52 return object.then(thenCallback, onError: errorCallback);
56 } 53 }
57 // `object` is a `_Future`. 54 // `object` is a `_Future`.
58 // 55 //
59 // Since the callbacks have been registered in the current zone (see 56 // Since the callbacks have been registered in the current zone (see
60 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid 57 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid
61 // another registration and directly invoke the no-zone-registration `.then`. 58 // another registration and directly invoke the no-zone-registration `.then`.
62 // 59 //
63 // We can only do this for our internal futures (the default implementation of 60 // We can only do this for our internal futures (the default implementation of
64 // all futures that are constructed by the `dart:async` library). 61 // all futures that are constructed by the `dart:async` library).
65 object._awaiter = awaiter;
66 return object._thenNoZoneRegistration(thenCallback, errorCallback); 62 return object._thenNoZoneRegistration(thenCallback, errorCallback);
67 } 63 }
68 64
69 // Called as part of the 'await for (...)' construct. Registers the
70 // awaiter on the stream.
71 void _asyncStarListenHelper(var object, var awaiter) {
72 if (object is! _StreamImpl) {
73 return;
74 }
75 // `object` is a `_StreamImpl`.
76 object._awaiter = awaiter;
77 }
78
79 // _AsyncStarStreamController is used by the compiler to implement 65 // _AsyncStarStreamController is used by the compiler to implement
80 // async* generator functions. 66 // async* generator functions.
81 class _AsyncStarStreamController { 67 class _AsyncStarStreamController {
82 StreamController controller; 68 StreamController controller;
83 Function asyncStarBody; 69 Function asyncStarBody;
84 bool isAdding = false; 70 bool isAdding = false;
85 bool onListenReceived = false; 71 bool onListenReceived = false;
86 bool isScheduled = false; 72 bool isScheduled = false;
87 bool isSuspendedAtYield = false; 73 bool isSuspendedAtYield = false;
88 Completer cancellationCompleter = null; 74 Completer cancellationCompleter = null;
89 75
90 Stream get stream { 76 Stream get stream => controller.stream;
91 Stream local = controller.stream;
92 if (local is! _StreamImpl) {
93 return local;
94 }
95 local._generator = asyncStarBody;
96 return local;
97 }
98 77
99 void runBody() { 78 void runBody() {
100 isScheduled = false; 79 isScheduled = false;
101 isSuspendedAtYield = false; 80 isSuspendedAtYield = false;
102 asyncStarBody(); 81 asyncStarBody();
103 } 82 }
104 83
105 void scheduleGenerator() { 84 void scheduleGenerator() {
106 if (isScheduled || controller.isPaused || isAdding) { 85 if (isScheduled || controller.isPaused || isAdding) {
107 return; 86 return;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if (isSuspendedAtYield) { 187 if (isSuspendedAtYield) {
209 scheduleGenerator(); 188 scheduleGenerator();
210 } 189 }
211 } 190 }
212 return cancellationCompleter.future; 191 return cancellationCompleter.future;
213 } 192 }
214 } 193 }
215 194
216 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow" ; 195 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow" ;
217 196
218 @patch class _Future<T> {
219 /// The closure implementing the async[*]-body that is `await`ing this future.
220 Function _awaiter;
221 }
222
223 @patch class _StreamImpl<T> {
224 /// The closure implementing the async[*]-body that is `await`ing this future.
225 Function _awaiter;
226 /// The closure implementing the async-generator body that is creating events
227 /// for this stream.
228 Function _generator;
229 }
230 197
231 /// Returns a [StackTrace] object containing the synchronous prefix for this 198 /// Returns a [StackTrace] object containing the synchronous prefix for this
232 /// asynchronous method. 199 /// asynchronous method.
233 Object _asyncStackTraceHelper() 200 Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper";
234 native "StackTrace_asyncStackTraceHelper";
235 201
236 void _clearAsyncThreadStackTrace() 202 void _clearAsyncThreadStackTrace()
237 native "StackTrace_clearAsyncThreadStackTrace"; 203 native "StackTrace_clearAsyncThreadStackTrace";
238 204
239 void _setAsyncThreadStackTrace(StackTrace stackTrace) native 205 void _setAsyncThreadStackTrace(StackTrace stackTrace) native
240 "StackTrace_setAsyncThreadStackTrace"; 206 "StackTrace_setAsyncThreadStackTrace";
OLDNEW
« no previous file with comments | « no previous file | runtime/observatory/tests/service/pause_on_unhandled_async_exceptions2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698