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 "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
227 args.SetAt(1, type); | 227 args.SetAt(1, type); |
228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
229 } | 229 } |
230 | 230 |
231 | 231 |
232 static RawInstance* CreateMethodMirror(const Function& func, | 232 static RawInstance* CreateMethodMirror(const Function& func, |
233 const Instance& owner_mirror) { | 233 const Instance& owner_mirror) { |
234 const Array& args = Array::Handle(Array::New(12)); | 234 const Array& args = Array::Handle(Array::New(12)); |
235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
236 args.SetAt(1, String::Handle(func.UserVisibleName())); | 236 |
| 237 String& name = String::Handle(func.name()); |
| 238 name = String::IdentifierPrettyNameRetainPrivate(name); |
| 239 args.SetAt(1, name); |
| 240 |
237 args.SetAt(2, owner_mirror); | 241 args.SetAt(2, owner_mirror); |
238 args.SetAt(3, Bool::Get(func.is_static())); | 242 args.SetAt(3, Bool::Get(func.is_static())); |
239 args.SetAt(4, Bool::Get(func.is_abstract())); | 243 args.SetAt(4, Bool::Get(func.is_abstract())); |
240 args.SetAt(5, Bool::Get(func.IsGetterFunction())); | 244 args.SetAt(5, Bool::Get(func.IsGetterFunction())); |
241 args.SetAt(6, Bool::Get(func.IsSetterFunction())); | 245 args.SetAt(6, Bool::Get(func.IsSetterFunction())); |
242 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor)); | 246 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor)); |
243 // TODO(mlippautz): Implement different constructor kinds. | 247 // TODO(mlippautz): Implement different constructor kinds. |
244 args.SetAt(8, Bool::False()); | 248 args.SetAt(8, Bool::False()); |
245 args.SetAt(9, Bool::False()); | 249 args.SetAt(9, Bool::False()); |
246 args.SetAt(10, Bool::False()); | 250 args.SetAt(10, Bool::False()); |
247 args.SetAt(11, Bool::False()); | 251 args.SetAt(11, Bool::False()); |
248 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); | 252 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); |
249 } | 253 } |
250 | 254 |
251 | 255 |
252 static RawInstance* CreateVariableMirror(const Field& field, | 256 static RawInstance* CreateVariableMirror(const Field& field, |
253 const Instance& owner_mirror) { | 257 const Instance& owner_mirror) { |
254 const MirrorReference& field_ref = | 258 const MirrorReference& field_ref = |
255 MirrorReference::Handle(MirrorReference::New(field)); | 259 MirrorReference::Handle(MirrorReference::New(field)); |
256 | 260 |
257 const String& name = String::Handle(field.UserVisibleName()); | 261 const String& name = String::Handle(field.name()); |
258 | 262 |
259 const Array& args = Array::Handle(Array::New(6)); | 263 const Array& args = Array::Handle(Array::New(6)); |
260 args.SetAt(0, field_ref); | 264 args.SetAt(0, field_ref); |
261 args.SetAt(1, name); | 265 args.SetAt(1, name); |
262 args.SetAt(2, owner_mirror); | 266 args.SetAt(2, owner_mirror); |
263 args.SetAt(3, Object::null_instance()); // Null for type. | 267 args.SetAt(3, Object::null_instance()); // Null for type. |
264 args.SetAt(4, Bool::Get(field.is_static())); | 268 args.SetAt(4, Bool::Get(field.is_static())); |
265 args.SetAt(5, Bool::Get(field.is_final())); | 269 args.SetAt(5, Bool::Get(field.is_final())); |
266 | 270 |
267 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 271 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); | 309 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
306 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); | 310 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); |
307 | 311 |
308 const Array& args = Array::Handle(Array::New(6)); | 312 const Array& args = Array::Handle(Array::New(6)); |
309 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 313 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
310 args.SetAt(1, type); | 314 args.SetAt(1, type); |
311 // We do not set the names of anonymous mixin applications because the mirrors | 315 // We do not set the names of anonymous mixin applications because the mirrors |
312 // use a different naming convention than the VM (lib.S with lib.M and S&M | 316 // use a different naming convention than the VM (lib.S with lib.M and S&M |
313 // respectively). | 317 // respectively). |
314 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { | 318 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { |
315 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 319 args.SetAt(2, String::Handle(cls.Name())); |
316 } | 320 } |
317 args.SetAt(3, is_generic); | 321 args.SetAt(3, is_generic); |
318 args.SetAt(4, is_mixin_typedef); | 322 args.SetAt(4, is_mixin_typedef); |
319 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); | 323 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); |
320 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 324 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
321 } | 325 } |
322 | 326 |
323 | 327 |
324 static RawInstance* CreateLibraryMirror(const Library& lib) { | 328 static RawInstance* CreateLibraryMirror(const Library& lib) { |
325 const Array& args = Array::Handle(Array::New(3)); | 329 const Array& args = Array::Handle(Array::New(3)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 445 |
442 | 446 |
443 static RawInstance* InvokeLibraryGetter(const Library& library, | 447 static RawInstance* InvokeLibraryGetter(const Library& library, |
444 const String& getter_name, | 448 const String& getter_name, |
445 const bool throw_nsm_if_absent) { | 449 const bool throw_nsm_if_absent) { |
446 // To access a top-level we may need to use the Field or the getter Function. | 450 // To access a top-level we may need to use the Field or the getter Function. |
447 // The getter function may either be in the library or in the field's owner | 451 // The getter function may either be in the library or in the field's owner |
448 // class, depending on whether it was an actual getter, or an uninitialized | 452 // class, depending on whether it was an actual getter, or an uninitialized |
449 // field. | 453 // field. |
450 const Field& field = Field::Handle( | 454 const Field& field = Field::Handle( |
| 455 library.LookupLocalField(getter_name)); |
| 456 Function& getter = Function::Handle(); |
| 457 if (field.IsNull()) { |
| 458 // No field found. Check for a getter in the lib. |
| 459 const String& internal_getter_name = |
| 460 String::Handle(Field::GetterName(getter_name)); |
| 461 getter = library.LookupLocalFunction(internal_getter_name); |
| 462 if (getter.IsNull()) { |
| 463 getter = library.LookupLocalFunction(getter_name); |
| 464 if (!getter.IsNull()) { |
| 465 // Looking for a getter but found a regular method: closurize it. |
| 466 const Function& closure_function = |
| 467 Function::Handle(getter.ImplicitClosureFunction()); |
| 468 return closure_function.ImplicitStaticClosure(); |
| 469 } |
| 470 } |
| 471 } else { |
| 472 if (!field.IsUninitialized()) { |
| 473 return field.value(); |
| 474 } |
| 475 // An uninitialized field was found. Check for a getter in the field's |
| 476 // owner classs. |
| 477 const Class& klass = Class::Handle(field.owner()); |
| 478 const String& internal_getter_name = |
| 479 String::Handle(Field::GetterName(getter_name)); |
| 480 getter = klass.LookupStaticFunction(internal_getter_name); |
| 481 } |
| 482 |
| 483 if (!getter.IsNull() && getter.is_visible()) { |
| 484 // Invoke the getter and return the result. |
| 485 const Object& result = Object::Handle( |
| 486 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 487 return ReturnResult(result); |
| 488 } |
| 489 |
| 490 if (throw_nsm_if_absent) { |
| 491 ThrowNoSuchMethod(Instance::null_instance(), |
| 492 getter_name, |
| 493 getter, |
| 494 InvocationMirror::kTopLevel, |
| 495 InvocationMirror::kGetter); |
| 496 UNREACHABLE(); |
| 497 } |
| 498 |
| 499 // Fall through case: Indicate that we didn't find any function or field using |
| 500 // a special null instance. This is different from a field being null. Callers |
| 501 // make sure that this null does not leak into Dartland. |
| 502 return Object::sentinel().raw(); |
| 503 } |
| 504 |
| 505 |
| 506 // TODO(13656): Remove AllowPrivate. |
| 507 static RawInstance* InvokeLibraryGetterAllowImports( |
| 508 const Library& library, |
| 509 const String& getter_name, |
| 510 const bool throw_nsm_if_absent) { |
| 511 // To access a top-level we may need to use the Field or the getter Function. |
| 512 // The getter function may either be in the library or in the field's owner |
| 513 // class, depending on whether it was an actual getter, or an uninitialized |
| 514 // field. |
| 515 const Field& field = Field::Handle( |
451 library.LookupFieldAllowPrivate(getter_name)); | 516 library.LookupFieldAllowPrivate(getter_name)); |
452 Function& getter = Function::Handle(); | 517 Function& getter = Function::Handle(); |
453 if (field.IsNull()) { | 518 if (field.IsNull()) { |
454 // No field found. Check for a getter in the lib. | 519 // No field found. Check for a getter in the lib. |
455 const String& internal_getter_name = | 520 const String& internal_getter_name = |
456 String::Handle(Field::GetterName(getter_name)); | 521 String::Handle(Field::GetterName(getter_name)); |
457 getter = library.LookupFunctionAllowPrivate(internal_getter_name); | 522 getter = library.LookupFunctionAllowPrivate(internal_getter_name); |
458 if (getter.IsNull()) { | 523 if (getter.IsNull()) { |
459 getter = library.LookupFunctionAllowPrivate(getter_name); | 524 getter = library.LookupFunctionAllowPrivate(getter_name); |
460 if (!getter.IsNull()) { | 525 if (!getter.IsNull()) { |
461 // Looking for a getter but found a regular method: closurize it. | 526 // Looking for a getter but found a regular method: closurize it. |
462 const Function& closure_function = | 527 const Function& closure_function = |
463 Function::Handle(getter.ImplicitClosureFunction()); | 528 Function::Handle(getter.ImplicitClosureFunction()); |
464 return closure_function.ImplicitStaticClosure(); | 529 return closure_function.ImplicitStaticClosure(); |
465 } | 530 } |
466 } | 531 } |
467 } else { | 532 } else { |
468 if (!field.IsUninitialized()) { | 533 if (!field.IsUninitialized()) { |
469 return field.value(); | 534 return field.value(); |
470 } | 535 } |
471 // An uninitialized field was found. Check for a getter in the field's | 536 // An uninitialized field was found. Check for a getter in the field's |
472 // owner classs. | 537 // owner classs. |
473 const Class& klass = Class::Handle(field.owner()); | 538 const Class& klass = Class::Handle(field.owner()); |
474 const String& internal_getter_name = | 539 const String& internal_getter_name = |
475 String::Handle(Field::GetterName(getter_name)); | 540 String::Handle(Field::GetterName(getter_name)); |
476 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 541 getter = klass.LookupStaticFunction(internal_getter_name); |
477 } | 542 } |
478 | 543 |
479 if (!getter.IsNull() && getter.is_visible()) { | 544 if (!getter.IsNull() && getter.is_visible()) { |
480 // Invoke the getter and return the result. | 545 // Invoke the getter and return the result. |
481 const Object& result = Object::Handle( | 546 const Object& result = Object::Handle( |
482 DartEntry::InvokeFunction(getter, Object::empty_array())); | 547 DartEntry::InvokeFunction(getter, Object::empty_array())); |
483 return ReturnResult(result); | 548 return ReturnResult(result); |
484 } | 549 } |
485 | 550 |
486 if (throw_nsm_if_absent) { | 551 if (throw_nsm_if_absent) { |
(...skipping 14 matching lines...) Expand all Loading... |
501 | 566 |
502 static RawInstance* InvokeClassGetter(const Class& klass, | 567 static RawInstance* InvokeClassGetter(const Class& klass, |
503 const String& getter_name, | 568 const String& getter_name, |
504 const bool throw_nsm_if_absent) { | 569 const bool throw_nsm_if_absent) { |
505 // Note static fields do not have implicit getters. | 570 // Note static fields do not have implicit getters. |
506 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 571 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
507 if (field.IsNull() || field.IsUninitialized()) { | 572 if (field.IsNull() || field.IsUninitialized()) { |
508 const String& internal_getter_name = String::Handle( | 573 const String& internal_getter_name = String::Handle( |
509 Field::GetterName(getter_name)); | 574 Field::GetterName(getter_name)); |
510 Function& getter = Function::Handle( | 575 Function& getter = Function::Handle( |
511 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 576 klass.LookupStaticFunction(internal_getter_name)); |
512 | 577 |
513 if (getter.IsNull() || !getter.is_visible()) { | 578 if (getter.IsNull() || !getter.is_visible()) { |
514 if (getter.IsNull()) { | 579 if (getter.IsNull()) { |
515 getter = klass.LookupStaticFunctionAllowPrivate(getter_name); | 580 getter = klass.LookupStaticFunction(getter_name); |
516 if (!getter.IsNull()) { | 581 if (!getter.IsNull()) { |
517 // Looking for a getter but found a regular method: closurize it. | 582 // Looking for a getter but found a regular method: closurize it. |
518 const Function& closure_function = | 583 const Function& closure_function = |
519 Function::Handle(getter.ImplicitClosureFunction()); | 584 Function::Handle(getter.ImplicitClosureFunction()); |
520 return closure_function.ImplicitStaticClosure(); | 585 return closure_function.ImplicitStaticClosure(); |
521 } | 586 } |
522 } | 587 } |
523 if (throw_nsm_if_absent) { | 588 if (throw_nsm_if_absent) { |
524 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 589 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
525 getter_name, | 590 getter_name, |
(...skipping 19 matching lines...) Expand all Loading... |
545 | 610 |
546 | 611 |
547 | 612 |
548 static RawInstance* InvokeInstanceGetter(const Class& klass, | 613 static RawInstance* InvokeInstanceGetter(const Class& klass, |
549 const Instance& reflectee, | 614 const Instance& reflectee, |
550 const String& getter_name, | 615 const String& getter_name, |
551 const bool throw_nsm_if_absent) { | 616 const bool throw_nsm_if_absent) { |
552 const String& internal_getter_name = String::Handle( | 617 const String& internal_getter_name = String::Handle( |
553 Field::GetterName(getter_name)); | 618 Field::GetterName(getter_name)); |
554 Function& function = Function::Handle( | 619 Function& function = Function::Handle( |
555 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, internal_getter_name)); | 620 Resolver::ResolveDynamicAnyArgs(klass, internal_getter_name)); |
556 | 621 |
557 if (!function.IsNull() || throw_nsm_if_absent) { | 622 if (!function.IsNull() || throw_nsm_if_absent) { |
558 const int kNumArgs = 1; | 623 const int kNumArgs = 1; |
559 const Array& args = Array::Handle(Array::New(kNumArgs)); | 624 const Array& args = Array::Handle(Array::New(kNumArgs)); |
560 args.SetAt(0, reflectee); | 625 args.SetAt(0, reflectee); |
561 const Array& args_descriptor = | 626 const Array& args_descriptor = |
562 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 627 Array::Handle(ArgumentsDescriptor::New(args.Length())); |
563 | 628 |
564 // InvokeDynamic invokes NoSuchMethod if the provided function is null. | 629 // InvokeDynamic invokes NoSuchMethod if the provided function is null. |
565 return InvokeDynamicFunction(reflectee, | 630 return InvokeDynamicFunction(reflectee, |
(...skipping 13 matching lines...) Expand all Loading... |
579 static RawInstance* LookupFunctionOrFieldInLibraryPrefix( | 644 static RawInstance* LookupFunctionOrFieldInLibraryPrefix( |
580 const LibraryPrefix& prefix, | 645 const LibraryPrefix& prefix, |
581 const String& lookup_name) { | 646 const String& lookup_name) { |
582 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name)); | 647 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name)); |
583 if (!entry.IsNull()) { | 648 if (!entry.IsNull()) { |
584 if (entry.IsField()) { | 649 if (entry.IsField()) { |
585 const Field& field = Field::Cast(entry); | 650 const Field& field = Field::Cast(entry); |
586 const Class& field_owner = Class::Handle(field.owner()); | 651 const Class& field_owner = Class::Handle(field.owner()); |
587 const Library& field_library = Library::Handle(field_owner.library()); | 652 const Library& field_library = Library::Handle(field_owner.library()); |
588 const Instance& result = Instance::Handle( | 653 const Instance& result = Instance::Handle( |
589 InvokeLibraryGetter(field_library, lookup_name, false)); | 654 InvokeLibraryGetterAllowImports(field_library, lookup_name, false)); |
590 if (result.raw() != Object::sentinel().raw()) { | 655 if (result.raw() != Object::sentinel().raw()) { |
591 return result.raw(); | 656 return result.raw(); |
592 } | 657 } |
593 } else if (entry.IsFunction()) { | 658 } else if (entry.IsFunction()) { |
594 const Function& func = Function::Cast(entry); | 659 const Function& func = Function::Cast(entry); |
595 const Function& closure_function = Function::Handle( | 660 const Function& closure_function = Function::Handle( |
596 func.ImplicitClosureFunction()); | 661 func.ImplicitClosureFunction()); |
597 return closure_function.ImplicitStaticClosure(); | 662 return closure_function.ImplicitStaticClosure(); |
598 } | 663 } |
599 } | 664 } |
(...skipping 10 matching lines...) Expand all Loading... |
610 const String& lookup_name) { | 675 const String& lookup_name) { |
611 Instance& result = Instance::Handle( | 676 Instance& result = Instance::Handle( |
612 InvokeClassGetter(klass, lookup_name, false)); | 677 InvokeClassGetter(klass, lookup_name, false)); |
613 if (result.raw() != Object::sentinel().raw()) { | 678 if (result.raw() != Object::sentinel().raw()) { |
614 return result.raw(); | 679 return result.raw(); |
615 } | 680 } |
616 | 681 |
617 Function& func = Function::Handle(); | 682 Function& func = Function::Handle(); |
618 Class& lookup_class = Class::Handle(klass.raw()); | 683 Class& lookup_class = Class::Handle(klass.raw()); |
619 while (func.IsNull() && !lookup_class.IsNull()) { | 684 while (func.IsNull() && !lookup_class.IsNull()) { |
620 func ^= lookup_class.LookupStaticFunctionAllowPrivate(lookup_name); | 685 func ^= lookup_class.LookupStaticFunction(lookup_name); |
621 lookup_class = lookup_class.SuperClass(); | 686 lookup_class = lookup_class.SuperClass(); |
622 } | 687 } |
623 if (!func.IsNull()) { | 688 if (!func.IsNull()) { |
624 const Function& closure_function = Function::Handle( | 689 const Function& closure_function = Function::Handle( |
625 func.ImplicitClosureFunction()); | 690 func.ImplicitClosureFunction()); |
626 ASSERT(!closure_function.IsNull()); | 691 ASSERT(!closure_function.IsNull()); |
627 return closure_function.ImplicitStaticClosure(); | 692 return closure_function.ImplicitStaticClosure(); |
628 } | 693 } |
629 | 694 |
630 // Fall through case: Indicate that we didn't find any function or field using | 695 // Fall through case: Indicate that we didn't find any function or field using |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 return Object::sentinel().raw(); | 736 return Object::sentinel().raw(); |
672 } | 737 } |
673 | 738 |
674 | 739 |
675 static RawInstance* LookupFunctionOrFieldInLibraryHelper( | 740 static RawInstance* LookupFunctionOrFieldInLibraryHelper( |
676 const Library& library, | 741 const Library& library, |
677 const String& class_name, | 742 const String& class_name, |
678 const String& lookup_name) { | 743 const String& lookup_name) { |
679 if (class_name.IsNull()) { | 744 if (class_name.IsNull()) { |
680 const Instance& result = Instance::Handle( | 745 const Instance& result = Instance::Handle( |
681 InvokeLibraryGetter(library, lookup_name, false)); | 746 InvokeLibraryGetterAllowImports(library, lookup_name, false)); |
682 if (result.raw() != Object::sentinel().raw()) { | 747 if (result.raw() != Object::sentinel().raw()) { |
683 return result.raw(); | 748 return result.raw(); |
684 } | 749 } |
685 const Function& func = Function::Handle( | 750 const Function& func = Function::Handle( |
686 library.LookupFunctionAllowPrivate(lookup_name)); | 751 library.LookupLocalFunction(lookup_name)); |
687 if (!func.IsNull()) { | 752 if (!func.IsNull()) { |
688 const Function& closure_function = Function::Handle( | 753 const Function& closure_function = Function::Handle( |
689 func.ImplicitClosureFunction()); | 754 func.ImplicitClosureFunction()); |
690 return closure_function.ImplicitStaticClosure(); | 755 return closure_function.ImplicitStaticClosure(); |
691 } | 756 } |
692 } else { | 757 } else { |
693 const Class& cls = Class::Handle( | 758 const Class& cls = Class::Handle( |
694 library.LookupClassAllowPrivate(class_name)); | 759 library.LookupClass(class_name)); |
695 if (!cls.IsNull()) { | 760 if (!cls.IsNull()) { |
696 return LookupStaticFunctionOrFieldInClass(cls, lookup_name); | 761 return LookupStaticFunctionOrFieldInClass(cls, lookup_name); |
697 } | 762 } |
698 } | 763 } |
699 | 764 |
700 // Fall through case: Indicate that we didn't find any function or field using | 765 // Fall through case: Indicate that we didn't find any function or field using |
701 // a special null instance. This is different from a field being null. Callers | 766 // a special null instance. This is different from a field being null. Callers |
702 // make sure that this null does not leak into Dartland. | 767 // make sure that this null does not leak into Dartland. |
703 return Object::sentinel().raw(); | 768 return Object::sentinel().raw(); |
704 } | 769 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 Bool::True(), // is_declaration | 816 Bool::True(), // is_declaration |
752 Object::null_instance()); | 817 Object::null_instance()); |
753 } | 818 } |
754 | 819 |
755 | 820 |
756 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 821 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
757 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 822 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
758 return CreateTypeMirror(type); | 823 return CreateTypeMirror(type); |
759 } | 824 } |
760 | 825 |
| 826 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) { |
| 827 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 828 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 829 const Library& lib = Library::Handle(ref.GetLibraryReferent()); |
| 830 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw(); |
| 831 } |
| 832 |
| 833 DEFINE_NATIVE_ENTRY(Mirrors_unmangleName, 1) { |
| 834 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 835 // It would be nice to unconditionally use IdentifierPrettyName, alas it |
| 836 // cannot cope with the symbols for the names of anonymous mixin applications. |
| 837 if (Library::IsPrivate(name) || |
| 838 Field::IsGetterName(name) || |
| 839 Field::IsSetterName(name)) { |
| 840 return String::IdentifierPrettyName(name); |
| 841 } |
| 842 return name.raw(); |
| 843 } |
| 844 |
761 | 845 |
762 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 846 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
763 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 847 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
764 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 848 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
765 return Bool::Get(a.referent() == b.referent()).raw(); | 849 return Bool::Get(a.referent() == b.referent()).raw(); |
766 } | 850 } |
767 | 851 |
768 | 852 |
769 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 853 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
770 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); | 854 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 // because this native is an instance method in order to be polymorphic | 1153 // because this native is an instance method in order to be polymorphic |
1070 // with its cousins. | 1154 // with its cousins. |
1071 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 1155 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
1072 GET_NON_NULL_NATIVE_ARGUMENT( | 1156 GET_NON_NULL_NATIVE_ARGUMENT( |
1073 String, function_name, arguments->NativeArgAt(2)); | 1157 String, function_name, arguments->NativeArgAt(2)); |
1074 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1158 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
1075 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1159 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
1076 | 1160 |
1077 Class& klass = Class::Handle(reflectee.clazz()); | 1161 Class& klass = Class::Handle(reflectee.clazz()); |
1078 Function& function = Function::Handle( | 1162 Function& function = Function::Handle( |
1079 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, function_name)); | 1163 Resolver::ResolveDynamicAnyArgs(klass, function_name)); |
1080 | 1164 |
1081 const Array& args_descriptor = | 1165 const Array& args_descriptor = |
1082 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1166 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1083 | 1167 |
1084 return InvokeDynamicFunction(reflectee, | 1168 return InvokeDynamicFunction(reflectee, |
1085 function, | 1169 function, |
1086 function_name, | 1170 function_name, |
1087 args, | 1171 args, |
1088 args_descriptor); | 1172 args_descriptor); |
1089 } | 1173 } |
(...skipping 28 matching lines...) Expand all Loading... |
1118 while (!klass.IsNull()) { | 1202 while (!klass.IsNull()) { |
1119 field = klass.LookupInstanceField(setter_name); | 1203 field = klass.LookupInstanceField(setter_name); |
1120 if (!field.IsNull() && field.is_final()) { | 1204 if (!field.IsNull() && field.is_final()) { |
1121 const String& message = String::Handle( | 1205 const String& message = String::Handle( |
1122 String::NewFormatted("%s: cannot set final field '%s'.", | 1206 String::NewFormatted("%s: cannot set final field '%s'.", |
1123 "InstanceMirror_invokeSetter", | 1207 "InstanceMirror_invokeSetter", |
1124 setter_name.ToCString())); | 1208 setter_name.ToCString())); |
1125 ThrowMirroredCompilationError(message); | 1209 ThrowMirroredCompilationError(message); |
1126 UNREACHABLE(); | 1210 UNREACHABLE(); |
1127 } | 1211 } |
1128 setter = klass.LookupDynamicFunctionAllowPrivate(internal_setter_name); | 1212 setter = klass.LookupDynamicFunction(internal_setter_name); |
1129 if (!setter.IsNull()) { | 1213 if (!setter.IsNull()) { |
1130 break; | 1214 break; |
1131 } | 1215 } |
1132 klass = klass.SuperClass(); | 1216 klass = klass.SuperClass(); |
1133 } | 1217 } |
1134 | 1218 |
1135 // Invoke the setter and return the result. | 1219 // Invoke the setter and return the result. |
1136 const int kNumArgs = 2; | 1220 const int kNumArgs = 2; |
1137 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1221 const Array& args = Array::Handle(Array::New(kNumArgs)); |
1138 args.SetAt(0, reflectee); | 1222 args.SetAt(0, reflectee); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1345 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1262 GET_NON_NULL_NATIVE_ARGUMENT( | 1346 GET_NON_NULL_NATIVE_ARGUMENT( |
1263 String, function_name, arguments->NativeArgAt(2)); | 1347 String, function_name, arguments->NativeArgAt(2)); |
1264 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1348 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
1265 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1349 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
1266 | 1350 |
1267 const Array& args_descriptor_array = | 1351 const Array& args_descriptor_array = |
1268 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1352 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1269 | 1353 |
1270 const Function& function = Function::Handle( | 1354 const Function& function = Function::Handle( |
1271 klass.LookupStaticFunctionAllowPrivate(function_name)); | 1355 klass.LookupStaticFunction(function_name)); |
1272 | |
1273 | 1356 |
1274 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1357 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1275 if (function.IsNull() || | 1358 if (function.IsNull() || |
1276 !function.AreValidArguments(args_descriptor, NULL) || | 1359 !function.AreValidArguments(args_descriptor, NULL) || |
1277 !function.is_visible()) { | 1360 !function.is_visible()) { |
1278 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1361 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1279 function_name, | 1362 function_name, |
1280 function, | 1363 function, |
1281 InvocationMirror::kStatic, | 1364 InvocationMirror::kStatic, |
1282 InvocationMirror::kMethod); | 1365 InvocationMirror::kMethod); |
(...skipping 29 matching lines...) Expand all Loading... |
1312 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1395 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1313 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1396 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
1314 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1397 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
1315 | 1398 |
1316 // Check for real fields and user-defined setters. | 1399 // Check for real fields and user-defined setters. |
1317 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1400 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
1318 if (field.IsNull()) { | 1401 if (field.IsNull()) { |
1319 const String& internal_setter_name = String::Handle( | 1402 const String& internal_setter_name = String::Handle( |
1320 Field::SetterName(setter_name)); | 1403 Field::SetterName(setter_name)); |
1321 const Function& setter = Function::Handle( | 1404 const Function& setter = Function::Handle( |
1322 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1405 klass.LookupStaticFunction(internal_setter_name)); |
1323 | 1406 |
1324 if (setter.IsNull() || !setter.is_visible()) { | 1407 if (setter.IsNull() || !setter.is_visible()) { |
1325 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1408 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1326 setter_name, | 1409 setter_name, |
1327 setter, | 1410 setter, |
1328 InvocationMirror::kStatic, | 1411 InvocationMirror::kStatic, |
1329 InvocationMirror::kSetter); | 1412 InvocationMirror::kSetter); |
1330 UNREACHABLE(); | 1413 UNREACHABLE(); |
1331 } | 1414 } |
1332 | 1415 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 // This convention prevents users from explicitly calling constructors. | 1456 // This convention prevents users from explicitly calling constructors. |
1374 const String& klass_name = String::Handle(klass.Name()); | 1457 const String& klass_name = String::Handle(klass.Name()); |
1375 String& internal_constructor_name = | 1458 String& internal_constructor_name = |
1376 String::Handle(String::Concat(klass_name, Symbols::Dot())); | 1459 String::Handle(String::Concat(klass_name, Symbols::Dot())); |
1377 if (!constructor_name.IsNull()) { | 1460 if (!constructor_name.IsNull()) { |
1378 internal_constructor_name = | 1461 internal_constructor_name = |
1379 String::Concat(internal_constructor_name, constructor_name); | 1462 String::Concat(internal_constructor_name, constructor_name); |
1380 } | 1463 } |
1381 | 1464 |
1382 Function& lookup_constructor = Function::Handle( | 1465 Function& lookup_constructor = Function::Handle( |
1383 klass.LookupFunctionAllowPrivate(internal_constructor_name)); | 1466 klass.LookupFunction(internal_constructor_name)); |
1384 | 1467 |
1385 if (lookup_constructor.IsNull() || | 1468 if (lookup_constructor.IsNull() || |
1386 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || | 1469 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || |
1387 !lookup_constructor.is_visible()) { | 1470 !lookup_constructor.is_visible()) { |
1388 // Pretend we didn't find the constructor at all when the arity is wrong | 1471 // Pretend we didn't find the constructor at all when the arity is wrong |
1389 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1472 // so as to produce the same NoSuchMethodError as the non-reflective case. |
1390 lookup_constructor = Function::null(); | 1473 lookup_constructor = Function::null(); |
1391 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1474 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1392 internal_constructor_name, | 1475 internal_constructor_name, |
1393 lookup_constructor, | 1476 lookup_constructor, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1588 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
1506 GET_NON_NULL_NATIVE_ARGUMENT( | 1589 GET_NON_NULL_NATIVE_ARGUMENT( |
1507 String, function_name, arguments->NativeArgAt(2)); | 1590 String, function_name, arguments->NativeArgAt(2)); |
1508 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1591 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
1509 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1592 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
1510 | 1593 |
1511 const Array& args_descriptor_array = | 1594 const Array& args_descriptor_array = |
1512 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1595 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1513 | 1596 |
1514 const Function& function = Function::Handle( | 1597 const Function& function = Function::Handle( |
1515 library.LookupFunctionAllowPrivate(function_name)); | 1598 library.LookupLocalFunction(function_name)); |
1516 | 1599 |
1517 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1600 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1518 if (function.IsNull() || | 1601 if (function.IsNull() || |
1519 !function.AreValidArguments(args_descriptor, NULL) || | 1602 !function.AreValidArguments(args_descriptor, NULL) || |
1520 !function.is_visible()) { | 1603 !function.is_visible()) { |
1521 ThrowNoSuchMethod(Instance::null_instance(), | 1604 ThrowNoSuchMethod(Instance::null_instance(), |
1522 function_name, | 1605 function_name, |
1523 function, | 1606 function, |
1524 InvocationMirror::kTopLevel, | 1607 InvocationMirror::kTopLevel, |
1525 InvocationMirror::kMethod); | 1608 InvocationMirror::kMethod); |
(...skipping 27 matching lines...) Expand all Loading... |
1553 // with its cousins. | 1636 // with its cousins. |
1554 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1637 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1555 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1638 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
1556 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1639 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
1557 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1640 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
1558 | 1641 |
1559 // To access a top-level we may need to use the Field or the | 1642 // To access a top-level we may need to use the Field or the |
1560 // setter Function. The setter function may either be in the | 1643 // setter Function. The setter function may either be in the |
1561 // library or in the field's owner class, depending. | 1644 // library or in the field's owner class, depending. |
1562 const Field& field = Field::Handle( | 1645 const Field& field = Field::Handle( |
1563 library.LookupFieldAllowPrivate(setter_name)); | 1646 library.LookupLocalField(setter_name)); |
1564 | 1647 |
1565 if (field.IsNull()) { | 1648 if (field.IsNull()) { |
1566 const String& internal_setter_name = | 1649 const String& internal_setter_name = |
1567 String::Handle(Field::SetterName(setter_name)); | 1650 String::Handle(Field::SetterName(setter_name)); |
1568 const Function& setter = Function::Handle( | 1651 const Function& setter = Function::Handle( |
1569 library.LookupFunctionAllowPrivate(internal_setter_name)); | 1652 library.LookupLocalFunction(internal_setter_name)); |
1570 if (setter.IsNull() || !setter.is_visible()) { | 1653 if (setter.IsNull() || !setter.is_visible()) { |
1571 ThrowNoSuchMethod(Instance::null_instance(), | 1654 ThrowNoSuchMethod(Instance::null_instance(), |
1572 setter_name, | 1655 setter_name, |
1573 setter, | 1656 setter, |
1574 InvocationMirror::kTopLevel, | 1657 InvocationMirror::kTopLevel, |
1575 InvocationMirror::kSetter); | 1658 InvocationMirror::kSetter); |
1576 UNREACHABLE(); | 1659 UNREACHABLE(); |
1577 } | 1660 } |
1578 | 1661 |
1579 // Invoke the setter and return the result. | 1662 // Invoke the setter and return the result. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 } | 1766 } |
1684 | 1767 |
1685 | 1768 |
1686 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1769 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
1687 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1770 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
1688 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1771 const Field& field = Field::Handle(ref.GetFieldReferent()); |
1689 return field.type(); | 1772 return field.type(); |
1690 } | 1773 } |
1691 | 1774 |
1692 } // namespace dart | 1775 } // namespace dart |
OLD | NEW |