| 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/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 250 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 251 args.SetAt(1, type); | 251 args.SetAt(1, type); |
| 252 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 252 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
| 253 } | 253 } |
| 254 | 254 |
| 255 | 255 |
| 256 static RawInstance* CreateMethodMirror(const Function& func, | 256 static RawInstance* CreateMethodMirror(const Function& func, |
| 257 const Instance& owner_mirror) { | 257 const Instance& owner_mirror) { |
| 258 const Array& args = Array::Handle(Array::New(12)); | 258 const Array& args = Array::Handle(Array::New(12)); |
| 259 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 259 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 260 args.SetAt(1, String::Handle(func.UserVisibleName())); | 260 |
| 261 String& name = String::Handle(func.name()); |
| 262 name = String::IdentifierPrettyNameRetainPrivate(name); |
| 263 args.SetAt(1, name); |
| 264 |
| 261 args.SetAt(2, owner_mirror); | 265 args.SetAt(2, owner_mirror); |
| 262 args.SetAt(3, Bool::Get(func.is_static())); | 266 args.SetAt(3, Bool::Get(func.is_static())); |
| 263 args.SetAt(4, Bool::Get(func.is_abstract())); | 267 args.SetAt(4, Bool::Get(func.is_abstract())); |
| 264 args.SetAt(5, Bool::Get(func.IsGetterFunction())); | 268 args.SetAt(5, Bool::Get(func.IsGetterFunction())); |
| 265 args.SetAt(6, Bool::Get(func.IsSetterFunction())); | 269 args.SetAt(6, Bool::Get(func.IsSetterFunction())); |
| 266 | 270 |
| 267 bool isConstructor = (func.kind() == RawFunction::kConstructor); | 271 bool isConstructor = (func.kind() == RawFunction::kConstructor); |
| 268 args.SetAt(7, Bool::Get(isConstructor)); | 272 args.SetAt(7, Bool::Get(isConstructor)); |
| 269 args.SetAt(8, Bool::Get(isConstructor && func.is_const())); | 273 args.SetAt(8, Bool::Get(isConstructor && func.is_const())); |
| 270 args.SetAt(9, Bool::Get(isConstructor && func.IsConstructor())); | 274 args.SetAt(9, Bool::Get(isConstructor && func.IsConstructor())); |
| 271 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting())); | 275 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting())); |
| 272 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory())); | 276 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory())); |
| 273 | 277 |
| 274 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); | 278 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); |
| 275 } | 279 } |
| 276 | 280 |
| 277 | 281 |
| 278 static RawInstance* CreateVariableMirror(const Field& field, | 282 static RawInstance* CreateVariableMirror(const Field& field, |
| 279 const Instance& owner_mirror) { | 283 const Instance& owner_mirror) { |
| 280 const MirrorReference& field_ref = | 284 const MirrorReference& field_ref = |
| 281 MirrorReference::Handle(MirrorReference::New(field)); | 285 MirrorReference::Handle(MirrorReference::New(field)); |
| 282 | 286 |
| 283 const String& name = String::Handle(field.UserVisibleName()); | 287 const String& name = String::Handle(field.name()); |
| 284 | 288 |
| 285 const Array& args = Array::Handle(Array::New(6)); | 289 const Array& args = Array::Handle(Array::New(6)); |
| 286 args.SetAt(0, field_ref); | 290 args.SetAt(0, field_ref); |
| 287 args.SetAt(1, name); | 291 args.SetAt(1, name); |
| 288 args.SetAt(2, owner_mirror); | 292 args.SetAt(2, owner_mirror); |
| 289 args.SetAt(3, Object::null_instance()); // Null for type. | 293 args.SetAt(3, Object::null_instance()); // Null for type. |
| 290 args.SetAt(4, Bool::Get(field.is_static())); | 294 args.SetAt(4, Bool::Get(field.is_static())); |
| 291 args.SetAt(5, Bool::Get(field.is_final())); | 295 args.SetAt(5, Bool::Get(field.is_final())); |
| 292 | 296 |
| 293 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 297 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); | 335 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
| 332 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); | 336 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); |
| 333 | 337 |
| 334 const Array& args = Array::Handle(Array::New(6)); | 338 const Array& args = Array::Handle(Array::New(6)); |
| 335 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 339 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 336 args.SetAt(1, type); | 340 args.SetAt(1, type); |
| 337 // We do not set the names of anonymous mixin applications because the mirrors | 341 // We do not set the names of anonymous mixin applications because the mirrors |
| 338 // use a different naming convention than the VM (lib.S with lib.M and S&M | 342 // use a different naming convention than the VM (lib.S with lib.M and S&M |
| 339 // respectively). | 343 // respectively). |
| 340 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { | 344 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { |
| 341 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 345 args.SetAt(2, String::Handle(cls.Name())); |
| 342 } | 346 } |
| 343 args.SetAt(3, is_generic); | 347 args.SetAt(3, is_generic); |
| 344 args.SetAt(4, is_mixin_typedef); | 348 args.SetAt(4, is_mixin_typedef); |
| 345 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); | 349 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); |
| 346 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 350 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 347 } | 351 } |
| 348 | 352 |
| 349 | 353 |
| 350 static RawInstance* CreateLibraryMirror(const Library& lib) { | 354 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 351 const Array& args = Array::Handle(Array::New(3)); | 355 const Array& args = Array::Handle(Array::New(3)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 476 |
| 473 | 477 |
| 474 static RawInstance* InvokeLibraryGetter(const Library& library, | 478 static RawInstance* InvokeLibraryGetter(const Library& library, |
| 475 const String& getter_name, | 479 const String& getter_name, |
| 476 const bool throw_nsm_if_absent) { | 480 const bool throw_nsm_if_absent) { |
| 477 // To access a top-level we may need to use the Field or the getter Function. | 481 // To access a top-level we may need to use the Field or the getter Function. |
| 478 // The getter function may either be in the library or in the field's owner | 482 // The getter function may either be in the library or in the field's owner |
| 479 // class, depending on whether it was an actual getter, or an uninitialized | 483 // class, depending on whether it was an actual getter, or an uninitialized |
| 480 // field. | 484 // field. |
| 481 const Field& field = Field::Handle( | 485 const Field& field = Field::Handle( |
| 486 library.LookupLocalField(getter_name)); |
| 487 Function& getter = Function::Handle(); |
| 488 if (field.IsNull()) { |
| 489 // No field found. Check for a getter in the lib. |
| 490 const String& internal_getter_name = |
| 491 String::Handle(Field::GetterName(getter_name)); |
| 492 getter = library.LookupLocalFunction(internal_getter_name); |
| 493 if (getter.IsNull()) { |
| 494 getter = library.LookupLocalFunction(getter_name); |
| 495 if (!getter.IsNull()) { |
| 496 // Looking for a getter but found a regular method: closurize it. |
| 497 const Function& closure_function = |
| 498 Function::Handle(getter.ImplicitClosureFunction()); |
| 499 return closure_function.ImplicitStaticClosure(); |
| 500 } |
| 501 } |
| 502 } else { |
| 503 if (!field.IsUninitialized()) { |
| 504 return field.value(); |
| 505 } |
| 506 // An uninitialized field was found. Check for a getter in the field's |
| 507 // owner classs. |
| 508 const Class& klass = Class::Handle(field.owner()); |
| 509 const String& internal_getter_name = |
| 510 String::Handle(Field::GetterName(getter_name)); |
| 511 getter = klass.LookupStaticFunction(internal_getter_name); |
| 512 } |
| 513 |
| 514 if (!getter.IsNull() && getter.is_visible()) { |
| 515 // Invoke the getter and return the result. |
| 516 const Object& result = Object::Handle( |
| 517 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 518 return ReturnResult(result); |
| 519 } |
| 520 |
| 521 if (throw_nsm_if_absent) { |
| 522 ThrowNoSuchMethod(Instance::null_instance(), |
| 523 getter_name, |
| 524 getter, |
| 525 InvocationMirror::kTopLevel, |
| 526 InvocationMirror::kGetter); |
| 527 UNREACHABLE(); |
| 528 } |
| 529 |
| 530 // Fall through case: Indicate that we didn't find any function or field using |
| 531 // a special null instance. This is different from a field being null. Callers |
| 532 // make sure that this null does not leak into Dartland. |
| 533 return Object::sentinel().raw(); |
| 534 } |
| 535 |
| 536 |
| 537 // TODO(13656): Remove AllowPrivate. |
| 538 static RawInstance* InvokeLibraryGetterAllowImports( |
| 539 const Library& library, |
| 540 const String& getter_name, |
| 541 const bool throw_nsm_if_absent) { |
| 542 // To access a top-level we may need to use the Field or the getter Function. |
| 543 // The getter function may either be in the library or in the field's owner |
| 544 // class, depending on whether it was an actual getter, or an uninitialized |
| 545 // field. |
| 546 const Field& field = Field::Handle( |
| 482 library.LookupFieldAllowPrivate(getter_name)); | 547 library.LookupFieldAllowPrivate(getter_name)); |
| 483 Function& getter = Function::Handle(); | 548 Function& getter = Function::Handle(); |
| 484 if (field.IsNull()) { | 549 if (field.IsNull()) { |
| 485 // No field found. Check for a getter in the lib. | 550 // No field found. Check for a getter in the lib. |
| 486 const String& internal_getter_name = | 551 const String& internal_getter_name = |
| 487 String::Handle(Field::GetterName(getter_name)); | 552 String::Handle(Field::GetterName(getter_name)); |
| 488 getter = library.LookupFunctionAllowPrivate(internal_getter_name); | 553 getter = library.LookupFunctionAllowPrivate(internal_getter_name); |
| 489 if (getter.IsNull()) { | 554 if (getter.IsNull()) { |
| 490 getter = library.LookupFunctionAllowPrivate(getter_name); | 555 getter = library.LookupFunctionAllowPrivate(getter_name); |
| 491 if (!getter.IsNull()) { | 556 if (!getter.IsNull()) { |
| 492 // Looking for a getter but found a regular method: closurize it. | 557 // Looking for a getter but found a regular method: closurize it. |
| 493 const Function& closure_function = | 558 const Function& closure_function = |
| 494 Function::Handle(getter.ImplicitClosureFunction()); | 559 Function::Handle(getter.ImplicitClosureFunction()); |
| 495 return closure_function.ImplicitStaticClosure(); | 560 return closure_function.ImplicitStaticClosure(); |
| 496 } | 561 } |
| 497 } | 562 } |
| 498 } else { | 563 } else { |
| 499 if (!field.IsUninitialized()) { | 564 if (!field.IsUninitialized()) { |
| 500 return field.value(); | 565 return field.value(); |
| 501 } | 566 } |
| 502 // An uninitialized field was found. Check for a getter in the field's | 567 // An uninitialized field was found. Check for a getter in the field's |
| 503 // owner classs. | 568 // owner classs. |
| 504 const Class& klass = Class::Handle(field.owner()); | 569 const Class& klass = Class::Handle(field.owner()); |
| 505 const String& internal_getter_name = | 570 const String& internal_getter_name = |
| 506 String::Handle(Field::GetterName(getter_name)); | 571 String::Handle(Field::GetterName(getter_name)); |
| 507 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 572 getter = klass.LookupStaticFunction(internal_getter_name); |
| 508 } | 573 } |
| 509 | 574 |
| 510 if (!getter.IsNull() && getter.is_visible()) { | 575 if (!getter.IsNull() && getter.is_visible()) { |
| 511 // Invoke the getter and return the result. | 576 // Invoke the getter and return the result. |
| 512 const Object& result = Object::Handle( | 577 const Object& result = Object::Handle( |
| 513 DartEntry::InvokeFunction(getter, Object::empty_array())); | 578 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 514 return ReturnResult(result); | 579 return ReturnResult(result); |
| 515 } | 580 } |
| 516 | 581 |
| 517 if (throw_nsm_if_absent) { | 582 if (throw_nsm_if_absent) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 532 | 597 |
| 533 static RawInstance* InvokeClassGetter(const Class& klass, | 598 static RawInstance* InvokeClassGetter(const Class& klass, |
| 534 const String& getter_name, | 599 const String& getter_name, |
| 535 const bool throw_nsm_if_absent) { | 600 const bool throw_nsm_if_absent) { |
| 536 // Note static fields do not have implicit getters. | 601 // Note static fields do not have implicit getters. |
| 537 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 602 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 538 if (field.IsNull() || field.IsUninitialized()) { | 603 if (field.IsNull() || field.IsUninitialized()) { |
| 539 const String& internal_getter_name = String::Handle( | 604 const String& internal_getter_name = String::Handle( |
| 540 Field::GetterName(getter_name)); | 605 Field::GetterName(getter_name)); |
| 541 Function& getter = Function::Handle( | 606 Function& getter = Function::Handle( |
| 542 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 607 klass.LookupStaticFunction(internal_getter_name)); |
| 543 | 608 |
| 544 if (getter.IsNull() || !getter.is_visible()) { | 609 if (getter.IsNull() || !getter.is_visible()) { |
| 545 if (getter.IsNull()) { | 610 if (getter.IsNull()) { |
| 546 getter = klass.LookupStaticFunctionAllowPrivate(getter_name); | 611 getter = klass.LookupStaticFunction(getter_name); |
| 547 if (!getter.IsNull()) { | 612 if (!getter.IsNull()) { |
| 548 // Looking for a getter but found a regular method: closurize it. | 613 // Looking for a getter but found a regular method: closurize it. |
| 549 const Function& closure_function = | 614 const Function& closure_function = |
| 550 Function::Handle(getter.ImplicitClosureFunction()); | 615 Function::Handle(getter.ImplicitClosureFunction()); |
| 551 return closure_function.ImplicitStaticClosure(); | 616 return closure_function.ImplicitStaticClosure(); |
| 552 } | 617 } |
| 553 } | 618 } |
| 554 if (throw_nsm_if_absent) { | 619 if (throw_nsm_if_absent) { |
| 555 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 620 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 556 getter_name, | 621 getter_name, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 576 | 641 |
| 577 | 642 |
| 578 | 643 |
| 579 static RawInstance* InvokeInstanceGetter(const Class& klass, | 644 static RawInstance* InvokeInstanceGetter(const Class& klass, |
| 580 const Instance& reflectee, | 645 const Instance& reflectee, |
| 581 const String& getter_name, | 646 const String& getter_name, |
| 582 const bool throw_nsm_if_absent) { | 647 const bool throw_nsm_if_absent) { |
| 583 const String& internal_getter_name = String::Handle( | 648 const String& internal_getter_name = String::Handle( |
| 584 Field::GetterName(getter_name)); | 649 Field::GetterName(getter_name)); |
| 585 Function& function = Function::Handle( | 650 Function& function = Function::Handle( |
| 586 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, internal_getter_name)); | 651 Resolver::ResolveDynamicAnyArgs(klass, internal_getter_name)); |
| 587 | 652 |
| 588 if (!function.IsNull() || throw_nsm_if_absent) { | 653 if (!function.IsNull() || throw_nsm_if_absent) { |
| 589 const int kNumArgs = 1; | 654 const int kNumArgs = 1; |
| 590 const Array& args = Array::Handle(Array::New(kNumArgs)); | 655 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 591 args.SetAt(0, reflectee); | 656 args.SetAt(0, reflectee); |
| 592 const Array& args_descriptor = | 657 const Array& args_descriptor = |
| 593 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 658 Array::Handle(ArgumentsDescriptor::New(args.Length())); |
| 594 | 659 |
| 595 // InvokeDynamic invokes NoSuchMethod if the provided function is null. | 660 // InvokeDynamic invokes NoSuchMethod if the provided function is null. |
| 596 return InvokeDynamicFunction(reflectee, | 661 return InvokeDynamicFunction(reflectee, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 610 static RawInstance* LookupFunctionOrFieldInLibraryPrefix( | 675 static RawInstance* LookupFunctionOrFieldInLibraryPrefix( |
| 611 const LibraryPrefix& prefix, | 676 const LibraryPrefix& prefix, |
| 612 const String& lookup_name) { | 677 const String& lookup_name) { |
| 613 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name)); | 678 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name)); |
| 614 if (!entry.IsNull()) { | 679 if (!entry.IsNull()) { |
| 615 if (entry.IsField()) { | 680 if (entry.IsField()) { |
| 616 const Field& field = Field::Cast(entry); | 681 const Field& field = Field::Cast(entry); |
| 617 const Class& field_owner = Class::Handle(field.owner()); | 682 const Class& field_owner = Class::Handle(field.owner()); |
| 618 const Library& field_library = Library::Handle(field_owner.library()); | 683 const Library& field_library = Library::Handle(field_owner.library()); |
| 619 const Instance& result = Instance::Handle( | 684 const Instance& result = Instance::Handle( |
| 620 InvokeLibraryGetter(field_library, lookup_name, false)); | 685 InvokeLibraryGetterAllowImports(field_library, lookup_name, false)); |
| 621 if (result.raw() != Object::sentinel().raw()) { | 686 if (result.raw() != Object::sentinel().raw()) { |
| 622 return result.raw(); | 687 return result.raw(); |
| 623 } | 688 } |
| 624 } else if (entry.IsFunction()) { | 689 } else if (entry.IsFunction()) { |
| 625 const Function& func = Function::Cast(entry); | 690 const Function& func = Function::Cast(entry); |
| 626 const Function& closure_function = Function::Handle( | 691 const Function& closure_function = Function::Handle( |
| 627 func.ImplicitClosureFunction()); | 692 func.ImplicitClosureFunction()); |
| 628 return closure_function.ImplicitStaticClosure(); | 693 return closure_function.ImplicitStaticClosure(); |
| 629 } | 694 } |
| 630 } | 695 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 641 const String& lookup_name) { | 706 const String& lookup_name) { |
| 642 Instance& result = Instance::Handle( | 707 Instance& result = Instance::Handle( |
| 643 InvokeClassGetter(klass, lookup_name, false)); | 708 InvokeClassGetter(klass, lookup_name, false)); |
| 644 if (result.raw() != Object::sentinel().raw()) { | 709 if (result.raw() != Object::sentinel().raw()) { |
| 645 return result.raw(); | 710 return result.raw(); |
| 646 } | 711 } |
| 647 | 712 |
| 648 Function& func = Function::Handle(); | 713 Function& func = Function::Handle(); |
| 649 Class& lookup_class = Class::Handle(klass.raw()); | 714 Class& lookup_class = Class::Handle(klass.raw()); |
| 650 while (func.IsNull() && !lookup_class.IsNull()) { | 715 while (func.IsNull() && !lookup_class.IsNull()) { |
| 651 func ^= lookup_class.LookupStaticFunctionAllowPrivate(lookup_name); | 716 func ^= lookup_class.LookupStaticFunction(lookup_name); |
| 652 lookup_class = lookup_class.SuperClass(); | 717 lookup_class = lookup_class.SuperClass(); |
| 653 } | 718 } |
| 654 if (!func.IsNull()) { | 719 if (!func.IsNull()) { |
| 655 const Function& closure_function = Function::Handle( | 720 const Function& closure_function = Function::Handle( |
| 656 func.ImplicitClosureFunction()); | 721 func.ImplicitClosureFunction()); |
| 657 ASSERT(!closure_function.IsNull()); | 722 ASSERT(!closure_function.IsNull()); |
| 658 return closure_function.ImplicitStaticClosure(); | 723 return closure_function.ImplicitStaticClosure(); |
| 659 } | 724 } |
| 660 | 725 |
| 661 // Fall through case: Indicate that we didn't find any function or field using | 726 // 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... |
| 702 return Object::sentinel().raw(); | 767 return Object::sentinel().raw(); |
| 703 } | 768 } |
| 704 | 769 |
| 705 | 770 |
| 706 static RawInstance* LookupFunctionOrFieldInLibraryHelper( | 771 static RawInstance* LookupFunctionOrFieldInLibraryHelper( |
| 707 const Library& library, | 772 const Library& library, |
| 708 const String& class_name, | 773 const String& class_name, |
| 709 const String& lookup_name) { | 774 const String& lookup_name) { |
| 710 if (class_name.IsNull()) { | 775 if (class_name.IsNull()) { |
| 711 const Instance& result = Instance::Handle( | 776 const Instance& result = Instance::Handle( |
| 712 InvokeLibraryGetter(library, lookup_name, false)); | 777 InvokeLibraryGetterAllowImports(library, lookup_name, false)); |
| 713 if (result.raw() != Object::sentinel().raw()) { | 778 if (result.raw() != Object::sentinel().raw()) { |
| 714 return result.raw(); | 779 return result.raw(); |
| 715 } | 780 } |
| 716 const Function& func = Function::Handle( | 781 const Function& func = Function::Handle( |
| 717 library.LookupFunctionAllowPrivate(lookup_name)); | 782 library.LookupLocalFunction(lookup_name)); |
| 718 if (!func.IsNull()) { | 783 if (!func.IsNull()) { |
| 719 const Function& closure_function = Function::Handle( | 784 const Function& closure_function = Function::Handle( |
| 720 func.ImplicitClosureFunction()); | 785 func.ImplicitClosureFunction()); |
| 721 return closure_function.ImplicitStaticClosure(); | 786 return closure_function.ImplicitStaticClosure(); |
| 722 } | 787 } |
| 723 } else { | 788 } else { |
| 724 const Class& cls = Class::Handle( | 789 const Class& cls = Class::Handle( |
| 725 library.LookupClassAllowPrivate(class_name)); | 790 library.LookupClass(class_name)); |
| 726 if (!cls.IsNull()) { | 791 if (!cls.IsNull()) { |
| 727 return LookupStaticFunctionOrFieldInClass(cls, lookup_name); | 792 return LookupStaticFunctionOrFieldInClass(cls, lookup_name); |
| 728 } | 793 } |
| 729 } | 794 } |
| 730 | 795 |
| 731 // Fall through case: Indicate that we didn't find any function or field using | 796 // Fall through case: Indicate that we didn't find any function or field using |
| 732 // a special null instance. This is different from a field being null. Callers | 797 // a special null instance. This is different from a field being null. Callers |
| 733 // make sure that this null does not leak into Dartland. | 798 // make sure that this null does not leak into Dartland. |
| 734 return Object::sentinel().raw(); | 799 return Object::sentinel().raw(); |
| 735 } | 800 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 Bool::True(), // is_declaration | 849 Bool::True(), // is_declaration |
| 785 Object::null_instance()); | 850 Object::null_instance()); |
| 786 } | 851 } |
| 787 | 852 |
| 788 | 853 |
| 789 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 854 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
| 790 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 855 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 791 return CreateTypeMirror(type); | 856 return CreateTypeMirror(type); |
| 792 } | 857 } |
| 793 | 858 |
| 859 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) { |
| 860 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 861 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 862 const Library& lib = Library::Handle(ref.GetLibraryReferent()); |
| 863 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw(); |
| 864 } |
| 865 |
| 866 DEFINE_NATIVE_ENTRY(Mirrors_unmangleName, 1) { |
| 867 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 868 // It would be nice to unconditionally use IdentifierPrettyName, alas it |
| 869 // cannot cope with the symbols for the names of anonymous mixin applications. |
| 870 if (Library::IsPrivate(name) || |
| 871 Field::IsGetterName(name) || |
| 872 Field::IsSetterName(name)) { |
| 873 return String::IdentifierPrettyName(name); |
| 874 } |
| 875 return name.raw(); |
| 876 } |
| 877 |
| 794 | 878 |
| 795 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 879 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
| 796 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 880 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
| 797 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 881 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
| 798 return Bool::Get(a.referent() == b.referent()).raw(); | 882 return Bool::Get(a.referent() == b.referent()).raw(); |
| 799 } | 883 } |
| 800 | 884 |
| 801 | 885 |
| 802 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 886 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
| 803 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); | 887 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 // because this native is an instance method in order to be polymorphic | 1233 // because this native is an instance method in order to be polymorphic |
| 1150 // with its cousins. | 1234 // with its cousins. |
| 1151 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 1235 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 1152 GET_NON_NULL_NATIVE_ARGUMENT( | 1236 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1153 String, function_name, arguments->NativeArgAt(2)); | 1237 String, function_name, arguments->NativeArgAt(2)); |
| 1154 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1238 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 1155 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1239 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1156 | 1240 |
| 1157 Class& klass = Class::Handle(reflectee.clazz()); | 1241 Class& klass = Class::Handle(reflectee.clazz()); |
| 1158 Function& function = Function::Handle( | 1242 Function& function = Function::Handle( |
| 1159 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, function_name)); | 1243 Resolver::ResolveDynamicAnyArgs(klass, function_name)); |
| 1160 | 1244 |
| 1161 const Array& args_descriptor = | 1245 const Array& args_descriptor = |
| 1162 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1246 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 1163 | 1247 |
| 1164 return InvokeDynamicFunction(reflectee, | 1248 return InvokeDynamicFunction(reflectee, |
| 1165 function, | 1249 function, |
| 1166 function_name, | 1250 function_name, |
| 1167 args, | 1251 args, |
| 1168 args_descriptor); | 1252 args_descriptor); |
| 1169 } | 1253 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1198 while (!klass.IsNull()) { | 1282 while (!klass.IsNull()) { |
| 1199 field = klass.LookupInstanceField(setter_name); | 1283 field = klass.LookupInstanceField(setter_name); |
| 1200 if (!field.IsNull() && field.is_final()) { | 1284 if (!field.IsNull() && field.is_final()) { |
| 1201 const String& message = String::Handle( | 1285 const String& message = String::Handle( |
| 1202 String::NewFormatted("%s: cannot set final field '%s'.", | 1286 String::NewFormatted("%s: cannot set final field '%s'.", |
| 1203 "InstanceMirror_invokeSetter", | 1287 "InstanceMirror_invokeSetter", |
| 1204 setter_name.ToCString())); | 1288 setter_name.ToCString())); |
| 1205 ThrowMirroredCompilationError(message); | 1289 ThrowMirroredCompilationError(message); |
| 1206 UNREACHABLE(); | 1290 UNREACHABLE(); |
| 1207 } | 1291 } |
| 1208 setter = klass.LookupDynamicFunctionAllowPrivate(internal_setter_name); | 1292 setter = klass.LookupDynamicFunction(internal_setter_name); |
| 1209 if (!setter.IsNull()) { | 1293 if (!setter.IsNull()) { |
| 1210 break; | 1294 break; |
| 1211 } | 1295 } |
| 1212 klass = klass.SuperClass(); | 1296 klass = klass.SuperClass(); |
| 1213 } | 1297 } |
| 1214 | 1298 |
| 1215 // Invoke the setter and return the result. | 1299 // Invoke the setter and return the result. |
| 1216 const int kNumArgs = 2; | 1300 const int kNumArgs = 2; |
| 1217 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1301 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 1218 args.SetAt(0, reflectee); | 1302 args.SetAt(0, reflectee); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1434 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1351 GET_NON_NULL_NATIVE_ARGUMENT( | 1435 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1352 String, function_name, arguments->NativeArgAt(2)); | 1436 String, function_name, arguments->NativeArgAt(2)); |
| 1353 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1437 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 1354 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1438 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1355 | 1439 |
| 1356 const Array& args_descriptor_array = | 1440 const Array& args_descriptor_array = |
| 1357 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1441 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 1358 | 1442 |
| 1359 const Function& function = Function::Handle( | 1443 const Function& function = Function::Handle( |
| 1360 klass.LookupStaticFunctionAllowPrivate(function_name)); | 1444 klass.LookupStaticFunction(function_name)); |
| 1361 | |
| 1362 | 1445 |
| 1363 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1446 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
| 1364 if (function.IsNull() || | 1447 if (function.IsNull() || |
| 1365 !function.AreValidArguments(args_descriptor, NULL) || | 1448 !function.AreValidArguments(args_descriptor, NULL) || |
| 1366 !function.is_visible()) { | 1449 !function.is_visible()) { |
| 1367 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1450 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 1368 function_name, | 1451 function_name, |
| 1369 function, | 1452 function, |
| 1370 InvocationMirror::kStatic, | 1453 InvocationMirror::kStatic, |
| 1371 InvocationMirror::kMethod); | 1454 InvocationMirror::kMethod); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1401 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1484 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1402 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1485 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1403 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1486 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1404 | 1487 |
| 1405 // Check for real fields and user-defined setters. | 1488 // Check for real fields and user-defined setters. |
| 1406 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1489 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 1407 if (field.IsNull()) { | 1490 if (field.IsNull()) { |
| 1408 const String& internal_setter_name = String::Handle( | 1491 const String& internal_setter_name = String::Handle( |
| 1409 Field::SetterName(setter_name)); | 1492 Field::SetterName(setter_name)); |
| 1410 const Function& setter = Function::Handle( | 1493 const Function& setter = Function::Handle( |
| 1411 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1494 klass.LookupStaticFunction(internal_setter_name)); |
| 1412 | 1495 |
| 1413 if (setter.IsNull() || !setter.is_visible()) { | 1496 if (setter.IsNull() || !setter.is_visible()) { |
| 1414 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1497 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 1415 setter_name, | 1498 setter_name, |
| 1416 setter, | 1499 setter, |
| 1417 InvocationMirror::kStatic, | 1500 InvocationMirror::kStatic, |
| 1418 InvocationMirror::kSetter); | 1501 InvocationMirror::kSetter); |
| 1419 UNREACHABLE(); | 1502 UNREACHABLE(); |
| 1420 } | 1503 } |
| 1421 | 1504 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 // This convention prevents users from explicitly calling constructors. | 1545 // This convention prevents users from explicitly calling constructors. |
| 1463 const String& klass_name = String::Handle(klass.Name()); | 1546 const String& klass_name = String::Handle(klass.Name()); |
| 1464 String& internal_constructor_name = | 1547 String& internal_constructor_name = |
| 1465 String::Handle(String::Concat(klass_name, Symbols::Dot())); | 1548 String::Handle(String::Concat(klass_name, Symbols::Dot())); |
| 1466 if (!constructor_name.IsNull()) { | 1549 if (!constructor_name.IsNull()) { |
| 1467 internal_constructor_name = | 1550 internal_constructor_name = |
| 1468 String::Concat(internal_constructor_name, constructor_name); | 1551 String::Concat(internal_constructor_name, constructor_name); |
| 1469 } | 1552 } |
| 1470 | 1553 |
| 1471 Function& lookup_constructor = Function::Handle( | 1554 Function& lookup_constructor = Function::Handle( |
| 1472 klass.LookupFunctionAllowPrivate(internal_constructor_name)); | 1555 klass.LookupFunction(internal_constructor_name)); |
| 1473 | 1556 |
| 1474 if (lookup_constructor.IsNull() || | 1557 if (lookup_constructor.IsNull() || |
| 1475 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || | 1558 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || |
| 1476 !lookup_constructor.is_visible()) { | 1559 !lookup_constructor.is_visible()) { |
| 1477 // Pretend we didn't find the constructor at all when the arity is wrong | 1560 // Pretend we didn't find the constructor at all when the arity is wrong |
| 1478 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1561 // so as to produce the same NoSuchMethodError as the non-reflective case. |
| 1479 lookup_constructor = Function::null(); | 1562 lookup_constructor = Function::null(); |
| 1480 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1563 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 1481 internal_constructor_name, | 1564 internal_constructor_name, |
| 1482 lookup_constructor, | 1565 lookup_constructor, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1677 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1595 GET_NON_NULL_NATIVE_ARGUMENT( | 1678 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1596 String, function_name, arguments->NativeArgAt(2)); | 1679 String, function_name, arguments->NativeArgAt(2)); |
| 1597 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1680 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 1598 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1681 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1599 | 1682 |
| 1600 const Array& args_descriptor_array = | 1683 const Array& args_descriptor_array = |
| 1601 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1684 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 1602 | 1685 |
| 1603 const Function& function = Function::Handle( | 1686 const Function& function = Function::Handle( |
| 1604 library.LookupFunctionAllowPrivate(function_name)); | 1687 library.LookupLocalFunction(function_name)); |
| 1605 | 1688 |
| 1606 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1689 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
| 1607 if (function.IsNull() || | 1690 if (function.IsNull() || |
| 1608 !function.AreValidArguments(args_descriptor, NULL) || | 1691 !function.AreValidArguments(args_descriptor, NULL) || |
| 1609 !function.is_visible()) { | 1692 !function.is_visible()) { |
| 1610 ThrowNoSuchMethod(Instance::null_instance(), | 1693 ThrowNoSuchMethod(Instance::null_instance(), |
| 1611 function_name, | 1694 function_name, |
| 1612 function, | 1695 function, |
| 1613 InvocationMirror::kTopLevel, | 1696 InvocationMirror::kTopLevel, |
| 1614 InvocationMirror::kMethod); | 1697 InvocationMirror::kMethod); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1642 // with its cousins. | 1725 // with its cousins. |
| 1643 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1726 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1644 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1727 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1645 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1728 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1646 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1729 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1647 | 1730 |
| 1648 // To access a top-level we may need to use the Field or the | 1731 // To access a top-level we may need to use the Field or the |
| 1649 // setter Function. The setter function may either be in the | 1732 // setter Function. The setter function may either be in the |
| 1650 // library or in the field's owner class, depending. | 1733 // library or in the field's owner class, depending. |
| 1651 const Field& field = Field::Handle( | 1734 const Field& field = Field::Handle( |
| 1652 library.LookupFieldAllowPrivate(setter_name)); | 1735 library.LookupLocalField(setter_name)); |
| 1653 | 1736 |
| 1654 if (field.IsNull()) { | 1737 if (field.IsNull()) { |
| 1655 const String& internal_setter_name = | 1738 const String& internal_setter_name = |
| 1656 String::Handle(Field::SetterName(setter_name)); | 1739 String::Handle(Field::SetterName(setter_name)); |
| 1657 const Function& setter = Function::Handle( | 1740 const Function& setter = Function::Handle( |
| 1658 library.LookupFunctionAllowPrivate(internal_setter_name)); | 1741 library.LookupLocalFunction(internal_setter_name)); |
| 1659 if (setter.IsNull() || !setter.is_visible()) { | 1742 if (setter.IsNull() || !setter.is_visible()) { |
| 1660 ThrowNoSuchMethod(Instance::null_instance(), | 1743 ThrowNoSuchMethod(Instance::null_instance(), |
| 1661 setter_name, | 1744 setter_name, |
| 1662 setter, | 1745 setter, |
| 1663 InvocationMirror::kTopLevel, | 1746 InvocationMirror::kTopLevel, |
| 1664 InvocationMirror::kSetter); | 1747 InvocationMirror::kSetter); |
| 1665 UNREACHABLE(); | 1748 UNREACHABLE(); |
| 1666 } | 1749 } |
| 1667 | 1750 |
| 1668 // Invoke the setter and return the result. | 1751 // Invoke the setter and return the result. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 } | 1855 } |
| 1773 | 1856 |
| 1774 | 1857 |
| 1775 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1858 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1776 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1859 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1777 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1860 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1778 return field.type(); | 1861 return field.type(); |
| 1779 } | 1862 } |
| 1780 | 1863 |
| 1781 } // namespace dart | 1864 } // namespace dart |
| OLD | NEW |