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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_debugger_api.h" | 6 #include "include/dart_debugger_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. | 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. |
10 #include "vm/bootstrap_natives.h" | 10 #include "vm/bootstrap_natives.h" |
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1665 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1666 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1666 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
1667 GET_NON_NULL_NATIVE_ARGUMENT( | 1667 GET_NON_NULL_NATIVE_ARGUMENT( |
1668 String, function_name, arguments->NativeArgAt(2)); | 1668 String, function_name, arguments->NativeArgAt(2)); |
1669 GET_NON_NULL_NATIVE_ARGUMENT( | 1669 GET_NON_NULL_NATIVE_ARGUMENT( |
1670 Array, positional_args, arguments->NativeArgAt(3)); | 1670 Array, positional_args, arguments->NativeArgAt(3)); |
1671 | 1671 |
1672 intptr_t number_of_arguments = positional_args.Length(); | 1672 intptr_t number_of_arguments = positional_args.Length(); |
1673 | 1673 |
1674 | 1674 |
| 1675 String& ambiguity_error_msg = String::Handle(isolate); |
1675 const Function& function = Function::Handle( | 1676 const Function& function = Function::Handle( |
1676 library.LookupFunctionAllowPrivate(function_name)); | 1677 library.LookupFunctionAllowPrivate(function_name, &ambiguity_error_msg)); |
1677 | 1678 |
1678 if (function.IsNull()) { | 1679 if (function.IsNull()) { |
1679 const String& message = String::Handle( | 1680 if (ambiguity_error_msg.IsNull()) { |
1680 String::NewFormatted("%s: did not find top-level function '%s'.", | 1681 const String& message = String::Handle( |
1681 "LibraryMirror_invoke", | 1682 String::NewFormatted("%s: did not find top-level function '%s'.", |
1682 function_name.ToCString())); | 1683 "LibraryMirror_invoke", |
1683 ThrowMirroredCompilationError(message); | 1684 function_name.ToCString())); |
| 1685 ThrowMirroredCompilationError(message); |
| 1686 } else { |
| 1687 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1688 } |
1684 UNREACHABLE(); | 1689 UNREACHABLE(); |
1685 } | 1690 } |
1686 | 1691 |
1687 // LookupFunctionAllowPrivate does not check argument arity, so we | 1692 // LookupFunctionAllowPrivate does not check argument arity, so we |
1688 // do it here. | 1693 // do it here. |
1689 String& error_message = String::Handle(); | 1694 String& error_message = String::Handle(); |
1690 if (!function.AreValidArgumentCounts(number_of_arguments, | 1695 if (!function.AreValidArgumentCounts(number_of_arguments, |
1691 /* num_named_args */ 0, | 1696 /* num_named_args */ 0, |
1692 &error_message)) { | 1697 &error_message)) { |
1693 const String& message = String::Handle( | 1698 const String& message = String::Handle( |
(...skipping 19 matching lines...) Expand all Loading... |
1713 // Argument 0 is the mirror, which is unused by the native. It exists | 1718 // Argument 0 is the mirror, which is unused by the native. It exists |
1714 // because this native is an instance method in order to be polymorphic | 1719 // because this native is an instance method in order to be polymorphic |
1715 // with its cousins. | 1720 // with its cousins. |
1716 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1721 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1717 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1722 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
1718 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 1723 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
1719 | 1724 |
1720 // To access a top-level we may need to use the Field or the | 1725 // To access a top-level we may need to use the Field or the |
1721 // getter Function. The getter function may either be in the | 1726 // getter Function. The getter function may either be in the |
1722 // library or in the field's owner class, depending. | 1727 // library or in the field's owner class, depending. |
1723 const Field& field = | 1728 String& ambiguity_error_msg = String::Handle(isolate); |
1724 Field::Handle(library.LookupFieldAllowPrivate(getter_name)); | 1729 const Field& field = Field::Handle( |
| 1730 library.LookupFieldAllowPrivate(getter_name, &ambiguity_error_msg)); |
1725 Function& getter = Function::Handle(); | 1731 Function& getter = Function::Handle(); |
1726 if (field.IsNull()) { | 1732 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
1727 // No field found. Check for a getter in the lib. | 1733 // No field found and no ambiguity error. Check for a getter in the lib. |
1728 const String& internal_getter_name = | 1734 const String& internal_getter_name = |
1729 String::Handle(Field::GetterName(getter_name)); | 1735 String::Handle(Field::GetterName(getter_name)); |
1730 getter = library.LookupFunctionAllowPrivate(internal_getter_name); | 1736 getter = library.LookupFunctionAllowPrivate(internal_getter_name, |
1731 } else if (FieldIsUninitialized(field)) { | 1737 &ambiguity_error_msg); |
| 1738 } else if (!field.IsNull() && FieldIsUninitialized(field)) { |
1732 // A field was found. Check for a getter in the field's owner classs. | 1739 // A field was found. Check for a getter in the field's owner classs. |
1733 const Class& klass = Class::Handle(field.owner()); | 1740 const Class& klass = Class::Handle(field.owner()); |
1734 const String& internal_getter_name = | 1741 const String& internal_getter_name = |
1735 String::Handle(Field::GetterName(getter_name)); | 1742 String::Handle(Field::GetterName(getter_name)); |
1736 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 1743 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); |
1737 } | 1744 } |
1738 | 1745 |
1739 if (!getter.IsNull()) { | 1746 if (!getter.IsNull()) { |
1740 // Invoke the getter and return the result. | 1747 // Invoke the getter and return the result. |
1741 const Object& result = Object::Handle( | 1748 const Object& result = Object::Handle( |
1742 DartEntry::InvokeFunction(getter, Object::empty_array())); | 1749 DartEntry::InvokeFunction(getter, Object::empty_array())); |
1743 if (result.IsError()) { | 1750 if (result.IsError()) { |
1744 ThrowInvokeError(Error::Cast(result)); | 1751 ThrowInvokeError(Error::Cast(result)); |
1745 UNREACHABLE(); | 1752 UNREACHABLE(); |
1746 } | 1753 } |
1747 return result.raw(); | 1754 return result.raw(); |
1748 } else if (!field.IsNull()) { | 1755 } |
| 1756 if (!field.IsNull()) { |
1749 return field.value(); | 1757 return field.value(); |
1750 } else { | 1758 } |
| 1759 if (ambiguity_error_msg.IsNull()) { |
1751 const String& message = String::Handle( | 1760 const String& message = String::Handle( |
1752 String::NewFormatted("%s: did not find top-level variable '%s'.", | 1761 String::NewFormatted("%s: did not find top-level variable '%s'.", |
1753 "LibraryMirror_invokeGetter", | 1762 "LibraryMirror_invokeGetter", |
1754 getter_name.ToCString())); | 1763 getter_name.ToCString())); |
1755 ThrowMirroredCompilationError(message); | 1764 ThrowMirroredCompilationError(message); |
1756 UNREACHABLE(); | 1765 } else { |
1757 return Instance::null(); | 1766 ThrowMirroredCompilationError(ambiguity_error_msg); |
1758 } | 1767 } |
| 1768 UNREACHABLE(); |
| 1769 return Instance::null(); |
1759 } | 1770 } |
1760 | 1771 |
1761 | 1772 |
1762 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { | 1773 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { |
1763 // Argument 0 is the mirror, which is unused by the native. It exists | 1774 // Argument 0 is the mirror, which is unused by the native. It exists |
1764 // because this native is an instance method in order to be polymorphic | 1775 // because this native is an instance method in order to be polymorphic |
1765 // with its cousins. | 1776 // with its cousins. |
1766 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1777 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1767 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1778 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
1768 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1779 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
1769 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1780 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
1770 | 1781 |
1771 // To access a top-level we may need to use the Field or the | 1782 // To access a top-level we may need to use the Field or the |
1772 // setter Function. The setter function may either be in the | 1783 // setter Function. The setter function may either be in the |
1773 // library or in the field's owner class, depending. | 1784 // library or in the field's owner class, depending. |
1774 const Field& field = | 1785 String& ambiguity_error_msg = String::Handle(isolate); |
1775 Field::Handle(library.LookupFieldAllowPrivate(setter_name)); | 1786 const Field& field = Field::Handle( |
| 1787 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); |
1776 | 1788 |
1777 if (field.IsNull()) { | 1789 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
1778 const String& internal_setter_name = | 1790 const String& internal_setter_name = |
1779 String::Handle(Field::SetterName(setter_name)); | 1791 String::Handle(Field::SetterName(setter_name)); |
1780 const Function& setter = Function::Handle( | 1792 const Function& setter = Function::Handle( |
1781 library.LookupFunctionAllowPrivate(internal_setter_name)); | 1793 library.LookupFunctionAllowPrivate(internal_setter_name, |
1782 | 1794 &ambiguity_error_msg)); |
1783 if (setter.IsNull()) { | 1795 if (setter.IsNull()) { |
1784 const String& message = String::Handle( | 1796 if (ambiguity_error_msg.IsNull()) { |
1785 String::NewFormatted("%s: did not find top-level variable '%s'.", | 1797 const String& message = String::Handle( |
1786 "LibraryMirror_invokeSetter", | 1798 String::NewFormatted("%s: did not find top-level variable '%s'.", |
1787 setter_name.ToCString())); | 1799 "LibraryMirror_invokeSetter", |
1788 ThrowMirroredCompilationError(message); | 1800 setter_name.ToCString())); |
| 1801 ThrowMirroredCompilationError(message); |
| 1802 } else { |
| 1803 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1804 } |
1789 UNREACHABLE(); | 1805 UNREACHABLE(); |
1790 } | 1806 } |
1791 | 1807 |
1792 // Invoke the setter and return the result. | 1808 // Invoke the setter and return the result. |
1793 const int kNumArgs = 1; | 1809 const int kNumArgs = 1; |
1794 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1810 const Array& args = Array::Handle(Array::New(kNumArgs)); |
1795 args.SetAt(0, value); | 1811 args.SetAt(0, value); |
1796 const Object& result = Object::Handle( | 1812 const Object& result = Object::Handle( |
1797 DartEntry::InvokeFunction(setter, args)); | 1813 DartEntry::InvokeFunction(setter, args)); |
1798 if (result.IsError()) { | 1814 if (result.IsError()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 | 1866 |
1851 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1867 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
1852 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1868 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
1853 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1869 const Field& field = Field::Handle(ref.GetFieldReferent()); |
1854 | 1870 |
1855 const AbstractType& type = AbstractType::Handle(field.type()); | 1871 const AbstractType& type = AbstractType::Handle(field.type()); |
1856 return CreateTypeMirror(type); | 1872 return CreateTypeMirror(type); |
1857 } | 1873 } |
1858 | 1874 |
1859 } // namespace dart | 1875 } // namespace dart |
OLD | NEW |