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

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

Issue 19188004: Make the ClassMirrors created through reflectClass() find their owners (libraries) lazily. (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') | no next file with comments »
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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (Dart_IsError(result)) { 414 if (Dart_IsError(result)) {
415 return result; 415 return result;
416 } 416 }
417 } 417 }
418 return map; 418 return map;
419 } 419 }
420 420
421 421
422 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, 422 static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
423 Dart_Handle cls_name, 423 Dart_Handle cls_name,
424 Dart_Handle owner,
425 Dart_Handle owner_mirror) { 424 Dart_Handle owner_mirror) {
426 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl"); 425 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl");
427 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); 426 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL);
428 if (Dart_IsError(mirror_type)) { 427 if (Dart_IsError(mirror_type)) {
429 return mirror_type; 428 return mirror_type;
430 } 429 }
431 430
432 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); 431 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls);
433 if (Dart_IsError(referent)) { 432 if (Dart_IsError(referent)) {
434 return referent; 433 return referent;
(...skipping 10 matching lines...) Expand all
445 } 444 }
446 445
447 446
448 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); 447 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror);
449 static Dart_Handle CreateConstructorMap(Dart_Handle owner, 448 static Dart_Handle CreateConstructorMap(Dart_Handle owner,
450 Dart_Handle owner_mirror); 449 Dart_Handle owner_mirror);
451 450
452 451
453 static Dart_Handle CreateClassMirror(Dart_Handle intf, 452 static Dart_Handle CreateClassMirror(Dart_Handle intf,
454 Dart_Handle intf_name, 453 Dart_Handle intf_name,
455 Dart_Handle lib,
456 Dart_Handle lib_mirror) { 454 Dart_Handle lib_mirror) {
457 ASSERT(Dart_IsClass(intf)); 455 ASSERT(Dart_IsClass(intf));
458 if (Dart_ClassIsTypedef(intf)) { 456 if (Dart_ClassIsTypedef(intf)) {
459 // This class is actually a typedef. Represent it specially in 457 // This class is actually a typedef. Represent it specially in
460 // reflection. 458 // reflection.
461 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); 459 return CreateTypedefMirror(intf, intf_name, lib_mirror);
462 } 460 }
463 461
464 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl"); 462 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl");
465 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 463 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
466 if (Dart_IsError(type)) { 464 if (Dart_IsError(type)) {
467 return type; 465 return type;
468 } 466 }
469 467
470 // TODO(turnidge): Why am I getting Null when I expect Object? 468 // TODO(turnidge): Why am I getting Null when I expect Object?
471 // TODO(gbracha): this is probably the root of bug 7868 469 // TODO(gbracha): this is probably the root of bug 7868
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 if (Dart_IsError(result)) { 602 if (Dart_IsError(result)) {
605 return result; 603 return result;
606 } 604 }
607 for (intptr_t i = 0; i < len; i++) { 605 for (intptr_t i = 0; i < len; i++) {
608 Dart_Handle intf_name = Dart_ListGetAt(names, i); 606 Dart_Handle intf_name = Dart_ListGetAt(names, i);
609 Dart_Handle intf = Dart_GetClass(owner, intf_name); 607 Dart_Handle intf = Dart_GetClass(owner, intf_name);
610 if (Dart_IsError(intf)) { 608 if (Dart_IsError(intf)) {
611 return intf; 609 return intf;
612 } 610 }
613 Dart_Handle intf_mirror = 611 Dart_Handle intf_mirror =
614 CreateClassMirror(intf, intf_name, owner, owner_mirror); 612 CreateClassMirror(intf, intf_name, owner_mirror);
615 if (Dart_IsError(intf_mirror)) { 613 if (Dart_IsError(intf_mirror)) {
616 return intf_mirror; 614 return intf_mirror;
617 } 615 }
618 result = MapAdd(map, intf_name, intf_mirror); 616 result = MapAdd(map, intf_name, intf_mirror);
619 if (Dart_IsError(result)) { 617 if (Dart_IsError(result)) {
620 return result; 618 return result;
621 } 619 }
622 } 620 }
623 return Dart_True(); 621 return Dart_True();
624 } 622 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 const Type& type = Api::UnwrapTypeHandle(isolate, key); 1002 const Type& type = Api::UnwrapTypeHandle(isolate, key);
1005 const Class& cls = Class::Handle(type.type_class()); 1003 const Class& cls = Class::Handle(type.type_class());
1006 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); 1004 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw());
1007 if (Dart_IsError(cls_handle)) { 1005 if (Dart_IsError(cls_handle)) {
1008 Dart_PropagateError(cls_handle); 1006 Dart_PropagateError(cls_handle);
1009 } 1007 }
1010 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); 1008 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
1011 if (Dart_IsError(name_handle)) { 1009 if (Dart_IsError(name_handle)) {
1012 Dart_PropagateError(name_handle); 1010 Dart_PropagateError(name_handle);
1013 } 1011 }
1014 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); 1012 Dart_Handle lib_mirror = Dart_Null();
1015 if (Dart_IsError(lib_handle)) {
1016 Dart_PropagateError(lib_handle);
1017 }
1018 Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle);
1019 if (Dart_IsError(lib_mirror)) {
1020 Dart_PropagateError(lib_mirror);
1021 }
1022 Dart_Handle result = CreateClassMirror(cls_handle, 1013 Dart_Handle result = CreateClassMirror(cls_handle,
1023 name_handle, 1014 name_handle,
1024 lib_handle,
1025 lib_mirror); 1015 lib_mirror);
1026 if (Dart_IsError(result)) { 1016 if (Dart_IsError(result)) {
1027 Dart_PropagateError(result); 1017 Dart_PropagateError(result);
1028 } 1018 }
1029 Dart_SetReturnValue(args, result); 1019 Dart_SetReturnValue(args, result);
1030 Dart_ExitScope(); 1020 Dart_ExitScope();
1031 } 1021 }
1032 1022
1033 1023
1034 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { 1024 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1175
1186 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { 1176 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) {
1187 const MirrorReference& klass_ref = 1177 const MirrorReference& klass_ref =
1188 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1178 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1189 Class& klass = Class::Handle(); 1179 Class& klass = Class::Handle();
1190 klass ^= klass_ref.referent(); 1180 klass ^= klass_ref.referent();
1191 return klass.Name(); 1181 return klass.Name();
1192 } 1182 }
1193 1183
1194 1184
1185 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) {
1186 const MirrorReference& klass_ref =
1187 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1188 Class& klass = Class::Handle();
1189 klass ^= klass_ref.referent();
1190
1191 // TODO(11742): This is transitional.
1192 Instance& result = Instance::Handle();
1193 Dart_EnterScope();
1194 DARTSCOPE(isolate);
rmacnak 2013/07/18 02:50:02 Is this needed, or is Dart_EnterScope fine by itse
rmacnak 2013/07/18 17:27:30 It appears not. Without it, tests pass and perform
1195 result = Instance::RawCast(
1196 Api::UnwrapHandle(
1197 CreateLibraryMirror(
1198 Api::NewHandle(isolate, klass.library()))));
1199 Dart_ExitScope();
1200 return result.raw();
1201 }
1202
1203
1195 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 1204 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
1196 // exceptions. Wrap and propagate any compilation errors. 1205 // exceptions. Wrap and propagate any compilation errors.
1197 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, 1206 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver,
1198 const Function& function, 1207 const Function& function,
1199 const String& target_name, 1208 const String& target_name,
1200 const Array& arguments) { 1209 const Array& arguments) {
1201 // Note "arguments" is already the internal arguments with the receiver as 1210 // Note "arguments" is already the internal arguments with the receiver as
1202 // the first element. 1211 // the first element.
1203 Object& result = Object::Handle(); 1212 Object& result = Object::Handle();
1204 if (function.IsNull()) { 1213 if (function.IsNull()) {
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 1751
1743 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { 1752 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) {
1744 const MirrorReference& func_ref = 1753 const MirrorReference& func_ref =
1745 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1754 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1746 Function& func = Function::Handle(); 1755 Function& func = Function::Handle();
1747 func ^= func_ref.referent(); 1756 func ^= func_ref.referent();
1748 return func.UserVisibleName(); 1757 return func.UserVisibleName();
1749 } 1758 }
1750 1759
1751 } // namespace dart 1760 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698