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 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 1336 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
1337 GET_NON_NULL_NATIVE_ARGUMENT(String, function_name, | 1337 GET_NON_NULL_NATIVE_ARGUMENT(String, function_name, |
1338 arguments->NativeArgAt(2)); | 1338 arguments->NativeArgAt(2)); |
1339 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1339 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
1340 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1340 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
1341 | 1341 |
1342 Class& klass = Class::Handle(reflectee.clazz()); | 1342 Class& klass = Class::Handle(reflectee.clazz()); |
1343 Function& function = Function::Handle( | 1343 Function& function = Function::Handle( |
1344 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, function_name)); | 1344 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, function_name)); |
1345 | 1345 |
1346 const Array& args_descriptor = | 1346 // TODO(regis): Support invocation of generic functions with type arguments. |
1347 Array::Handle(zone, ArgumentsDescriptor::New(args.Length(), arg_names)); | 1347 const Array& args_descriptor = Array::Handle( |
| 1348 zone, ArgumentsDescriptor::New(0, args.Length(), arg_names)); |
1348 | 1349 |
1349 if (function.IsNull()) { | 1350 if (function.IsNull()) { |
1350 // Didn't find a method: try to find a getter and invoke call on its result. | 1351 // Didn't find a method: try to find a getter and invoke call on its result. |
1351 const String& getter_name = | 1352 const String& getter_name = |
1352 String::Handle(zone, Field::GetterName(function_name)); | 1353 String::Handle(zone, Field::GetterName(function_name)); |
1353 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name); | 1354 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name); |
1354 if (!function.IsNull()) { | 1355 if (!function.IsNull()) { |
1355 ASSERT(function.kind() != RawFunction::kMethodExtractor); | 1356 ASSERT(function.kind() != RawFunction::kMethodExtractor); |
1356 // Invoke the getter. | 1357 // Invoke the getter. |
1357 const int kNumArgs = 1; | 1358 const int kNumArgs = 1; |
1358 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs)); | 1359 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs)); |
1359 getter_args.SetAt(0, reflectee); | 1360 getter_args.SetAt(0, reflectee); |
1360 const Array& getter_args_descriptor = | 1361 const Array& getter_args_descriptor = Array::Handle( |
1361 Array::Handle(zone, ArgumentsDescriptor::New(getter_args.Length())); | 1362 zone, ArgumentsDescriptor::New(0, getter_args.Length())); |
1362 const Instance& getter_result = Instance::Handle( | 1363 const Instance& getter_result = Instance::Handle( |
1363 zone, InvokeDynamicFunction(reflectee, function, getter_name, | 1364 zone, InvokeDynamicFunction(reflectee, function, getter_name, |
1364 getter_args, getter_args_descriptor)); | 1365 getter_args, getter_args_descriptor)); |
1365 // Replace the closure as the receiver in the arguments list. | 1366 // Replace the closure as the receiver in the arguments list. |
1366 args.SetAt(0, getter_result); | 1367 args.SetAt(0, getter_result); |
1367 // Call the closure. | 1368 // Call the closure. |
1368 const Object& call_result = | 1369 const Object& call_result = |
1369 Object::Handle(zone, DartEntry::InvokeClosure(args, args_descriptor)); | 1370 Object::Handle(zone, DartEntry::InvokeClosure(args, args_descriptor)); |
1370 if (call_result.IsError()) { | 1371 if (call_result.IsError()) { |
1371 Exceptions::PropagateError(Error::Cast(call_result)); | 1372 Exceptions::PropagateError(Error::Cast(call_result)); |
(...skipping 29 matching lines...) Expand all Loading... |
1401 const Function& closure_function = | 1402 const Function& closure_function = |
1402 Function::Handle(zone, function.ImplicitClosureFunction()); | 1403 Function::Handle(zone, function.ImplicitClosureFunction()); |
1403 return closure_function.ImplicitInstanceClosure(reflectee); | 1404 return closure_function.ImplicitInstanceClosure(reflectee); |
1404 } | 1405 } |
1405 } | 1406 } |
1406 | 1407 |
1407 const int kNumArgs = 1; | 1408 const int kNumArgs = 1; |
1408 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); | 1409 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); |
1409 args.SetAt(0, reflectee); | 1410 args.SetAt(0, reflectee); |
1410 const Array& args_descriptor = | 1411 const Array& args_descriptor = |
1411 Array::Handle(zone, ArgumentsDescriptor::New(args.Length())); | 1412 Array::Handle(zone, ArgumentsDescriptor::New(0, args.Length())); |
1412 | 1413 |
1413 // InvokeDynamic invokes NoSuchMethod if the provided function is null. | 1414 // InvokeDynamic invokes NoSuchMethod if the provided function is null. |
1414 return InvokeDynamicFunction(reflectee, function, internal_getter_name, args, | 1415 return InvokeDynamicFunction(reflectee, function, internal_getter_name, args, |
1415 args_descriptor); | 1416 args_descriptor); |
1416 } | 1417 } |
1417 | 1418 |
1418 | 1419 |
1419 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) { | 1420 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) { |
1420 // Argument 0 is the mirror, which is unused by the native. It exists | 1421 // Argument 0 is the mirror, which is unused by the native. It exists |
1421 // because this native is an instance method in order to be polymorphic | 1422 // because this native is an instance method in order to be polymorphic |
1422 // with its cousins. | 1423 // with its cousins. |
1423 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 1424 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
1424 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1425 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
1425 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1426 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
1426 | 1427 |
1427 const Class& klass = Class::Handle(zone, reflectee.clazz()); | 1428 const Class& klass = Class::Handle(zone, reflectee.clazz()); |
1428 const String& internal_setter_name = | 1429 const String& internal_setter_name = |
1429 String::Handle(zone, Field::SetterName(setter_name)); | 1430 String::Handle(zone, Field::SetterName(setter_name)); |
1430 const Function& setter = Function::Handle( | 1431 const Function& setter = Function::Handle( |
1431 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name)); | 1432 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name)); |
1432 | 1433 |
1433 const int kNumArgs = 2; | 1434 const int kNumArgs = 2; |
1434 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); | 1435 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); |
1435 args.SetAt(0, reflectee); | 1436 args.SetAt(0, reflectee); |
1436 args.SetAt(1, value); | 1437 args.SetAt(1, value); |
1437 const Array& args_descriptor = | 1438 const Array& args_descriptor = |
1438 Array::Handle(zone, ArgumentsDescriptor::New(args.Length())); | 1439 Array::Handle(zone, ArgumentsDescriptor::New(0, args.Length())); |
1439 | 1440 |
1440 return InvokeDynamicFunction(reflectee, setter, internal_setter_name, args, | 1441 return InvokeDynamicFunction(reflectee, setter, internal_setter_name, args, |
1441 args_descriptor); | 1442 args_descriptor); |
1442 } | 1443 } |
1443 | 1444 |
1444 | 1445 |
1445 DEFINE_NATIVE_ENTRY(InstanceMirror_computeType, 1) { | 1446 DEFINE_NATIVE_ENTRY(InstanceMirror_computeType, 1) { |
1446 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); | 1447 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); |
1447 const AbstractType& type = AbstractType::Handle(instance.GetType(Heap::kNew)); | 1448 const AbstractType& type = AbstractType::Handle(instance.GetType(Heap::kNew)); |
1448 // The static type of null is specified to be the bottom type, however, the | 1449 // The static type of null is specified to be the bottom type, however, the |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 // Make room for the closure (receiver) in the argument list. | 1523 // Make room for the closure (receiver) in the argument list. |
1523 intptr_t numArgs = args.Length(); | 1524 intptr_t numArgs = args.Length(); |
1524 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); | 1525 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); |
1525 Object& temp = Object::Handle(); | 1526 Object& temp = Object::Handle(); |
1526 for (int i = 0; i < numArgs; i++) { | 1527 for (int i = 0; i < numArgs; i++) { |
1527 temp = args.At(i); | 1528 temp = args.At(i); |
1528 call_args.SetAt(i + 1, temp); | 1529 call_args.SetAt(i + 1, temp); |
1529 } | 1530 } |
1530 call_args.SetAt(0, getter_result); | 1531 call_args.SetAt(0, getter_result); |
1531 const Array& call_args_descriptor_array = Array::Handle( | 1532 const Array& call_args_descriptor_array = Array::Handle( |
1532 ArgumentsDescriptor::New(call_args.Length(), arg_names)); | 1533 ArgumentsDescriptor::New(0, call_args.Length(), arg_names)); |
1533 // Call the closure. | 1534 // Call the closure. |
1534 const Object& call_result = Object::Handle( | 1535 const Object& call_result = Object::Handle( |
1535 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); | 1536 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); |
1536 if (call_result.IsError()) { | 1537 if (call_result.IsError()) { |
1537 Exceptions::PropagateError(Error::Cast(call_result)); | 1538 Exceptions::PropagateError(Error::Cast(call_result)); |
1538 UNREACHABLE(); | 1539 UNREACHABLE(); |
1539 } | 1540 } |
1540 return call_result.raw(); | 1541 return call_result.raw(); |
1541 } | 1542 } |
1542 } | 1543 } |
1543 | 1544 |
1544 const Array& args_descriptor_array = | 1545 const Array& args_descriptor_array = |
1545 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1546 Array::Handle(ArgumentsDescriptor::New(0, args.Length(), arg_names)); |
1546 | 1547 |
1547 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1548 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1548 | 1549 |
1549 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || | 1550 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || |
1550 !function.is_reflectable()) { | 1551 !function.is_reflectable()) { |
1551 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), function_name, | 1552 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), function_name, |
1552 function, args, arg_names, InvocationMirror::kStatic, | 1553 function, args, arg_names, InvocationMirror::kStatic, |
1553 InvocationMirror::kMethod); | 1554 InvocationMirror::kMethod); |
1554 UNREACHABLE(); | 1555 UNREACHABLE(); |
1555 } | 1556 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 Array::Handle(Array::New(num_implicit_args + num_explicit_args)); | 1738 Array::Handle(Array::New(num_implicit_args + num_explicit_args)); |
1738 | 1739 |
1739 // Copy over the explicit arguments. | 1740 // Copy over the explicit arguments. |
1740 Object& explicit_argument = Object::Handle(); | 1741 Object& explicit_argument = Object::Handle(); |
1741 for (int i = 0; i < num_explicit_args; i++) { | 1742 for (int i = 0; i < num_explicit_args; i++) { |
1742 explicit_argument = explicit_args.At(i); | 1743 explicit_argument = explicit_args.At(i); |
1743 args.SetAt(i + num_implicit_args, explicit_argument); | 1744 args.SetAt(i + num_implicit_args, explicit_argument); |
1744 } | 1745 } |
1745 | 1746 |
1746 const Array& args_descriptor_array = | 1747 const Array& args_descriptor_array = |
1747 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1748 Array::Handle(ArgumentsDescriptor::New(0, args.Length(), arg_names)); |
1748 | 1749 |
1749 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1750 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1750 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL)) { | 1751 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL)) { |
1751 external_constructor_name = redirected_constructor.name(); | 1752 external_constructor_name = redirected_constructor.name(); |
1752 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1753 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1753 external_constructor_name, redirected_constructor, | 1754 external_constructor_name, redirected_constructor, |
1754 explicit_args, arg_names, InvocationMirror::kConstructor, | 1755 explicit_args, arg_names, InvocationMirror::kConstructor, |
1755 InvocationMirror::kMethod); | 1756 InvocationMirror::kMethod); |
1756 UNREACHABLE(); | 1757 UNREACHABLE(); |
1757 } | 1758 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 // Make room for the closure (receiver) in arguments. | 1816 // Make room for the closure (receiver) in arguments. |
1816 intptr_t numArgs = args.Length(); | 1817 intptr_t numArgs = args.Length(); |
1817 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); | 1818 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); |
1818 Object& temp = Object::Handle(); | 1819 Object& temp = Object::Handle(); |
1819 for (int i = 0; i < numArgs; i++) { | 1820 for (int i = 0; i < numArgs; i++) { |
1820 temp = args.At(i); | 1821 temp = args.At(i); |
1821 call_args.SetAt(i + 1, temp); | 1822 call_args.SetAt(i + 1, temp); |
1822 } | 1823 } |
1823 call_args.SetAt(0, getter_result); | 1824 call_args.SetAt(0, getter_result); |
1824 const Array& call_args_descriptor_array = Array::Handle( | 1825 const Array& call_args_descriptor_array = Array::Handle( |
1825 ArgumentsDescriptor::New(call_args.Length(), arg_names)); | 1826 ArgumentsDescriptor::New(0, call_args.Length(), arg_names)); |
1826 // Call closure. | 1827 // Call closure. |
1827 const Object& call_result = Object::Handle( | 1828 const Object& call_result = Object::Handle( |
1828 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); | 1829 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); |
1829 if (call_result.IsError()) { | 1830 if (call_result.IsError()) { |
1830 Exceptions::PropagateError(Error::Cast(call_result)); | 1831 Exceptions::PropagateError(Error::Cast(call_result)); |
1831 UNREACHABLE(); | 1832 UNREACHABLE(); |
1832 } | 1833 } |
1833 return call_result.raw(); | 1834 return call_result.raw(); |
1834 } | 1835 } |
1835 } | 1836 } |
1836 | 1837 |
1837 const Array& args_descriptor_array = | 1838 const Array& args_descriptor_array = |
1838 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1839 Array::Handle(ArgumentsDescriptor::New(0, args.Length(), arg_names)); |
1839 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1840 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1840 | 1841 |
1841 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || | 1842 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || |
1842 !function.is_reflectable()) { | 1843 !function.is_reflectable()) { |
1843 ThrowNoSuchMethod(Instance::null_instance(), function_name, function, args, | 1844 ThrowNoSuchMethod(Instance::null_instance(), function_name, function, args, |
1844 arg_names, InvocationMirror::kTopLevel, | 1845 arg_names, InvocationMirror::kTopLevel, |
1845 InvocationMirror::kMethod); | 1846 InvocationMirror::kMethod); |
1846 UNREACHABLE(); | 1847 UNREACHABLE(); |
1847 } | 1848 } |
1848 | 1849 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 | 2099 |
2099 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2100 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
2100 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2101 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
2101 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2102 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
2102 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); | 2103 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); |
2103 } | 2104 } |
2104 | 2105 |
2105 #endif // !PRODUCT && !DART_PRECOMPILED_RUNTIME | 2106 #endif // !PRODUCT && !DART_PRECOMPILED_RUNTIME |
2106 | 2107 |
2107 } // namespace dart | 2108 } // namespace dart |
OLD | NEW |