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/mirrors.h" | 5 #include "lib/mirrors.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bootstrap_natives.h" | 8 #include "vm/bootstrap_natives.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 const Instance& receiver, | 583 const Instance& receiver, |
584 const Function& function, | 584 const Function& function, |
585 const String& target_name, | 585 const String& target_name, |
586 const Array& args, | 586 const Array& args, |
587 const Array& args_descriptor_array) { | 587 const Array& args_descriptor_array) { |
588 // Note "args" is already the internal arguments with the receiver as the | 588 // Note "args" is already the internal arguments with the receiver as the |
589 // first element. | 589 // first element. |
590 Object& result = Object::Handle(); | 590 Object& result = Object::Handle(); |
591 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 591 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
592 if (function.IsNull() || | 592 if (function.IsNull() || |
593 !function.is_visible() || | 593 !function.is_reflectable() || |
594 !function.AreValidArguments(args_descriptor, NULL)) { | 594 !function.AreValidArguments(args_descriptor, NULL)) { |
595 result = DartEntry::InvokeNoSuchMethod(receiver, | 595 result = DartEntry::InvokeNoSuchMethod(receiver, |
596 target_name, | 596 target_name, |
597 args, | 597 args, |
598 args_descriptor_array); | 598 args_descriptor_array); |
599 } else { | 599 } else { |
600 result = DartEntry::InvokeFunction(function, | 600 result = DartEntry::InvokeFunction(function, |
601 args, | 601 args, |
602 args_descriptor_array); | 602 args_descriptor_array); |
603 } | 603 } |
(...skipping 30 matching lines...) Expand all Loading... |
634 return field.value(); | 634 return field.value(); |
635 } | 635 } |
636 // An uninitialized field was found. Check for a getter in the field's | 636 // An uninitialized field was found. Check for a getter in the field's |
637 // owner classs. | 637 // owner classs. |
638 const Class& klass = Class::Handle(field.owner()); | 638 const Class& klass = Class::Handle(field.owner()); |
639 const String& internal_getter_name = | 639 const String& internal_getter_name = |
640 String::Handle(Field::GetterName(getter_name)); | 640 String::Handle(Field::GetterName(getter_name)); |
641 getter = klass.LookupStaticFunction(internal_getter_name); | 641 getter = klass.LookupStaticFunction(internal_getter_name); |
642 } | 642 } |
643 | 643 |
644 if (!getter.IsNull() && getter.is_visible()) { | 644 if (!getter.IsNull() && getter.is_reflectable()) { |
645 // Invoke the getter and return the result. | 645 // Invoke the getter and return the result. |
646 const Object& result = Object::Handle( | 646 const Object& result = Object::Handle( |
647 DartEntry::InvokeFunction(getter, Object::empty_array())); | 647 DartEntry::InvokeFunction(getter, Object::empty_array())); |
648 return ReturnResult(result); | 648 return ReturnResult(result); |
649 } | 649 } |
650 | 650 |
651 if (throw_nsm_if_absent) { | 651 if (throw_nsm_if_absent) { |
652 ThrowNoSuchMethod(Instance::null_instance(), | 652 ThrowNoSuchMethod(Instance::null_instance(), |
653 getter_name, | 653 getter_name, |
654 getter, | 654 getter, |
(...skipping 14 matching lines...) Expand all Loading... |
669 const String& getter_name, | 669 const String& getter_name, |
670 const bool throw_nsm_if_absent) { | 670 const bool throw_nsm_if_absent) { |
671 // Note static fields do not have implicit getters. | 671 // Note static fields do not have implicit getters. |
672 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 672 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
673 if (field.IsNull() || field.IsUninitialized()) { | 673 if (field.IsNull() || field.IsUninitialized()) { |
674 const String& internal_getter_name = String::Handle( | 674 const String& internal_getter_name = String::Handle( |
675 Field::GetterName(getter_name)); | 675 Field::GetterName(getter_name)); |
676 Function& getter = Function::Handle( | 676 Function& getter = Function::Handle( |
677 klass.LookupStaticFunction(internal_getter_name)); | 677 klass.LookupStaticFunction(internal_getter_name)); |
678 | 678 |
679 if (getter.IsNull() || !getter.is_visible()) { | 679 if (getter.IsNull() || !getter.is_reflectable()) { |
680 if (getter.IsNull()) { | 680 if (getter.IsNull()) { |
681 getter = klass.LookupStaticFunction(getter_name); | 681 getter = klass.LookupStaticFunction(getter_name); |
682 if (!getter.IsNull()) { | 682 if (!getter.IsNull()) { |
683 // Looking for a getter but found a regular method: closurize it. | 683 // Looking for a getter but found a regular method: closurize it. |
684 const Function& closure_function = | 684 const Function& closure_function = |
685 Function::Handle(getter.ImplicitClosureFunction()); | 685 Function::Handle(getter.ImplicitClosureFunction()); |
686 return closure_function.ImplicitStaticClosure(); | 686 return closure_function.ImplicitStaticClosure(); |
687 } | 687 } |
688 } | 688 } |
689 if (throw_nsm_if_absent) { | 689 if (throw_nsm_if_absent) { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 field ^= fields.At(i); | 1035 field ^= fields.At(i); |
1036 if (!field.is_synthetic()) { | 1036 if (!field.is_synthetic()) { |
1037 member_mirror = CreateVariableMirror(field, owner_mirror); | 1037 member_mirror = CreateVariableMirror(field, owner_mirror); |
1038 member_mirrors.Add(member_mirror); | 1038 member_mirrors.Add(member_mirror); |
1039 } | 1039 } |
1040 } | 1040 } |
1041 | 1041 |
1042 Function& func = Function::Handle(); | 1042 Function& func = Function::Handle(); |
1043 for (intptr_t i = 0; i < num_functions; i++) { | 1043 for (intptr_t i = 0; i < num_functions; i++) { |
1044 func ^= functions.At(i); | 1044 func ^= functions.At(i); |
1045 if (func.is_visible() && | 1045 if (func.is_reflectable() && |
1046 (func.kind() == RawFunction::kRegularFunction || | 1046 (func.kind() == RawFunction::kRegularFunction || |
1047 func.kind() == RawFunction::kGetterFunction || | 1047 func.kind() == RawFunction::kGetterFunction || |
1048 func.kind() == RawFunction::kSetterFunction)) { | 1048 func.kind() == RawFunction::kSetterFunction)) { |
1049 member_mirror = CreateMethodMirror(func, owner_mirror); | 1049 member_mirror = CreateMethodMirror(func, owner_mirror); |
1050 member_mirrors.Add(member_mirror); | 1050 member_mirrors.Add(member_mirror); |
1051 } | 1051 } |
1052 } | 1052 } |
1053 | 1053 |
1054 return member_mirrors.raw(); | 1054 return member_mirrors.raw(); |
1055 } | 1055 } |
(...skipping 14 matching lines...) Expand all Loading... |
1070 const Array& functions = Array::Handle(klass.functions()); | 1070 const Array& functions = Array::Handle(klass.functions()); |
1071 const intptr_t num_functions = functions.Length(); | 1071 const intptr_t num_functions = functions.Length(); |
1072 | 1072 |
1073 Instance& constructor_mirror = Instance::Handle(); | 1073 Instance& constructor_mirror = Instance::Handle(); |
1074 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( | 1074 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( |
1075 GrowableObjectArray::New(num_functions)); | 1075 GrowableObjectArray::New(num_functions)); |
1076 | 1076 |
1077 Function& func = Function::Handle(); | 1077 Function& func = Function::Handle(); |
1078 for (intptr_t i = 0; i < num_functions; i++) { | 1078 for (intptr_t i = 0; i < num_functions; i++) { |
1079 func ^= functions.At(i); | 1079 func ^= functions.At(i); |
1080 if (func.is_visible() && func.kind() == RawFunction::kConstructor) { | 1080 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) { |
1081 constructor_mirror = CreateMethodMirror(func, owner_mirror); | 1081 constructor_mirror = CreateMethodMirror(func, owner_mirror); |
1082 constructor_mirrors.Add(constructor_mirror); | 1082 constructor_mirrors.Add(constructor_mirror); |
1083 } | 1083 } |
1084 } | 1084 } |
1085 | 1085 |
1086 return constructor_mirrors.raw(); | 1086 return constructor_mirrors.raw(); |
1087 } | 1087 } |
1088 | 1088 |
1089 | 1089 |
1090 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { | 1090 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 member_mirrors.Add(member_mirror); | 1122 member_mirrors.Add(member_mirror); |
1123 } | 1123 } |
1124 } else if (entry.IsField()) { | 1124 } else if (entry.IsField()) { |
1125 const Field& field = Field::Cast(entry); | 1125 const Field& field = Field::Cast(entry); |
1126 if (!field.is_synthetic()) { | 1126 if (!field.is_synthetic()) { |
1127 member_mirror = CreateVariableMirror(field, owner_mirror); | 1127 member_mirror = CreateVariableMirror(field, owner_mirror); |
1128 member_mirrors.Add(member_mirror); | 1128 member_mirrors.Add(member_mirror); |
1129 } | 1129 } |
1130 } else if (entry.IsFunction()) { | 1130 } else if (entry.IsFunction()) { |
1131 const Function& func = Function::Cast(entry); | 1131 const Function& func = Function::Cast(entry); |
1132 if (func.is_visible() && | 1132 if (func.is_reflectable() && |
1133 (func.kind() == RawFunction::kRegularFunction || | 1133 (func.kind() == RawFunction::kRegularFunction || |
1134 func.kind() == RawFunction::kGetterFunction || | 1134 func.kind() == RawFunction::kGetterFunction || |
1135 func.kind() == RawFunction::kSetterFunction)) { | 1135 func.kind() == RawFunction::kSetterFunction)) { |
1136 member_mirror = CreateMethodMirror(func, owner_mirror); | 1136 member_mirror = CreateMethodMirror(func, owner_mirror); |
1137 member_mirrors.Add(member_mirror); | 1137 member_mirrors.Add(member_mirror); |
1138 } | 1138 } |
1139 } | 1139 } |
1140 } | 1140 } |
1141 | 1141 |
1142 return member_mirrors.raw(); | 1142 return member_mirrors.raw(); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 } | 1420 } |
1421 } | 1421 } |
1422 | 1422 |
1423 const Array& args_descriptor_array = | 1423 const Array& args_descriptor_array = |
1424 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1424 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1425 | 1425 |
1426 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1426 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1427 | 1427 |
1428 if (function.IsNull() || | 1428 if (function.IsNull() || |
1429 !function.AreValidArguments(args_descriptor, NULL) || | 1429 !function.AreValidArguments(args_descriptor, NULL) || |
1430 !function.is_visible()) { | 1430 !function.is_reflectable()) { |
1431 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1431 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1432 function_name, | 1432 function_name, |
1433 function, | 1433 function, |
1434 Object::null_array(), | 1434 Object::null_array(), |
1435 InvocationMirror::kStatic, | 1435 InvocationMirror::kStatic, |
1436 InvocationMirror::kMethod); | 1436 InvocationMirror::kMethod); |
1437 UNREACHABLE(); | 1437 UNREACHABLE(); |
1438 } | 1438 } |
1439 | 1439 |
1440 Object& result = Object::Handle( | 1440 Object& result = Object::Handle( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 const String& internal_setter_name = String::Handle( | 1473 const String& internal_setter_name = String::Handle( |
1474 Field::SetterName(setter_name)); | 1474 Field::SetterName(setter_name)); |
1475 | 1475 |
1476 if (field.IsNull()) { | 1476 if (field.IsNull()) { |
1477 setter = klass.LookupStaticFunction(internal_setter_name); | 1477 setter = klass.LookupStaticFunction(internal_setter_name); |
1478 | 1478 |
1479 const int kNumArgs = 1; | 1479 const int kNumArgs = 1; |
1480 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1480 const Array& args = Array::Handle(Array::New(kNumArgs)); |
1481 args.SetAt(0, value); | 1481 args.SetAt(0, value); |
1482 | 1482 |
1483 if (setter.IsNull() || !setter.is_visible()) { | 1483 if (setter.IsNull() || !setter.is_reflectable()) { |
1484 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1484 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1485 internal_setter_name, | 1485 internal_setter_name, |
1486 setter, | 1486 setter, |
1487 args, | 1487 args, |
1488 InvocationMirror::kStatic, | 1488 InvocationMirror::kStatic, |
1489 InvocationMirror::kSetter); | 1489 InvocationMirror::kSetter); |
1490 UNREACHABLE(); | 1490 UNREACHABLE(); |
1491 } | 1491 } |
1492 | 1492 |
1493 // Invoke the setter and return the result. | 1493 // Invoke the setter and return the result. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 if (!constructor_name.IsNull()) { | 1534 if (!constructor_name.IsNull()) { |
1535 internal_constructor_name = | 1535 internal_constructor_name = |
1536 String::Concat(internal_constructor_name, constructor_name); | 1536 String::Concat(internal_constructor_name, constructor_name); |
1537 } | 1537 } |
1538 | 1538 |
1539 Function& lookup_constructor = Function::Handle( | 1539 Function& lookup_constructor = Function::Handle( |
1540 klass.LookupFunction(internal_constructor_name)); | 1540 klass.LookupFunction(internal_constructor_name)); |
1541 | 1541 |
1542 if (lookup_constructor.IsNull() || | 1542 if (lookup_constructor.IsNull() || |
1543 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || | 1543 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || |
1544 !lookup_constructor.is_visible()) { | 1544 !lookup_constructor.is_reflectable()) { |
1545 // Pretend we didn't find the constructor at all when the arity is wrong | 1545 // Pretend we didn't find the constructor at all when the arity is wrong |
1546 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1546 // so as to produce the same NoSuchMethodError as the non-reflective case. |
1547 lookup_constructor = Function::null(); | 1547 lookup_constructor = Function::null(); |
1548 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1548 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1549 internal_constructor_name, | 1549 internal_constructor_name, |
1550 lookup_constructor, | 1550 lookup_constructor, |
1551 Object::null_array(), | 1551 Object::null_array(), |
1552 InvocationMirror::kConstructor, | 1552 InvocationMirror::kConstructor, |
1553 InvocationMirror::kMethod); | 1553 InvocationMirror::kMethod); |
1554 UNREACHABLE(); | 1554 UNREACHABLE(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 explicit_argument = explicit_args.At(i); | 1612 explicit_argument = explicit_args.At(i); |
1613 args.SetAt(i + num_implicit_args, explicit_argument); | 1613 args.SetAt(i + num_implicit_args, explicit_argument); |
1614 } | 1614 } |
1615 | 1615 |
1616 const Array& args_descriptor_array = | 1616 const Array& args_descriptor_array = |
1617 Array::Handle(ArgumentsDescriptor::New(args.Length(), | 1617 Array::Handle(ArgumentsDescriptor::New(args.Length(), |
1618 arg_names)); | 1618 arg_names)); |
1619 | 1619 |
1620 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1620 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1621 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL) || | 1621 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL) || |
1622 !redirected_constructor.is_visible()) { | 1622 !redirected_constructor.is_reflectable()) { |
1623 // Pretend we didn't find the constructor at all when the arity is wrong | 1623 // Pretend we didn't find the constructor at all when the arity is wrong |
1624 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1624 // so as to produce the same NoSuchMethodError as the non-reflective case. |
1625 redirected_constructor = Function::null(); | 1625 redirected_constructor = Function::null(); |
1626 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1626 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1627 internal_constructor_name, | 1627 internal_constructor_name, |
1628 redirected_constructor, | 1628 redirected_constructor, |
1629 Object::null_array(), | 1629 Object::null_array(), |
1630 InvocationMirror::kConstructor, | 1630 InvocationMirror::kConstructor, |
1631 InvocationMirror::kMethod); | 1631 InvocationMirror::kMethod); |
1632 UNREACHABLE(); | 1632 UNREACHABLE(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 return call_result.raw(); | 1712 return call_result.raw(); |
1713 } | 1713 } |
1714 } | 1714 } |
1715 | 1715 |
1716 const Array& args_descriptor_array = | 1716 const Array& args_descriptor_array = |
1717 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1717 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1718 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1718 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1719 | 1719 |
1720 if (function.IsNull() || | 1720 if (function.IsNull() || |
1721 !function.AreValidArguments(args_descriptor, NULL) || | 1721 !function.AreValidArguments(args_descriptor, NULL) || |
1722 !function.is_visible()) { | 1722 !function.is_reflectable()) { |
1723 ThrowNoSuchMethod(Instance::null_instance(), | 1723 ThrowNoSuchMethod(Instance::null_instance(), |
1724 function_name, | 1724 function_name, |
1725 function, | 1725 function, |
1726 Object::null_array(), | 1726 Object::null_array(), |
1727 InvocationMirror::kTopLevel, | 1727 InvocationMirror::kTopLevel, |
1728 InvocationMirror::kMethod); | 1728 InvocationMirror::kMethod); |
1729 UNREACHABLE(); | 1729 UNREACHABLE(); |
1730 } | 1730 } |
1731 | 1731 |
1732 const Object& result = Object::Handle( | 1732 const Object& result = Object::Handle( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 const String& internal_setter_name = | 1768 const String& internal_setter_name = |
1769 String::Handle(Field::SetterName(setter_name)); | 1769 String::Handle(Field::SetterName(setter_name)); |
1770 | 1770 |
1771 if (field.IsNull()) { | 1771 if (field.IsNull()) { |
1772 setter = library.LookupLocalFunction(internal_setter_name); | 1772 setter = library.LookupLocalFunction(internal_setter_name); |
1773 | 1773 |
1774 const int kNumArgs = 1; | 1774 const int kNumArgs = 1; |
1775 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1775 const Array& args = Array::Handle(Array::New(kNumArgs)); |
1776 args.SetAt(0, value); | 1776 args.SetAt(0, value); |
1777 | 1777 |
1778 if (setter.IsNull() || !setter.is_visible()) { | 1778 if (setter.IsNull() || !setter.is_reflectable()) { |
1779 ThrowNoSuchMethod(Instance::null_instance(), | 1779 ThrowNoSuchMethod(Instance::null_instance(), |
1780 internal_setter_name, | 1780 internal_setter_name, |
1781 setter, | 1781 setter, |
1782 args, | 1782 args, |
1783 InvocationMirror::kTopLevel, | 1783 InvocationMirror::kTopLevel, |
1784 InvocationMirror::kSetter); | 1784 InvocationMirror::kSetter); |
1785 UNREACHABLE(); | 1785 UNREACHABLE(); |
1786 } | 1786 } |
1787 | 1787 |
1788 // Invoke the setter and return the result. | 1788 // Invoke the setter and return the result. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 } | 1965 } |
1966 | 1966 |
1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { | 1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { |
1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); | 1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); |
1971 } | 1971 } |
1972 | 1972 |
1973 | 1973 |
1974 } // namespace dart | 1974 } // namespace dart |
OLD | NEW |