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

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

Issue 11523002: Pass the proper invocation mirror argument to noSuchMethod. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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
« no previous file with comments | « runtime/lib/invocation_mirror_patch.dart ('k') | runtime/lib/object_patch.dart » ('j') | 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->NativeArgAt(0)); 14 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
15 const char* c_str = instance.ToCString(); 15 const char* c_str = instance.ToCString();
16 return String::New(c_str); 16 return String::New(c_str);
17 } 17 }
18 18
19 19
20 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 3) { 20 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 5) {
21 const Instance& instance = 21 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
22 Instance::CheckedHandle(arguments->NativeArgAt(0)); 22 GET_NON_NULL_NATIVE_ARGUMENT(Bool, is_method, arguments->NativeArgAt(1));
23 GET_NON_NULL_NATIVE_ARGUMENT(String, member_name, arguments->NativeArgAt(2));
24 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_args, arguments->NativeArgAt(3));
23 GET_NON_NULL_NATIVE_ARGUMENT( 25 GET_NON_NULL_NATIVE_ARGUMENT(
24 String, function_name, arguments->NativeArgAt(1)); 26 Instance, func_named_args, arguments->NativeArgAt(4));
25 GET_NON_NULL_NATIVE_ARGUMENT(Array, func_args, arguments->NativeArgAt(2)); 27 GrowableArray<const Object*> dart_arguments(5);
26 const Object& null_object = Object::Handle(Object::null());
27 GrowableArray<const Object*> dart_arguments(4);
28 dart_arguments.Add(&instance); 28 dart_arguments.Add(&instance);
29 dart_arguments.Add(&function_name); 29 dart_arguments.Add(&member_name);
30 dart_arguments.Add(&func_args); 30 dart_arguments.Add(&func_args);
31 dart_arguments.Add(&null_object); 31 dart_arguments.Add(&func_named_args);
32 32
33 // Report if a function with same name (but different arguments) has been 33 if (is_method.value()) {
34 // found. 34 // Report if a function with same name (but different arguments) has been
35 Class& instance_class = Class::Handle(instance.clazz()); 35 // found.
36 Function& function = 36 Class& instance_class = Class::Handle(instance.clazz());
37 Function::Handle(instance_class.LookupDynamicFunction(function_name)); 37 Function& function =
38 while (function.IsNull()) { 38 Function::Handle(instance_class.LookupDynamicFunction(member_name));
39 instance_class = instance_class.SuperClass(); 39 while (function.IsNull()) {
40 if (instance_class.IsNull()) break; 40 instance_class = instance_class.SuperClass();
41 function = instance_class.LookupDynamicFunction(function_name); 41 if (instance_class.IsNull()) break;
42 } 42 function = instance_class.LookupDynamicFunction(member_name);
43 if (!function.IsNull()) {
44 const int total_num_parameters = function.NumParameters();
45 const Array& array = Array::Handle(Array::New(total_num_parameters - 1));
46 // Skip receiver.
47 for (int i = 1; i < total_num_parameters; i++) {
48 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i)));
49 } 43 }
50 dart_arguments.Add(&array); 44 if (!function.IsNull()) {
45 const int total_num_parameters = function.NumParameters();
46 const Array& array = Array::Handle(Array::New(total_num_parameters - 1));
47 // Skip receiver.
48 for (int i = 1; i < total_num_parameters; i++) {
49 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i)));
50 }
51 dart_arguments.Add(&array);
52 }
51 } 53 }
52 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); 54 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments);
53 return Object::null(); 55 return Object::null();
54 } 56 }
55 57
56 58
57 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { 59 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) {
58 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
59 const Type& type = Type::Handle(instance.GetType()); 61 const Type& type = Type::Handle(instance.GetType());
60 return type.Canonicalize(); 62 return type.Canonicalize();
61 } 63 }
62 64
63 65
64 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { 66 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) {
65 const AbstractType& type = 67 const AbstractType& type =
66 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); 68 AbstractType::CheckedHandle(arguments->NativeArgAt(0));
67 return type.Name(); 69 return type.Name();
68 } 70 }
69 71
70 } // namespace dart 72 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/invocation_mirror_patch.dart ('k') | runtime/lib/object_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698