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

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: Address review comments 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
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/async_stacktrace_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 990c54190cbaae8918b8a9b3187de7c62c0020d8..a739289056301df621b707f704d85ad485bdc2d7 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -1780,6 +1780,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)) {
@@ -1903,7 +1906,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;
@@ -3551,6 +3559,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
@@ -3582,8 +3599,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;
}
@@ -3698,8 +3719,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) {
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/async_stacktrace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698