| 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 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 library ^= library_ref.referent(); | 1621 library ^= library_ref.referent(); |
| 1622 | 1622 |
| 1623 const String& function_name = | 1623 const String& function_name = |
| 1624 String::CheckedHandle(arguments->NativeArgAt(2)); | 1624 String::CheckedHandle(arguments->NativeArgAt(2)); |
| 1625 | 1625 |
| 1626 const Array& positional_args = | 1626 const Array& positional_args = |
| 1627 Array::CheckedHandle(arguments->NativeArgAt(3)); | 1627 Array::CheckedHandle(arguments->NativeArgAt(3)); |
| 1628 intptr_t number_of_arguments = positional_args.Length(); | 1628 intptr_t number_of_arguments = positional_args.Length(); |
| 1629 | 1629 |
| 1630 | 1630 |
| 1631 String& ambiguity_error_msg = String::Handle(isolate); |
| 1631 const Function& function = Function::Handle( | 1632 const Function& function = Function::Handle( |
| 1632 library.LookupFunctionAllowPrivate(function_name)); | 1633 library.LookupFunctionAllowPrivate(function_name, &ambiguity_error_msg)); |
| 1633 | 1634 |
| 1634 if (function.IsNull()) { | 1635 if (function.IsNull()) { |
| 1635 const String& message = String::Handle( | 1636 if (ambiguity_error_msg.IsNull()) { |
| 1636 String::NewFormatted("%s: did not find top-level function '%s'.", | 1637 const String& message = String::Handle( |
| 1637 "LibraryMirror_invoke", | 1638 String::NewFormatted("%s: did not find top-level function '%s'.", |
| 1638 function_name.ToCString())); | 1639 "LibraryMirror_invoke", |
| 1639 ThrowMirroredCompilationError(message); | 1640 function_name.ToCString())); |
| 1641 ThrowMirroredCompilationError(message); |
| 1642 } else { |
| 1643 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1644 } |
| 1640 UNREACHABLE(); | 1645 UNREACHABLE(); |
| 1641 } | 1646 } |
| 1642 | 1647 |
| 1643 // LookupFunctionAllowPrivate does not check argument arity, so we | 1648 // LookupFunctionAllowPrivate does not check argument arity, so we |
| 1644 // do it here. | 1649 // do it here. |
| 1645 String& error_message = String::Handle(); | 1650 String& error_message = String::Handle(); |
| 1646 if (!function.AreValidArgumentCounts(number_of_arguments, | 1651 if (!function.AreValidArgumentCounts(number_of_arguments, |
| 1647 /* num_named_args */ 0, | 1652 /* num_named_args */ 0, |
| 1648 &error_message)) { | 1653 &error_message)) { |
| 1649 const String& message = String::Handle( | 1654 const String& message = String::Handle( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1674 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1679 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); |
| 1675 Library& library = Library::Handle(); | 1680 Library& library = Library::Handle(); |
| 1676 library ^= library_ref.referent(); | 1681 library ^= library_ref.referent(); |
| 1677 | 1682 |
| 1678 const String& getter_name = | 1683 const String& getter_name = |
| 1679 String::CheckedHandle(arguments->NativeArgAt(2)); | 1684 String::CheckedHandle(arguments->NativeArgAt(2)); |
| 1680 | 1685 |
| 1681 // To access a top-level we may need to use the Field or the | 1686 // To access a top-level we may need to use the Field or the |
| 1682 // getter Function. The getter function may either be in the | 1687 // getter Function. The getter function may either be in the |
| 1683 // library or in the field's owner class, depending. | 1688 // library or in the field's owner class, depending. |
| 1684 const Field& field = | 1689 String& ambiguity_error_msg = String::Handle(isolate); |
| 1685 Field::Handle(library.LookupFieldAllowPrivate(getter_name)); | 1690 const Field& field = Field::Handle( |
| 1691 library.LookupFieldAllowPrivate(getter_name, &ambiguity_error_msg)); |
| 1686 Function& getter = Function::Handle(); | 1692 Function& getter = Function::Handle(); |
| 1687 if (field.IsNull()) { | 1693 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| 1688 // No field found. Check for a getter in the lib. | 1694 // No field found and no ambiguity error. Check for a getter in the lib. |
| 1689 const String& internal_getter_name = | 1695 const String& internal_getter_name = |
| 1690 String::Handle(Field::GetterName(getter_name)); | 1696 String::Handle(Field::GetterName(getter_name)); |
| 1691 getter = library.LookupFunctionAllowPrivate(internal_getter_name); | 1697 getter = library.LookupFunctionAllowPrivate(internal_getter_name, |
| 1692 } else if (FieldIsUninitialized(field)) { | 1698 &ambiguity_error_msg); |
| 1699 } else if (!field.IsNull() && FieldIsUninitialized(field)) { |
| 1693 // A field was found. Check for a getter in the field's owner classs. | 1700 // A field was found. Check for a getter in the field's owner classs. |
| 1694 const Class& klass = Class::Handle(field.owner()); | 1701 const Class& klass = Class::Handle(field.owner()); |
| 1695 const String& internal_getter_name = | 1702 const String& internal_getter_name = |
| 1696 String::Handle(Field::GetterName(getter_name)); | 1703 String::Handle(Field::GetterName(getter_name)); |
| 1697 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 1704 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); |
| 1698 } | 1705 } |
| 1699 | 1706 |
| 1700 if (!getter.IsNull()) { | 1707 if (!getter.IsNull()) { |
| 1701 // Invoke the getter and return the result. | 1708 // Invoke the getter and return the result. |
| 1702 const Object& result = Object::Handle( | 1709 const Object& result = Object::Handle( |
| 1703 DartEntry::InvokeFunction(getter, Object::empty_array())); | 1710 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 1704 if (result.IsError()) { | 1711 if (result.IsError()) { |
| 1705 ThrowInvokeError(Error::Cast(result)); | 1712 ThrowInvokeError(Error::Cast(result)); |
| 1706 UNREACHABLE(); | 1713 UNREACHABLE(); |
| 1707 } | 1714 } |
| 1708 return result.raw(); | 1715 return result.raw(); |
| 1709 } else if (!field.IsNull()) { | 1716 } |
| 1717 if (!field.IsNull()) { |
| 1710 return field.value(); | 1718 return field.value(); |
| 1711 } else { | 1719 } |
| 1720 if (ambiguity_error_msg.IsNull()) { |
| 1712 const String& message = String::Handle( | 1721 const String& message = String::Handle( |
| 1713 String::NewFormatted("%s: did not find top-level variable '%s'.", | 1722 String::NewFormatted("%s: did not find top-level variable '%s'.", |
| 1714 "LibraryMirror_invokeGetter", | 1723 "LibraryMirror_invokeGetter", |
| 1715 getter_name.ToCString())); | 1724 getter_name.ToCString())); |
| 1716 ThrowMirroredCompilationError(message); | 1725 ThrowMirroredCompilationError(message); |
| 1717 UNREACHABLE(); | 1726 } else { |
| 1718 return Instance::null(); | 1727 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1719 } | 1728 } |
| 1729 UNREACHABLE(); |
| 1730 return Instance::null(); |
| 1720 } | 1731 } |
| 1721 | 1732 |
| 1722 | 1733 |
| 1723 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { | 1734 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { |
| 1724 // Argument 0 is the mirror, which is unused by the native. It exists | 1735 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1725 // because this native is an instance method in order to be polymorphic | 1736 // because this native is an instance method in order to be polymorphic |
| 1726 // with its cousins. | 1737 // with its cousins. |
| 1727 | 1738 |
| 1728 const MirrorReference& library_ref = | 1739 const MirrorReference& library_ref = |
| 1729 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1740 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); |
| 1730 Library& library = Library::Handle(); | 1741 Library& library = Library::Handle(); |
| 1731 library ^= library_ref.referent(); | 1742 library ^= library_ref.referent(); |
| 1732 | 1743 |
| 1733 const String& setter_name = | 1744 const String& setter_name = |
| 1734 String::CheckedHandle(arguments->NativeArgAt(2)); | 1745 String::CheckedHandle(arguments->NativeArgAt(2)); |
| 1735 | 1746 |
| 1736 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); | 1747 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); |
| 1737 | 1748 |
| 1738 // To access a top-level we may need to use the Field or the | 1749 // To access a top-level we may need to use the Field or the |
| 1739 // setter Function. The setter function may either be in the | 1750 // setter Function. The setter function may either be in the |
| 1740 // library or in the field's owner class, depending. | 1751 // library or in the field's owner class, depending. |
| 1741 const Field& field = | 1752 String& ambiguity_error_msg = String::Handle(isolate); |
| 1742 Field::Handle(library.LookupFieldAllowPrivate(setter_name)); | 1753 const Field& field = Field::Handle( |
| 1754 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); |
| 1743 | 1755 |
| 1744 if (field.IsNull()) { | 1756 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| 1745 const String& internal_setter_name = | 1757 const String& internal_setter_name = |
| 1746 String::Handle(Field::SetterName(setter_name)); | 1758 String::Handle(Field::SetterName(setter_name)); |
| 1747 const Function& setter = Function::Handle( | 1759 const Function& setter = Function::Handle( |
| 1748 library.LookupFunctionAllowPrivate(internal_setter_name)); | 1760 library.LookupFunctionAllowPrivate(internal_setter_name, |
| 1749 | 1761 &ambiguity_error_msg)); |
| 1750 if (setter.IsNull()) { | 1762 if (setter.IsNull()) { |
| 1751 const String& message = String::Handle( | 1763 if (ambiguity_error_msg.IsNull()) { |
| 1752 String::NewFormatted("%s: did not find top-level variable '%s'.", | 1764 const String& message = String::Handle( |
| 1753 "LibraryMirror_invokeSetter", | 1765 String::NewFormatted("%s: did not find top-level variable '%s'.", |
| 1754 setter_name.ToCString())); | 1766 "LibraryMirror_invokeSetter", |
| 1755 ThrowMirroredCompilationError(message); | 1767 setter_name.ToCString())); |
| 1768 ThrowMirroredCompilationError(message); |
| 1769 } else { |
| 1770 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1771 } |
| 1756 UNREACHABLE(); | 1772 UNREACHABLE(); |
| 1757 } | 1773 } |
| 1758 | 1774 |
| 1759 // Invoke the setter and return the result. | 1775 // Invoke the setter and return the result. |
| 1760 const int kNumArgs = 1; | 1776 const int kNumArgs = 1; |
| 1761 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1777 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 1762 args.SetAt(0, value); | 1778 args.SetAt(0, value); |
| 1763 const Object& result = Object::Handle( | 1779 const Object& result = Object::Handle( |
| 1764 DartEntry::InvokeFunction(setter, args)); | 1780 DartEntry::InvokeFunction(setter, args)); |
| 1765 if (result.IsError()) { | 1781 if (result.IsError()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1785 | 1801 |
| 1786 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1802 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1787 const MirrorReference& func_ref = | 1803 const MirrorReference& func_ref = |
| 1788 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1804 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1789 Function& func = Function::Handle(); | 1805 Function& func = Function::Handle(); |
| 1790 func ^= func_ref.referent(); | 1806 func ^= func_ref.referent(); |
| 1791 return func.UserVisibleName(); | 1807 return func.UserVisibleName(); |
| 1792 } | 1808 } |
| 1793 | 1809 |
| 1794 } // namespace dart | 1810 } // namespace dart |
| OLD | NEW |