Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10695137: Provide better error message when passing wrong number of arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 9601)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -3019,14 +3019,16 @@
}
}
int extra_args = (constructor.IsConstructor() ? 2 : 1);
- if (!constructor.AreValidArgumentCounts(num_args + extra_args, 0)) {
+ String& error_message = String::Handle();
+ if (!constructor.AreValidArgumentCounts(num_args + extra_args,
+ 0,
+ &error_message)) {
const String& message = String::Handle(
- String::NewFormatted("%s: wrong argument count for constructor '%s': "
- "expected %d but saw %d.",
+ String::NewFormatted("%s: wrong argument count for "
+ "constructor '%s': %s.",
current_func,
constr_name.ToCString(),
- constructor.num_fixed_parameters() - extra_args,
- num_args));
+ error_message.ToCString()));
return ApiError::New(message);
}
return constructor.raw();
@@ -3273,17 +3275,22 @@
Function& function = Function::Handle(isolate);
function = lib.LookupFunctionAllowPrivate(function_name);
- // LookupFunctionAllowPrivate does not check argument arity, so we
- // do it here.
- if (!function.IsNull() &&
- !function.AreValidArgumentCounts(number_of_arguments, 0)) {
- function = Function::null();
- }
if (function.IsNull()) {
return Api::NewError("%s: did not find top-level function '%s'.",
CURRENT_FUNC,
function_name.ToCString());
}
+ // LookupFunctionAllowPrivate does not check argument arity, so we
+ // do it here.
+ String& error_message = String::Handle();
+ if (!function.AreValidArgumentCounts(number_of_arguments,
+ 0,
+ &error_message)) {
+ return Api::NewError("%s: wrong argument count for function '%s': %s.",
+ CURRENT_FUNC,
+ function_name.ToCString(),
+ error_message.ToCString());
+ }
return Api::NewHandle(
isolate, DartEntry::InvokeStatic(function, args, kNoArgNames));
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698