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

Side by Side Diff: runtime/lib/object.cc

Issue 10034026: Add optional arguments to NullPointerException so that it can report more information (make it simi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
« corelib/src/exceptions.dart ('K') | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DEFINE_NATIVE_ENTRY(Object_toString, 1) { 13 DEFINE_NATIVE_ENTRY(Object_toString, 1) {
14 const Instance& instance = Instance::CheckedHandle(arguments->At(0)); 14 const Instance& instance = Instance::CheckedHandle(arguments->At(0));
15 const char* c_str = instance.ToCString(); 15 const char* c_str = instance.ToCString();
16 arguments->SetReturn(String::Handle(String::New(c_str))); 16 arguments->SetReturn(String::Handle(String::New(c_str)));
17 } 17 }
18 18
19 19
20 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 3) { 20 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 3) {
21 const Instance& instance = Instance::CheckedHandle(arguments->At(0)); 21 const Instance& instance = Instance::CheckedHandle(arguments->At(0));
22 GET_NATIVE_ARGUMENT(String, function_name, arguments->At(1));
23 GET_NATIVE_ARGUMENT(Array, func_args, arguments->At(2));
22 if (instance.IsNull()) { 24 if (instance.IsNull()) {
23 GrowableArray<const Object*> args; 25 GrowableArray<const Object*> args;
26 args.Add(&function_name);
27 args.Add(&func_args);
24 Exceptions::ThrowByType(Exceptions::kNullPointer, args); 28 Exceptions::ThrowByType(Exceptions::kNullPointer, args);
25 } 29 }
26 GET_NATIVE_ARGUMENT(String, function_name, arguments->At(1));
27 GET_NATIVE_ARGUMENT(Array, func_args, arguments->At(2));
28 GrowableArray<const Object*> dart_arguments(3); 30 GrowableArray<const Object*> dart_arguments(3);
29 dart_arguments.Add(&instance); 31 dart_arguments.Add(&instance);
30 dart_arguments.Add(&function_name); 32 dart_arguments.Add(&function_name);
31 dart_arguments.Add(&func_args); 33 dart_arguments.Add(&func_args);
34
32 // Report if a function with same name (but different arguments) has been 35 // Report if a function with same name (but different arguments) has been
33 // found. 36 // found.
34 Class& instance_class = Class::Handle(instance.clazz()); 37 Class& instance_class = Class::Handle(instance.clazz());
35 Function& function = 38 Function& function =
36 Function::Handle(instance_class.LookupDynamicFunction(function_name)); 39 Function::Handle(instance_class.LookupDynamicFunction(function_name));
37 while (function.IsNull()) { 40 while (function.IsNull()) {
38 instance_class = instance_class.SuperClass(); 41 instance_class = instance_class.SuperClass();
39 if (instance_class.IsNull()) break; 42 if (instance_class.IsNull()) break;
40 function = instance_class.LookupDynamicFunction(function_name); 43 function = instance_class.LookupDynamicFunction(function_name);
41 } 44 }
42 if (!function.IsNull()) { 45 if (!function.IsNull()) {
43 const int total_num_parameters = 46 const int total_num_parameters =
44 function.num_fixed_parameters() + function.num_optional_parameters(); 47 function.num_fixed_parameters() + function.num_optional_parameters();
45 const Array& array = Array::Handle(Array::New(total_num_parameters - 1)); 48 const Array& array = Array::Handle(Array::New(total_num_parameters - 1));
46 // Skip receiver. 49 // Skip receiver.
47 for (int i = 1; i < total_num_parameters; i++) { 50 for (int i = 1; i < total_num_parameters; i++) {
48 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i))); 51 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i)));
49 } 52 }
50 dart_arguments.Add(&array); 53 dart_arguments.Add(&array);
51 } 54 }
52 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); 55 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments);
53 } 56 }
54 57
55 } // namespace dart 58 } // namespace dart
OLDNEW
« corelib/src/exceptions.dart ('K') | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698