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

Unified Diff: runtime/lib/async_patch.dart

Issue 2692803006: Track the 'awaiter return' call stack use it to detect uncaught exceptions in async functions (Closed)
Patch Set: port to other architectures Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/async_patch.dart
diff --git a/runtime/lib/async_patch.dart b/runtime/lib/async_patch.dart
index 0dd99e01784cedaf278b890cba31687d2e708cde..cf647684f2cb319ebdab3c4e0b8dd9902a009a44 100644
--- a/runtime/lib/async_patch.dart
+++ b/runtime/lib/async_patch.dart
@@ -45,7 +45,10 @@ Function _asyncErrorWrapperHelper(continuation) {
///
/// Returns the result of registering with `.then`.
Future _awaitHelper(
- var object, Function thenCallback, Function errorCallback) {
+ var object,
+ Function thenCallback,
+ Function errorCallback,
+ var awaiter) {
if (object is! Future) {
object = new _Future().._setValue(object);
} else if (object is! _Future) {
@@ -59,9 +62,20 @@ Future _awaitHelper(
//
// We can only do this for our internal futures (the default implementation of
// all futures that are constructed by the `dart:async` library).
+ object._awaiter = awaiter;
return object._thenNoZoneRegistration(thenCallback, errorCallback);
}
+// Called as part of the 'await for (...)' construct. Registers the
+// awaiter on the stream.
+void _asyncStarListenHelper(var object, var awaiter) {
+ if (object is! _StreamImpl) {
+ return;
+ }
+ // `object` is a `_StreamImpl`.
+ object._awaiter = awaiter;
+}
+
// _AsyncStarStreamController is used by the compiler to implement
// async* generator functions.
class _AsyncStarStreamController {
@@ -73,7 +87,14 @@ class _AsyncStarStreamController {
bool isSuspendedAtYield = false;
Completer cancellationCompleter = null;
- Stream get stream => controller.stream;
+ Stream get stream {
+ Stream local = controller.stream;
+ if (local is! _StreamImpl) {
+ return local;
+ }
+ local._generator = asyncStarBody;
+ return local;
+ }
void runBody() {
isScheduled = false;
@@ -194,10 +215,19 @@ class _AsyncStarStreamController {
@patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow";
+@patch class _Future<T> {
+ Object _awaiter;
rmacnak 2017/02/23 17:50:55 /// The closure implementing the async[*]-body tha
Cutch 2017/02/24 20:19:20 Done.
+}
+
+@patch class _StreamImpl<T> {
+ Object _awaiter;
rmacnak 2017/02/23 17:50:55 "
Cutch 2017/02/24 20:19:20 Done.
+ Object _generator;
rmacnak 2017/02/23 17:50:55 /// The closure implementing the async-generator b
Cutch 2017/02/24 20:19:20 Done.
+}
/// Returns a [StackTrace] object containing the synchronous prefix for this
/// asynchronous method.
-Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper";
+Object _asyncStackTraceHelper()
+ native "StackTrace_asyncStackTraceHelper";
void _clearAsyncThreadStackTrace()
native "StackTrace_clearAsyncThreadStackTrace";

Powered by Google App Engine
This is Rietveld 408576698