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/dart_entry.h" | 5 #include "vm/dart_entry.h" |
6 | 6 |
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/debugger.h" | 9 #include "vm/debugger.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 206 |
207 // No compatible method or getter so invoke noSuchMethod. | 207 // No compatible method or getter so invoke noSuchMethod. |
208 return InvokeNoSuchMethod(instance, Symbols::Call(), arguments, | 208 return InvokeNoSuchMethod(instance, Symbols::Call(), arguments, |
209 arguments_descriptor); | 209 arguments_descriptor); |
210 } | 210 } |
211 | 211 |
212 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, | 212 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, |
213 const String& target_name, | 213 const String& target_name, |
214 const Array& arguments, | 214 const Array& arguments, |
215 const Array& arguments_descriptor) { | 215 const Array& arguments_descriptor) { |
216 ASSERT(receiver.raw() == arguments.At(0)); | 216 const ArgumentsDescriptor args_desc(arguments_descriptor); |
| 217 const intptr_t receiver_index = args_desc.TypeArgsLen() == 0 ? 0 : 1; |
| 218 ASSERT(receiver.raw() == arguments.At(receiver_index)); |
217 // Allocate an Invocation object. | 219 // Allocate an Invocation object. |
218 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 220 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
219 | 221 |
220 Class& invocation_mirror_class = Class::Handle(core_lib.LookupClass( | 222 Class& invocation_mirror_class = Class::Handle(core_lib.LookupClass( |
221 String::Handle(core_lib.PrivateName(Symbols::InvocationMirror())))); | 223 String::Handle(core_lib.PrivateName(Symbols::InvocationMirror())))); |
222 ASSERT(!invocation_mirror_class.IsNull()); | 224 ASSERT(!invocation_mirror_class.IsNull()); |
223 const String& function_name = | 225 const String& function_name = |
224 String::Handle(core_lib.PrivateName(Symbols::AllocateInvocationMirror())); | 226 String::Handle(core_lib.PrivateName(Symbols::AllocateInvocationMirror())); |
225 const Function& allocation_function = Function::Handle( | 227 const Function& allocation_function = Function::Handle( |
226 invocation_mirror_class.LookupStaticFunction(function_name)); | 228 invocation_mirror_class.LookupStaticFunction(function_name)); |
227 ASSERT(!allocation_function.IsNull()); | 229 ASSERT(!allocation_function.IsNull()); |
228 const int kNumAllocationArgs = 4; | 230 const int kNumAllocationArgs = 4; |
229 const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs)); | 231 const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs)); |
230 allocation_args.SetAt(0, target_name); | 232 allocation_args.SetAt(0, target_name); |
231 allocation_args.SetAt(1, arguments_descriptor); | 233 allocation_args.SetAt(1, arguments_descriptor); |
232 allocation_args.SetAt(2, arguments); | 234 allocation_args.SetAt(2, arguments); |
233 allocation_args.SetAt(3, Bool::False()); // Not a super invocation. | 235 allocation_args.SetAt(3, Bool::False()); // Not a super invocation. |
234 const Object& invocation_mirror = | 236 const Object& invocation_mirror = |
235 Object::Handle(InvokeFunction(allocation_function, allocation_args)); | 237 Object::Handle(InvokeFunction(allocation_function, allocation_args)); |
236 if (invocation_mirror.IsError()) { | 238 if (invocation_mirror.IsError()) { |
237 Exceptions::PropagateError(Error::Cast(invocation_mirror)); | 239 Exceptions::PropagateError(Error::Cast(invocation_mirror)); |
238 UNREACHABLE(); | 240 UNREACHABLE(); |
239 } | 241 } |
240 | 242 |
241 // Now use the invocation mirror object and invoke NoSuchMethod. | 243 // Now use the invocation mirror object and invoke NoSuchMethod. |
242 const int kTypeArgsLen = 0; | 244 const int kTypeArgsLen = 0; |
243 const int kNumArguments = 2; | 245 const int kNumArguments = 2; |
244 ArgumentsDescriptor args_desc( | 246 ArgumentsDescriptor nsm_args_desc( |
245 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); | 247 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
246 Function& function = Function::Handle( | 248 Function& function = Function::Handle(Resolver::ResolveDynamic( |
247 Resolver::ResolveDynamic(receiver, Symbols::NoSuchMethod(), args_desc)); | 249 receiver, Symbols::NoSuchMethod(), nsm_args_desc)); |
248 if (function.IsNull()) { | 250 if (function.IsNull()) { |
249 ASSERT(!FLAG_lazy_dispatchers); | 251 ASSERT(!FLAG_lazy_dispatchers); |
250 // If noSuchMethod(invocation) is not found, call Object::noSuchMethod. | 252 // If noSuchMethod(invocation) is not found, call Object::noSuchMethod. |
251 Thread* thread = Thread::Current(); | 253 Thread* thread = Thread::Current(); |
252 function ^= Resolver::ResolveDynamicForReceiverClass( | 254 function ^= Resolver::ResolveDynamicForReceiverClass( |
253 Class::Handle(thread->zone(), | 255 Class::Handle(thread->zone(), |
254 thread->isolate()->object_store()->object_class()), | 256 thread->isolate()->object_store()->object_class()), |
255 Symbols::NoSuchMethod(), args_desc); | 257 Symbols::NoSuchMethod(), nsm_args_desc); |
256 } | 258 } |
257 ASSERT(!function.IsNull()); | 259 ASSERT(!function.IsNull()); |
258 const Array& args = Array::Handle(Array::New(kNumArguments)); | 260 const Array& args = Array::Handle(Array::New(kNumArguments)); |
259 args.SetAt(0, receiver); | 261 args.SetAt(0, receiver); |
260 args.SetAt(1, invocation_mirror); | 262 args.SetAt(1, invocation_mirror); |
261 return InvokeFunction(function, args); | 263 return InvokeFunction(function, args); |
262 } | 264 } |
263 | 265 |
264 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {} | 266 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {} |
265 | 267 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 const Array& args = Array::Handle(Array::New(kNumArguments)); | 621 const Array& args = Array::Handle(Array::New(kNumArguments)); |
620 args.SetAt(0, map); | 622 args.SetAt(0, map); |
621 args.SetAt(1, key); | 623 args.SetAt(1, key); |
622 args.SetAt(2, value); | 624 args.SetAt(2, value); |
623 const Object& result = | 625 const Object& result = |
624 Object::Handle(DartEntry::InvokeFunction(function, args)); | 626 Object::Handle(DartEntry::InvokeFunction(function, args)); |
625 return result.raw(); | 627 return result.raw(); |
626 } | 628 } |
627 | 629 |
628 } // namespace dart | 630 } // namespace dart |
OLD | NEW |