Chromium Code Reviews| Index: frog/corejs.dart |
| diff --git a/frog/corejs.dart b/frog/corejs.dart |
| index 6193659a8853094db044fecffe1310a7317e32df..fd5f1f81efaacd6e7c000457b3ccbce591841819 100644 |
| --- a/frog/corejs.dart |
| +++ b/frog/corejs.dart |
| @@ -253,42 +253,58 @@ function $stackTraceOf(e) { |
| // Translate a JavaScript exception to a Dart exception |
| // TODO(jmesserly): cross browser support. This is Chrome specific. |
| function $toDartException(e) { |
| - var res = e; |
| + function attachStack(dartEx) { |
| + // TODO(jmesserly): setting the stack property is not a long term solution. |
| + var stack = e.stack; |
| + // The stack contains the error message, and the stack is all that is |
| + // printed (the exception's toString() is never called). Attempt to replace |
| + // the JS message (e.g. TypeError) with the Dart exception's toString(). |
| + if (typeof stack == 'string') { |
| + try { // toString is in a try-catch due to Issue 470. |
|
Jennifer Messerly
2011/11/29 00:46:18
Issue 470 is fixed--can you see if the try-catch c
|
| + var message = dartEx.toString(); |
| + if (/^(Type|Range)Error:/.test(stack)) { |
| + // Remove JS message. |
| + stack = stack.substring(stack.indexOf('\n') + 1); |
| + } |
| + stack = message + '\n' + stack; |
| + } catch(_) { |
| + stack = '' + dartEx.constructor.name + ': (corrupt)\n' + stack; |
| + } |
| + } |
| + dartEx.stack = stack; |
| + return dartEx; |
| + } |
| + |
| if (e instanceof TypeError) { |
| switch(e.type) { |
| case 'property_not_function': |
| case 'called_non_callable': |
| if (e.arguments[0] == null) { |
| - res = new NullPointerException(); |
| + return attachStack(new NullPointerException()); |
| } else { |
| - res = new ObjectNotClosureException(); |
| + return attachStack(new ObjectNotClosureException()); |
| } |
| break; |
| case 'non_object_property_call': |
| case 'non_object_property_load': |
| - res = new NullPointerException(); |
| + return attachStack(new NullPointerException()); |
| break; |
| case 'undefined_method': |
| if (e.arguments[0] == 'call' || e.arguments[0] == 'apply') { |
| - res = new ObjectNotClosureException(); |
| + return attachStack(new ObjectNotClosureException()); |
| } else { |
| // TODO(jmesserly): can this ever happen? |
| - res = new NoSuchMethodException('', e.arguments[0], []); |
| + // sra: Yes. |
|
Jennifer Messerly
2011/11/29 00:46:18
Can you add context about what conditions it happe
|
| + return attachStack(new NoSuchMethodException('', e.arguments[0], [])); |
| } |
| break; |
| } |
| } else if (e instanceof RangeError) { |
| if (e.message.indexOf('call stack') >= 0) { |
| - res = new StackOverflowException(); |
| + return attachStack(new StackOverflowException()); |
| } |
| } |
| - if (res) { |
| - // TODO(jmesserly): setting the stack property is not a long term solution. |
| - // Also it causes the exception to print as if it were a JS TypeError or |
| - // RangeError, instead of using the proper toString. |
| - res.stack = e.stack; |
| - } |
| - return res; |
| + return e; |
| }"""); |
| } |