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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 3001 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 lookup_class_name.ToCString())); 3012 lookup_class_name.ToCString()));
3013 return ApiError::New(message); 3013 return ApiError::New(message);
3014 } else { 3014 } else {
3015 const String& message = String::Handle( 3015 const String& message = String::Handle(
3016 String::NewFormatted("%s: could not find constructor '%s'.", 3016 String::NewFormatted("%s: could not find constructor '%s'.",
3017 current_func, constr_name.ToCString())); 3017 current_func, constr_name.ToCString()));
3018 return ApiError::New(message); 3018 return ApiError::New(message);
3019 } 3019 }
3020 } 3020 }
3021 int extra_args = (constructor.IsConstructor() ? 2 : 1); 3021 int extra_args = (constructor.IsConstructor() ? 2 : 1);
3022 if (!constructor.AreValidArgumentCounts(num_args + extra_args, 0)) { 3022 const intptr_t kMessageBufferSize = 256;
3023 char message_buffer[kMessageBufferSize];
3024 if (!constructor.AreValidArgumentCounts(num_args + extra_args,
3025 0,
3026 message_buffer,
3027 kMessageBufferSize)) {
3023 const String& message = String::Handle( 3028 const String& message = String::Handle(
3024 String::NewFormatted("%s: wrong argument count for constructor '%s': " 3029 String::NewFormatted("%s: wrong argument count for "
3025 "expected %d but saw %d.", 3030 "constructor '%s': %s.",
3026 current_func, 3031 current_func,
3027 constr_name.ToCString(), 3032 constr_name.ToCString(),
3028 constructor.num_fixed_parameters() - extra_args, 3033 message_buffer));
3029 num_args));
3030 return ApiError::New(message); 3034 return ApiError::New(message);
3031 } 3035 }
3032 return constructor.raw(); 3036 return constructor.raw();
3033 } 3037 }
3034 3038
3035 3039
3036 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, 3040 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz,
3037 Dart_Handle constructor_name, 3041 Dart_Handle constructor_name,
3038 int number_of_arguments, 3042 int number_of_arguments,
3039 Dart_Handle* arguments) { 3043 Dart_Handle* arguments) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 // Finalize all classes if needed. 3270 // Finalize all classes if needed.
3267 if (finalize_classes) { 3271 if (finalize_classes) {
3268 const char* msg = CheckIsolateState(isolate); 3272 const char* msg = CheckIsolateState(isolate);
3269 if (msg != NULL) { 3273 if (msg != NULL) {
3270 return Api::NewError(msg); 3274 return Api::NewError(msg);
3271 } 3275 }
3272 } 3276 }
3273 3277
3274 Function& function = Function::Handle(isolate); 3278 Function& function = Function::Handle(isolate);
3275 function = lib.LookupFunctionAllowPrivate(function_name); 3279 function = lib.LookupFunctionAllowPrivate(function_name);
3276 // LookupFunctionAllowPrivate does not check argument arity, so we
3277 // do it here.
3278 if (!function.IsNull() &&
3279 !function.AreValidArgumentCounts(number_of_arguments, 0)) {
3280 function = Function::null();
3281 }
3282 if (function.IsNull()) { 3280 if (function.IsNull()) {
3283 return Api::NewError("%s: did not find top-level function '%s'.", 3281 return Api::NewError("%s: did not find top-level function '%s'.",
3284 CURRENT_FUNC, 3282 CURRENT_FUNC,
3285 function_name.ToCString()); 3283 function_name.ToCString());
3286 } 3284 }
3285 // LookupFunctionAllowPrivate does not check argument arity, so we
3286 // do it here.
3287 const intptr_t kMessageBufferSize = 256;
3288 char message_buffer[kMessageBufferSize];
3289 if (!function.AreValidArgumentCounts(number_of_arguments,
3290 0,
3291 message_buffer,
3292 kMessageBufferSize)) {
3293 return Api::NewError("%s: wrong argument count for function '%s': %s.",
3294 CURRENT_FUNC,
3295 function_name.ToCString(),
3296 message_buffer);
3297 }
3287 return Api::NewHandle( 3298 return Api::NewHandle(
3288 isolate, DartEntry::InvokeStatic(function, args, kNoArgNames)); 3299 isolate, DartEntry::InvokeStatic(function, args, kNoArgNames));
3289 3300
3290 } else { 3301 } else {
3291 return Api::NewError( 3302 return Api::NewError(
3292 "%s expects argument 'target' to be an object, class, or library.", 3303 "%s expects argument 'target' to be an object, class, or library.",
3293 CURRENT_FUNC); 3304 CURRENT_FUNC);
3294 } 3305 }
3295 } 3306 }
3296 3307
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
4113 *buffer_size = 0; 4124 *buffer_size = 0;
4114 } 4125 }
4115 } 4126 }
4116 4127
4117 4128
4118 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { 4129 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) {
4119 Dart::set_flow_graph_writer(function); 4130 Dart::set_flow_graph_writer(function);
4120 } 4131 }
4121 4132
4122 } // namespace dart 4133 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698