| 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 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 // Return getter method for uninitialized fields, rather than the | 1310 // Return getter method for uninitialized fields, rather than the |
| 1311 // field object, since the value in the field object will not be | 1311 // field object, since the value in the field object will not be |
| 1312 // initialized until the first time the getter is invoked. | 1312 // initialized until the first time the getter is invoked. |
| 1313 const Instance& value = Instance::Handle(field.value()); | 1313 const Instance& value = Instance::Handle(field.value()); |
| 1314 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 1314 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 1315 return value.raw() == Object::sentinel().raw(); | 1315 return value.raw() == Object::sentinel().raw(); |
| 1316 } | 1316 } |
| 1317 | 1317 |
| 1318 | 1318 |
| 1319 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { | 1319 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { |
| 1320 const MirrorReference& klass_ref = | 1320 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1321 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1321 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1322 Class& klass = Class::Handle(); | |
| 1323 klass ^= klass_ref.referent(); | |
| 1324 return klass.Name(); | 1322 return klass.Name(); |
| 1325 } | 1323 } |
| 1326 | 1324 |
| 1327 | 1325 |
| 1328 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { | 1326 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { |
| 1329 const MirrorReference& klass_ref = | 1327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1330 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1328 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1331 Class& klass = Class::Handle(); | |
| 1332 klass ^= klass_ref.referent(); | |
| 1333 | |
| 1334 return CreateLibraryMirror(Library::Handle(klass.library())); | 1329 return CreateLibraryMirror(Library::Handle(klass.library())); |
| 1335 } | 1330 } |
| 1336 | 1331 |
| 1337 | 1332 |
| 1338 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled | 1333 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled |
| 1339 // exceptions. Wrap and propagate any compilation errors. | 1334 // exceptions. Wrap and propagate any compilation errors. |
| 1340 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, | 1335 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, |
| 1341 const Function& function, | 1336 const Function& function, |
| 1342 const String& target_name, | 1337 const String& target_name, |
| 1343 const Array& arguments) { | 1338 const Array& arguments) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1360 UNREACHABLE(); | 1355 UNREACHABLE(); |
| 1361 } | 1356 } |
| 1362 return result.raw(); | 1357 return result.raw(); |
| 1363 } | 1358 } |
| 1364 | 1359 |
| 1365 | 1360 |
| 1366 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 4) { | 1361 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 4) { |
| 1367 // Argument 0 is the mirror, which is unused by the native. It exists | 1362 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1368 // because this native is an instance method in order to be polymorphic | 1363 // because this native is an instance method in order to be polymorphic |
| 1369 // with its cousins. | 1364 // with its cousins. |
| 1365 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 1366 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1367 String, function_name, arguments->NativeArgAt(2)); |
| 1368 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1369 Array, positional_args, arguments->NativeArgAt(3)); |
| 1370 | 1370 |
| 1371 const Instance& reflectee = | |
| 1372 Instance::CheckedHandle(arguments->NativeArgAt(1)); | |
| 1373 | |
| 1374 const String& function_name = | |
| 1375 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1376 | |
| 1377 const Array& positional_args = | |
| 1378 Array::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1379 intptr_t number_of_arguments = positional_args.Length(); | 1371 intptr_t number_of_arguments = positional_args.Length(); |
| 1380 | 1372 |
| 1381 const Array& args = | 1373 const Array& args = |
| 1382 Array::Handle(Array::New(number_of_arguments + 1)); // Plus receiver. | 1374 Array::Handle(Array::New(number_of_arguments + 1)); // Plus receiver. |
| 1383 Object& arg = Object::Handle(); | 1375 Object& arg = Object::Handle(); |
| 1384 args.SetAt(0, reflectee); | 1376 args.SetAt(0, reflectee); |
| 1385 for (int i = 0; i < number_of_arguments; i++) { | 1377 for (int i = 0; i < number_of_arguments; i++) { |
| 1386 arg = positional_args.At(i); | 1378 arg = positional_args.At(i); |
| 1387 args.SetAt(i + 1, arg); // Plus receiver. | 1379 args.SetAt(i + 1, arg); // Plus receiver. |
| 1388 } | 1380 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1399 function, | 1391 function, |
| 1400 function_name, | 1392 function_name, |
| 1401 args); | 1393 args); |
| 1402 } | 1394 } |
| 1403 | 1395 |
| 1404 | 1396 |
| 1405 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { | 1397 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { |
| 1406 // Argument 0 is the mirror, which is unused by the native. It exists | 1398 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1407 // because this native is an instance method in order to be polymorphic | 1399 // because this native is an instance method in order to be polymorphic |
| 1408 // with its cousins. | 1400 // with its cousins. |
| 1409 | 1401 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 1410 const Instance& reflectee = | 1402 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 1411 Instance::CheckedHandle(arguments->NativeArgAt(1)); | |
| 1412 | |
| 1413 const String& getter_name = | |
| 1414 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1415 | 1403 |
| 1416 // Every instance field has a getter Function. Try to find the | 1404 // Every instance field has a getter Function. Try to find the |
| 1417 // getter in any superclass and use that function to access the | 1405 // getter in any superclass and use that function to access the |
| 1418 // field. | 1406 // field. |
| 1419 // NB: We do not use Resolver::ResolveDynamic because we want to find private | 1407 // NB: We do not use Resolver::ResolveDynamic because we want to find private |
| 1420 // members. | 1408 // members. |
| 1421 Class& klass = Class::Handle(reflectee.clazz()); | 1409 Class& klass = Class::Handle(reflectee.clazz()); |
| 1422 String& internal_getter_name = String::Handle(Field::GetterName(getter_name)); | 1410 String& internal_getter_name = String::Handle(Field::GetterName(getter_name)); |
| 1423 Function& getter = Function::Handle(); | 1411 Function& getter = Function::Handle(); |
| 1424 while (!klass.IsNull()) { | 1412 while (!klass.IsNull()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1437 getter, | 1425 getter, |
| 1438 internal_getter_name, | 1426 internal_getter_name, |
| 1439 args); | 1427 args); |
| 1440 } | 1428 } |
| 1441 | 1429 |
| 1442 | 1430 |
| 1443 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) { | 1431 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) { |
| 1444 // Argument 0 is the mirror, which is unused by the native. It exists | 1432 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1445 // because this native is an instance method in order to be polymorphic | 1433 // because this native is an instance method in order to be polymorphic |
| 1446 // with its cousins. | 1434 // with its cousins. |
| 1447 | 1435 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 1448 const Instance& reflectee = | 1436 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1449 Instance::CheckedHandle(arguments->NativeArgAt(1)); | 1437 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1450 | |
| 1451 const String& setter_name = | |
| 1452 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1453 | |
| 1454 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1455 | 1438 |
| 1456 String& internal_setter_name = | 1439 String& internal_setter_name = |
| 1457 String::Handle(Field::SetterName(setter_name)); | 1440 String::Handle(Field::SetterName(setter_name)); |
| 1458 Function& setter = Function::Handle(); | 1441 Function& setter = Function::Handle(); |
| 1459 | 1442 |
| 1460 Class& klass = Class::Handle(reflectee.clazz()); | 1443 Class& klass = Class::Handle(reflectee.clazz()); |
| 1461 Field& field = Field::Handle(); | 1444 Field& field = Field::Handle(); |
| 1462 | 1445 |
| 1463 while (!klass.IsNull()) { | 1446 while (!klass.IsNull()) { |
| 1464 field = klass.LookupInstanceField(setter_name); | 1447 field = klass.LookupInstanceField(setter_name); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1484 args.SetAt(1, value); | 1467 args.SetAt(1, value); |
| 1485 | 1468 |
| 1486 return ReflectivelyInvokeDynamicFunction(reflectee, | 1469 return ReflectivelyInvokeDynamicFunction(reflectee, |
| 1487 setter, | 1470 setter, |
| 1488 internal_setter_name, | 1471 internal_setter_name, |
| 1489 args); | 1472 args); |
| 1490 } | 1473 } |
| 1491 | 1474 |
| 1492 | 1475 |
| 1493 DEFINE_NATIVE_ENTRY(ClosureMirror_apply, 2) { | 1476 DEFINE_NATIVE_ENTRY(ClosureMirror_apply, 2) { |
| 1494 const Instance& closure = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 1477 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 1495 ASSERT(!closure.IsNull() && closure.IsCallable(NULL, NULL)); | 1478 ASSERT(!closure.IsNull() && closure.IsCallable(NULL, NULL)); |
| 1496 | 1479 |
| 1497 const Array& positional_args = | 1480 const Array& positional_args = |
| 1498 Array::CheckedHandle(arguments->NativeArgAt(1)); | 1481 Array::CheckedHandle(arguments->NativeArgAt(1)); |
| 1499 intptr_t number_of_arguments = positional_args.Length(); | 1482 intptr_t number_of_arguments = positional_args.Length(); |
| 1500 | 1483 |
| 1501 // Set up arguments to include the closure as the first argument. | 1484 // Set up arguments to include the closure as the first argument. |
| 1502 const Array& args = Array::Handle(Array::New(number_of_arguments + 1)); | 1485 const Array& args = Array::Handle(Array::New(number_of_arguments + 1)); |
| 1503 Object& obj = Object::Handle(); | 1486 Object& obj = Object::Handle(); |
| 1504 args.SetAt(0, closure); | 1487 args.SetAt(0, closure); |
| 1505 for (int i = 0; i < number_of_arguments; i++) { | 1488 for (int i = 0; i < number_of_arguments; i++) { |
| 1506 obj = positional_args.At(i); | 1489 obj = positional_args.At(i); |
| 1507 args.SetAt(i + 1, obj); | 1490 args.SetAt(i + 1, obj); |
| 1508 } | 1491 } |
| 1509 | 1492 |
| 1510 obj = DartEntry::InvokeClosure(args); | 1493 obj = DartEntry::InvokeClosure(args); |
| 1511 if (obj.IsError()) { | 1494 if (obj.IsError()) { |
| 1512 ThrowInvokeError(Error::Cast(obj)); | 1495 ThrowInvokeError(Error::Cast(obj)); |
| 1513 UNREACHABLE(); | 1496 UNREACHABLE(); |
| 1514 } | 1497 } |
| 1515 return obj.raw(); | 1498 return obj.raw(); |
| 1516 } | 1499 } |
| 1517 | 1500 |
| 1518 | 1501 |
| 1519 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { | 1502 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { |
| 1520 // Argument 0 is the mirror, which is unused by the native. It exists | 1503 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1521 // because this native is an instance method in order to be polymorphic | 1504 // because this native is an instance method in order to be polymorphic |
| 1522 // with its cousins. | 1505 // with its cousins. |
| 1506 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1507 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1508 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1509 String, function_name, arguments->NativeArgAt(2)); |
| 1510 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1511 Array, positional_args, arguments->NativeArgAt(3)); |
| 1523 | 1512 |
| 1524 const MirrorReference& klass_ref = | |
| 1525 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | |
| 1526 Class& klass = Class::Handle(); | |
| 1527 klass ^= klass_ref.referent(); | |
| 1528 | |
| 1529 const String& function_name = | |
| 1530 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1531 | |
| 1532 const Array& positional_args = | |
| 1533 Array::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1534 intptr_t number_of_arguments = positional_args.Length(); | 1513 intptr_t number_of_arguments = positional_args.Length(); |
| 1535 | 1514 |
| 1536 // TODO(11771): This won't find private members. | 1515 // TODO(11771): This won't find private members. |
| 1537 const Function& function = Function::Handle( | 1516 const Function& function = Function::Handle( |
| 1538 Resolver::ResolveStatic(klass, | 1517 Resolver::ResolveStatic(klass, |
| 1539 function_name, | 1518 function_name, |
| 1540 number_of_arguments, | 1519 number_of_arguments, |
| 1541 Object::empty_array(), | 1520 Object::empty_array(), |
| 1542 Resolver::kIsQualified)); | 1521 Resolver::kIsQualified)); |
| 1543 if (function.IsNull()) { | 1522 if (function.IsNull()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1557 UNREACHABLE(); | 1536 UNREACHABLE(); |
| 1558 } | 1537 } |
| 1559 return result.raw(); | 1538 return result.raw(); |
| 1560 } | 1539 } |
| 1561 | 1540 |
| 1562 | 1541 |
| 1563 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { | 1542 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { |
| 1564 // Argument 0 is the mirror, which is unused by the native. It exists | 1543 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1565 // because this native is an instance method in order to be polymorphic | 1544 // because this native is an instance method in order to be polymorphic |
| 1566 // with its cousins. | 1545 // with its cousins. |
| 1567 | 1546 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1568 const MirrorReference& klass_ref = | 1547 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1569 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1548 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 1570 Class& klass = Class::Handle(); | |
| 1571 klass ^= klass_ref.referent(); | |
| 1572 | |
| 1573 const String& getter_name = | |
| 1574 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1575 | 1549 |
| 1576 // Note static fields do not have implicit getters. | 1550 // Note static fields do not have implicit getters. |
| 1577 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 1551 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 1578 if (field.IsNull() || FieldIsUninitialized(field)) { | 1552 if (field.IsNull() || FieldIsUninitialized(field)) { |
| 1579 const String& internal_getter_name = String::Handle( | 1553 const String& internal_getter_name = String::Handle( |
| 1580 Field::GetterName(getter_name)); | 1554 Field::GetterName(getter_name)); |
| 1581 const Function& getter = Function::Handle( | 1555 const Function& getter = Function::Handle( |
| 1582 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 1556 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
| 1583 | 1557 |
| 1584 if (getter.IsNull()) { | 1558 if (getter.IsNull()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1600 return result.raw(); | 1574 return result.raw(); |
| 1601 } | 1575 } |
| 1602 return field.value(); | 1576 return field.value(); |
| 1603 } | 1577 } |
| 1604 | 1578 |
| 1605 | 1579 |
| 1606 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { | 1580 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { |
| 1607 // Argument 0 is the mirror, which is unused by the native. It exists | 1581 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1608 // because this native is an instance method in order to be polymorphic | 1582 // because this native is an instance method in order to be polymorphic |
| 1609 // with its cousins. | 1583 // with its cousins. |
| 1610 | 1584 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1611 const MirrorReference& klass_ref = | 1585 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1612 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1586 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1613 Class& klass = Class::Handle(); | 1587 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1614 klass ^= klass_ref.referent(); | |
| 1615 | |
| 1616 const String& setter_name = | |
| 1617 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1618 | |
| 1619 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1620 | 1588 |
| 1621 // Check for real fields and user-defined setters. | 1589 // Check for real fields and user-defined setters. |
| 1622 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1590 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 1623 if (field.IsNull()) { | 1591 if (field.IsNull()) { |
| 1624 const String& internal_setter_name = String::Handle( | 1592 const String& internal_setter_name = String::Handle( |
| 1625 Field::SetterName(setter_name)); | 1593 Field::SetterName(setter_name)); |
| 1626 const Function& setter = Function::Handle( | 1594 const Function& setter = Function::Handle( |
| 1627 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1595 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
| 1628 | 1596 |
| 1629 if (setter.IsNull()) { | 1597 if (setter.IsNull()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1657 ThrowMirroredCompilationError(message); | 1625 ThrowMirroredCompilationError(message); |
| 1658 UNREACHABLE(); | 1626 UNREACHABLE(); |
| 1659 } | 1627 } |
| 1660 | 1628 |
| 1661 field.set_value(value); | 1629 field.set_value(value); |
| 1662 return value.raw(); | 1630 return value.raw(); |
| 1663 } | 1631 } |
| 1664 | 1632 |
| 1665 | 1633 |
| 1666 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 3) { | 1634 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 3) { |
| 1667 const MirrorReference& klass_ref = | 1635 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1668 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1636 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1669 Class& klass = Class::Handle(); | 1637 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1670 klass ^= klass_ref.referent(); | 1638 String, constructor_name, arguments->NativeArgAt(1)); |
| 1671 | 1639 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1672 const String& constructor_name = | 1640 Array, positional_args, arguments->NativeArgAt(2)); |
| 1673 String::CheckedHandle(arguments->NativeArgAt(1)); | |
| 1674 | |
| 1675 const Array& positional_args = | |
| 1676 Array::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1677 | 1641 |
| 1678 intptr_t number_of_arguments = positional_args.Length(); | 1642 intptr_t number_of_arguments = positional_args.Length(); |
| 1679 | 1643 |
| 1680 // By convention, the static function implementing a named constructor 'C' | 1644 // By convention, the static function implementing a named constructor 'C' |
| 1681 // for class 'A' is labeled 'A.C', and the static function implementing the | 1645 // for class 'A' is labeled 'A.C', and the static function implementing the |
| 1682 // unnamed constructor for class 'A' is labeled 'A.'. | 1646 // unnamed constructor for class 'A' is labeled 'A.'. |
| 1683 // This convention prevents users from explicitly calling constructors. | 1647 // This convention prevents users from explicitly calling constructors. |
| 1684 const String& klass_name = String::Handle(klass.Name()); | 1648 const String& klass_name = String::Handle(klass.Name()); |
| 1685 String& internal_constructor_name = | 1649 String& internal_constructor_name = |
| 1686 String::Handle(String::Concat(klass_name, Symbols::Dot())); | 1650 String::Handle(String::Concat(klass_name, Symbols::Dot())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1707 // Factories may return null. | 1671 // Factories may return null. |
| 1708 ASSERT(result.IsInstance() || result.IsNull()); | 1672 ASSERT(result.IsInstance() || result.IsNull()); |
| 1709 return result.raw(); | 1673 return result.raw(); |
| 1710 } | 1674 } |
| 1711 | 1675 |
| 1712 | 1676 |
| 1713 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 4) { | 1677 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 4) { |
| 1714 // Argument 0 is the mirror, which is unused by the native. It exists | 1678 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1715 // because this native is an instance method in order to be polymorphic | 1679 // because this native is an instance method in order to be polymorphic |
| 1716 // with its cousins. | 1680 // with its cousins. |
| 1681 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1682 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1683 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1684 String, function_name, arguments->NativeArgAt(2)); |
| 1685 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1686 Array, positional_args, arguments->NativeArgAt(3)); |
| 1717 | 1687 |
| 1718 const MirrorReference& library_ref = | |
| 1719 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | |
| 1720 Library& library = Library::Handle(); | |
| 1721 library ^= library_ref.referent(); | |
| 1722 | |
| 1723 const String& function_name = | |
| 1724 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1725 | |
| 1726 const Array& positional_args = | |
| 1727 Array::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1728 intptr_t number_of_arguments = positional_args.Length(); | 1688 intptr_t number_of_arguments = positional_args.Length(); |
| 1729 | 1689 |
| 1730 | 1690 |
| 1731 const Function& function = Function::Handle( | 1691 const Function& function = Function::Handle( |
| 1732 library.LookupFunctionAllowPrivate(function_name)); | 1692 library.LookupFunctionAllowPrivate(function_name)); |
| 1733 | 1693 |
| 1734 if (function.IsNull()) { | 1694 if (function.IsNull()) { |
| 1735 const String& message = String::Handle( | 1695 const String& message = String::Handle( |
| 1736 String::NewFormatted("%s: did not find top-level function '%s'.", | 1696 String::NewFormatted("%s: did not find top-level function '%s'.", |
| 1737 "LibraryMirror_invoke", | 1697 "LibraryMirror_invoke", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1762 UNREACHABLE(); | 1722 UNREACHABLE(); |
| 1763 } | 1723 } |
| 1764 return result.raw(); | 1724 return result.raw(); |
| 1765 } | 1725 } |
| 1766 | 1726 |
| 1767 | 1727 |
| 1768 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeGetter, 3) { | 1728 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeGetter, 3) { |
| 1769 // Argument 0 is the mirror, which is unused by the native. It exists | 1729 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1770 // because this native is an instance method in order to be polymorphic | 1730 // because this native is an instance method in order to be polymorphic |
| 1771 // with its cousins. | 1731 // with its cousins. |
| 1772 | 1732 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1773 const MirrorReference& library_ref = | 1733 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1774 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1734 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 1775 Library& library = Library::Handle(); | |
| 1776 library ^= library_ref.referent(); | |
| 1777 | |
| 1778 const String& getter_name = | |
| 1779 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1780 | 1735 |
| 1781 // To access a top-level we may need to use the Field or the | 1736 // To access a top-level we may need to use the Field or the |
| 1782 // getter Function. The getter function may either be in the | 1737 // getter Function. The getter function may either be in the |
| 1783 // library or in the field's owner class, depending. | 1738 // library or in the field's owner class, depending. |
| 1784 const Field& field = | 1739 const Field& field = |
| 1785 Field::Handle(library.LookupFieldAllowPrivate(getter_name)); | 1740 Field::Handle(library.LookupFieldAllowPrivate(getter_name)); |
| 1786 Function& getter = Function::Handle(); | 1741 Function& getter = Function::Handle(); |
| 1787 if (field.IsNull()) { | 1742 if (field.IsNull()) { |
| 1788 // No field found. Check for a getter in the lib. | 1743 // No field found. Check for a getter in the lib. |
| 1789 const String& internal_getter_name = | 1744 const String& internal_getter_name = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1817 UNREACHABLE(); | 1772 UNREACHABLE(); |
| 1818 return Instance::null(); | 1773 return Instance::null(); |
| 1819 } | 1774 } |
| 1820 } | 1775 } |
| 1821 | 1776 |
| 1822 | 1777 |
| 1823 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { | 1778 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { |
| 1824 // Argument 0 is the mirror, which is unused by the native. It exists | 1779 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1825 // because this native is an instance method in order to be polymorphic | 1780 // because this native is an instance method in order to be polymorphic |
| 1826 // with its cousins. | 1781 // with its cousins. |
| 1827 | 1782 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1828 const MirrorReference& library_ref = | 1783 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1829 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); | 1784 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1830 Library& library = Library::Handle(); | 1785 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1831 library ^= library_ref.referent(); | |
| 1832 | |
| 1833 const String& setter_name = | |
| 1834 String::CheckedHandle(arguments->NativeArgAt(2)); | |
| 1835 | |
| 1836 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); | |
| 1837 | 1786 |
| 1838 // To access a top-level we may need to use the Field or the | 1787 // To access a top-level we may need to use the Field or the |
| 1839 // setter Function. The setter function may either be in the | 1788 // setter Function. The setter function may either be in the |
| 1840 // library or in the field's owner class, depending. | 1789 // library or in the field's owner class, depending. |
| 1841 const Field& field = | 1790 const Field& field = |
| 1842 Field::Handle(library.LookupFieldAllowPrivate(setter_name)); | 1791 Field::Handle(library.LookupFieldAllowPrivate(setter_name)); |
| 1843 | 1792 |
| 1844 if (field.IsNull()) { | 1793 if (field.IsNull()) { |
| 1845 const String& internal_setter_name = | 1794 const String& internal_setter_name = |
| 1846 String::Handle(Field::SetterName(setter_name)); | 1795 String::Handle(Field::SetterName(setter_name)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1877 ThrowMirroredCompilationError(message); | 1826 ThrowMirroredCompilationError(message); |
| 1878 UNREACHABLE(); | 1827 UNREACHABLE(); |
| 1879 } | 1828 } |
| 1880 | 1829 |
| 1881 field.set_value(value); | 1830 field.set_value(value); |
| 1882 return value.raw(); | 1831 return value.raw(); |
| 1883 } | 1832 } |
| 1884 | 1833 |
| 1885 | 1834 |
| 1886 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1835 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1887 const MirrorReference& func_ref = | 1836 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1888 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1837 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1889 Function& func = Function::Handle(); | |
| 1890 func ^= func_ref.referent(); | |
| 1891 return func.UserVisibleName(); | 1838 return func.UserVisibleName(); |
| 1892 } | 1839 } |
| 1893 | 1840 |
| 1894 | 1841 |
| 1895 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { | 1842 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { |
| 1896 const MirrorReference& func_ref = | 1843 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1897 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1844 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1898 Function& func = Function::Handle(); | |
| 1899 func ^= func_ref.referent(); | |
| 1900 if (func.IsNonImplicitClosureFunction()) { | 1845 if (func.IsNonImplicitClosureFunction()) { |
| 1901 return CreateMethodMirror(Function::Handle( | 1846 return CreateMethodMirror(Function::Handle( |
| 1902 func.parent_function()), Instance::Handle()); | 1847 func.parent_function()), Object::null_instance()); |
| 1903 } | 1848 } |
| 1904 const Class& owner = Class::Handle(func.Owner()); | 1849 const Class& owner = Class::Handle(func.Owner()); |
| 1905 if (owner.IsTopLevel()) { | 1850 if (owner.IsTopLevel()) { |
| 1906 return CreateLibraryMirror(Library::Handle(owner.library())); | 1851 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1907 } | 1852 } |
| 1908 return CreateClassMirror(owner, Instance::Handle()); | 1853 return CreateClassMirror(owner, Object::null_instance()); |
| 1909 } | 1854 } |
| 1910 | 1855 |
| 1911 | 1856 |
| 1912 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1857 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1913 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1858 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1914 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1859 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1915 // We handle constructors in Dart code. | 1860 // We handle constructors in Dart code. |
| 1916 ASSERT(!func.IsConstructor()); | 1861 ASSERT(!func.IsConstructor()); |
| 1917 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1862 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1918 return CreateTypeMirror(return_type); | 1863 return CreateTypeMirror(return_type); |
| 1919 } | 1864 } |
| 1920 | 1865 |
| 1921 } // namespace dart | 1866 } // namespace dart |
| OLD | NEW |