OLD | NEW |
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, 5) { | 20 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 5) { |
21 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 21 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
22 GET_NON_NULL_NATIVE_ARGUMENT(Bool, is_method, arguments->NativeArgAt(1)); | 22 GET_NON_NULL_NATIVE_ARGUMENT(Bool, is_method, arguments->NativeArgAt(1)); |
23 GET_NON_NULL_NATIVE_ARGUMENT(String, member_name, arguments->NativeArgAt(2)); | 23 GET_NON_NULL_NATIVE_ARGUMENT(String, member_name, arguments->NativeArgAt(2)); |
24 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_args, arguments->NativeArgAt(3)); | 24 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_args, arguments->NativeArgAt(3)); |
25 GET_NON_NULL_NATIVE_ARGUMENT( | 25 GET_NON_NULL_NATIVE_ARGUMENT( |
26 Instance, func_named_args, arguments->NativeArgAt(4)); | 26 Instance, func_named_args, arguments->NativeArgAt(4)); |
27 GrowableArray<const Object*> dart_arguments(5); | 27 const Array& dart_arguments = Array::Handle(Array::New(5)); |
28 dart_arguments.Add(&instance); | 28 dart_arguments.SetAt(0, instance); |
29 dart_arguments.Add(&member_name); | 29 dart_arguments.SetAt(1, member_name); |
30 dart_arguments.Add(&func_args); | 30 dart_arguments.SetAt(2, func_args); |
31 dart_arguments.Add(&func_named_args); | 31 dart_arguments.SetAt(3, func_named_args); |
32 | 32 |
33 if (is_method.value()) { | 33 if (is_method.value()) { |
34 // Report if a function with same name (but different arguments) has been | 34 // Report if a function with same name (but different arguments) has been |
35 // found. | 35 // found. |
36 Class& instance_class = Class::Handle(instance.clazz()); | 36 Class& instance_class = Class::Handle(instance.clazz()); |
37 Function& function = | 37 Function& function = |
38 Function::Handle(instance_class.LookupDynamicFunction(member_name)); | 38 Function::Handle(instance_class.LookupDynamicFunction(member_name)); |
39 while (function.IsNull()) { | 39 while (function.IsNull()) { |
40 instance_class = instance_class.SuperClass(); | 40 instance_class = instance_class.SuperClass(); |
41 if (instance_class.IsNull()) break; | 41 if (instance_class.IsNull()) break; |
42 function = instance_class.LookupDynamicFunction(member_name); | 42 function = instance_class.LookupDynamicFunction(member_name); |
43 } | 43 } |
44 if (!function.IsNull()) { | 44 if (!function.IsNull()) { |
45 const int total_num_parameters = function.NumParameters(); | 45 const int total_num_parameters = function.NumParameters(); |
46 const Array& array = Array::Handle(Array::New(total_num_parameters - 1)); | 46 const Array& array = Array::Handle(Array::New(total_num_parameters - 1)); |
47 // Skip receiver. | 47 // Skip receiver. |
48 for (int i = 1; i < total_num_parameters; i++) { | 48 for (int i = 1; i < total_num_parameters; i++) { |
49 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i))); | 49 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i))); |
50 } | 50 } |
51 dart_arguments.Add(&array); | 51 dart_arguments.SetAt(4, array); |
52 } | 52 } |
53 } | 53 } |
54 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | 54 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); |
55 return Object::null(); | 55 return Object::null(); |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { | 59 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { |
60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
61 const Type& type = Type::Handle(instance.GetType()); | 61 const Type& type = Type::Handle(instance.GetType()); |
62 return type.Canonicalize(); | 62 return type.Canonicalize(); |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { | 66 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { |
67 const AbstractType& type = | 67 const AbstractType& type = |
68 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); | 68 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); |
69 return type.Name(); | 69 return type.Name(); |
70 } | 70 } |
71 | 71 |
72 } // namespace dart | 72 } // namespace dart |
OLD | NEW |