Chromium Code Reviews| 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 |
| 11 patch class NoSuchMethodError { | 11 patch class NoSuchMethodError { |
| 12 // The compiler emits a call to _throwNew when it cannot resolve a static | 12 // The compiler emits a call to _throwNew when it cannot resolve a static |
| 13 // method at compile time. The receiver is actually the literal class of the | 13 // method at compile time. The receiver is actually the literal class of the |
| 14 // unresolved method. | 14 // unresolved method. |
| 15 static void _throwNew(Object receiver, | 15 static void _throwNew(Object receiver, |
| 16 String memberName, | 16 String memberName, |
| 17 int invocation_type, | 17 int invocation_type, |
| 18 List arguments, | 18 List arguments, |
| 19 List argumentNames, | 19 List argumentNames, |
| 20 List existingArgumentNames) { | 20 List existingArgumentNames) { |
| 21 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length; | 21 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length; |
| 22 int numPositionalArguments = arguments == null ? 0 : arguments.length; | 22 int numPositionalArguments = arguments == null ? 0 : arguments.length; |
| 23 numPositionalArguments -= numNamedArguments; | 23 numPositionalArguments -= numNamedArguments; |
| 24 List positionalArguments; | 24 List positionalArguments; |
| 25 if (numPositionalArguments == 0) { | 25 if (numPositionalArguments == 0) { |
| 26 positionalArguments = []; | 26 // Differ between no arguments specified and 0 arguments. |
|
regis
2013/04/30 19:07:10
When is _throwNew called with unspecified argument
srdjan
2013/04/30 21:46:52
Adding comments: TODO(srdjan): This can currently
| |
| 27 positionalArguments = argumentNames == null ? null : []; | |
| 27 } else { | 28 } else { |
| 28 positionalArguments = arguments.sublist(0, numPositionalArguments); | 29 positionalArguments = arguments.sublist(0, numPositionalArguments); |
| 29 } | 30 } |
| 30 Map<String, dynamic> namedArguments = new Map<String, dynamic>(); | 31 Map<String, dynamic> namedArguments = new Map<String, dynamic>(); |
| 31 for (int i = 0; i < numNamedArguments; i++) { | 32 for (int i = 0; i < numNamedArguments; i++) { |
| 32 var arg_value = arguments[numPositionalArguments + i]; | 33 var arg_value = arguments[numPositionalArguments + i]; |
| 33 namedArguments[argumentNames[i]] = arg_value; | 34 namedArguments[argumentNames[i]] = arg_value; |
| 34 } | 35 } |
| 35 throw new NoSuchMethodError._withType(receiver, | 36 throw new NoSuchMethodError._withType(receiver, |
| 36 memberName, | 37 memberName, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 var type_str = | 73 var type_str = |
| 73 (const ["method", "getter", "setter", "getter or setter"])[type]; | 74 (const ["method", "getter", "setter", "getter or setter"])[type]; |
| 74 var args_message = args_mismatch ? " with matching arguments" : ""; | 75 var args_message = args_mismatch ? " with matching arguments" : ""; |
| 75 var msg; | 76 var msg; |
| 76 switch (level) { | 77 switch (level) { |
| 77 case _InvocationMirror._DYNAMIC: { | 78 case _InvocationMirror._DYNAMIC: { |
| 78 if (_receiver == null) { | 79 if (_receiver == null) { |
| 79 msg = "The null object does not have a $type_str '$_memberName'" | 80 msg = "The null object does not have a $type_str '$_memberName'" |
| 80 "$args_message."; | 81 "$args_message."; |
| 81 } else { | 82 } else { |
| 82 msg = "Class '${_receiver.runtimeType}' has no instance $type_str " | 83 if (_receiver is Function) { |
| 83 "'$_memberName'$args_message."; | 84 msg = "Closure call with mismatched arguments: " |
| 85 "function '$_memberName'"; | |
| 86 } else { | |
| 87 msg = "Class '${_receiver.runtimeType}' has no instance $type_str " | |
| 88 "'$_memberName'$args_message."; | |
| 89 } | |
| 84 } | 90 } |
| 85 break; | 91 break; |
| 86 } | 92 } |
| 87 case _InvocationMirror._STATIC: { | 93 case _InvocationMirror._STATIC: { |
| 88 msg = "No static $type_str '$_memberName' declared in class " | 94 msg = "No static $type_str '$_memberName' declared in class " |
| 89 "'$_receiver'."; | 95 "'$_receiver'."; |
| 90 break; | 96 break; |
| 91 } | 97 } |
| 92 case _InvocationMirror._CONSTRUCTOR: { | 98 case _InvocationMirror._CONSTRUCTOR: { |
| 93 msg = "No constructor '$_memberName' declared in class '$_receiver'."; | 99 msg = "No constructor '$_memberName' declared in class '$_receiver'."; |
| 94 break; | 100 break; |
| 95 } | 101 } |
| 96 case _InvocationMirror._TOP_LEVEL: { | 102 case _InvocationMirror._TOP_LEVEL: { |
| 97 msg = "No top-level $type_str '$_memberName' declared."; | 103 msg = "No top-level $type_str '$_memberName'$args_message declared."; |
| 98 break; | 104 break; |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 return "$msg\n\n"; | 107 return "$msg\n\n"; |
| 102 } | 108 } |
| 103 | 109 |
| 104 /* patch */ String toString() { | 110 /* patch */ String toString() { |
| 105 StringBuffer actual_buf = new StringBuffer(); | 111 StringBuffer actual_buf = new StringBuffer(); |
| 106 int i = 0; | 112 int i = 0; |
| 107 if (_arguments != null) { | 113 if (_arguments == null) { |
| 114 // Actual arguments unknown. | |
|
regis
2013/04/30 19:07:10
ditto
srdjan
2013/04/30 21:46:52
Adding TODO(regis): Remove once arguments are pass
| |
| 115 actual_buf.write("..."); | |
|
regis
2013/04/30 19:07:10
Same question.
srdjan
2013/04/30 21:46:52
Answered above.
| |
| 116 } else { | |
| 108 for (; i < _arguments.length; i++) { | 117 for (; i < _arguments.length; i++) { |
| 109 if (i > 0) { | 118 if (i > 0) { |
| 110 actual_buf.write(", "); | 119 actual_buf.write(", "); |
| 111 } | 120 } |
| 112 actual_buf.write(Error.safeToString(_arguments[i])); | 121 actual_buf.write(Error.safeToString(_arguments[i])); |
| 113 } | 122 } |
| 114 } | 123 } |
| 115 if (_namedArguments != null) { | 124 if (_namedArguments != null) { |
| 116 _namedArguments.forEach((String key, var value) { | 125 _namedArguments.forEach((String key, var value) { |
| 117 if (i > 0) { | 126 if (i > 0) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 147 msg_buf.write( | 156 msg_buf.write( |
| 148 "NoSuchMethodError: incorrect number of arguments passed to " | 157 "NoSuchMethodError: incorrect number of arguments passed to " |
| 149 "method named '$_memberName'\n" | 158 "method named '$_memberName'\n" |
| 150 "Receiver: $receiver_str\n" | 159 "Receiver: $receiver_str\n" |
| 151 "Tried calling: $_memberName($actualParameters)\n" | 160 "Tried calling: $_memberName($actualParameters)\n" |
| 152 "Found: $_memberName($formalParameters)"); | 161 "Found: $_memberName($formalParameters)"); |
| 153 } | 162 } |
| 154 return msg_buf.toString(); | 163 return msg_buf.toString(); |
| 155 } | 164 } |
| 156 } | 165 } |
| OLD | NEW |