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

Unified Diff: runtime/lib/mirrors.cc

Issue 23065007: Implement ParameterMirror.{isFinal,hasDefaultValue,defaultValue}. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors.cc
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
index 7ab68b6a0c650a8e397e785e62f31e4daa7eccca..6218f0947b6107a06412453edd49e62b6e80585f 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -8,6 +8,7 @@
#include "vm/dart_entry.h"
#include "vm/exceptions.h"
#include "vm/object_store.h"
+#include "vm/parser.h"
#include "vm/port.h"
#include "vm/symbols.h"
@@ -45,6 +46,9 @@ DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) {
}
+static void ThrowInvokeError(const Error& error);
+
+
static RawInstance* CreateParameterMirrorList(const Function& func,
const Instance& owner_mirror) {
HANDLESCOPE(Isolate::Current());
@@ -56,21 +60,42 @@ static RawInstance* CreateParameterMirrorList(const Function& func,
const intptr_t index_of_first_named_param =
non_implicit_param_count - func.NumOptionalNamedParameters();
const Array& results = Array::Handle(Array::New(non_implicit_param_count));
- const Array& args = Array::Handle(Array::New(6));
+ const Array& args = Array::Handle(Array::New(8));
+
args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
args.SetAt(2, owner_mirror);
+
Smi& pos = Smi::Handle();
String& name = String::Handle();
Instance& param = Instance::Handle();
+ Bool& is_final = Bool::Handle();
+ Object& default_value = Object::Handle();
+
+ // Reparse the function for the following information:
+ // * The default value of a parameter.
+ // * Whether a parameters has been deflared as final.
+ const Object& result = Object::Handle(Parser::ParseFunctionParameters(func));
+ if (result.IsError()) {
+ ThrowInvokeError(Error::Cast(result));
+ UNREACHABLE();
+ }
+
+ const Array& param_descriptor = Array::Cast(result);
for (intptr_t i = 0; i < non_implicit_param_count; i++) {
pos ^= Smi::New(i);
name ^= func.ParameterNameAt(implicit_param_count + i);
+ is_final ^= param_descriptor.At(i * 2);
+ default_value = param_descriptor.At(i * 2 + 1);
+ ASSERT(default_value.IsInstance());
+
args.SetAt(1, name);
args.SetAt(3, pos);
args.SetAt(4, (i >= index_of_first_optional_param) ?
Bool::True() : Bool::False());
args.SetAt(5, (i >= index_of_first_named_param) ?
Bool::True() : Bool::False());
+ args.SetAt(6, is_final.value() ? Bool::True() : Bool::False());
+ args.SetAt(7, default_value);
param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args);
results.SetAt(i, param);
}
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698