Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: runtime/lib/mirrors.cc

Issue 10854197: A round of edits to make mirrors.dart more like our current working (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "include/dart_debugger_api.h" 9 #include "include/dart_debugger_api.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return Dart_New(cls, Dart_Null(), 0, NULL); 49 return Dart_New(cls, Dart_Null(), 0, NULL);
50 } 50 }
51 51
52 52
53 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { 53 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) {
54 Dart_Handle args[] = { key, value }; 54 Dart_Handle args[] = { key, value };
55 return Dart_Invoke(map, Dart_NewString("[]="), ARRAY_SIZE(args), args); 55 return Dart_Invoke(map, Dart_NewString("[]="), ARRAY_SIZE(args), args);
56 } 56 }
57 57
58 58
59 static Dart_Handle MapGet(Dart_Handle map, Dart_Handle key) {
60 Dart_Handle args[] = { key };
61 return Dart_Invoke(map, Dart_NewString("[]"), ARRAY_SIZE(args), args);
62 }
63
64
65 static Dart_Handle MirrorLib() { 59 static Dart_Handle MirrorLib() {
66 Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors"); 60 Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors");
67 return Dart_LookupLibrary(mirror_lib_name); 61 return Dart_LookupLibrary(mirror_lib_name);
68 } 62 }
69 63
70 64
71 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) { 65 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) {
72 Dart_Handle cls_name = Dart_NewString("Mirror"); 66 Dart_Handle cls_name = Dart_NewString("Mirror");
73 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 67 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
74 if (Dart_IsError(cls)) { 68 if (Dart_IsError(cls)) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (Dart_IsNull(target)) { 199 if (Dart_IsNull(target)) {
206 return target; 200 return target;
207 } 201 }
208 if (Dart_IsLibrary(target)) { 202 if (Dart_IsLibrary(target)) {
209 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); 203 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror");
210 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 204 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
211 Dart_Handle args[] = { Dart_LibraryName(target) }; 205 Dart_Handle args[] = { Dart_LibraryName(target) };
212 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 206 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
213 } else { 207 } else {
214 ASSERT(Dart_IsClass(target) || Dart_IsInterface(target)); 208 ASSERT(Dart_IsClass(target) || Dart_IsInterface(target));
215 Dart_Handle cls_name = Dart_NewString("_LazyInterfaceMirror"); 209 Dart_Handle cls_name = Dart_NewString("_LazyClassMirror");
216 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 210 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
217 211
218 Dart_Handle lib = Dart_ClassGetLibrary(target); 212 Dart_Handle lib = Dart_ClassGetLibrary(target);
219 Dart_Handle lib_name; 213 Dart_Handle lib_name;
220 if (Dart_IsNull(lib)) { 214 if (Dart_IsNull(lib)) {
221 lib_name = Dart_Null(); 215 lib_name = Dart_Null();
222 } else { 216 } else {
223 lib_name = Dart_LibraryName(lib); 217 lib_name = Dart_LibraryName(lib);
224 } 218 }
225 219
(...skipping 29 matching lines...) Expand all
255 return result; 249 return result;
256 } 250 }
257 } 251 }
258 return mirror_list; 252 return mirror_list;
259 } 253 }
260 254
261 255
262 static Dart_Handle CreateMemberMap(Dart_Handle owner); 256 static Dart_Handle CreateMemberMap(Dart_Handle owner);
263 257
264 258
265 static Dart_Handle CreateInterfaceMirror(Dart_Handle intf, 259 static Dart_Handle CreateClassMirror(Dart_Handle intf,
266 Dart_Handle intf_name, 260 Dart_Handle intf_name,
267 Dart_Handle lib, 261 Dart_Handle lib,
268 Dart_Handle lib_mirror) { 262 Dart_Handle lib_mirror) {
269 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); 263 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf));
270 Dart_Handle cls_name = Dart_NewString("_LocalInterfaceMirrorImpl"); 264 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl");
271 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 265 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
272 if (Dart_IsError(cls)) { 266 if (Dart_IsError(cls)) {
273 return cls; 267 return cls;
274 } 268 }
275 269
276 // TODO(turnidge): Why am I getting Null when I expect Object? 270 // TODO(turnidge): Why am I getting Null when I expect Object?
277 Dart_Handle super_class = Dart_GetSuperclass(intf); 271 Dart_Handle super_class = Dart_GetSuperclass(intf);
278 if (Dart_IsNull(super_class)) { 272 if (Dart_IsNull(super_class)) {
279 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); 273 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object"));
280 } 274 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (Dart_IsError(result)) { 446 if (Dart_IsError(result)) {
453 return result; 447 return result;
454 } 448 }
455 for (int i = 0; i < len; i++) { 449 for (int i = 0; i < len; i++) {
456 Dart_Handle intf_name = Dart_ListGetAt(names, i); 450 Dart_Handle intf_name = Dart_ListGetAt(names, i);
457 Dart_Handle intf = Dart_GetClass(owner, intf_name); 451 Dart_Handle intf = Dart_GetClass(owner, intf_name);
458 if (Dart_IsError(intf)) { 452 if (Dart_IsError(intf)) {
459 return intf; 453 return intf;
460 } 454 }
461 Dart_Handle intf_mirror = 455 Dart_Handle intf_mirror =
462 CreateInterfaceMirror(intf, intf_name, owner, owner_mirror); 456 CreateClassMirror(intf, intf_name, owner, owner_mirror);
463 if (Dart_IsError(intf_mirror)) { 457 if (Dart_IsError(intf_mirror)) {
464 return intf_mirror; 458 return intf_mirror;
465 } 459 }
466 result = MapAdd(map, intf_name, intf_mirror); 460 result = MapAdd(map, intf_name, intf_mirror);
467 if (Dart_IsError(result)) { 461 if (Dart_IsError(result)) {
468 return result; 462 return result;
469 } 463 }
470 } 464 }
471 return Dart_True(); 465 return Dart_True();
472 } 466 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 return map; 613 return map;
620 } 614 }
621 615
622 616
623 static Dart_Handle CreateIsolateMirror() { 617 static Dart_Handle CreateIsolateMirror() {
624 Dart_Handle cls_name = Dart_NewString("_LocalIsolateMirrorImpl"); 618 Dart_Handle cls_name = Dart_NewString("_LocalIsolateMirrorImpl");
625 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 619 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
626 if (Dart_IsError(cls)) { 620 if (Dart_IsError(cls)) {
627 return cls; 621 return cls;
628 } 622 }
629 623 Dart_Handle args[] = {
630 Dart_Handle args[] = { Dart_DebugName() }; 624 Dart_DebugName(),
631 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 625 CreateLazyMirror(Dart_RootLibrary()),
632 if (Dart_IsError(mirror)) { 626 };
633 return mirror; 627 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
634 }
635
636 return mirror;
637 } 628 }
638 629
639 630
640 static Dart_Handle CreateMirrorSystem() { 631 static Dart_Handle CreateMirrorSystem() {
641 Dart_Handle cls_name = Dart_NewString("_LocalMirrorSystemImpl"); 632 Dart_Handle cls_name = Dart_NewString("_LocalMirrorSystemImpl");
642 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 633 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
643 if (Dart_IsError(cls)) { 634 if (Dart_IsError(cls)) {
644 return cls; 635 return cls;
645 } 636 }
646 637
647 Dart_Handle libraries = CreateLibrariesMap(); 638 Dart_Handle libraries = CreateLibrariesMap();
648 if (Dart_IsError(libraries)) { 639 if (Dart_IsError(libraries)) {
649 return libraries; 640 return libraries;
650 } 641 }
651 642
652 // Lookup the root_lib_mirror from the library list to canonicalize it.
653 Dart_Handle root_lib_name = Dart_LibraryName(Dart_RootLibrary());
654 Dart_Handle root_lib_mirror = MapGet(libraries, root_lib_name);
655 if (Dart_IsError(root_lib_mirror)) {
656 return root_lib_mirror;
657 }
658
659 Dart_Handle args[] = { 643 Dart_Handle args[] = {
660 root_lib_mirror,
661 libraries, 644 libraries,
662 CreateIsolateMirror(), 645 CreateIsolateMirror(),
663 }; 646 };
664 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 647 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
665 if (Dart_IsError(mirror)) { 648 if (Dart_IsError(mirror)) {
666 return mirror; 649 return mirror;
667 } 650 }
668 651
669 return mirror; 652 return mirror;
670 } 653 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 699 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
717 700
718 if (is_closure) { 701 if (is_closure) {
719 // We set the function field of ClosureMirrors outside of the constructor 702 // We set the function field of ClosureMirrors outside of the constructor
720 // to break the mutual recursion. 703 // to break the mutual recursion.
721 Dart_Handle func = Dart_ClosureFunction(instance); 704 Dart_Handle func = Dart_ClosureFunction(instance);
722 if (Dart_IsError(func)) { 705 if (Dart_IsError(func)) {
723 return func; 706 return func;
724 } 707 }
725 Dart_Handle func_name = Dart_NewString("call"); 708 Dart_Handle func_name = Dart_NewString("call");
709 // TODO(turnidge): Passing in 'mirror' here as the method owner
710 // seems wrong to me. Investigate.
726 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror); 711 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror);
727 if (Dart_IsError(func_mirror)) { 712 if (Dart_IsError(func_mirror)) {
728 return func_mirror; 713 return func_mirror;
729 } 714 }
730 715
731 Dart_Handle func_field_name = Dart_NewString("_function"); 716 Dart_Handle func_field_name = Dart_NewString("_function");
732 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror); 717 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror);
733 if (Dart_IsError(result)) { 718 if (Dart_IsError(result)) {
734 return result; 719 return result;
735 } 720 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 } 887 }
903 888
904 Dart_Handle wrapped_result = CreateInstanceMirror(result); 889 Dart_Handle wrapped_result = CreateInstanceMirror(result);
905 if (Dart_IsError(wrapped_result)) { 890 if (Dart_IsError(wrapped_result)) {
906 Dart_PropagateError(wrapped_result); 891 Dart_PropagateError(wrapped_result);
907 } 892 }
908 Dart_SetReturnValue(args, wrapped_result); 893 Dart_SetReturnValue(args, wrapped_result);
909 } 894 }
910 895
911 896
912 void NATIVE_ENTRY_FUNCTION(LocalInterfaceMirrorImpl_invokeConstructor)( 897 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)(
913 Dart_NativeArguments args) { 898 Dart_NativeArguments args) {
914 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); 899 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0);
915 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); 900 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1);
916 // The wrapped arguments are either simple values or instance mirrors. 901 // The wrapped arguments are either simple values or instance mirrors.
917 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); 902 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2);
918 903
919 Dart_Handle klass = UnwrapMirror(klass_mirror); 904 Dart_Handle klass = UnwrapMirror(klass_mirror);
920 GrowableArray<Dart_Handle> invoke_args; 905 GrowableArray<Dart_Handle> invoke_args;
921 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); 906 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args);
922 if (Dart_IsError(result)) { 907 if (Dart_IsError(result)) {
(...skipping 17 matching lines...) Expand all
940 } 925 }
941 926
942 927
943 void HandleMirrorsMessage(Isolate* isolate, 928 void HandleMirrorsMessage(Isolate* isolate,
944 Dart_Port reply_port, 929 Dart_Port reply_port,
945 const Instance& message) { 930 const Instance& message) {
946 UNIMPLEMENTED(); 931 UNIMPLEMENTED();
947 } 932 }
948 933
949 } // namespace dart 934 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698