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 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 for (int i = 0; i < numNamedArguments; i++) { | 30 for (int i = 0; i < numNamedArguments; i++) { |
31 var arg_value = arguments[numPositionalArguments + i]; | 31 var arg_value = arguments[numPositionalArguments + i]; |
32 namedArguments[argumentNames[i]] = arg_value; | 32 namedArguments[argumentNames[i]] = arg_value; |
33 } | 33 } |
34 throw new NoSuchMethodError(receiver, | 34 throw new NoSuchMethodError(receiver, |
35 memberName, | 35 memberName, |
36 positionalArguments, | 36 positionalArguments, |
37 namedArguments, | 37 namedArguments, |
38 existingArgumentNames); | 38 existingArgumentNames); |
39 } | 39 } |
| 40 |
| 41 const NoSuchMethodError(Object this._receiver, |
| 42 String this._memberName, |
| 43 List this._arguments, |
| 44 Map<String,dynamic> this._namedArguments, |
| 45 [List existingArgumentNames = null]) |
| 46 : this._existingArgumentNames = existingArgumentNames; |
| 47 |
| 48 /* patch */ String toString() { |
| 49 StringBuffer actual_buf = new StringBuffer(); |
| 50 int i = 0; |
| 51 if (_arguments != null) { |
| 52 for (; i < _arguments.length; i++) { |
| 53 if (i > 0) { |
| 54 actual_buf.add(", "); |
| 55 } |
| 56 actual_buf.add(Error.safeToString(_arguments[i])); |
| 57 } |
| 58 } |
| 59 if (_namedArguments != null) { |
| 60 _namedArguments.forEach((String key, var value) { |
| 61 if (i > 0) { |
| 62 actual_buf.add(", "); |
| 63 } |
| 64 actual_buf.add(key); |
| 65 actual_buf.add(": "); |
| 66 actual_buf.add(Error.safeToString(value)); |
| 67 i++; |
| 68 }); |
| 69 } |
| 70 StringBuffer msg_buf = new StringBuffer(); |
| 71 if (_existingArgumentNames == null) { |
| 72 msg_buf.add( |
| 73 "NoSuchMethodError : method not found: '$_memberName'\n" |
| 74 "Receiver: ${Error.safeToString(_receiver)}\n" |
| 75 "Arguments: [$actual_buf]"); |
| 76 } else { |
| 77 String actualParameters = actual_buf.toString(); |
| 78 StringBuffer formal_buf = new StringBuffer(); |
| 79 for (int i = 0; i < _existingArgumentNames.length; i++) { |
| 80 if (i > 0) { |
| 81 formal_buf.add(", "); |
| 82 } |
| 83 formal_buf.add(_existingArgumentNames[i]); |
| 84 } |
| 85 String formalParameters = formal_buf.toString(); |
| 86 msg_buf.add( |
| 87 "NoSuchMethodError: incorrect number of arguments passed to " |
| 88 "method named '$_memberName'\n" |
| 89 "Receiver: ${Error.safeToString(_receiver)}\n" |
| 90 "Tried calling: $_memberName($actualParameters)\n" |
| 91 "Found: $_memberName($formalParameters)"); |
| 92 } |
| 93 return msg_buf.toString(); |
| 94 } |
40 } | 95 } |
OLD | NEW |