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

Unified Diff: lib/compiler/implementation/lib/js_helper.dart

Issue 10443081: Update unwrapException to give better exceptions on Firefox. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/lib/js_helper.dart
diff --git a/lib/compiler/implementation/lib/js_helper.dart b/lib/compiler/implementation/lib/js_helper.dart
index e325b3e018f62b87659620a661f469c25ae95df6..77ccc7bd3fdabea6e4024d7d411ba991ad1137d7 100644
--- a/lib/compiler/implementation/lib/js_helper.dart
+++ b/lib/compiler/implementation/lib/js_helper.dart
@@ -770,8 +770,16 @@ unwrapException(ex) {
// has, it could be set to null if the thrown value is null.
if (JS('bool', @'"dartException" in #', ex)) {
return JS('Object', @'#.dartException', ex);
- } else if (JS('bool', @'# instanceof TypeError', ex)) {
- // TODO(ahe): ex.type is Chrome specific.
+ }
+
+ // Grab hold of the exception message. This field is available on
+ // all supported browsers.
+ var message = JS('var', @'#.message', ex);
+
+ if (JS('bool', @'# instanceof TypeError', ex)) {
+ // The type and arguments fields are Chrome specific but they
+ // allow us to get very detailed information about what kind of
+ // exception occurred.
var type = JS('var', @'#.type', ex);
var name = JS('var', @'#.arguments ? #.arguments[0] : ""', ex, ex);
if (type == 'property_not_function' ||
@@ -790,13 +798,46 @@ unwrapException(ex) {
return new NoSuchMethodException('', name, []);
}
}
- } else if (JS('bool', @'# instanceof RangeError', ex)) {
- var message = JS('var', @'#.message', ex);
+
+ // If we cannot use [type] to determine what kind of exception
+ // we're dealing with we fall back on looking at the exception
+ // message if it is available and a string.
+ if (message is String) {
+ if (message.endsWith('is null') || message.endsWith('is undefined')) {
+ return new NullPointerException();
+ } else if (message.endsWith('is not a function')) {
+ // TODO(kasperl): Compute the right name if possible.
+ return new NoSuchMethodException('', '<unknown>', []);
+ }
+ }
+
+ // If we cannot determine what kind of error this is, we fall back
+ // to reporting this as a TypeError even though that may be
+ // inaccurate. It's probably better than nothing.
+ return new TypeError(message);
+ }
+
+ if (JS('bool', @'# instanceof RangeError', ex)) {
if (message is String && message.contains('call stack')) {
return new StackOverflowException();
}
+
+ // In general, a RangeError is thrown when trying to pass a number
+ // as an argument to a function that does not allow a range that
+ // includes that number.
+ return new IllegalArgumentException();
+ }
+
+ // Check for the Firefox specific stack overflow signal.
+ if (JS('bool', @'InternalError && # instanceof InternalError', ex)) {
+ if (message is String && message == 'too much recursion') {
+ return new StackOverflowException();
+ }
}
- return ex;
+
+ // Last resort: Create a completely generic exception object and use
+ // the JS exception message as its argument.
+ return new Exception(message);
}
/**
« no previous file with comments | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698