| 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 /* patch */ StackTrace get stackTrace => _stackTrace; | 10 /* patch */ StackTrace get stackTrace => _stackTrace; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (numPositionalArguments == 0) { | 141 if (numPositionalArguments == 0) { |
| 142 // Differ between no arguments specified and 0 arguments. | 142 // Differ between no arguments specified and 0 arguments. |
| 143 // TODO(srdjan): This can currently occur for unresolvable static methods. | 143 // TODO(srdjan): This can currently occur for unresolvable static methods. |
| 144 // In that case, the arguments are evaluated but not passed to the | 144 // In that case, the arguments are evaluated but not passed to the |
| 145 // throwing stub (see EffectGraphVisitor::BuildThrowNoSuchMethodError and | 145 // throwing stub (see EffectGraphVisitor::BuildThrowNoSuchMethodError and |
| 146 // Parser::ThrowNoSuchMethodError)). | 146 // Parser::ThrowNoSuchMethodError)). |
| 147 positionalArguments = argumentNames == null ? null : []; | 147 positionalArguments = argumentNames == null ? null : []; |
| 148 } else { | 148 } else { |
| 149 positionalArguments = arguments.sublist(0, numPositionalArguments); | 149 positionalArguments = arguments.sublist(0, numPositionalArguments); |
| 150 } | 150 } |
| 151 Map<String, dynamic> namedArguments = new Map<String, dynamic>(); | 151 Map<Symbol, dynamic> namedArguments = new Map<Symbol, dynamic>(); |
| 152 for (int i = 0; i < numNamedArguments; i++) { | 152 for (int i = 0; i < numNamedArguments; i++) { |
| 153 var arg_value = arguments[numPositionalArguments + i]; | 153 var arg_value = arguments[numPositionalArguments + i]; |
| 154 namedArguments[argumentNames[i]] = arg_value; | 154 namedArguments[new Symbol(argumentNames[i])] = arg_value; |
| 155 } | 155 } |
| 156 throw new NoSuchMethodError._withType(receiver, | 156 throw new NoSuchMethodError._withType(receiver, |
| 157 memberName, | 157 new Symbol(memberName), |
| 158 invocation_type, | 158 invocation_type, |
| 159 positionalArguments, | 159 positionalArguments, |
| 160 namedArguments, | 160 namedArguments, |
| 161 existingArgumentNames); | 161 existingArgumentNames); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Remember the type from the invocation mirror or static compilation | 164 // Remember the type from the invocation mirror or static compilation |
| 165 // analysis when thrown directly with _throwNew. A negative value means | 165 // analysis when thrown directly with _throwNew. A negative value means |
| 166 // that no information is available. | 166 // that no information is available. |
| 167 final int _invocation_type; | 167 final int _invocation_type; |
| 168 | 168 |
| 169 NoSuchMethodError(Object this._receiver, | 169 NoSuchMethodError(Object this._receiver, |
| 170 String this._memberName, | 170 Symbol this._memberName, |
| 171 List this._arguments, | 171 List this._arguments, |
| 172 Map<String,dynamic> this._namedArguments, | 172 Map<Symbol, dynamic> this._namedArguments, |
| 173 [List existingArgumentNames = null]) | 173 [List existingArgumentNames = null]) |
| 174 : this._existingArgumentNames = existingArgumentNames, | 174 : this._existingArgumentNames = existingArgumentNames, |
| 175 this._invocation_type = -1; | 175 this._invocation_type = -1; |
| 176 | 176 |
| 177 // This constructor seems to be called with either strings or |
| 178 // values read from another NoSuchMethodError. |
| 177 NoSuchMethodError._withType(Object this._receiver, | 179 NoSuchMethodError._withType(Object this._receiver, |
| 178 String this._memberName, | 180 /*String|Symbol*/ memberName, |
| 179 this._invocation_type, | 181 this._invocation_type, |
| 180 List this._arguments, | 182 List this._arguments, |
| 181 Map<String,dynamic> this._namedArguments, | 183 Map<dynamic, dynamic> namedArguments, |
| 182 [List existingArgumentNames = null]) | 184 [List existingArgumentNames = null]) |
| 183 : this._existingArgumentNames = existingArgumentNames; | 185 : this._memberName = |
| 186 (memberName is String) ? new Symbol(memberName) : memberName, |
| 187 this._namedArguments = |
| 188 (namedArguments == null) |
| 189 ? null |
| 190 : new Map<Symbol, dynamic>.fromIterable( |
| 191 namedArguments.keys, |
| 192 key: (k) => (k is String) ? new Symbol(k) : k, |
| 193 value: (k) => namedArguments[k]), |
| 194 this._existingArgumentNames = existingArgumentNames; |
| 184 | 195 |
| 185 | 196 |
| 186 String _developerMessage(args_mismatch) { | 197 String _developerMessage(args_mismatch) { |
| 187 if (_invocation_type < 0) { | 198 if (_invocation_type < 0) { |
| 188 return ""; | 199 return ""; |
| 189 } | 200 } |
| 190 var type = _invocation_type & _InvocationMirror._TYPE_MASK; | 201 var type = _invocation_type & _InvocationMirror._TYPE_MASK; |
| 191 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) & | 202 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) & |
| 192 _InvocationMirror._CALL_MASK; | 203 _InvocationMirror._CALL_MASK; |
| 193 var type_str = | 204 var type_str = |
| 194 (const ["method", "getter", "setter", "getter or setter"])[type]; | 205 (const ["method", "getter", "setter", "getter or setter"])[type]; |
| 195 var args_message = args_mismatch ? " with matching arguments" : ""; | 206 var args_message = args_mismatch ? " with matching arguments" : ""; |
| 196 var msg; | 207 var msg; |
| 208 var memberName = |
| 209 (_memberName == null) ? "" :_collection_dev.Symbol.getName(_memberName); |
| 197 switch (level) { | 210 switch (level) { |
| 198 case _InvocationMirror._DYNAMIC: { | 211 case _InvocationMirror._DYNAMIC: { |
| 199 if (_receiver == null) { | 212 if (_receiver == null) { |
| 200 msg = "The null object does not have a $type_str '$_memberName'" | 213 msg = "The null object does not have a $type_str '$memberName'" |
| 201 "$args_message."; | 214 "$args_message."; |
| 202 } else { | 215 } else { |
| 203 if (_receiver is Function) { | 216 if (_receiver is Function) { |
| 204 msg = "Closure call with mismatched arguments: " | 217 msg = "Closure call with mismatched arguments: " |
| 205 "function '$_memberName'"; | 218 "function '$memberName'"; |
| 206 } else { | 219 } else { |
| 207 msg = "Class '${_receiver.runtimeType}' has no instance $type_str " | 220 msg = "Class '${_receiver.runtimeType}' has no instance $type_str " |
| 208 "'$_memberName'$args_message."; | 221 "'$memberName'$args_message."; |
| 209 } | 222 } |
| 210 } | 223 } |
| 211 break; | 224 break; |
| 212 } | 225 } |
| 213 case _InvocationMirror._STATIC: { | 226 case _InvocationMirror._STATIC: { |
| 214 msg = "No static $type_str '$_memberName' declared in class " | 227 msg = "No static $type_str '$memberName' declared in class " |
| 215 "'$_receiver'."; | 228 "'$_receiver'."; |
| 216 break; | 229 break; |
| 217 } | 230 } |
| 218 case _InvocationMirror._CONSTRUCTOR: { | 231 case _InvocationMirror._CONSTRUCTOR: { |
| 219 msg = "No constructor '$_memberName' declared in class '$_receiver'."; | 232 msg = "No constructor '$memberName' declared in class '$_receiver'."; |
| 220 break; | 233 break; |
| 221 } | 234 } |
| 222 case _InvocationMirror._TOP_LEVEL: { | 235 case _InvocationMirror._TOP_LEVEL: { |
| 223 msg = "No top-level $type_str '$_memberName'$args_message declared."; | 236 msg = "No top-level $type_str '$memberName'$args_message declared."; |
| 224 break; | 237 break; |
| 225 } | 238 } |
| 226 } | 239 } |
| 227 return "$msg\n\n"; | 240 return "$msg\n\n"; |
| 228 } | 241 } |
| 229 | 242 |
| 230 /* patch */ String toString() { | 243 /* patch */ String toString() { |
| 231 StringBuffer actual_buf = new StringBuffer(); | 244 StringBuffer actual_buf = new StringBuffer(); |
| 232 int i = 0; | 245 int i = 0; |
| 233 if (_arguments == null) { | 246 if (_arguments == null) { |
| 234 // Actual arguments unknown. | 247 // Actual arguments unknown. |
| 235 // TODO(srdjan): Remove once arguments are passed for unresolvable | 248 // TODO(srdjan): Remove once arguments are passed for unresolvable |
| 236 // static methods. | 249 // static methods. |
| 237 actual_buf.write("..."); | 250 actual_buf.write("..."); |
| 238 } else { | 251 } else { |
| 239 for (; i < _arguments.length; i++) { | 252 for (; i < _arguments.length; i++) { |
| 240 if (i > 0) { | 253 if (i > 0) { |
| 241 actual_buf.write(", "); | 254 actual_buf.write(", "); |
| 242 } | 255 } |
| 243 actual_buf.write(Error.safeToString(_arguments[i])); | 256 actual_buf.write(Error.safeToString(_arguments[i])); |
| 244 } | 257 } |
| 245 } | 258 } |
| 246 if (_namedArguments != null) { | 259 if (_namedArguments != null) { |
| 247 _namedArguments.forEach((String key, var value) { | 260 _namedArguments.forEach((Symbol key, var value) { |
| 248 if (i > 0) { | 261 if (i > 0) { |
| 249 actual_buf.write(", "); | 262 actual_buf.write(", "); |
| 250 } | 263 } |
| 251 actual_buf.write(key); | 264 actual_buf.write(_collection_dev.Symbol.getName(key)); |
| 252 actual_buf.write(": "); | 265 actual_buf.write(": "); |
| 253 actual_buf.write(Error.safeToString(value)); | 266 actual_buf.write(Error.safeToString(value)); |
| 254 i++; | 267 i++; |
| 255 }); | 268 }); |
| 256 } | 269 } |
| 257 var args_mismatch = _existingArgumentNames != null; | 270 var args_mismatch = _existingArgumentNames != null; |
| 258 StringBuffer msg_buf = new StringBuffer(_developerMessage(args_mismatch)); | 271 StringBuffer msg_buf = new StringBuffer(_developerMessage(args_mismatch)); |
| 259 String receiver_str; | 272 String receiver_str; |
| 260 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) & | 273 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) & |
| 261 _InvocationMirror._CALL_MASK; | 274 _InvocationMirror._CALL_MASK; |
| 262 if ( level == _InvocationMirror._TOP_LEVEL) { | 275 if ( level == _InvocationMirror._TOP_LEVEL) { |
| 263 receiver_str = "top-level"; | 276 receiver_str = "top-level"; |
| 264 } else { | 277 } else { |
| 265 receiver_str = Error.safeToString(_receiver); | 278 receiver_str = Error.safeToString(_receiver); |
| 266 } | 279 } |
| 280 var memberName = |
| 281 (_memberName == null) ? "" :_collection_dev.Symbol.getName(_memberName); |
| 267 if (!args_mismatch) { | 282 if (!args_mismatch) { |
| 268 msg_buf.write( | 283 msg_buf.write( |
| 269 "NoSuchMethodError : method not found: '$_memberName'\n" | 284 "NoSuchMethodError : method not found: '$memberName'\n" |
| 270 "Receiver: $receiver_str\n" | 285 "Receiver: $receiver_str\n" |
| 271 "Arguments: [$actual_buf]"); | 286 "Arguments: [$actual_buf]"); |
| 272 } else { | 287 } else { |
| 273 String actualParameters = actual_buf.toString(); | 288 String actualParameters = actual_buf.toString(); |
| 274 StringBuffer formal_buf = new StringBuffer(); | 289 StringBuffer formal_buf = new StringBuffer(); |
| 275 for (int i = 0; i < _existingArgumentNames.length; i++) { | 290 for (int i = 0; i < _existingArgumentNames.length; i++) { |
| 276 if (i > 0) { | 291 if (i > 0) { |
| 277 formal_buf.write(", "); | 292 formal_buf.write(", "); |
| 278 } | 293 } |
| 279 formal_buf.write(_existingArgumentNames[i]); | 294 formal_buf.write(_existingArgumentNames[i]); |
| 280 } | 295 } |
| 281 String formalParameters = formal_buf.toString(); | 296 String formalParameters = formal_buf.toString(); |
| 282 msg_buf.write( | 297 msg_buf.write( |
| 283 "NoSuchMethodError: incorrect number of arguments passed to " | 298 "NoSuchMethodError: incorrect number of arguments passed to " |
| 284 "method named '$_memberName'\n" | 299 "method named '$memberName'\n" |
| 285 "Receiver: $receiver_str\n" | 300 "Receiver: $receiver_str\n" |
| 286 "Tried calling: $_memberName($actualParameters)\n" | 301 "Tried calling: $_memberName($actualParameters)\n" |
| 287 "Found: $_memberName($formalParameters)"); | 302 "Found: $_memberName($formalParameters)"); |
| 288 } | 303 } |
| 289 return msg_buf.toString(); | 304 return msg_buf.toString(); |
| 290 } | 305 } |
| 291 } | 306 } |
| 292 | 307 |
| 293 class _JavascriptIntegerOverflowError extends Error { | 308 class _JavascriptIntegerOverflowError extends Error { |
| 294 final Object _value; | 309 final Object _value; |
| 295 | 310 |
| 296 _JavascriptIntegerOverflowError(this._value); | 311 _JavascriptIntegerOverflowError(this._value); |
| 297 String toString() => "Javascript Integer Overflow: $_value"; | 312 String toString() => "Javascript Integer Overflow: $_value"; |
| 298 } | 313 } |
| OLD | NEW |