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 class Error { | 5 class Error { |
6 const Error(); | 6 const Error(); |
7 } | 7 } |
8 | 8 |
9 /** | 9 /** |
10 * Error thrown by the runtime system when an assert statement fails. | 10 * Error thrown by the runtime system when an assert statement fails. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 String toString() => "Cannot instantiate abstract class: '$_className'"; | 68 String toString() => "Cannot instantiate abstract class: '$_className'"; |
69 } | 69 } |
70 | 70 |
71 /** | 71 /** |
72 * Error thrown by the default implementation of [:noSuchMethod:] on [Object]. | 72 * Error thrown by the default implementation of [:noSuchMethod:] on [Object]. |
73 */ | 73 */ |
74 class NoSuchMethodError implements Error { | 74 class NoSuchMethodError implements Error { |
75 final Object _receiver; | 75 final Object _receiver; |
76 final String _functionName; | 76 final String _functionName; |
77 final List _arguments; | 77 final List _arguments; |
| 78 final Map<String,Dynamic> _namedArguments; |
78 final List _existingArgumentNames; | 79 final List _existingArgumentNames; |
79 | 80 |
80 /** | 81 /** |
81 * Create a [NoSuchMethodError] corresponding to a failed method call. | 82 * Create a [NoSuchMethodError] corresponding to a failed method call. |
82 * | 83 * |
83 * The first parameter is the receiver of the method call. | 84 * The first parameter is the receiver of the method call. |
84 * The second parameter is the name of the called method. | 85 * The second parameter is the name of the called method. |
85 * The third parameter is the positional arguments that the method was | 86 * The third parameter is the positional arguments that the method was |
86 * called with. | 87 * called with. |
87 * The optional [exisitingArgumentNames] is the expected parameters of a | 88 * The optional [exisitingArgumentNames] is the expected parameters of a |
88 * method with the same name on the receiver, if available. This is | 89 * method with the same name on the receiver, if available. This is |
89 * the method that would have been called if the parameters had matched. | 90 * the method that would have been called if the parameters had matched. |
90 * | 91 * |
91 * TODO(lrn): This will be rewritten to use mirrors when they are available. | 92 * TODO(lrn): This will be rewritten to use mirrors when they are available. |
92 */ | 93 */ |
93 const NoSuchMethodError(Object this._receiver, | 94 const NoSuchMethodError(Object this._receiver, |
94 String this._functionName, | 95 String this._functionName, |
95 List this._arguments, | 96 List this._arguments, |
| 97 Map<String,Dynamic> this._namedArguments, |
96 [List existingArgumentNames = null]) | 98 [List existingArgumentNames = null]) |
97 : this._existingArgumentNames = existingArgumentNames; | 99 : this._existingArgumentNames = existingArgumentNames; |
98 | 100 |
99 String toString() { | 101 String toString() { |
100 StringBuffer sb = new StringBuffer(); | 102 StringBuffer sb = new StringBuffer(); |
101 for (int i = 0; i < _arguments.length; i++) { | 103 int i = 0; |
102 if (i > 0) { | 104 if (_arguments != null) { |
103 sb.add(", "); | 105 for (; i < _arguments.length; i++) { |
| 106 if (i > 0) { |
| 107 sb.add(", "); |
| 108 } |
| 109 sb.add(safeToString(_arguments[i])); |
104 } | 110 } |
105 sb.add(safeToString(_arguments[i])); | 111 } |
| 112 if (_namedArguments != null) { |
| 113 _namedArguments.forEach((String key, var value) { |
| 114 if (i > 0) { |
| 115 sb.add(", "); |
| 116 } |
| 117 sb.add(key); |
| 118 sb.add(": "); |
| 119 sb.add(safeToString(value)); |
| 120 i++; |
| 121 }); |
106 } | 122 } |
107 if (_existingArgumentNames === null) { | 123 if (_existingArgumentNames === null) { |
108 return "NoSuchMethodError : method not found: '$_functionName'\n" | 124 return "NoSuchMethodError : method not found: '$_functionName'\n" |
109 "Receiver: ${safeToString(_receiver)}\n" | 125 "Receiver: ${safeToString(_receiver)}\n" |
110 "Arguments: [$sb]"; | 126 "Arguments: [$sb]"; |
111 } else { | 127 } else { |
112 String actualParameters = sb.toString(); | 128 String actualParameters = sb.toString(); |
113 sb = new StringBuffer(); | 129 sb = new StringBuffer(); |
114 for (int i = 0; i < _existingArgumentNames.length; i++) { | 130 for (int i = 0; i < _existingArgumentNames.length; i++) { |
115 if (i > 0) { | 131 if (i > 0) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 190 |
175 class OutOfMemoryError implements Error { | 191 class OutOfMemoryError implements Error { |
176 const OutOfMemoryError(); | 192 const OutOfMemoryError(); |
177 String toString() => "Out of Memory"; | 193 String toString() => "Out of Memory"; |
178 } | 194 } |
179 | 195 |
180 class StackOverflowError implements Error { | 196 class StackOverflowError implements Error { |
181 const StackOverflowError(); | 197 const StackOverflowError(); |
182 String toString() => "Stack Overflow"; | 198 String toString() => "Stack Overflow"; |
183 } | 199 } |
OLD | NEW |