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

Unified Diff: dart/frog/leg/lib/js_helper.dart

Issue 9474040: Improve exception handling: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | « dart/frog/leg/emitter.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/js_helper.dart
diff --git a/dart/frog/leg/lib/js_helper.dart b/dart/frog/leg/lib/js_helper.dart
index 34f32554e6d30a1451a377a2e9874ff3038edcfe..d730fa097f52c06284dd16c8f6629a26c3af305f 100644
--- a/dart/frog/leg/lib/js_helper.dart
+++ b/dart/frog/leg/lib/js_helper.dart
@@ -1229,3 +1229,44 @@ makeLiteralListConst(list) {
JS('bool', @'$0.fixed$length = $1', list, true);
return list;
}
+
+/**
+ * Called from catch blocks in generated code to extract the Dart
+ * exception from the thrown value. The thrown value may have been
+ * created by [captureStackTrace] or it may be a "native" JS
+ * exception.
+ *
+ * Some native exceptions are mapped to new Dart instances, others are
+ * returned unmodified.
+ */
+unwrapException(ex) {
+ if (JS('bool', @'"dartException" in $0', ex)) {
+ return JS('Object', @'$0.dartException', ex);
+ } else if (JS('bool', @'$0 instanceof TypeError', ex)) {
+ var type = JS('String', @'$0.type', ex);
kasperl 2012/02/28 09:22:11 This (ex.type) is very Chrome specific code. Maybe
ahe 2012/02/28 16:25:53 Done.
+ var jsArguments = JS('Object', @'$0.arguments', ex);
+ var name = jsArguments[0];
+ if (type == 'property_not_function' ||
+ type == 'called_non_callable' ||
+ type == 'non_object_property_call' ||
+ type == 'non_object_property_load') {
+ if (name !== null && name.startsWith(@'$call$')) {
+ return new ObjectNotClosureException();
+ } else {
+ return new NullPointerException();
+ }
+ } else if (type == 'undefined_method') {
+ if (name is String && name.startsWith(@'$call$')) {
+ return new ObjectNotClosureException();
+ } else {
+ return new NoSuchMethodException('', name, []);
+ }
+ }
+ } else if (JS('bool', @'$0 instanceof RangeError', ex)) {
+ var message = JS('String', @'$0.message', ex);
+ if (message.contains('call stack')) {
+ return new StackOverflowException();
+ }
+ }
+ return ex;
+}
« no previous file with comments | « dart/frog/leg/emitter.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698