| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 return CreateClassMirror(cls, ref_type, is_declaration, owner_mirror); | 326 return CreateClassMirror(cls, ref_type, is_declaration, owner_mirror); |
| 327 } | 327 } |
| 328 ASSERT(!cls.IsDynamicClass() && !cls.IsVoidClass()); | 328 ASSERT(!cls.IsDynamicClass() && !cls.IsVoidClass()); |
| 329 ASSERT(!type.IsNull()); | 329 ASSERT(!type.IsNull()); |
| 330 ASSERT(type.IsFinalized()); | 330 ASSERT(type.IsFinalized()); |
| 331 | 331 |
| 332 if (cls.IsTypedefClass()) { | 332 if (cls.IsTypedefClass()) { |
| 333 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); | 333 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); |
| 334 } | 334 } |
| 335 | 335 |
| 336 const Error& error = Error::Handle(cls.EnsureIsFinalized(Thread::Current())); | |
| 337 if (!error.IsNull()) { | |
| 338 Exceptions::PropagateError(error); | |
| 339 UNREACHABLE(); | |
| 340 } | |
| 341 | |
| 342 const Array& args = Array::Handle(Array::New(9)); | 336 const Array& args = Array::Handle(Array::New(9)); |
| 343 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 337 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 344 args.SetAt(1, type); | 338 args.SetAt(1, type); |
| 345 // Note that the VM does not consider mixin application aliases to be mixin | 339 // Note that the VM does not consider mixin application aliases to be mixin |
| 346 // applications, so this only covers anonymous mixin applications. We do not | 340 // applications, so this only covers anonymous mixin applications. We do not |
| 347 // set the names of anonymous mixin applications here because the mirrors | 341 // set the names of anonymous mixin applications here because the mirrors |
| 348 // use a different naming convention than the VM (lib.S with lib.M and S&M | 342 // use a different naming convention than the VM (lib.S with lib.M and S&M |
| 349 // respectively). | 343 // respectively). |
| 350 if (!cls.IsMixinApplication()) { | 344 if (!cls.IsMixinApplication()) { |
| 351 args.SetAt(2, String::Handle(cls.Name())); | 345 args.SetAt(2, String::Handle(cls.Name())); |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 // Argument 0 is the mirror, which is unused by the native. It exists | 1458 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1465 // because this native is an instance method in order to be polymorphic | 1459 // because this native is an instance method in order to be polymorphic |
| 1466 // with its cousins. | 1460 // with its cousins. |
| 1467 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1461 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1468 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1462 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1469 GET_NON_NULL_NATIVE_ARGUMENT( | 1463 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1470 String, function_name, arguments->NativeArgAt(2)); | 1464 String, function_name, arguments->NativeArgAt(2)); |
| 1471 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1465 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 1472 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1466 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1473 | 1467 |
| 1468 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); |
| 1469 if (!error.IsNull()) { |
| 1470 Exceptions::PropagateError(error); |
| 1471 UNREACHABLE(); |
| 1472 } |
| 1473 |
| 1474 Function& function = Function::Handle( | 1474 Function& function = Function::Handle( |
| 1475 klass.LookupStaticFunction(function_name)); | 1475 klass.LookupStaticFunction(function_name)); |
| 1476 | 1476 |
| 1477 if (function.IsNull()) { | 1477 if (function.IsNull()) { |
| 1478 // Didn't find a method: try to find a getter and invoke call on its result. | 1478 // Didn't find a method: try to find a getter and invoke call on its result. |
| 1479 const String& getter_name = | 1479 const String& getter_name = |
| 1480 String::Handle(Field::GetterName(function_name)); | 1480 String::Handle(Field::GetterName(function_name)); |
| 1481 function = klass.LookupStaticFunction(getter_name); | 1481 function = klass.LookupStaticFunction(getter_name); |
| 1482 if (!function.IsNull()) { | 1482 if (!function.IsNull()) { |
| 1483 // Invoke the getter. | 1483 // Invoke the getter. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 return result.raw(); | 1536 return result.raw(); |
| 1537 } | 1537 } |
| 1538 | 1538 |
| 1539 | 1539 |
| 1540 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { | 1540 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { |
| 1541 // Argument 0 is the mirror, which is unused by the native. It exists | 1541 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1542 // because this native is an instance method in order to be polymorphic | 1542 // because this native is an instance method in order to be polymorphic |
| 1543 // with its cousins. | 1543 // with its cousins. |
| 1544 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1544 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1545 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1545 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1546 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); |
| 1547 if (!error.IsNull()) { |
| 1548 Exceptions::PropagateError(error); |
| 1549 UNREACHABLE(); |
| 1550 } |
| 1546 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 1551 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 1547 return InvokeClassGetter(klass, getter_name, true); | 1552 return InvokeClassGetter(klass, getter_name, true); |
| 1548 } | 1553 } |
| 1549 | 1554 |
| 1550 | 1555 |
| 1551 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { | 1556 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { |
| 1552 // Argument 0 is the mirror, which is unused by the native. It exists | 1557 // Argument 0 is the mirror, which is unused by the native. It exists |
| 1553 // because this native is an instance method in order to be polymorphic | 1558 // because this native is an instance method in order to be polymorphic |
| 1554 // with its cousins. | 1559 // with its cousins. |
| 1555 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1560 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1556 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1561 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1557 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1562 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1558 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1563 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1559 | 1564 |
| 1565 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); |
| 1566 if (!error.IsNull()) { |
| 1567 Exceptions::PropagateError(error); |
| 1568 UNREACHABLE(); |
| 1569 } |
| 1570 |
| 1560 // Check for real fields and user-defined setters. | 1571 // Check for real fields and user-defined setters. |
| 1561 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1572 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 1562 Function& setter = Function::Handle(); | 1573 Function& setter = Function::Handle(); |
| 1563 const String& internal_setter_name = String::Handle( | 1574 const String& internal_setter_name = String::Handle( |
| 1564 Field::SetterName(setter_name)); | 1575 Field::SetterName(setter_name)); |
| 1565 | 1576 |
| 1566 if (field.IsNull()) { | 1577 if (field.IsNull()) { |
| 1567 setter = klass.LookupStaticFunction(internal_setter_name); | 1578 setter = klass.LookupStaticFunction(internal_setter_name); |
| 1568 | 1579 |
| 1569 const int kNumArgs = 1; | 1580 const int kNumArgs = 1; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 | 1620 |
| 1610 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) { | 1621 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) { |
| 1611 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1622 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1612 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1623 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1613 GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1)); | 1624 GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1)); |
| 1614 GET_NON_NULL_NATIVE_ARGUMENT( | 1625 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1615 String, constructor_name, arguments->NativeArgAt(2)); | 1626 String, constructor_name, arguments->NativeArgAt(2)); |
| 1616 GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3)); | 1627 GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3)); |
| 1617 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1628 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1618 | 1629 |
| 1630 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); |
| 1631 if (!error.IsNull()) { |
| 1632 Exceptions::PropagateError(error); |
| 1633 UNREACHABLE(); |
| 1634 } |
| 1635 |
| 1619 // By convention, the static function implementing a named constructor 'C' | 1636 // By convention, the static function implementing a named constructor 'C' |
| 1620 // for class 'A' is labeled 'A.C', and the static function implementing the | 1637 // for class 'A' is labeled 'A.C', and the static function implementing the |
| 1621 // unnamed constructor for class 'A' is labeled 'A.'. | 1638 // unnamed constructor for class 'A' is labeled 'A.'. |
| 1622 // This convention prevents users from explicitly calling constructors. | 1639 // This convention prevents users from explicitly calling constructors. |
| 1623 const String& klass_name = String::Handle(klass.Name()); | 1640 const String& klass_name = String::Handle(klass.Name()); |
| 1624 String& external_constructor_name = String::Handle(klass_name.raw()); | 1641 String& external_constructor_name = String::Handle(klass_name.raw()); |
| 1625 String& internal_constructor_name = | 1642 String& internal_constructor_name = |
| 1626 String::Handle(String::Concat(klass_name, Symbols::Dot())); | 1643 String::Handle(String::Concat(klass_name, Symbols::Dot())); |
| 1627 if (!constructor_name.IsNull() && constructor_name.Length() > 0) { | 1644 if (!constructor_name.IsNull() && constructor_name.Length() > 0) { |
| 1628 internal_constructor_name = | 1645 internal_constructor_name = |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 | 2104 |
| 2088 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2105 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
| 2089 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2106 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
| 2090 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2107 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
| 2091 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); | 2108 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); |
| 2092 } | 2109 } |
| 2093 | 2110 |
| 2094 #endif // !PRODUCT | 2111 #endif // !PRODUCT |
| 2095 | 2112 |
| 2096 } // namespace dart | 2113 } // namespace dart |
| OLD | NEW |