| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 final String _className; | 66 final String _className; |
| 67 const AbstractClassInstantiationError(String this._className); | 67 const AbstractClassInstantiationError(String this._className); |
| 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 _memberName; | 76 final String _functionName; |
| 77 final List _arguments; | 77 final List _arguments; |
| 78 final Map<String,Dynamic> _namedArguments; | |
| 79 final List _existingArgumentNames; | 78 final List _existingArgumentNames; |
| 80 | 79 |
| 81 /** | 80 /** |
| 82 * Create a [NoSuchMethodError] corresponding to a failed method call. | 81 * Create a [NoSuchMethodError] corresponding to a failed method call. |
| 83 * | 82 * |
| 84 * The first parameter to this constructor is the receiver of the method call. | 83 * The first parameter is the receiver of the method call. |
| 85 * That is, the object on which the method was attempted called. | 84 * The second parameter is the name of the called method. |
| 86 * The second parameter is the name of the called method or accessor. | 85 * The third parameter is the positional arguments that the method was |
| 87 * The third parameter is a list of the positional arguments that the method | 86 * called with. |
| 88 * was called with. | |
| 89 * The fourth parameter is a map from [String] names to the values of named | |
| 90 * arguments that the method was called with. | |
| 91 * The optional [exisitingArgumentNames] is the expected parameters of a | 87 * The optional [exisitingArgumentNames] is the expected parameters of a |
| 92 * method with the same name on the receiver, if available. This is | 88 * method with the same name on the receiver, if available. This is |
| 93 * the method that would have been called if the parameters had matched. | 89 * the method that would have been called if the parameters had matched. |
| 90 * |
| 91 * TODO(lrn): This will be rewritten to use mirrors when they are available. |
| 94 */ | 92 */ |
| 95 const NoSuchMethodError(Object this._receiver, | 93 const NoSuchMethodError(Object this._receiver, |
| 96 String this._memberName, | 94 String this._functionName, |
| 97 List this._arguments, | 95 List this._arguments, |
| 98 Map<String,Dynamic> this._namedArguments, | |
| 99 [List existingArgumentNames = null]) | 96 [List existingArgumentNames = null]) |
| 100 : this._existingArgumentNames = existingArgumentNames; | 97 : this._existingArgumentNames = existingArgumentNames; |
| 101 | 98 |
| 102 String toString() { | 99 String toString() { |
| 103 StringBuffer sb = new StringBuffer(); | 100 StringBuffer sb = new StringBuffer(); |
| 104 int i = 0; | 101 for (int i = 0; i < _arguments.length; i++) { |
| 105 if (_arguments != null) { | 102 if (i > 0) { |
| 106 for (; i < _arguments.length; i++) { | 103 sb.add(", "); |
| 107 if (i > 0) { | |
| 108 sb.add(", "); | |
| 109 } | |
| 110 sb.add(safeToString(_arguments[i])); | |
| 111 } | 104 } |
| 112 } | 105 sb.add(safeToString(_arguments[i])); |
| 113 if (_namedArguments != null) { | |
| 114 _namedArguments.forEach((String key, var value) { | |
| 115 if (i > 0) { | |
| 116 sb.add(", "); | |
| 117 } | |
| 118 sb.add(key); | |
| 119 sb.add(": "); | |
| 120 sb.add(safeToString(value)); | |
| 121 i++; | |
| 122 }); | |
| 123 } | 106 } |
| 124 if (_existingArgumentNames === null) { | 107 if (_existingArgumentNames === null) { |
| 125 return "NoSuchMethodError : method not found: '$_memberName'\n" | 108 return "NoSuchMethodError : method not found: '$_functionName'\n" |
| 126 "Receiver: ${safeToString(_receiver)}\n" | 109 "Receiver: ${safeToString(_receiver)}\n" |
| 127 "Arguments: [$sb]"; | 110 "Arguments: [$sb]"; |
| 128 } else { | 111 } else { |
| 129 String actualParameters = sb.toString(); | 112 String actualParameters = sb.toString(); |
| 130 sb = new StringBuffer(); | 113 sb = new StringBuffer(); |
| 131 for (int i = 0; i < _existingArgumentNames.length; i++) { | 114 for (int i = 0; i < _existingArgumentNames.length; i++) { |
| 132 if (i > 0) { | 115 if (i > 0) { |
| 133 sb.add(", "); | 116 sb.add(", "); |
| 134 } | 117 } |
| 135 sb.add(_existingArgumentNames[i]); | 118 sb.add(_existingArgumentNames[i]); |
| 136 } | 119 } |
| 137 String formalParameters = sb.toString(); | 120 String formalParameters = sb.toString(); |
| 138 return "NoSuchMethodError: incorrect number of arguments passed to " | 121 return "NoSuchMethodError: incorrect number of arguments passed to " |
| 139 "method named '$_memberName'\n" | 122 "method named '$_functionName'\n" |
| 140 "Receiver: ${safeToString(_receiver)}\n" | 123 "Receiver: ${safeToString(_receiver)}\n" |
| 141 "Tried calling: $_memberName($actualParameters)\n" | 124 "Tried calling: $_functionName($actualParameters)\n" |
| 142 "Found: $_memberName($formalParameters)"; | 125 "Found: $_functionName($formalParameters)"; |
| 143 } | 126 } |
| 144 } | 127 } |
| 145 | 128 |
| 146 static String safeToString(Object object) { | 129 static String safeToString(Object object) { |
| 147 if (object is int || object is double || object is bool || null == object) { | 130 if (object is int || object is double || object is bool || null == object) { |
| 148 return object.toString(); | 131 return object.toString(); |
| 149 } | 132 } |
| 150 if (object is String) { | 133 if (object is String) { |
| 151 // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed. | 134 // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed. |
| 152 const backslash = '\\'; | 135 const backslash = '\\'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 174 |
| 192 class OutOfMemoryError implements Error { | 175 class OutOfMemoryError implements Error { |
| 193 const OutOfMemoryError(); | 176 const OutOfMemoryError(); |
| 194 String toString() => "Out of Memory"; | 177 String toString() => "Out of Memory"; |
| 195 } | 178 } |
| 196 | 179 |
| 197 class StackOverflowError implements Error { | 180 class StackOverflowError implements Error { |
| 198 const StackOverflowError(); | 181 const StackOverflowError(); |
| 199 String toString() => "Stack Overflow"; | 182 String toString() => "Stack Overflow"; |
| 200 } | 183 } |
| OLD | NEW |