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

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

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « runtime/lib/double_patch.dart ('k') | runtime/lib/expando_patch.dart » ('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) 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 5 @patch class Error {
6 class Error { 6 @patch static String _objectToString(Object object) {
7 @patch
8 static String _objectToString(Object object) {
9 return Object._toString(object); 7 return Object._toString(object);
10 } 8 }
11 9
12 @patch 10 @patch static String _stringToSafeString(String string) {
13 static String _stringToSafeString(String string) {
14 return JSON.encode(string); 11 return JSON.encode(string);
15 } 12 }
16 13
17 @patch 14 @patch StackTrace get stackTrace => _stackTrace;
18 StackTrace get stackTrace => _stackTrace;
19 15
20 StackTrace _stackTrace; 16 StackTrace _stackTrace;
21 } 17 }
22 18
23 class _AssertionError extends Error implements AssertionError { 19 class _AssertionError extends Error implements AssertionError {
24 _AssertionError._create( 20 _AssertionError._create(
25 this._failedAssertion, this._url, this._line, this._column, this.message); 21 this._failedAssertion, this._url, this._line, this._column,
22 this.message);
23
26 24
27 // AssertionError_throwNew in errors.cc fishes the assertion source code 25 // AssertionError_throwNew in errors.cc fishes the assertion source code
28 // out of the script. It expects a Dart stack frame from class 26 // out of the script. It expects a Dart stack frame from class
29 // _AssertionError. Thus we need a Dart stub that calls the native code. 27 // _AssertionError. Thus we need a Dart stub that calls the native code.
30 static _throwNew(int assertionStart, int assertionEnd, Object message) { 28 static _throwNew(int assertionStart, int assertionEnd, Object message) {
31 _doThrowNew(assertionStart, assertionEnd, message); 29 _doThrowNew(assertionStart, assertionEnd, message);
32 } 30 }
33 31
34 static _doThrowNew(int assertionStart, int assertionEnd, Object message) 32 static _doThrowNew(int assertionStart, int assertionEnd, Object message)
35 native "AssertionError_throwNew"; 33 native "AssertionError_throwNew";
36 34
37 static _evaluateAssertion(condition) { 35 static _evaluateAssertion(condition) {
38 if (identical(condition, true) || identical(condition, false)) { 36 if (identical(condition, true) || identical(condition, false)) {
39 return condition; 37 return condition;
40 } 38 }
41 if (condition is _Closure) { 39 if (condition is _Closure) {
42 return condition(); 40 return condition();
43 } 41 }
44 if (condition is Function) { 42 if (condition is Function) {
45 condition = condition(); 43 condition = condition();
(...skipping 13 matching lines...) Expand all
59 return "'$_failedAssertion': $_messageString"; 57 return "'$_failedAssertion': $_messageString";
60 } 58 }
61 var columnInfo = ""; 59 var columnInfo = "";
62 if (_column > 0) { 60 if (_column > 0) {
63 // Only add column information if it is valid. 61 // Only add column information if it is valid.
64 columnInfo = " pos $_column"; 62 columnInfo = " pos $_column";
65 } 63 }
66 return "'$_url': Failed assertion: line $_line$columnInfo: " 64 return "'$_url': Failed assertion: line $_line$columnInfo: "
67 "'$_failedAssertion': $_messageString"; 65 "'$_failedAssertion': $_messageString";
68 } 66 }
69
70 final String _failedAssertion; 67 final String _failedAssertion;
71 final String _url; 68 final String _url;
72 final int _line; 69 final int _line;
73 final int _column; 70 final int _column;
74 final Object message; 71 final Object message;
75 } 72 }
76 73
77 class _TypeError extends _AssertionError implements TypeError { 74 class _TypeError extends _AssertionError implements TypeError {
78 _TypeError._create(String url, int line, int column, String errorMsg) 75 _TypeError._create(String url, int line, int column, String errorMsg)
79 : super._create("is assignable", url, line, column, errorMsg); 76 : super._create("is assignable", url, line, column, errorMsg);
80 77
81 static _throwNew(int location, Object src_value, _Type dst_type, 78 static _throwNew(int location,
82 String dst_name, String bound_error_msg) native "TypeError_throwNew"; 79 Object src_value,
80 _Type dst_type,
81 String dst_name,
82 String bound_error_msg)
83 native "TypeError_throwNew";
83 84
84 static _throwNewIfNotLoaded( 85 static _throwNewIfNotLoaded(_LibraryPrefix prefix,
85 _LibraryPrefix prefix, 86 int location,
86 int location, 87 Object src_value,
87 Object src_value, 88 _Type dst_type,
88 _Type dst_type, 89 String dst_name,
89 String dst_name, 90 String bound_error_msg) {
90 String bound_error_msg) {
91 if (!prefix.isLoaded()) { 91 if (!prefix.isLoaded()) {
92 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg); 92 _throwNew(location, src_value, dst_type, dst_name, bound_error_msg);
93 } 93 }
94 } 94 }
95 95
96 String toString() => super.message; 96 String toString() => super.message;
97 } 97 }
98 98
99 class _CastError extends Error implements CastError { 99 class _CastError extends Error implements CastError {
100 _CastError._create(this._url, this._line, this._column, this._errorMsg); 100 _CastError._create(this._url, this._line, this._column, this._errorMsg);
101 101
102 // A CastError is allocated by TypeError._throwNew() when dst_name equals 102 // A CastError is allocated by TypeError._throwNew() when dst_name equals
103 // Symbols::InTypeCast(). 103 // Symbols::InTypeCast().
104 104
105 String toString() => _errorMsg; 105 String toString() => _errorMsg;
106 106
107 // Fields _url, _line, and _column are only used for debugging purposes. 107 // Fields _url, _line, and _column are only used for debugging purposes.
108 final String _url; 108 final String _url;
109 final int _line; 109 final int _line;
110 final int _column; 110 final int _column;
111 final String _errorMsg; 111 final String _errorMsg;
112 } 112 }
113 113
114 @patch 114 @patch class FallThroughError {
115 class FallThroughError {
116 FallThroughError._create(this._url, this._line); 115 FallThroughError._create(this._url, this._line);
117 116
118 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew"; 117 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew";
119 118
120 @patch 119 @patch
121 String toString() { 120 String toString() {
122 return "'$_url': Switch case fall-through at line $_line."; 121 return "'$_url': Switch case fall-through at line $_line.";
123 } 122 }
124 123
125 // These new fields cannot be declared final, because a constructor exists 124 // These new fields cannot be declared final, because a constructor exists
126 // in the original version of this patched class. 125 // in the original version of this patched class.
127 String _url; 126 String _url;
128 int _line; 127 int _line;
129 } 128 }
130 129
131 class _InternalError { 130 class _InternalError {
132 const _InternalError(this._msg); 131 const _InternalError(this._msg);
133 String toString() => "InternalError: '${_msg}'"; 132 String toString() => "InternalError: '${_msg}'";
134 final String _msg; 133 final String _msg;
135 } 134 }
136 135
137 @patch 136 @patch class UnsupportedError {
138 class UnsupportedError {
139 static _throwNew(String msg) { 137 static _throwNew(String msg) {
140 throw new UnsupportedError(msg); 138 throw new UnsupportedError(msg);
141 } 139 }
142 } 140 }
143 141
144 @patch 142 @patch class CyclicInitializationError {
145 class CyclicInitializationError {
146 static _throwNew(String variableName) { 143 static _throwNew(String variableName) {
147 throw new CyclicInitializationError(variableName); 144 throw new CyclicInitializationError(variableName);
148 } 145 }
149 } 146 }
150 147
151 @patch 148 @patch class AbstractClassInstantiationError {
152 class AbstractClassInstantiationError {
153 AbstractClassInstantiationError._create( 149 AbstractClassInstantiationError._create(
154 this._className, this._url, this._line); 150 this._className, this._url, this._line);
155 151
156 static _throwNew(int case_clause_pos, String className) 152 static _throwNew(int case_clause_pos, String className)
157 native "AbstractClassInstantiationError_throwNew"; 153 native "AbstractClassInstantiationError_throwNew";
158 154
159 @patch 155 @patch String toString() {
160 String toString() {
161 return "Cannot instantiate abstract class $_className: " 156 return "Cannot instantiate abstract class $_className: "
162 "_url '$_url' line $_line"; 157 "_url '$_url' line $_line";
163 } 158 }
164 159
165 // These new fields cannot be declared final, because a constructor exists 160 // These new fields cannot be declared final, because a constructor exists
166 // in the original version of this patched class. 161 // in the original version of this patched class.
167 String _url; 162 String _url;
168 int _line; 163 int _line;
169 } 164 }
170 165
171 @patch 166 @patch class NoSuchMethodError {
172 class NoSuchMethodError {
173 // The compiler emits a call to _throwNew when it cannot resolve a static 167 // The compiler emits a call to _throwNew when it cannot resolve a static
174 // method at compile time. The receiver is actually the literal class of the 168 // method at compile time. The receiver is actually the literal class of the
175 // unresolved method. 169 // unresolved method.
176 static void _throwNew(Object receiver, String memberName, int invocation_type, 170 static void _throwNew(Object receiver,
177 List arguments, List argumentNames, List existingArgumentNames) { 171 String memberName,
172 int invocation_type,
173 List arguments,
174 List argumentNames,
175 List existingArgumentNames) {
178 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length; 176 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length;
179 int numPositionalArguments = arguments == null ? 0 : arguments.length; 177 int numPositionalArguments = arguments == null ? 0 : arguments.length;
180 numPositionalArguments -= numNamedArguments; 178 numPositionalArguments -= numNamedArguments;
181 List positionalArguments; 179 List positionalArguments;
182 if (numPositionalArguments > 0) { 180 if (numPositionalArguments > 0) {
183 // TODO(srdjan): Unresolvable static methods sometimes do not provide the 181 // TODO(srdjan): Unresolvable static methods sometimes do not provide the
184 // arguments, because the arguments are evaluated but not passed to the 182 // arguments, because the arguments are evaluated but not passed to the
185 // throwing stub (see EffectGraphVisitor::BuildThrowNoSuchMethodError and 183 // throwing stub (see EffectGraphVisitor::BuildThrowNoSuchMethodError and
186 // Parser::ThrowNoSuchMethodError)). There is no way to distinguish the 184 // Parser::ThrowNoSuchMethodError)). There is no way to distinguish the
187 // case of no arguments from the case of the arguments not being passed 185 // case of no arguments from the case of the arguments not being passed
188 // in here, though. See https://github.com/dart-lang/sdk/issues/27572 186 // in here, though. See https://github.com/dart-lang/sdk/issues/27572
189 positionalArguments = arguments.sublist(0, numPositionalArguments); 187 positionalArguments = arguments.sublist(0, numPositionalArguments);
190 } 188 }
191 Map<Symbol, dynamic> namedArguments = new Map<Symbol, dynamic>(); 189 Map<Symbol, dynamic> namedArguments = new Map<Symbol, dynamic>();
192 for (int i = 0; i < numNamedArguments; i++) { 190 for (int i = 0; i < numNamedArguments; i++) {
193 var arg_value = arguments[numPositionalArguments + i]; 191 var arg_value = arguments[numPositionalArguments + i];
194 namedArguments[new Symbol(argumentNames[i])] = arg_value; 192 namedArguments[new Symbol(argumentNames[i])] = arg_value;
195 } 193 }
196 throw new NoSuchMethodError._withType( 194 throw new NoSuchMethodError._withType(receiver,
197 receiver, 195 new Symbol(memberName),
198 new Symbol(memberName), 196 invocation_type,
199 invocation_type, 197 positionalArguments,
200 positionalArguments, 198 namedArguments,
201 namedArguments, 199 existingArgumentNames);
202 existingArgumentNames);
203 } 200 }
204 201
205 static void _throwNewIfNotLoaded( 202 static void _throwNewIfNotLoaded(_LibraryPrefix prefix,
206 _LibraryPrefix prefix, 203 Object receiver,
207 Object receiver, 204 String memberName,
208 String memberName, 205 int invocation_type,
209 int invocation_type, 206 List arguments,
210 List arguments, 207 List argumentNames,
211 List argumentNames, 208 List existingArgumentNames) {
212 List existingArgumentNames) {
213 if (!prefix.isLoaded()) { 209 if (!prefix.isLoaded()) {
214 _throwNew(receiver, memberName, invocation_type, arguments, argumentNames, 210 _throwNew(receiver, memberName, invocation_type, arguments,
215 existingArgumentNames); 211 argumentNames, existingArgumentNames);
216 } 212 }
217 } 213 }
218 214
219 // Remember the type from the invocation mirror or static compilation 215 // Remember the type from the invocation mirror or static compilation
220 // analysis when thrown directly with _throwNew. A negative value means 216 // analysis when thrown directly with _throwNew. A negative value means
221 // that no information is available. 217 // that no information is available.
222 final int _invocation_type; 218 final int _invocation_type;
223 219
224 @patch 220 @patch
225 NoSuchMethodError(Object receiver, Symbol memberName, 221 NoSuchMethodError(Object receiver,
226 List positionalArguments, Map<Symbol, dynamic> namedArguments, 222 Symbol memberName,
227 [List existingArgumentNames = null]) 223 List positionalArguments,
224 Map<Symbol, dynamic> namedArguments,
225 [List existingArgumentNames = null])
228 : _receiver = receiver, 226 : _receiver = receiver,
229 _memberName = memberName, 227 _memberName = memberName,
230 _arguments = positionalArguments, 228 _arguments = positionalArguments,
231 _namedArguments = namedArguments, 229 _namedArguments = namedArguments,
232 _existingArgumentNames = existingArgumentNames, 230 _existingArgumentNames = existingArgumentNames,
233 _invocation_type = -1; 231 _invocation_type = -1;
234 232
235 // This constructor seems to be called with either strings or 233 // This constructor seems to be called with either strings or
236 // values read from another NoSuchMethodError. 234 // values read from another NoSuchMethodError.
237 NoSuchMethodError._withType( 235 NoSuchMethodError._withType(this._receiver,
238 this._receiver, 236 /*String|Symbol*/ memberName,
239 /*String|Symbol*/ memberName, 237 this._invocation_type,
240 this._invocation_type, 238 this._arguments,
241 this._arguments, 239 Map<dynamic, dynamic> namedArguments,
242 Map<dynamic, dynamic> namedArguments, 240 [List existingArgumentNames = null])
243 [List existingArgumentNames = null])
244 : this._memberName = 241 : this._memberName =
245 (memberName is String) ? new Symbol(memberName) : memberName, 242 (memberName is String) ? new Symbol(memberName) : memberName,
246 this._namedArguments = (namedArguments == null) 243 this._namedArguments =
247 ? null 244 (namedArguments == null)
248 : new Map<Symbol, dynamic>.fromIterable(namedArguments.keys, 245 ? null
249 key: (k) => (k is String) ? new Symbol(k) : k, 246 : new Map<Symbol, dynamic>.fromIterable(
250 value: (k) => namedArguments[k]), 247 namedArguments.keys,
248 key: (k) => (k is String) ? new Symbol(k) : k,
249 value: (k) => namedArguments[k]),
251 this._existingArgumentNames = existingArgumentNames; 250 this._existingArgumentNames = existingArgumentNames;
252 251
253 @patch 252 @patch String toString() {
254 String toString() {
255 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) & 253 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) &
256 _InvocationMirror._CALL_MASK; 254 _InvocationMirror._CALL_MASK;
257 var type = _invocation_type & _InvocationMirror._TYPE_MASK; 255 var type = _invocation_type & _InvocationMirror._TYPE_MASK;
258 String memberName = (_memberName == null) 256 String memberName = (_memberName == null) ? "" :
259 ? "" 257 internal.Symbol.getUnmangledName(_memberName);
260 : internal.Symbol.getUnmangledName(_memberName);
261 258
262 if (type == _InvocationMirror._LOCAL_VAR) { 259 if (type == _InvocationMirror._LOCAL_VAR) {
263 return "NoSuchMethodError: Cannot assign to final variable '$memberName'"; 260 return "NoSuchMethodError: Cannot assign to final variable '$memberName'";
264 } 261 }
265 262
266 StringBuffer arguments = new StringBuffer(); 263 StringBuffer arguments = new StringBuffer();
267 int argumentCount = 0; 264 int argumentCount = 0;
268 if (_arguments != null) { 265 if (_arguments != null) {
269 for (; argumentCount < _arguments.length; argumentCount++) { 266 for (; argumentCount < _arguments.length; argumentCount++) {
270 if (argumentCount > 0) { 267 if (argumentCount > 0) {
(...skipping 11 matching lines...) Expand all
282 arguments.write(": "); 279 arguments.write(": ");
283 arguments.write(Error.safeToString(value)); 280 arguments.write(Error.safeToString(value));
284 argumentCount++; 281 argumentCount++;
285 }); 282 });
286 } 283 }
287 bool args_mismatch = _existingArgumentNames != null; 284 bool args_mismatch = _existingArgumentNames != null;
288 String args_message = args_mismatch ? " with matching arguments" : ""; 285 String args_message = args_mismatch ? " with matching arguments" : "";
289 286
290 String type_str; 287 String type_str;
291 if (type >= 0 && type < 5) { 288 if (type >= 0 && type < 5) {
292 type_str = (const [ 289 type_str = (const ["method", "getter", "setter", "getter or setter",
293 "method", 290 "variable"])[type];
294 "getter",
295 "setter",
296 "getter or setter",
297 "variable"
298 ])[type];
299 } 291 }
300 292
301 StringBuffer msg_buf = new StringBuffer("NoSuchMethodError: "); 293 StringBuffer msg_buf = new StringBuffer("NoSuchMethodError: ");
302 bool is_type_call = false; 294 bool is_type_call = false;
303 switch (level) { 295 switch (level) {
304 case _InvocationMirror._DYNAMIC: 296 case _InvocationMirror._DYNAMIC: {
305 { 297 if (_receiver == null) {
306 if (_receiver == null) { 298 if (args_mismatch) {
307 if (args_mismatch) { 299 msg_buf.writeln("The null object does not have a $type_str "
308 msg_buf.writeln("The null object does not have a $type_str " 300 "'$memberName'$args_message.");
309 "'$memberName'$args_message.");
310 } else {
311 msg_buf
312 .writeln("The $type_str '$memberName' was called on null.");
313 }
314 } else { 301 } else {
315 if (_receiver is Function) { 302 msg_buf.writeln("The $type_str '$memberName' was called on null.");
316 msg_buf.writeln("Closure call with mismatched arguments: "
317 "function '$memberName'");
318 } else if (_receiver is _Type && memberName == "call") {
319 is_type_call = true;
320 String name = _receiver.toString();
321 msg_buf.writeln("Attempted to use type '$name' as a function. "
322 "Since types do not define a method 'call', this is not "
323 "possible. Did you intend to call the $name constructor and "
324 "forget the 'new' operator?");
325 } else {
326 msg_buf
327 .writeln("Class '${_receiver.runtimeType}' has no instance "
328 "$type_str '$memberName'$args_message.");
329 }
330 } 303 }
331 break; 304 } else {
305 if (_receiver is Function) {
306 msg_buf.writeln("Closure call with mismatched arguments: "
307 "function '$memberName'");
308 } else if (_receiver is _Type && memberName == "call") {
309 is_type_call = true;
310 String name = _receiver.toString();
311 msg_buf.writeln("Attempted to use type '$name' as a function. "
312 "Since types do not define a method 'call', this is not "
313 "possible. Did you intend to call the $name constructor and "
314 "forget the 'new' operator?");
315 } else {
316 msg_buf.writeln("Class '${_receiver.runtimeType}' has no instance "
317 "$type_str '$memberName'$args_message.");
318 }
332 } 319 }
333 case _InvocationMirror._SUPER: 320 break;
334 { 321 }
335 msg_buf.writeln("Super class of class '${_receiver.runtimeType}' has " 322 case _InvocationMirror._SUPER: {
323 msg_buf.writeln("Super class of class '${_receiver.runtimeType}' has "
336 "no instance $type_str '$memberName'$args_message."); 324 "no instance $type_str '$memberName'$args_message.");
337 memberName = "super.$memberName"; 325 memberName = "super.$memberName";
338 break; 326 break;
339 } 327 }
340 case _InvocationMirror._STATIC: 328 case _InvocationMirror._STATIC: {
341 { 329 msg_buf.writeln("No static $type_str '$memberName'$args_message "
342 msg_buf.writeln("No static $type_str '$memberName'$args_message " 330 "declared in class '$_receiver'.");
343 "declared in class '$_receiver'."); 331 break;
344 break; 332 }
345 } 333 case _InvocationMirror._CONSTRUCTOR: {
346 case _InvocationMirror._CONSTRUCTOR: 334 msg_buf.writeln("No constructor '$memberName'$args_message declared "
347 { 335 "in class '$_receiver'.");
348 msg_buf.writeln("No constructor '$memberName'$args_message declared " 336 memberName = "new $memberName";
349 "in class '$_receiver'."); 337 break;
350 memberName = "new $memberName"; 338 }
351 break; 339 case _InvocationMirror._TOP_LEVEL: {
352 } 340 msg_buf.writeln("No top-level $type_str '$memberName'$args_message "
353 case _InvocationMirror._TOP_LEVEL: 341 "declared.");
354 { 342 break;
355 msg_buf.writeln("No top-level $type_str '$memberName'$args_message " 343 }
356 "declared.");
357 break;
358 }
359 } 344 }
360 345
361 if (level == _InvocationMirror._TOP_LEVEL) { 346 if (level == _InvocationMirror._TOP_LEVEL) {
362 msg_buf.writeln("Receiver: top-level"); 347 msg_buf.writeln("Receiver: top-level");
363 } else { 348 } else {
364 msg_buf.writeln("Receiver: ${Error.safeToString(_receiver)}"); 349 msg_buf.writeln("Receiver: ${Error.safeToString(_receiver)}");
365 } 350 }
366 351
367 if (type == _InvocationMirror._METHOD) { 352 if (type == _InvocationMirror._METHOD) {
368 String m = is_type_call ? "$_receiver" : "$memberName"; 353 String m = is_type_call ? "$_receiver" : "$memberName";
(...skipping 14 matching lines...) Expand all
383 } 368 }
384 formalParameters.write(_existingArgumentNames[i]); 369 formalParameters.write(_existingArgumentNames[i]);
385 } 370 }
386 msg_buf.write("\nFound: $memberName($formalParameters)"); 371 msg_buf.write("\nFound: $memberName($formalParameters)");
387 } 372 }
388 373
389 return msg_buf.toString(); 374 return msg_buf.toString();
390 } 375 }
391 } 376 }
392 377
378
393 class _CompileTimeError extends Error { 379 class _CompileTimeError extends Error {
394 final String _errorMsg; 380 final String _errorMsg;
395 _CompileTimeError(this._errorMsg); 381 _CompileTimeError(this._errorMsg);
396 String toString() => _errorMsg; 382 String toString() => _errorMsg;
397 } 383 }
OLDNEW
« no previous file with comments | « runtime/lib/double_patch.dart ('k') | runtime/lib/expando_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698