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

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

Issue 21430002: Allow InstanceMirror.invoke to find private members. Resolves issue 11771. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | tests/lib/mirrors/invoke_private_test.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"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/exceptions.h" 12 #include "vm/exceptions.h"
13 #include "vm/message.h" 13 #include "vm/message.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/port.h" 15 #include "vm/port.h"
16 #include "vm/resolver.h"
17 #include "vm/symbols.h" 16 #include "vm/symbols.h"
18 #include "lib/invocation_mirror.h" 17 #include "lib/invocation_mirror.h"
19 18
20 namespace dart { 19 namespace dart {
21 20
22 static RawInstance* CreateMirror(const String& mirror_class_name, 21 static RawInstance* CreateMirror(const String& mirror_class_name,
23 const Array& constructor_arguments) { 22 const Array& constructor_arguments) {
24 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); 23 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary());
25 const String& constructor_name = Symbols::Dot(); 24 const String& constructor_name = Symbols::Dot();
26 25
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 Array::Handle(Array::New(number_of_arguments + 1)); // Plus receiver. 725 Array::Handle(Array::New(number_of_arguments + 1)); // Plus receiver.
727 Object& arg = Object::Handle(); 726 Object& arg = Object::Handle();
728 args.SetAt(0, reflectee); 727 args.SetAt(0, reflectee);
729 for (int i = 0; i < number_of_arguments; i++) { 728 for (int i = 0; i < number_of_arguments; i++) {
730 arg = positional_args.At(i); 729 arg = positional_args.At(i);
731 args.SetAt(i + 1, arg); // Plus receiver. 730 args.SetAt(i + 1, arg); // Plus receiver.
732 } 731 }
733 732
734 ArgumentsDescriptor args_desc( 733 ArgumentsDescriptor args_desc(
735 Array::Handle(ArgumentsDescriptor::New(args.Length()))); 734 Array::Handle(ArgumentsDescriptor::New(args.Length())));
736 // TODO(11771): This won't find private members. 735
737 const Function& function = Function::Handle( 736 Class& klass = Class::Handle(reflectee.clazz());
738 Resolver::ResolveDynamic(reflectee, 737 Function& function = Function::Handle();
739 function_name, 738 while (!klass.IsNull()) {
740 args_desc)); 739 function = klass.LookupDynamicFunctionAllowPrivate(function_name);
740 if (!function.IsNull()) {
741 break;
742 }
743 klass = klass.SuperClass();
744 }
745
746 if (!function.IsNull() &&
747 !function.AreValidArguments(args_desc, NULL)) {
748 function = Function::null();
749 }
741 750
742 return ReflectivelyInvokeDynamicFunction(reflectee, 751 return ReflectivelyInvokeDynamicFunction(reflectee,
743 function, 752 function,
744 function_name, 753 function_name,
745 args); 754 args);
746 } 755 }
747 756
748 757
749 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { 758 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) {
750 // Argument 0 is the mirror, which is unused by the native. It exists 759 // Argument 0 is the mirror, which is unused by the native. It exists
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 1323
1315 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1324 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1316 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1325 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1317 const Field& field = Field::Handle(ref.GetFieldReferent()); 1326 const Field& field = Field::Handle(ref.GetFieldReferent());
1318 1327
1319 const AbstractType& type = AbstractType::Handle(field.type()); 1328 const AbstractType& type = AbstractType::Handle(field.type());
1320 return CreateTypeMirror(type); 1329 return CreateTypeMirror(type);
1321 } 1330 }
1322 1331
1323 } // namespace dart 1332 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | tests/lib/mirrors/invoke_private_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698