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

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

Issue 10704259: Added getField/setField to ObjectMirror. For InstanceMirrors, this get/sets (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 | « lib/mirrors/mirrors.dart ('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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { 157 static Dart_Handle UnwrapMirror(Dart_Handle mirror) {
158 Dart_Handle field_name = Dart_NewString("_reference"); 158 Dart_Handle field_name = Dart_NewString("_reference");
159 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); 159 Dart_Handle vm_ref = Dart_GetField(mirror, field_name);
160 if (Dart_IsError(vm_ref)) { 160 if (Dart_IsError(vm_ref)) {
161 return vm_ref; 161 return vm_ref;
162 } 162 }
163 return UnwrapVMReference(vm_ref); 163 return UnwrapVMReference(vm_ref);
164 } 164 }
165 165
166 166
167 static Dart_Handle UnwrapArg(Dart_Handle arg) {
168 if (Dart_IsError(arg)) {
169 return arg;
170 }
171 bool is_mirror = false;
172 Dart_Handle result = IsMirror(arg, &is_mirror);
173 if (Dart_IsError(result)) {
174 return result;
175 }
176 if (is_mirror) {
177 return UnwrapMirror(arg);
178 } else {
179 // Simple value.
180 ASSERT(IsSimpleValue(arg));
181 return arg;
182 }
183 }
184
167 static Dart_Handle UnwrapArgList(Dart_Handle arg_list, 185 static Dart_Handle UnwrapArgList(Dart_Handle arg_list,
168 GrowableArray<Dart_Handle>* arg_array) { 186 GrowableArray<Dart_Handle>* arg_array) {
169 intptr_t len = 0; 187 intptr_t len = 0;
170 Dart_Handle result = Dart_ListLength(arg_list, &len); 188 Dart_Handle result = Dart_ListLength(arg_list, &len);
171 if (Dart_IsError(result)) { 189 if (Dart_IsError(result)) {
172 return result; 190 return result;
173 } 191 }
174 for (int i = 0; i < len; i++) { 192 for (int i = 0; i < len; i++) {
175 Dart_Handle arg = Dart_ListGetAt(arg_list, i); 193 Dart_Handle arg = Dart_ListGetAt(arg_list, i);
176 if (Dart_IsError(arg)) { 194 Dart_Handle unwrapped_arg = UnwrapArg(arg);
177 return arg; 195 if (Dart_IsError(unwrapped_arg)) {
196 return unwrapped_arg;
178 } 197 }
179 bool is_mirror = false; 198 arg_array->Add(unwrapped_arg);
180 result = IsMirror(arg, &is_mirror);
181 if (Dart_IsError(result)) {
182 return result;
183 }
184 if (is_mirror) {
185 arg_array->Add(UnwrapMirror(arg));
186 } else {
187 // Simple value.
188 ASSERT(IsSimpleValue(arg));
189 arg_array->Add(arg);
190 }
191 } 199 }
192 return Dart_True(); 200 return Dart_True();
193 } 201 }
194 202
195 203
196 static Dart_Handle CreateLazyMirror(Dart_Handle target) { 204 static Dart_Handle CreateLazyMirror(Dart_Handle target) {
197 if (Dart_IsNull(target)) { 205 if (Dart_IsNull(target)) {
198 return target; 206 return target;
199 } 207 }
200 if (Dart_IsLibrary(target)) { 208 if (Dart_IsLibrary(target)) {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 // provide reflective access to the error. 798 // provide reflective access to the error.
791 Dart_PropagateError(CreateMirroredError(result)); 799 Dart_PropagateError(CreateMirroredError(result));
792 } 800 }
793 801
794 Dart_Handle wrapped_result = CreateInstanceMirror(result); 802 Dart_Handle wrapped_result = CreateInstanceMirror(result);
795 if (Dart_IsError(wrapped_result)) { 803 if (Dart_IsError(wrapped_result)) {
796 Dart_PropagateError(wrapped_result); 804 Dart_PropagateError(wrapped_result);
797 } 805 }
798 Dart_SetReturnValue(args, wrapped_result); 806 Dart_SetReturnValue(args, wrapped_result);
799 } 807 }
800 808
Ivan Posva 2012/07/23 20:57:32 Should be two lines vertical white space. Can you
809 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_getField)(
810 Dart_NativeArguments args) {
811 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
812 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1);
813
814 Dart_Handle reflectee = UnwrapMirror(mirror);
815 Dart_Handle result = Dart_GetField(reflectee, fieldName);
816 if (Dart_IsError(result)) {
817 // Instead of propagating the error from a GetField directly, we
818 // provide reflective access to the error.
819 Dart_PropagateError(CreateMirroredError(result));
820 }
821
822 Dart_Handle wrapped_result = CreateInstanceMirror(result);
823 if (Dart_IsError(wrapped_result)) {
824 Dart_PropagateError(wrapped_result);
825 }
826 Dart_SetReturnValue(args, wrapped_result);
827 }
828
Ivan Posva 2012/07/23 20:57:32 ditto
829 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)(
830 Dart_NativeArguments args) {
831 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
832 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1);
833 Dart_Handle raw_arg = Dart_GetNativeArgument(args, 2);
834
835 Dart_Handle reflectee = UnwrapMirror(mirror);
836 Dart_Handle set_arg = UnwrapArg(raw_arg);
837 if (Dart_IsError(set_arg)) {
838 Dart_PropagateError(set_arg);
839 }
840 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg);
841 if (Dart_IsError(result)) {
842 // Instead of propagating the error from a SetField directly, we
843 // provide reflective access to the error.
844 Dart_PropagateError(CreateMirroredError(result));
845 }
846
847 Dart_Handle wrapped_result = CreateInstanceMirror(result);
848 if (Dart_IsError(wrapped_result)) {
849 Dart_PropagateError(wrapped_result);
850 }
851 Dart_SetReturnValue(args, wrapped_result);
852 }
853
801 void HandleMirrorsMessage(Isolate* isolate, 854 void HandleMirrorsMessage(Isolate* isolate,
802 Dart_Port reply_port, 855 Dart_Port reply_port,
803 const Instance& message) { 856 const Instance& message) {
804 UNIMPLEMENTED(); 857 UNIMPLEMENTED();
805 } 858 }
806 859
807 } // namespace dart 860 } // namespace dart
OLDNEW
« no previous file with comments | « lib/mirrors/mirrors.dart ('k') | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698