Chromium Code Reviews| 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; |
| +} |