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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 945783002: Dart2js async-await. Propagate stacktraces from futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix status file Created 5 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: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index 4f970badadc918199ff78fd7e0cc496384e22483..e62c2c0105fe11872400fac14086da44dc1f7b16 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -1784,6 +1784,9 @@ unwrapException(ex) {
// Note that we are checking if the object has the property. If it
// has, it could be set to null if the thrown value is null.
if (ex == null) return null;
+ if (ex is ExceptionAndStackTrace) {
+ return saveStackTrace(ex.dartException);
+ }
if (JS('bool', 'typeof # !== "object"', ex)) return ex;
if (JS('bool', r'"dartException" in #', ex)) {
@@ -1907,7 +1910,12 @@ unwrapException(ex) {
* Called by generated code to fetch the stack trace from an
* exception. Should never return null.
*/
-StackTrace getTraceFromException(exception) => new _StackTrace(exception);
+StackTrace getTraceFromException(exception) {
+ if (exception is ExceptionAndStackTrace) {
+ return exception.stackTrace;
+ }
+ return new _StackTrace(exception);
+}
class _StackTrace implements StackTrace {
var _exception;
@@ -3556,6 +3564,15 @@ void mainHasTooManyParameters() {
throw new MainError("'main' expects too many parameters.");
}
+/// A wrapper around an exception, much like the one created by [wrapException]
+/// but with a pre-given stack-trace.
+class ExceptionAndStackTrace {
+ dynamic dartException;
+ StackTrace stackTrace;
+
+ ExceptionAndStackTrace(this.dartException, this.stackTrace);
+}
+
/// Runtime support for async-await transformation.
///
/// This function is called by a transformed function on each await and return
@@ -3587,8 +3604,12 @@ dynamic asyncHelper(dynamic object,
Future future = object is Future ? object : new Future.value(object);
future.then(_wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
async_error_codes.SUCCESS),
- onError: _wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
- async_error_codes.ERROR));
+ onError: (dynamic error, StackTrace stackTrace) {
+ ExceptionAndStackTrace wrapped =
+ new ExceptionAndStackTrace(error, stackTrace);
+ return _wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
+ async_error_codes.ERROR)(wrapped);
+ });
return completer.future;
}
@@ -3703,8 +3724,13 @@ void asyncStarHelper(dynamic object,
Future future = object is Future ? object : new Future.value(object);
future.then(_wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
async_error_codes.SUCCESS),
- onError: _wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
- async_error_codes.ERROR));
+ onError: (error, StackTrace stackTrace) {
+ ExceptionAndStackTrace wrapped =
+ new ExceptionAndStackTrace(error, stackTrace);
+ return _wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
+ async_error_codes.ERROR)
+ (wrapped);
+ });
}
Stream streamOfController(AsyncStarStreamController controller) {
@@ -3729,16 +3755,17 @@ class AsyncStarStreamController {
addError(error, stackTrace) => controller.addError(error, stackTrace);
close() => controller.close();
- AsyncStarStreamController(helperCallback) {
+ AsyncStarStreamController(body) {
controller = new StreamController(
onListen: () {
scheduleMicrotask(() {
- JS('', '#(#, null)', helperCallback, async_error_codes.SUCCESS);
+ _wrapJsFunctionForAsync(body,
+ async_error_codes.SUCCESS)(null);
});
},
onResume: () {
if (!isAdding) {
- asyncStarHelper(null, helperCallback, this);
+ asyncStarHelper(null, body, this);
}
}, onCancel: () {
stopRunning = true;
@@ -3746,8 +3773,8 @@ class AsyncStarStreamController {
}
}
-makeAsyncStarController(helperCallback) {
- return new AsyncStarStreamController(helperCallback);
+makeAsyncStarController(body) {
+ return new AsyncStarStreamController(body);
}
class IterationMarker {

Powered by Google App Engine
This is Rietveld 408576698