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

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

Issue 19235015: Implement metadata as an internal native. Be honest about which mirrors don't yet support metadata … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 Dart_False(), 624 Dart_False(),
625 }; 625 };
626 Dart_Handle mirror = 626 Dart_Handle mirror =
627 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); 627 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args);
628 return mirror; 628 return mirror;
629 } 629 }
630 630
631 631
632 static Dart_Handle CreateVariableMirror(Dart_Handle var, 632 static Dart_Handle CreateVariableMirror(Dart_Handle var,
633 Dart_Handle var_name, 633 Dart_Handle var_name,
634 Dart_Handle lib_mirror) { 634 Dart_Handle owner_mirror) {
635 ASSERT(Dart_IsVariable(var)); 635 ASSERT(Dart_IsVariable(var));
636 Dart_Handle cls_name = NewString("_LocalVariableMirrorImpl"); 636 Dart_Handle cls_name = NewString("_LocalVariableMirrorImpl");
637 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 637 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
638 if (Dart_IsError(type)) { 638 if (Dart_IsError(type)) {
639 return type; 639 return type;
640 } 640 }
641 641
642 bool is_static = false; 642 bool is_static = false;
643 bool is_final = false; 643 bool is_final = false;
644 644
645 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); 645 Dart_Handle result = Dart_VariableIsStatic(var, &is_static);
646 if (Dart_IsError(result)) { 646 if (Dart_IsError(result)) {
647 return result; 647 return result;
648 } 648 }
649 result = Dart_VariableIsFinal(var, &is_final); 649 result = Dart_VariableIsFinal(var, &is_final);
650 if (Dart_IsError(result)) { 650 if (Dart_IsError(result)) {
651 return result; 651 return result;
652 } 652 }
653 653
654 Dart_Handle var_type = Dart_VariableType(var); 654 Dart_Handle var_type = Dart_VariableType(var);
655 if (Dart_IsError(var_type)) { 655 if (Dart_IsError(var_type)) {
656 return var_type; 656 return var_type;
657 } 657 }
658 658
659 Dart_Handle args[] = { 659 Dart_Handle args[] = {
660 CreateMirrorReference(var),
660 var_name, 661 var_name,
661 lib_mirror, 662 owner_mirror,
662 CreateLazyMirror(var_type), 663 CreateLazyMirror(var_type),
663 Dart_NewBoolean(is_static), 664 Dart_NewBoolean(is_static),
664 Dart_NewBoolean(is_final), 665 Dart_NewBoolean(is_final),
665 }; 666 };
666 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 667 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
667 return mirror; 668 return mirror;
668 } 669 }
669 670
670 671
671 static Dart_Handle AddMemberClasses(Dart_Handle map, 672 static Dart_Handle AddMemberClasses(Dart_Handle map,
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 name_handle, 1106 name_handle,
1106 lib_handle, 1107 lib_handle,
1107 lib_mirror); 1108 lib_mirror);
1108 if (Dart_IsError(result)) { 1109 if (Dart_IsError(result)) {
1109 Dart_PropagateError(result); 1110 Dart_PropagateError(result);
1110 } 1111 }
1111 Dart_SetReturnValue(args, result); 1112 Dart_SetReturnValue(args, result);
1112 Dart_ExitScope(); 1113 Dart_ExitScope();
1113 } 1114 }
1114 1115
1115 void NATIVE_ENTRY_FUNCTION(Mirrors_metadata)(Dart_NativeArguments args) {
1116 Dart_EnterScope();
1117 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
1118
1119 Dart_Handle reflectee = UnwrapMirror(mirror);
1120 Dart_Handle result = Dart_GetMetadata(reflectee);
1121 if (Dart_IsError(result)) {
1122 Dart_PropagateError(result);
1123 }
1124 ASSERT(Dart_IsList(result));
1125 Dart_SetReturnValue(args, result);
1126 Dart_ExitScope();
1127 }
1128
1129 1116
1117 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
1118 const MirrorReference& decl_ref =
1119 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1120 const Object& decl = Object::Handle(decl_ref.referent());
1121
1122 Class& klass = Class::Handle();
1123 if (decl.IsClass()) {
1124 klass ^= decl.raw();
1125 } else if (decl.IsFunction()) {
1126 klass = Function::Cast(decl).origin();
1127 } else if (decl.IsField()) {
1128 klass = Field::Cast(decl).origin();
1129 } else {
1130 return Object::empty_array().raw();
1131 }
1132
1133 const Library& library = Library::Handle(klass.library());
1134 return library.GetMetadata(decl);
1135 }
1136
1137
1130 void HandleMirrorsMessage(Isolate* isolate, 1138 void HandleMirrorsMessage(Isolate* isolate,
1131 Dart_Port reply_port, 1139 Dart_Port reply_port,
1132 const Instance& message) { 1140 const Instance& message) {
1133 UNIMPLEMENTED(); 1141 UNIMPLEMENTED();
1134 } 1142 }
1135 1143
1136 1144
1137 // TODO(11742): This is transitional. 1145 // TODO(11742): This is transitional.
1138 static RawInstance* Reflect(const Instance& reflectee) { 1146 static RawInstance* Reflect(const Instance& reflectee) {
1139 Isolate* isolate = Isolate::Current(); 1147 Isolate* isolate = Isolate::Current();
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 1825
1818 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { 1826 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) {
1819 const MirrorReference& func_ref = 1827 const MirrorReference& func_ref =
1820 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1828 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1821 Function& func = Function::Handle(); 1829 Function& func = Function::Handle();
1822 func ^= func_ref.referent(); 1830 func ^= func_ref.referent();
1823 return func.UserVisibleName(); 1831 return func.UserVisibleName();
1824 } 1832 }
1825 1833
1826 } // namespace dart 1834 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698