Skip to content

Commit

Permalink
Make dart2js code retain the original stack trace for uncaught async …
Browse files Browse the repository at this point in the history
…errors.

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1383213002 .
  • Loading branch information
lrhn committed Nov 17, 2015
1 parent aa16622 commit 5363e5c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sdk/lib/_internal/js_runtime/lib/async_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'dart:_js_helper' show
convertDartClosureToJS,
getTraceFromException,
requiresPreamble,
wrapException,
unwrapException;
import 'dart:_isolate_helper' show
IsolateNatives,
Expand Down Expand Up @@ -518,5 +519,7 @@ class _SyncStarIterable extends IterableBase {

@patch
void _rethrow(Object error, StackTrace stackTrace) {
throw new AsyncError(error, stackTrace);
error = wrapException(error);
JS("void", "#.stack = #", error, stackTrace.toString());
JS("void", "throw #", error);
}
46 changes: 46 additions & 0 deletions tests/lib/async/dart2js_uncaught_error_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import "dart:async";
import "dart:js";
import "dart:collection" show Queue;
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";

var errors = new Queue();
int ctr = 0;

main() {
print("STARTED");
asyncStart();

void errorHandler(self, message, url, line, [column, error]) {
print(">> $message / $ctr");
var expect = errors.removeFirst();
if (ctr == 2) {
asyncEnd();
print("DONE");
}
Expect.equals(expect[0].toString(), message);
Expect.equals(expect[1].toString(), error["stack"].toString());
}
context["onerror"] = new JsFunction.withThis(errorHandler);

void throwit() {
var err = ++ctr;
try {
throw err;
} catch (e, s) {
errors.add([e, s]);
rethrow;
}
}

() async {
() async {
throwit();
}();
throwit();
}();
}
3 changes: 3 additions & 0 deletions tests/lib/lib.status
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ mirrors/mirrors_used_typedef_declaration_test/01: Crash # Assertion failure: typ
mirrors/mirrors_used_typedef_declaration_test/none: Crash # Assertion failure: typedef(Foo) has not been checked for cycles.
mirrors/typedef_library_test: Crash # Assertion failure: typedef(G) has not been checked for cycles.

[ $compiler != dart2js ]
async/dart2js_uncaught_error_test: Skip # JS-integration only test

[ $noopt ]
mirrors/*: SkipByDesign
convert/chunked_conversion_utf88_test: Pass, Timeout
Expand Down

0 comments on commit 5363e5c

Please sign in to comment.