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