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

Side by Side Diff: frog/corejs.dart

Issue 8694007: Ensure that exception message is printed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: x Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/frogsh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Generates JS helpers for dart:core. This used to be in a file "core.js". 6 * Generates JS helpers for dart:core. This used to be in a file "core.js".
7 * Having them in Dart code means we can easily control which are generated. 7 * Having them in Dart code means we can easily control which are generated.
8 */ 8 */
9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native" 9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native"
10 // methods somewhere in a library that we import. This would be rather elegant 10 // methods somewhere in a library that we import. This would be rather elegant
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // Need to mangle it. 246 // Need to mangle it.
247 return (e && e.stack) ? e.stack : null; 247 return (e && e.stack) ? e.stack : null;
248 }"""); 248 }""");
249 } 249 }
250 250
251 if (useToDartException) { 251 if (useToDartException) {
252 w.writeln(@""" 252 w.writeln(@"""
253 // Translate a JavaScript exception to a Dart exception 253 // Translate a JavaScript exception to a Dart exception
254 // TODO(jmesserly): cross browser support. This is Chrome specific. 254 // TODO(jmesserly): cross browser support. This is Chrome specific.
255 function $toDartException(e) { 255 function $toDartException(e) {
256 var res = e; 256 function attachStack(dartEx) {
257 // TODO(jmesserly): setting the stack property is not a long term solution.
258 var stack = e.stack;
259 // The stack contains the error message, and the stack is all that is
260 // printed (the exception's toString() is never called). Attempt to replace
261 // the JS message (e.g. TypeError) with the Dart exception's toString().
262 if (typeof stack == 'string') {
263 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
264 var message = dartEx.toString();
265 if (/^(Type|Range)Error:/.test(stack)) {
266 // Remove JS message.
267 stack = stack.substring(stack.indexOf('\n') + 1);
268 }
269 stack = message + '\n' + stack;
270 } catch(_) {
271 stack = '' + dartEx.constructor.name + ': (corrupt)\n' + stack;
272 }
273 }
274 dartEx.stack = stack;
275 return dartEx;
276 }
277
257 if (e instanceof TypeError) { 278 if (e instanceof TypeError) {
258 switch(e.type) { 279 switch(e.type) {
259 case 'property_not_function': 280 case 'property_not_function':
260 case 'called_non_callable': 281 case 'called_non_callable':
261 if (e.arguments[0] == null) { 282 if (e.arguments[0] == null) {
262 res = new NullPointerException(); 283 return attachStack(new NullPointerException());
263 } else { 284 } else {
264 res = new ObjectNotClosureException(); 285 return attachStack(new ObjectNotClosureException());
265 } 286 }
266 break; 287 break;
267 case 'non_object_property_call': 288 case 'non_object_property_call':
268 case 'non_object_property_load': 289 case 'non_object_property_load':
269 res = new NullPointerException(); 290 return attachStack(new NullPointerException());
270 break; 291 break;
271 case 'undefined_method': 292 case 'undefined_method':
272 if (e.arguments[0] == 'call' || e.arguments[0] == 'apply') { 293 if (e.arguments[0] == 'call' || e.arguments[0] == 'apply') {
273 res = new ObjectNotClosureException(); 294 return attachStack(new ObjectNotClosureException());
274 } else { 295 } else {
275 // TODO(jmesserly): can this ever happen? 296 // TODO(jmesserly): can this ever happen?
276 res = new NoSuchMethodException('', e.arguments[0], []); 297 // sra: Yes.
Jennifer Messerly 2011/11/29 00:46:18 Can you add context about what conditions it happe
298 return attachStack(new NoSuchMethodException('', e.arguments[0], []));
277 } 299 }
278 break; 300 break;
279 } 301 }
280 } else if (e instanceof RangeError) { 302 } else if (e instanceof RangeError) {
281 if (e.message.indexOf('call stack') >= 0) { 303 if (e.message.indexOf('call stack') >= 0) {
282 res = new StackOverflowException(); 304 return attachStack(new StackOverflowException());
283 } 305 }
284 } 306 }
285 if (res) { 307 return e;
286 // TODO(jmesserly): setting the stack property is not a long term solution.
287 // Also it causes the exception to print as if it were a JS TypeError or
288 // RangeError, instead of using the proper toString.
289 res.stack = e.stack;
290 }
291 return res;
292 }"""); 308 }""");
293 } 309 }
294 310
295 if (useNotNullBool) { 311 if (useNotNullBool) {
296 useThrow = true; 312 useThrow = true;
297 // This pattern chosen because IE9 does really badly with typeof, and 313 // This pattern chosen because IE9 does really badly with typeof, and
298 // it's still decent on other browsers. 314 // it's still decent on other browsers.
299 w.writeln(@""" 315 w.writeln(@"""
300 function $notnull_bool(test) { 316 function $notnull_bool(test) {
301 return (test === true || test === false) ? test : test.is$bool(); // TypeError 317 return (test === true || test === false) ? test : test.is$bool(); // TypeError
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 w.writeln(@"function $wrap_call$1(fn) { return fn; }"); 451 w.writeln(@"function $wrap_call$1(fn) { return fn; }");
436 } 452 }
437 } 453 }
438 454
439 // Write operator helpers 455 // Write operator helpers
440 for (var opImpl in orderValuesByKeys(_usedOperators)) { 456 for (var opImpl in orderValuesByKeys(_usedOperators)) {
441 w.writeln(opImpl); 457 w.writeln(opImpl);
442 } 458 }
443 } 459 }
444 } 460 }
OLDNEW
« no previous file with comments | « no previous file | frog/frogsh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698