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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/mirrors.cc
===================================================================
--- runtime/lib/mirrors.cc (revision 9728)
+++ runtime/lib/mirrors.cc (working copy)
@@ -164,31 +164,39 @@
}
-static Dart_Handle UnwrapArgList(Dart_Handle arg_list,
- GrowableArray<Dart_Handle>* arg_array) {
- intptr_t len = 0;
- Dart_Handle result = Dart_ListLength(arg_list, &len);
- if (Dart_IsError(result)) {
- return result;
- }
- for (int i = 0; i < len; i++) {
- Dart_Handle arg = Dart_ListGetAt(arg_list, i);
+static Dart_Handle UnwrapArg(Dart_Handle arg) {
if (Dart_IsError(arg)) {
return arg;
}
bool is_mirror = false;
- result = IsMirror(arg, &is_mirror);
+ Dart_Handle result = IsMirror(arg, &is_mirror);
if (Dart_IsError(result)) {
return result;
}
if (is_mirror) {
- arg_array->Add(UnwrapMirror(arg));
+ return UnwrapMirror(arg);
} else {
// Simple value.
ASSERT(IsSimpleValue(arg));
- arg_array->Add(arg);
+ return arg;
}
+}
+
+static Dart_Handle UnwrapArgList(Dart_Handle arg_list,
+ GrowableArray<Dart_Handle>* arg_array) {
+ intptr_t len = 0;
+ Dart_Handle result = Dart_ListLength(arg_list, &len);
+ if (Dart_IsError(result)) {
+ return result;
}
+ for (int i = 0; i < len; i++) {
+ Dart_Handle arg = Dart_ListGetAt(arg_list, i);
+ Dart_Handle unwrapped_arg = UnwrapArg(arg);
+ if (Dart_IsError(unwrapped_arg)) {
+ return unwrapped_arg;
+ }
+ arg_array->Add(unwrapped_arg);
+ }
return Dart_True();
}
@@ -798,6 +806,53 @@
Dart_SetReturnValue(args, wrapped_result);
}
+void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_getField)(
+ Dart_NativeArguments args) {
+ Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
+ Dart_Handle fieldName = Dart_GetNativeArgument(args, 1);
+
+ Dart_Handle reflectee = UnwrapMirror(mirror);
+ Dart_Handle result =
turnidge 2012/07/17 23:59:33 Can this fit on one line?
+ Dart_GetField(reflectee, fieldName);
+ if (Dart_IsError(result)) {
+ // Instead of propagating the error from an invoke directly, we
+ // provide reflective access to the error.
turnidge 2012/07/17 23:59:33 Update comment to not refer to invoke.
+ Dart_PropagateError(CreateMirroredError(result));
+ }
+
+ Dart_Handle wrapped_result = CreateInstanceMirror(result);
+ if (Dart_IsError(wrapped_result)) {
+ Dart_PropagateError(wrapped_result);
+ }
+ Dart_SetReturnValue(args, wrapped_result);
+}
+
+void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)(
+ Dart_NativeArguments args) {
+ Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
+ Dart_Handle fieldName = Dart_GetNativeArgument(args, 1);
+ Dart_Handle raw_arg = Dart_GetNativeArgument(args, 2);
+
+ Dart_Handle reflectee = UnwrapMirror(mirror);
+ Dart_Handle set_arg = UnwrapArg(raw_arg);
+ if (Dart_IsError(set_arg)) {
+ Dart_PropagateError(set_arg);
+ }
+ Dart_Handle result =
turnidge 2012/07/17 23:59:33 Can this fit on one line?
+ Dart_SetField(reflectee, fieldName, set_arg);
+ if (Dart_IsError(result)) {
+ // Instead of propagating the error from an invoke directly, we
+ // provide reflective access to the error.
turnidge 2012/07/17 23:59:33 Update commentto not refer to invoke.
+ Dart_PropagateError(CreateMirroredError(result));
+ }
+
+ Dart_Handle wrapped_result = CreateInstanceMirror(result);
+ if (Dart_IsError(wrapped_result)) {
+ Dart_PropagateError(wrapped_result);
+ }
+ Dart_SetReturnValue(args, wrapped_result);
+}
+
void HandleMirrorsMessage(Isolate* isolate,
Dart_Port reply_port,
const Instance& message) {

Powered by Google App Engine
This is Rietveld 408576698