| OLD | NEW |
| 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 @patch class Error { | 5 @patch class Error { |
| 6 @patch static String _objectToString(Object object) { | 6 @patch static String _objectToString(Object object) { |
| 7 return Object._toString(object); | 7 return Object._toString(object); |
| 8 } | 8 } |
| 9 | 9 |
| 10 @patch static String _stringToSafeString(String string) { | 10 @patch static String _stringToSafeString(String string) { |
| 11 return JSON.encode(string); | 11 return JSON.encode(string); |
| 12 } | 12 } |
| 13 | 13 |
| 14 @patch StackTrace get stackTrace => _stackTrace; | 14 @patch StackTrace get stackTrace => _stackTrace; |
| 15 | 15 |
| 16 StackTrace _stackTrace; | 16 StackTrace _stackTrace; |
| 17 } | 17 } |
| 18 | 18 |
| 19 class _AssertionError extends Error implements AssertionError { | 19 class _AssertionError extends Error implements AssertionError { |
| 20 _AssertionError._create( | 20 _AssertionError._create( |
| 21 this._failedAssertion, this._url, this._line, this._column, | 21 this._failedAssertion, this._url, this._line, this._column); |
| 22 this.message); | |
| 23 | 22 |
| 24 static _throwNew(int assertionStart, int assertionEnd, Object message) { | 23 static _throwNew(int assertionStart, int assertionEnd) |
| 25 _doThrowNew(assertionStart, assertionEnd, message); | |
| 26 } | |
| 27 | |
| 28 static _doThrowNew(int assertionStart, int assertionEnd, Object message) | |
| 29 native "AssertionError_throwNew"; | 24 native "AssertionError_throwNew"; |
| 30 | 25 |
| 31 static _checkAssertion(condition) { | 26 static void _checkAssertion(condition, int start, int end) { |
| 32 if (condition is Function) { | 27 if (condition is Function) { |
| 33 condition = condition(); | 28 condition = condition(); |
| 34 } | 29 } |
| 35 return condition; | 30 if (!condition) { |
| 31 _throwNew(start, end); |
| 32 } |
| 36 } | 33 } |
| 37 | 34 |
| 38 String get _messageString { | 35 static void _checkConstAssertion(bool condition, int start, int end) { |
| 39 if (message == null) return "is not true."; | 36 if (!condition) { |
| 40 if (message is String) return message; | 37 _throwNew(start, end); |
| 41 return Error.safeToString(message); | 38 } |
| 42 } | 39 } |
| 43 | 40 |
| 44 String toString() { | 41 String toString() { |
| 45 if (_url == null) { | 42 if (_url == null) { |
| 46 if (message == null) return _failedAssertion; | 43 return _failedAssertion; |
| 47 return "'$_failedAssertion': $_messageString"; | |
| 48 } | 44 } |
| 49 var columnInfo = ""; | 45 var columnInfo = ""; |
| 50 if (_column > 0) { | 46 if (_column > 0) { |
| 51 // Only add column information if it is valid. | 47 // Only add column information if it is valid. |
| 52 columnInfo = " pos $_column"; | 48 columnInfo = " pos $_column"; |
| 53 } | 49 } |
| 54 return "'$_url': Failed assertion: line $_line$columnInfo: " | 50 return "'$_url': Failed assertion: line $_line$columnInfo: " |
| 55 "'$_failedAssertion': $_messageString"; | 51 "'$_failedAssertion' is not true."; |
| 56 } | 52 } |
| 57 final String _failedAssertion; | 53 final String _failedAssertion; |
| 58 final String _url; | 54 final String _url; |
| 59 final int _line; | 55 final int _line; |
| 60 final int _column; | 56 final int _column; |
| 61 final Object message; | |
| 62 } | 57 } |
| 63 | 58 |
| 64 class _TypeError extends _AssertionError implements TypeError { | 59 class _TypeError extends _AssertionError implements TypeError { |
| 65 _TypeError._create(String url, int line, int column, String errorMsg) | 60 _TypeError._create(String url, int line, int column, this._errorMsg) |
| 66 : super._create("is assignable", url, line, column, errorMsg); | 61 : super._create("is assignable", url, line, column); |
| 67 | 62 |
| 68 static _throwNew(int location, | 63 static _throwNew(int location, |
| 69 Object src_value, | 64 Object src_value, |
| 70 _Type dst_type, | 65 _Type dst_type, |
| 71 String dst_name, | 66 String dst_name, |
| 72 String bound_error_msg) | 67 String bound_error_msg) |
| 73 native "TypeError_throwNew"; | 68 native "TypeError_throwNew"; |
| 74 | 69 |
| 75 static _throwNewIfNotLoaded(_LibraryPrefix prefix, | 70 static _throwNewIfNotLoaded(_LibraryPrefix prefix, |
| 76 int location, | 71 int location, |
| 77 Object src_value, | 72 Object src_value, |
| 78 _Type dst_type, | 73 _Type dst_type, |
| 79 String dst_name, | 74 String dst_name, |
| 80 String bound_error_msg) { | 75 String bound_error_msg) { |
| 81 if (!prefix.isLoaded()) { | 76 if (!prefix.isLoaded()) { |
| 82 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); | 77 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); |
| 83 } | 78 } |
| 84 } | 79 } |
| 85 | 80 |
| 86 String toString() => super.message; | 81 String toString() => _errorMsg; |
| 82 |
| 83 final String _errorMsg; |
| 87 } | 84 } |
| 88 | 85 |
| 89 class _CastError extends Error implements CastError { | 86 class _CastError extends Error implements CastError { |
| 90 _CastError._create(this._url, this._line, this._column, this._errorMsg); | 87 _CastError._create(this._url, this._line, this._column, this._errorMsg); |
| 91 | 88 |
| 92 // A CastError is allocated by TypeError._throwNew() when dst_name equals | 89 // A CastError is allocated by TypeError._throwNew() when dst_name equals |
| 93 // Symbols::InTypeCast(). | 90 // Symbols::InTypeCast(). |
| 94 | 91 |
| 95 String toString() => _errorMsg; | 92 String toString() => _errorMsg; |
| 96 | 93 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return msg_buf.toString(); | 356 return msg_buf.toString(); |
| 360 } | 357 } |
| 361 } | 358 } |
| 362 | 359 |
| 363 | 360 |
| 364 class _CompileTimeError extends Error { | 361 class _CompileTimeError extends Error { |
| 365 final String _errorMsg; | 362 final String _errorMsg; |
| 366 _CompileTimeError(this._errorMsg); | 363 _CompileTimeError(this._errorMsg); |
| 367 String toString() => _errorMsg; | 364 String toString() => _errorMsg; |
| 368 } | 365 } |
| OLD | NEW |