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

Side by Side Diff: runtime/lib/errors_patch.dart

Issue 2574003003: Add optional message argument to assert statements in the VM. (Closed)
Patch Set: Created 4 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
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 @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 static _throwNew(int assertionStart, int assertionEnd, Object message) {
25 _doThrowNew(assertionStart, assertionEnd, message);
26 }
27
28 static _doThrowNew(int assertionStart, int assertionEnd, Object message)
regis 2016/12/13 23:26:51 Why do we need this new function _doThrowNew calle
hausner 2016/12/14 16:59:35 Eliminated _doThrowNew
24 native "AssertionError_throwNew"; 29 native "AssertionError_throwNew";
25 30
26 static void _checkAssertion(condition, int start, int end) { 31 static _checkAssertion(condition) {
regis 2016/12/13 23:26:51 This is not checking the assertion anymore (no thr
hausner 2016/12/14 16:59:35 Done.
27 if (condition is Function) { 32 if (condition is Function) {
28 condition = condition(); 33 condition = condition();
29 } 34 }
30 if (!condition) { 35 return condition;
31 _throwNew(start, end);
32 }
33 } 36 }
34 37
35 static void _checkConstAssertion(bool condition, int start, int end) { 38 String get _messageString {
36 if (!condition) { 39 if (message == null) return "is not true.";
37 _throwNew(start, end); 40 if (message is String) return message;
38 } 41 return Error.safeToString(message);
39 } 42 }
40 43
41 String toString() { 44 String toString() {
42 if (_url == null) { 45 if (_url == null) {
43 return _failedAssertion; 46 if (message == null) return _failedAssertion;
47 return "'$_failedAssertion': $_messageString";
44 } 48 }
45 var columnInfo = ""; 49 var columnInfo = "";
46 if (_column > 0) { 50 if (_column > 0) {
47 // Only add column information if it is valid. 51 // Only add column information if it is valid.
48 columnInfo = " pos $_column"; 52 columnInfo = " pos $_column";
49 } 53 }
50 return "'$_url': Failed assertion: line $_line$columnInfo: " 54 return "'$_url': Failed assertion: line $_line$columnInfo: "
51 "'$_failedAssertion' is not true."; 55 "'$_failedAssertion': $_messageString";
52 } 56 }
53 final String _failedAssertion; 57 final String _failedAssertion;
54 final String _url; 58 final String _url;
55 final int _line; 59 final int _line;
56 final int _column; 60 final int _column;
61 final Object message;
57 } 62 }
58 63
59 class _TypeError extends _AssertionError implements TypeError { 64 class _TypeError extends _AssertionError implements TypeError {
60 _TypeError._create(String url, int line, int column, this._errorMsg) 65 _TypeError._create(String url, int line, int column, String errorMsg)
61 : super._create("is assignable", url, line, column); 66 : super._create("is assignable", url, line, column, errorMsg);
62 67
63 static _throwNew(int location, 68 static _throwNew(int location,
64 Object src_value, 69 Object src_value,
65 _Type dst_type, 70 _Type dst_type,
66 String dst_name, 71 String dst_name,
67 String bound_error_msg) 72 String bound_error_msg)
68 native "TypeError_throwNew"; 73 native "TypeError_throwNew";
69 74
70 static _throwNewIfNotLoaded(_LibraryPrefix prefix, 75 static _throwNewIfNotLoaded(_LibraryPrefix prefix,
71 int location, 76 int location,
72 Object src_value, 77 Object src_value,
73 _Type dst_type, 78 _Type dst_type,
74 String dst_name, 79 String dst_name,
75 String bound_error_msg) { 80 String bound_error_msg) {
76 if (!prefix.isLoaded()) { 81 if (!prefix.isLoaded()) {
77 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); 82 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg);
78 } 83 }
79 } 84 }
80 85
81 String toString() => _errorMsg; 86 String toString() => super.message;
82
83 final String _errorMsg;
84 } 87 }
85 88
86 class _CastError extends Error implements CastError { 89 class _CastError extends Error implements CastError {
87 _CastError._create(this._url, this._line, this._column, this._errorMsg); 90 _CastError._create(this._url, this._line, this._column, this._errorMsg);
88 91
89 // A CastError is allocated by TypeError._throwNew() when dst_name equals 92 // A CastError is allocated by TypeError._throwNew() when dst_name equals
90 // Symbols::InTypeCast(). 93 // Symbols::InTypeCast().
91 94
92 String toString() => _errorMsg; 95 String toString() => _errorMsg;
93 96
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return msg_buf.toString(); 359 return msg_buf.toString();
357 } 360 }
358 } 361 }
359 362
360 363
361 class _CompileTimeError extends Error { 364 class _CompileTimeError extends Error {
362 final String _errorMsg; 365 final String _errorMsg;
363 _CompileTimeError(this._errorMsg); 366 _CompileTimeError(this._errorMsg);
364 String toString() => _errorMsg; 367 String toString() => _errorMsg;
365 } 368 }
OLDNEW
« no previous file with comments | « runtime/lib/errors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698