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

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
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 CreateLazyMirror(default_class), 286 CreateLazyMirror(default_class),
287 member_map, 287 member_map,
288 }; 288 };
289 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 289 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
290 return mirror; 290 return mirror;
291 } 291 }
292 292
293 293
294 static Dart_Handle CreateMethodMirror(Dart_Handle func, 294 static Dart_Handle CreateMethodMirror(Dart_Handle func,
295 Dart_Handle func_name, 295 Dart_Handle func_name,
296 Dart_Handle lib_mirror) { 296 Dart_Handle owner_mirror) {
297 ASSERT(Dart_IsFunction(func)); 297 ASSERT(Dart_IsFunction(func));
298 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl"); 298 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl");
299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
300 if (Dart_IsError(cls)) { 300 if (Dart_IsError(cls)) {
301 return cls; 301 return cls;
302 } 302 }
303 303
304 bool is_static = false; 304 bool is_static = false;
305 bool is_abstract = false; 305 bool is_abstract = false;
306 bool is_getter = false; 306 bool is_getter = false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 373 }
374 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param); 374 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param);
375 if (Dart_IsError(result)) { 375 if (Dart_IsError(result)) {
376 return result; 376 return result;
377 } 377 }
378 } 378 }
379 379
380 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). 380 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10).
381 Dart_Handle args[] = { 381 Dart_Handle args[] = {
382 func_name, 382 func_name,
383 lib_mirror, 383 owner_mirror,
384 parameter_mirrors, 384 parameter_mirrors,
385 Dart_NewBoolean(is_static), 385 Dart_NewBoolean(is_static),
386 Dart_NewBoolean(is_abstract), 386 Dart_NewBoolean(is_abstract),
387 Dart_NewBoolean(is_getter), 387 Dart_NewBoolean(is_getter),
388 Dart_NewBoolean(is_setter), 388 Dart_NewBoolean(is_setter),
389 Dart_NewBoolean(is_constructor), 389 Dart_NewBoolean(is_constructor),
390 Dart_False(), 390 Dart_False(),
391 Dart_False(), 391 Dart_False(),
392 Dart_False(), 392 Dart_False(),
393 Dart_False(), 393 Dart_False(),
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 680 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
681 return mirror; 681 return mirror;
682 } 682 }
683 683
684 684
685 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { 685 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
686 if (Dart_IsNull(instance)) { 686 if (Dart_IsNull(instance)) {
687 return CreateNullMirror(); 687 return CreateNullMirror();
688 } 688 }
689 ASSERT(Dart_IsInstance(instance)); 689 ASSERT(Dart_IsInstance(instance));
690 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); 690
691 bool is_closure = Dart_IsClosure(instance);
692 Dart_Handle cls_name = Dart_NewString(
693 is_closure ? "_LocalClosureMirrorImpl" : "_LocalInstanceMirrorImpl");
691 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 694 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
692 if (Dart_IsError(cls)) { 695 if (Dart_IsError(cls)) {
693 return cls; 696 return cls;
694 } 697 }
695 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); 698 Dart_Handle instance_cls = Dart_InstanceGetClass(instance);
696 if (Dart_IsError(instance_cls)) { 699 if (Dart_IsError(instance_cls)) {
697 return instance_cls; 700 return instance_cls;
698 } 701 }
699 702
700 Dart_Handle args[] = { 703 Dart_Handle args[] = {
701 CreateVMReference(instance), 704 CreateVMReference(instance),
702 CreateLazyMirror(instance_cls), 705 CreateLazyMirror(instance_cls),
703 instance 706 instance
704 }; 707 };
705 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 708 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
709
710 if (is_closure) {
711 // We set the function field of ClosureMirrors outside of the contructor to
712 // break the mutual recursion.
713 Dart_Handle func = Dart_ClosureFunction(instance);
714 if (Dart_IsError(func)) {
715 return func;
716 }
717 Dart_Handle func_name = Dart_NewString("call");
718 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror);
719 if (Dart_IsError(func_mirror)) {
720 return func_mirror;
721 }
722
723 Dart_Handle func_field_name = Dart_NewString("_function");
724 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror);
725 if (Dart_IsError(result)) {
726 return result;
727 }
728 }
706 return mirror; 729 return mirror;
707 } 730 }
708 731
709 732
710 static Dart_Handle CreateMirroredError(Dart_Handle error) { 733 static Dart_Handle CreateMirroredError(Dart_Handle error) {
711 ASSERT(Dart_IsError(error)); 734 ASSERT(Dart_IsError(error));
712 if (Dart_IsUnhandledExceptionError(error)) { 735 if (Dart_IsUnhandledExceptionError(error)) {
713 Dart_Handle exc = Dart_ErrorGetException(error); 736 Dart_Handle exc = Dart_ErrorGetException(error);
714 if (Dart_IsError(exc)) { 737 if (Dart_IsError(exc)) {
715 return exc; 738 return exc;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 Dart_PropagateError(CreateMirroredError(result)); 814 Dart_PropagateError(CreateMirroredError(result));
792 } 815 }
793 816
794 Dart_Handle wrapped_result = CreateInstanceMirror(result); 817 Dart_Handle wrapped_result = CreateInstanceMirror(result);
795 if (Dart_IsError(wrapped_result)) { 818 if (Dart_IsError(wrapped_result)) {
796 Dart_PropagateError(wrapped_result); 819 Dart_PropagateError(wrapped_result);
797 } 820 }
798 Dart_SetReturnValue(args, wrapped_result); 821 Dart_SetReturnValue(args, wrapped_result);
799 } 822 }
800 823
824 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)(
825 Dart_NativeArguments args) {
826 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
827 Dart_Handle raw_invoke_args = Dart_GetNativeArgument(args, 1);
828
829 Dart_Handle reflectee = UnwrapMirror(mirror);
830 GrowableArray<Dart_Handle> invoke_args;
831 Dart_Handle result = UnwrapArgList(raw_invoke_args, &invoke_args);
832 if (Dart_IsError(result)) {
833 Dart_PropagateError(result);
834 }
835 result =
836 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data());
837 if (Dart_IsError(result)) {
838 // Instead of propagating the error from an apply directly, we
839 // provide reflective access to the error.
840 Dart_PropagateError(CreateMirroredError(result));
841 }
842
843 Dart_Handle wrapped_result = CreateInstanceMirror(result);
844 if (Dart_IsError(wrapped_result)) {
845 Dart_PropagateError(wrapped_result);
846 }
847 Dart_SetReturnValue(args, wrapped_result);
848 }
849
801 void HandleMirrorsMessage(Isolate* isolate, 850 void HandleMirrorsMessage(Isolate* isolate,
802 Dart_Port reply_port, 851 Dart_Port reply_port,
803 const Instance& message) { 852 const Instance& message) {
804 UNIMPLEMENTED(); 853 UNIMPLEMENTED();
805 } 854 }
806 855
807 } // namespace dart 856 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698