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

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

Issue 10800065: Added ClosureMirror to dart:mirrors. Added Dart_ClosureFunction to the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « runtime/include/dart_api.h ('k') | 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 "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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 CreateLazyMirror(default_class), 294 CreateLazyMirror(default_class),
295 member_map, 295 member_map,
296 }; 296 };
297 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 297 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
298 return mirror; 298 return mirror;
299 } 299 }
300 300
301 301
302 static Dart_Handle CreateMethodMirror(Dart_Handle func, 302 static Dart_Handle CreateMethodMirror(Dart_Handle func,
303 Dart_Handle func_name, 303 Dart_Handle func_name,
304 Dart_Handle lib_mirror) { 304 Dart_Handle owner_mirror) {
305 ASSERT(Dart_IsFunction(func)); 305 ASSERT(Dart_IsFunction(func));
306 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl"); 306 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl");
307 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 307 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
308 if (Dart_IsError(cls)) { 308 if (Dart_IsError(cls)) {
309 return cls; 309 return cls;
310 } 310 }
311 311
312 bool is_static = false; 312 bool is_static = false;
313 bool is_abstract = false; 313 bool is_abstract = false;
314 bool is_getter = false; 314 bool is_getter = false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param); 382 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param);
383 if (Dart_IsError(result)) { 383 if (Dart_IsError(result)) {
384 return result; 384 return result;
385 } 385 }
386 } 386 }
387 387
388 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). 388 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10).
389 Dart_Handle args[] = { 389 Dart_Handle args[] = {
390 func_name, 390 func_name,
391 lib_mirror, 391 owner_mirror,
392 parameter_mirrors, 392 parameter_mirrors,
393 Dart_NewBoolean(is_static), 393 Dart_NewBoolean(is_static),
394 Dart_NewBoolean(is_abstract), 394 Dart_NewBoolean(is_abstract),
395 Dart_NewBoolean(is_getter), 395 Dart_NewBoolean(is_getter),
396 Dart_NewBoolean(is_setter), 396 Dart_NewBoolean(is_setter),
397 Dart_NewBoolean(is_constructor), 397 Dart_NewBoolean(is_constructor),
398 Dart_False(), 398 Dart_False(),
399 Dart_False(), 399 Dart_False(),
400 Dart_False(), 400 Dart_False(),
401 Dart_False(), 401 Dart_False(),
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 688 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
689 return mirror; 689 return mirror;
690 } 690 }
691 691
692 692
693 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { 693 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
694 if (Dart_IsNull(instance)) { 694 if (Dart_IsNull(instance)) {
695 return CreateNullMirror(); 695 return CreateNullMirror();
696 } 696 }
697 ASSERT(Dart_IsInstance(instance)); 697 ASSERT(Dart_IsInstance(instance));
698 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); 698
699 bool is_closure = Dart_IsClosure(instance);
700 Dart_Handle cls_name = Dart_NewString(
701 is_closure ? "_LocalClosureMirrorImpl" : "_LocalInstanceMirrorImpl");
699 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 702 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
700 if (Dart_IsError(cls)) { 703 if (Dart_IsError(cls)) {
701 return cls; 704 return cls;
702 } 705 }
703 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); 706 Dart_Handle instance_cls = Dart_InstanceGetClass(instance);
704 if (Dart_IsError(instance_cls)) { 707 if (Dart_IsError(instance_cls)) {
705 return instance_cls; 708 return instance_cls;
706 } 709 }
707 710
708 Dart_Handle args[] = { 711 Dart_Handle args[] = {
709 CreateVMReference(instance), 712 CreateVMReference(instance),
710 CreateLazyMirror(instance_cls), 713 CreateLazyMirror(instance_cls),
711 instance 714 instance
712 }; 715 };
713 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 716 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
717
718 if (is_closure) {
719 // We set the function field of ClosureMirrors outside of the constructor
720 // to break the mutual recursion.
721 Dart_Handle func = Dart_ClosureFunction(instance);
722 if (Dart_IsError(func)) {
723 return func;
724 }
725 Dart_Handle func_name = Dart_NewString("call");
726 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror);
727 if (Dart_IsError(func_mirror)) {
728 return func_mirror;
729 }
730
731 Dart_Handle func_field_name = Dart_NewString("_function");
732 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror);
733 if (Dart_IsError(result)) {
734 return result;
735 }
736 }
714 return mirror; 737 return mirror;
715 } 738 }
716 739
717 740
718 static Dart_Handle CreateMirroredError(Dart_Handle error) { 741 static Dart_Handle CreateMirroredError(Dart_Handle error) {
719 ASSERT(Dart_IsError(error)); 742 ASSERT(Dart_IsError(error));
720 if (Dart_IsUnhandledExceptionError(error)) { 743 if (Dart_IsUnhandledExceptionError(error)) {
721 Dart_Handle exc = Dart_ErrorGetException(error); 744 Dart_Handle exc = Dart_ErrorGetException(error);
722 if (Dart_IsError(exc)) { 745 if (Dart_IsError(exc)) {
723 return exc; 746 return exc;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 } 872 }
850 873
851 Dart_Handle wrapped_result = CreateInstanceMirror(result); 874 Dart_Handle wrapped_result = CreateInstanceMirror(result);
852 if (Dart_IsError(wrapped_result)) { 875 if (Dart_IsError(wrapped_result)) {
853 Dart_PropagateError(wrapped_result); 876 Dart_PropagateError(wrapped_result);
854 } 877 }
855 Dart_SetReturnValue(args, wrapped_result); 878 Dart_SetReturnValue(args, wrapped_result);
856 } 879 }
857 880
858 881
882 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)(
883 Dart_NativeArguments args) {
884 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
885 Dart_Handle raw_invoke_args = Dart_GetNativeArgument(args, 1);
886
887 Dart_Handle reflectee = UnwrapMirror(mirror);
888 GrowableArray<Dart_Handle> invoke_args;
889 Dart_Handle result = UnwrapArgList(raw_invoke_args, &invoke_args);
890 if (Dart_IsError(result)) {
891 Dart_PropagateError(result);
892 }
893 result =
894 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data());
895 if (Dart_IsError(result)) {
896 // Instead of propagating the error from an apply directly, we
897 // provide reflective access to the error.
898 Dart_PropagateError(CreateMirroredError(result));
899 }
900
901 Dart_Handle wrapped_result = CreateInstanceMirror(result);
902 if (Dart_IsError(wrapped_result)) {
903 Dart_PropagateError(wrapped_result);
904 }
905 Dart_SetReturnValue(args, wrapped_result);
906 }
907
908
859 void HandleMirrorsMessage(Isolate* isolate, 909 void HandleMirrorsMessage(Isolate* isolate,
860 Dart_Port reply_port, 910 Dart_Port reply_port,
861 const Instance& message) { 911 const Instance& message) {
862 UNIMPLEMENTED(); 912 UNIMPLEMENTED();
863 } 913 }
864 914
865 } // namespace dart 915 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698