Chromium Code Reviews| 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 if (Dart_IsError(result)) { | 460 if (Dart_IsError(result)) { |
| 461 return result; | 461 return result; |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 return map; | 464 return map; |
| 465 } | 465 } |
| 466 | 466 |
| 467 | 467 |
| 468 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, | 468 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, |
| 469 Dart_Handle cls_name, | 469 Dart_Handle cls_name, |
| 470 Dart_Handle owner, | |
| 471 Dart_Handle owner_mirror) { | 470 Dart_Handle owner_mirror) { |
| 472 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl"); | 471 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl"); |
| 473 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | 472 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); |
| 474 if (Dart_IsError(mirror_type)) { | 473 if (Dart_IsError(mirror_type)) { |
| 475 return mirror_type; | 474 return mirror_type; |
| 476 } | 475 } |
| 477 | 476 |
| 478 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); | 477 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); |
| 479 if (Dart_IsError(referent)) { | 478 if (Dart_IsError(referent)) { |
| 480 return referent; | 479 return referent; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 491 } | 490 } |
| 492 | 491 |
| 493 | 492 |
| 494 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); | 493 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); |
| 495 static Dart_Handle CreateConstructorMap(Dart_Handle owner, | 494 static Dart_Handle CreateConstructorMap(Dart_Handle owner, |
| 496 Dart_Handle owner_mirror); | 495 Dart_Handle owner_mirror); |
| 497 | 496 |
| 498 | 497 |
| 499 static Dart_Handle CreateClassMirror(Dart_Handle intf, | 498 static Dart_Handle CreateClassMirror(Dart_Handle intf, |
| 500 Dart_Handle intf_name, | 499 Dart_Handle intf_name, |
| 501 Dart_Handle lib, | |
| 502 Dart_Handle lib_mirror) { | 500 Dart_Handle lib_mirror) { |
| 503 ASSERT(Dart_IsClass(intf)); | 501 ASSERT(Dart_IsClass(intf)); |
| 504 if (Dart_ClassIsTypedef(intf)) { | 502 if (Dart_ClassIsTypedef(intf)) { |
| 505 // This class is actually a typedef. Represent it specially in | 503 // This class is actually a typedef. Represent it specially in |
| 506 // reflection. | 504 // reflection. |
| 507 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); | 505 return CreateTypedefMirror(intf, intf_name, lib_mirror); |
| 508 } | 506 } |
| 509 | 507 |
| 510 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl"); | 508 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl"); |
| 511 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 509 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 512 if (Dart_IsError(type)) { | 510 if (Dart_IsError(type)) { |
| 513 return type; | 511 return type; |
| 514 } | 512 } |
| 515 | 513 |
| 516 // TODO(turnidge): Why am I getting Null when I expect Object? | 514 // TODO(turnidge): Why am I getting Null when I expect Object? |
| 517 // TODO(gbracha): this is probably the root of bug 7868 | 515 // TODO(gbracha): this is probably the root of bug 7868 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 if (Dart_IsError(result)) { | 680 if (Dart_IsError(result)) { |
| 683 return result; | 681 return result; |
| 684 } | 682 } |
| 685 for (intptr_t i = 0; i < len; i++) { | 683 for (intptr_t i = 0; i < len; i++) { |
| 686 Dart_Handle intf_name = Dart_ListGetAt(names, i); | 684 Dart_Handle intf_name = Dart_ListGetAt(names, i); |
| 687 Dart_Handle intf = Dart_GetClass(owner, intf_name); | 685 Dart_Handle intf = Dart_GetClass(owner, intf_name); |
| 688 if (Dart_IsError(intf)) { | 686 if (Dart_IsError(intf)) { |
| 689 return intf; | 687 return intf; |
| 690 } | 688 } |
| 691 Dart_Handle intf_mirror = | 689 Dart_Handle intf_mirror = |
| 692 CreateClassMirror(intf, intf_name, owner, owner_mirror); | 690 CreateClassMirror(intf, intf_name, owner_mirror); |
| 693 if (Dart_IsError(intf_mirror)) { | 691 if (Dart_IsError(intf_mirror)) { |
| 694 return intf_mirror; | 692 return intf_mirror; |
| 695 } | 693 } |
| 696 result = MapAdd(map, intf_name, intf_mirror); | 694 result = MapAdd(map, intf_name, intf_mirror); |
| 697 if (Dart_IsError(result)) { | 695 if (Dart_IsError(result)) { |
| 698 return result; | 696 return result; |
| 699 } | 697 } |
| 700 } | 698 } |
| 701 return Dart_True(); | 699 return Dart_True(); |
| 702 } | 700 } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 const Type& type = Api::UnwrapTypeHandle(isolate, key); | 1084 const Type& type = Api::UnwrapTypeHandle(isolate, key); |
| 1087 const Class& cls = Class::Handle(type.type_class()); | 1085 const Class& cls = Class::Handle(type.type_class()); |
| 1088 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); | 1086 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); |
| 1089 if (Dart_IsError(cls_handle)) { | 1087 if (Dart_IsError(cls_handle)) { |
| 1090 Dart_PropagateError(cls_handle); | 1088 Dart_PropagateError(cls_handle); |
| 1091 } | 1089 } |
| 1092 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); | 1090 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); |
| 1093 if (Dart_IsError(name_handle)) { | 1091 if (Dart_IsError(name_handle)) { |
| 1094 Dart_PropagateError(name_handle); | 1092 Dart_PropagateError(name_handle); |
| 1095 } | 1093 } |
| 1096 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); | 1094 Dart_Handle lib_mirror = Dart_Null(); |
| 1097 if (Dart_IsError(lib_handle)) { | |
| 1098 Dart_PropagateError(lib_handle); | |
| 1099 } | |
| 1100 Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); | |
| 1101 if (Dart_IsError(lib_mirror)) { | |
| 1102 Dart_PropagateError(lib_mirror); | |
| 1103 } | |
| 1104 Dart_Handle result = CreateClassMirror(cls_handle, | 1095 Dart_Handle result = CreateClassMirror(cls_handle, |
| 1105 name_handle, | 1096 name_handle, |
| 1106 lib_handle, | |
| 1107 lib_mirror); | 1097 lib_mirror); |
| 1108 if (Dart_IsError(result)) { | 1098 if (Dart_IsError(result)) { |
| 1109 Dart_PropagateError(result); | 1099 Dart_PropagateError(result); |
| 1110 } | 1100 } |
| 1111 Dart_SetReturnValue(args, result); | 1101 Dart_SetReturnValue(args, result); |
| 1112 Dart_ExitScope(); | 1102 Dart_ExitScope(); |
| 1113 } | 1103 } |
| 1114 | 1104 |
| 1115 void NATIVE_ENTRY_FUNCTION(Mirrors_metadata)(Dart_NativeArguments args) { | 1105 void NATIVE_ENTRY_FUNCTION(Mirrors_metadata)(Dart_NativeArguments args) { |
| 1116 Dart_EnterScope(); | 1106 Dart_EnterScope(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 | 1250 |
| 1261 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { | 1251 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { |
| 1262 const MirrorReference& klass_ref = | 1252 const MirrorReference& klass_ref = |
| 1263 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1253 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1264 Class& klass = Class::Handle(); | 1254 Class& klass = Class::Handle(); |
| 1265 klass ^= klass_ref.referent(); | 1255 klass ^= klass_ref.referent(); |
| 1266 return klass.Name(); | 1256 return klass.Name(); |
| 1267 } | 1257 } |
| 1268 | 1258 |
| 1269 | 1259 |
| 1260 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { | |
| 1261 const MirrorReference& klass_ref = | |
|
siva
2013/07/16 21:06:46
why not call it klass_mirror instead of klass_ref
| |
| 1262 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | |
| 1263 Class& klass = Class::Handle(); | |
| 1264 klass ^= klass_ref.referent(); | |
| 1265 | |
| 1266 DARTSCOPE(isolate); | |
| 1267 return Instance::RawCast( | |
| 1268 Api::UnwrapHandle( | |
| 1269 CreateLibraryMirror( | |
| 1270 Api::NewHandle(isolate, klass.library())))); | |
|
siva
2013/07/16 21:06:46
Please add a TODO on top stating that this API cal
| |
| 1271 } | |
| 1272 | |
| 1273 | |
| 1270 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled | 1274 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled |
| 1271 // exceptions. Wrap and propagate any compilation errors. | 1275 // exceptions. Wrap and propagate any compilation errors. |
| 1272 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, | 1276 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, |
| 1273 const Function& function, | 1277 const Function& function, |
| 1274 const String& target_name, | 1278 const String& target_name, |
| 1275 const Array& arguments) { | 1279 const Array& arguments) { |
| 1276 // Note "arguments" is already the internal arguments with the receiver as | 1280 // Note "arguments" is already the internal arguments with the receiver as |
| 1277 // the first element. | 1281 // the first element. |
| 1278 Object& result = Object::Handle(); | 1282 Object& result = Object::Handle(); |
| 1279 if (function.IsNull()) { | 1283 if (function.IsNull()) { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1818 | 1822 |
| 1819 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1823 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1820 const MirrorReference& func_ref = | 1824 const MirrorReference& func_ref = |
| 1821 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1825 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1822 Function& func = Function::Handle(); | 1826 Function& func = Function::Handle(); |
| 1823 func ^= func_ref.referent(); | 1827 func ^= func_ref.referent(); |
| 1824 return func.UserVisibleName(); | 1828 return func.UserVisibleName(); |
| 1825 } | 1829 } |
| 1826 | 1830 |
| 1827 } // namespace dart | 1831 } // namespace dart |
| OLD | NEW |