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); |
22 | 23 |
23 static _throwNew(int assertionStart, int assertionEnd) | |
24 native "AssertionError_throwNew"; | |
25 | 24 |
26 static void _checkAssertion(condition, int start, int end) { | 25 // AssertionError_throwNew in errors.cc fishes the assertion source code |
| 26 // out of the script. It expects a Dart stack frame from class |
| 27 // _AssertionError. Thus we need a Dart stub that calls the native code. |
| 28 static _throwNew(int assertionStart, int assertionEnd, Object message) { |
| 29 _doThrowNew(assertionStart, assertionEnd, message); |
| 30 } |
| 31 |
| 32 static _doThrowNew(int assertionStart, int assertionEnd, Object message) |
| 33 native "AssertionError_throwNew"; |
| 34 |
| 35 static _evaluateAssertion(condition) { |
27 if (condition is Function) { | 36 if (condition is Function) { |
28 condition = condition(); | 37 condition = condition(); |
29 } | 38 } |
30 if (!condition) { | 39 return condition; |
31 _throwNew(start, end); | |
32 } | |
33 } | 40 } |
34 | 41 |
35 static void _checkConstAssertion(bool condition, int start, int end) { | 42 String get _messageString { |
36 if (!condition) { | 43 if (message == null) return "is not true."; |
37 _throwNew(start, end); | 44 if (message is String) return message; |
38 } | 45 return Error.safeToString(message); |
39 } | 46 } |
40 | 47 |
41 String toString() { | 48 String toString() { |
42 if (_url == null) { | 49 if (_url == null) { |
43 return _failedAssertion; | 50 if (message == null) return _failedAssertion; |
| 51 return "'$_failedAssertion': $_messageString"; |
44 } | 52 } |
45 var columnInfo = ""; | 53 var columnInfo = ""; |
46 if (_column > 0) { | 54 if (_column > 0) { |
47 // Only add column information if it is valid. | 55 // Only add column information if it is valid. |
48 columnInfo = " pos $_column"; | 56 columnInfo = " pos $_column"; |
49 } | 57 } |
50 return "'$_url': Failed assertion: line $_line$columnInfo: " | 58 return "'$_url': Failed assertion: line $_line$columnInfo: " |
51 "'$_failedAssertion' is not true."; | 59 "'$_failedAssertion': $_messageString"; |
52 } | 60 } |
53 final String _failedAssertion; | 61 final String _failedAssertion; |
54 final String _url; | 62 final String _url; |
55 final int _line; | 63 final int _line; |
56 final int _column; | 64 final int _column; |
| 65 final Object message; |
57 } | 66 } |
58 | 67 |
59 class _TypeError extends _AssertionError implements TypeError { | 68 class _TypeError extends _AssertionError implements TypeError { |
60 _TypeError._create(String url, int line, int column, this._errorMsg) | 69 _TypeError._create(String url, int line, int column, String errorMsg) |
61 : super._create("is assignable", url, line, column); | 70 : super._create("is assignable", url, line, column, errorMsg); |
62 | 71 |
63 static _throwNew(int location, | 72 static _throwNew(int location, |
64 Object src_value, | 73 Object src_value, |
65 _Type dst_type, | 74 _Type dst_type, |
66 String dst_name, | 75 String dst_name, |
67 String bound_error_msg) | 76 String bound_error_msg) |
68 native "TypeError_throwNew"; | 77 native "TypeError_throwNew"; |
69 | 78 |
70 static _throwNewIfNotLoaded(_LibraryPrefix prefix, | 79 static _throwNewIfNotLoaded(_LibraryPrefix prefix, |
71 int location, | 80 int location, |
72 Object src_value, | 81 Object src_value, |
73 _Type dst_type, | 82 _Type dst_type, |
74 String dst_name, | 83 String dst_name, |
75 String bound_error_msg) { | 84 String bound_error_msg) { |
76 if (!prefix.isLoaded()) { | 85 if (!prefix.isLoaded()) { |
77 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); | 86 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); |
78 } | 87 } |
79 } | 88 } |
80 | 89 |
81 String toString() => _errorMsg; | 90 String toString() => super.message; |
82 | |
83 final String _errorMsg; | |
84 } | 91 } |
85 | 92 |
86 class _CastError extends Error implements CastError { | 93 class _CastError extends Error implements CastError { |
87 _CastError._create(this._url, this._line, this._column, this._errorMsg); | 94 _CastError._create(this._url, this._line, this._column, this._errorMsg); |
88 | 95 |
89 // A CastError is allocated by TypeError._throwNew() when dst_name equals | 96 // A CastError is allocated by TypeError._throwNew() when dst_name equals |
90 // Symbols::InTypeCast(). | 97 // Symbols::InTypeCast(). |
91 | 98 |
92 String toString() => _errorMsg; | 99 String toString() => _errorMsg; |
93 | 100 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return msg_buf.toString(); | 363 return msg_buf.toString(); |
357 } | 364 } |
358 } | 365 } |
359 | 366 |
360 | 367 |
361 class _CompileTimeError extends Error { | 368 class _CompileTimeError extends Error { |
362 final String _errorMsg; | 369 final String _errorMsg; |
363 _CompileTimeError(this._errorMsg); | 370 _CompileTimeError(this._errorMsg); |
364 String toString() => _errorMsg; | 371 String toString() => _errorMsg; |
365 } | 372 } |
OLD | NEW |