OLD | NEW |
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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 SetupStaticFunction(test_library_name, | 85 SetupStaticFunction(test_library_name, |
86 test_class_name, | 86 test_class_name, |
87 test_static_function_name); | 87 test_static_function_name); |
88 | 88 |
89 const String& library_name = String::Handle(String::New(test_library_name)); | 89 const String& library_name = String::Handle(String::New(test_library_name)); |
90 const Library& library = | 90 const Library& library = |
91 Library::Handle(Library::LookupLibrary(library_name)); | 91 Library::Handle(Library::LookupLibrary(library_name)); |
92 const String& class_name = String::Handle(String::New(test_class_name)); | 92 const String& class_name = String::Handle(String::New(test_class_name)); |
93 const String& static_function_name = | 93 const String& static_function_name = |
94 String::Handle(String::New(test_static_function_name)); | 94 String::Handle(String::New(test_static_function_name)); |
| 95 String& ambiguity_error_msg = String::Handle(); |
95 | 96 |
96 // Now try to resolve and invoke the static function in this class. | 97 // Now try to resolve and invoke the static function in this class. |
97 { | 98 { |
98 const int kNumArguments = 2; | 99 const int kNumArguments = 2; |
99 const Function& function = Function::Handle( | 100 const Function& function = Function::Handle( |
100 Resolver::ResolveStatic(library, | 101 Resolver::ResolveStatic(library, |
101 class_name, | 102 class_name, |
102 static_function_name, | 103 static_function_name, |
103 kNumArguments, | 104 kNumArguments, |
104 Object::empty_array(), | 105 Object::empty_array(), |
105 kResolveType)); | 106 kResolveType, |
106 EXPECT(!function.IsNull()); | 107 &ambiguity_error_msg)); |
| 108 EXPECT(!function.IsNull()); // No ambiguity error expected. |
107 const Array& args = Array::Handle(Array::New(kNumArguments)); | 109 const Array& args = Array::Handle(Array::New(kNumArguments)); |
108 const String& arg0 = String::Handle(String::New("junk")); | 110 const String& arg0 = String::Handle(String::New("junk")); |
109 args.SetAt(0, arg0); | 111 args.SetAt(0, arg0); |
110 const Smi& arg1 = Smi::Handle(Smi::New(kTestValue)); | 112 const Smi& arg1 = Smi::Handle(Smi::New(kTestValue)); |
111 args.SetAt(1, arg1); | 113 args.SetAt(1, arg1); |
112 const Smi& retval = Smi::Handle( | 114 const Smi& retval = Smi::Handle( |
113 reinterpret_cast<RawSmi*>(DartEntry::InvokeFunction(function, args))); | 115 reinterpret_cast<RawSmi*>(DartEntry::InvokeFunction(function, args))); |
114 EXPECT_EQ(kTestValue, retval.Value()); | 116 EXPECT_EQ(kTestValue, retval.Value()); |
115 } | 117 } |
116 | 118 |
117 // Now try to resolve a static function with invalid argument count. | 119 // Now try to resolve a static function with invalid argument count. |
118 { | 120 { |
119 const int kNumArguments = 1; | 121 const int kNumArguments = 1; |
120 const Function& bad_function = Function::Handle( | 122 const Function& bad_function = Function::Handle( |
121 Resolver::ResolveStatic(library, | 123 Resolver::ResolveStatic(library, |
122 class_name, | 124 class_name, |
123 static_function_name, | 125 static_function_name, |
124 kNumArguments, | 126 kNumArguments, |
125 Object::empty_array(), | 127 Object::empty_array(), |
126 kResolveType)); | 128 kResolveType, |
127 EXPECT(bad_function.IsNull()); | 129 &ambiguity_error_msg)); |
| 130 EXPECT(bad_function.IsNull()); // No ambiguity error expected. |
128 } | 131 } |
129 | 132 |
130 // Hierarchy walking. | 133 // Hierarchy walking. |
131 { | 134 { |
132 const String& super_static_function_name = | 135 const String& super_static_function_name = |
133 String::Handle(String::New("statCall")); | 136 String::Handle(String::New("statCall")); |
134 const String& super_class_name = String::Handle(String::New("Base")); | 137 const String& super_class_name = String::Handle(String::New("Base")); |
135 const int kNumArguments = 0; | 138 const int kNumArguments = 0; |
136 const Function& super_function = Function::Handle( | 139 const Function& super_function = Function::Handle( |
137 Resolver::ResolveStatic(library, | 140 Resolver::ResolveStatic(library, |
138 super_class_name, | 141 super_class_name, |
139 super_static_function_name, | 142 super_static_function_name, |
140 kNumArguments, | 143 kNumArguments, |
141 Object::empty_array(), | 144 Object::empty_array(), |
142 kResolveType)); | 145 kResolveType, |
143 EXPECT(!super_function.IsNull()); | 146 &ambiguity_error_msg)); |
| 147 EXPECT(!super_function.IsNull()); // No ambiguity error expected. |
144 } | 148 } |
145 } | 149 } |
146 | 150 |
147 | 151 |
148 TEST_CASE(DartDynamicResolve) { | 152 TEST_CASE(DartDynamicResolve) { |
149 const char* test_library_name = "ResolverApp"; | 153 const char* test_library_name = "ResolverApp"; |
150 const char* test_class_name = "A"; | 154 const char* test_class_name = "A"; |
151 const char* test_function_name = "foo"; | 155 const char* test_function_name = "foo"; |
152 const int kTestValue = 42; | 156 const int kTestValue = 42; |
153 | 157 |
154 // Setup a function which can be invoked. | 158 // Setup a function which can be invoked. |
155 SetupInstanceFunction(test_library_name, | 159 SetupInstanceFunction(test_library_name, |
156 test_class_name, | 160 test_class_name, |
157 test_function_name); | 161 test_function_name); |
158 | 162 |
159 // Now create an instance object of the class and try to | 163 // Now create an instance object of the class and try to |
160 // resolve a function in it. | 164 // resolve a function in it. |
161 const String& lib_name = String::Handle(String::New(test_library_name)); | 165 const String& lib_name = String::Handle(String::New(test_library_name)); |
162 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); | 166 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); |
163 ASSERT(!lib.IsNull()); | 167 ASSERT(!lib.IsNull()); |
| 168 String& ambiguity_error_msg = String::Handle(); |
164 const Class& cls = Class::Handle(lib.LookupClass( | 169 const Class& cls = Class::Handle(lib.LookupClass( |
165 String::Handle(Symbols::New(test_class_name)))); | 170 String::Handle(Symbols::New(test_class_name)), &ambiguity_error_msg)); |
166 EXPECT(!cls.IsNull()); | 171 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
167 | 172 |
168 Instance& receiver = Instance::Handle(Instance::New(cls)); | 173 Instance& receiver = Instance::Handle(Instance::New(cls)); |
169 const String& function_name = String::Handle(String::New(test_function_name)); | 174 const String& function_name = String::Handle(String::New(test_function_name)); |
170 | 175 |
171 // Now try to resolve and invoke the instance function in this class. | 176 // Now try to resolve and invoke the instance function in this class. |
172 { | 177 { |
173 const int kNumArguments = 3; | 178 const int kNumArguments = 3; |
174 ArgumentsDescriptor args_desc( | 179 ArgumentsDescriptor args_desc( |
175 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 180 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); |
176 const Function& function = Function::Handle( | 181 const Function& function = Function::Handle( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 String::Handle(String::New("dynCall")); | 215 String::Handle(String::New("dynCall")); |
211 const Function& super_function = Function::Handle( | 216 const Function& super_function = Function::Handle( |
212 Resolver::ResolveDynamic(receiver, | 217 Resolver::ResolveDynamic(receiver, |
213 super_function_name, | 218 super_function_name, |
214 args_desc)); | 219 args_desc)); |
215 EXPECT(!super_function.IsNull()); | 220 EXPECT(!super_function.IsNull()); |
216 } | 221 } |
217 } | 222 } |
218 | 223 |
219 } // namespace dart | 224 } // namespace dart |
OLD | NEW |