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

Side by Side Diff: sdk/lib/_internal/lib/js_helper.dart

Issue 18529003: Add stackTrace to Error object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library _js_helper; 5 library _js_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, 8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS,
9 JS, 9 JS,
10 JS_CALL_IN_ISOLATE, 10 JS_CALL_IN_ISOLATE,
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 return value; 672 return value;
673 } 673 }
674 674
675 /** 675 /**
676 * Wrap the given Dart object and record a stack trace. 676 * Wrap the given Dart object and record a stack trace.
677 * 677 *
678 * The code in [unwrapException] deals with getting the original Dart 678 * The code in [unwrapException] deals with getting the original Dart
679 * object out of the wrapper again. 679 * object out of the wrapper again.
680 */ 680 */
681 wrapException(ex) { 681 wrapException(ex) {
682 if (ex == null) ex = const NullThrownError(); 682 if (ex == null) ex = new NullThrownError();
683 var wrapper = new DartError(ex); 683 var wrapper = new DartError(ex);
684 684
685 if (JS('bool', '!!Error.captureStackTrace')) { 685 if (JS('bool', '!!Error.captureStackTrace')) {
686 // Use V8 API for recording a "fast" stack trace (this installs a 686 // Use V8 API for recording a "fast" stack trace (this installs a
687 // "stack" property getter on [wrapper]). 687 // "stack" property getter on [wrapper]).
688 JS('void', r'Error.captureStackTrace(#, #)', 688 JS('void', r'Error.captureStackTrace(#, #)',
689 wrapper, RAW_DART_FUNCTION_REF(wrapException)); 689 wrapper, RAW_DART_FUNCTION_REF(wrapException));
690 } else { 690 } else {
691 // Otherwise, produce a stack trace and record it in the wrapper. 691 // Otherwise, produce a stack trace and record it in the wrapper.
692 // This is a slower way to create a stack trace which works on 692 // This is a slower way to create a stack trace which works on
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1016 }
1017 1017
1018 jsPropertyAccess(var jsObject, String property) { 1018 jsPropertyAccess(var jsObject, String property) {
1019 return JS('var', r'#[#]', jsObject, property); 1019 return JS('var', r'#[#]', jsObject, property);
1020 } 1020 }
1021 1021
1022 /** 1022 /**
1023 * Called at the end of unaborted switch cases to get the singleton 1023 * Called at the end of unaborted switch cases to get the singleton
1024 * FallThroughError exception that will be thrown. 1024 * FallThroughError exception that will be thrown.
1025 */ 1025 */
1026 getFallThroughError() => const FallThroughErrorImplementation(); 1026 getFallThroughError() => new FallThroughErrorImplementation();
1027 1027
1028 /** 1028 /**
1029 * Represents the type dynamic. The compiler treats this specially. 1029 * Represents the type dynamic. The compiler treats this specially.
1030 */ 1030 */
1031 abstract class Dynamic_ { 1031 abstract class Dynamic_ {
1032 } 1032 }
1033 1033
1034 /** 1034 /**
1035 * A metadata annotation describing the types instantiated by a native element. 1035 * A metadata annotation describing the types instantiated by a native element.
1036 * 1036 *
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 CastErrorImplementation.malformedTypeCast(Object value, 1432 CastErrorImplementation.malformedTypeCast(Object value,
1433 String type, String reasons) 1433 String type, String reasons)
1434 : message = "CastError: Type '${Primitives.objectTypeName(value)}' " 1434 : message = "CastError: Type '${Primitives.objectTypeName(value)}' "
1435 "cannot be cast to type '$type' because '$type' is " 1435 "cannot be cast to type '$type' because '$type' is "
1436 "malformed: $reasons."; 1436 "malformed: $reasons.";
1437 1437
1438 1438
1439 String toString() => message; 1439 String toString() => message;
1440 } 1440 }
1441 1441
1442 class FallThroughErrorImplementation implements FallThroughError { 1442 class FallThroughErrorImplementation extends FallThroughError {
1443 const FallThroughErrorImplementation(); 1443 FallThroughErrorImplementation();
1444 String toString() => "Switch case fall-through."; 1444 String toString() => "Switch case fall-through.";
1445 } 1445 }
1446 1446
1447 /** 1447 /**
1448 * Helper function for implementing asserts. The compiler treats this specially. 1448 * Helper function for implementing asserts. The compiler treats this specially.
1449 */ 1449 */
1450 void assertHelper(condition) { 1450 void assertHelper(condition) {
1451 if (condition is Function) condition = condition(); 1451 if (condition is Function) condition = condition();
1452 if (condition is !bool) { 1452 if (condition is !bool) {
1453 throw new TypeErrorImplementation(condition, 'bool'); 1453 throw new TypeErrorImplementation(condition, 'bool');
(...skipping 17 matching lines...) Expand all
1471 * field that is currently being initialized. 1471 * field that is currently being initialized.
1472 */ 1472 */
1473 void throwCyclicInit(String staticName) { 1473 void throwCyclicInit(String staticName) {
1474 throw new CyclicInitializationError( 1474 throw new CyclicInitializationError(
1475 "Cyclic initialization for static $staticName"); 1475 "Cyclic initialization for static $staticName");
1476 } 1476 }
1477 1477
1478 /** 1478 /**
1479 * Error thrown when a runtime error occurs. 1479 * Error thrown when a runtime error occurs.
1480 */ 1480 */
1481 class RuntimeError implements Error { 1481 class RuntimeError extends Error {
1482 final message; 1482 final message;
1483 RuntimeError(this.message); 1483 RuntimeError(this.message);
1484 String toString() => "RuntimeError: $message"; 1484 String toString() => "RuntimeError: $message";
1485 } 1485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698