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

Unified Diff: runtime/vm/compiler.cc

Issue 22909009: Evaluate expression in context of an object (Closed) Base URL: http://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
Index: runtime/vm/compiler.cc
===================================================================
--- runtime/vm/compiler.cc (revision 26007)
+++ runtime/vm/compiler.cc (working copy)
@@ -854,7 +854,57 @@
return error.raw();
}
+static RawPatchClass* MakeTempPatchClass(const Class& cls,
+ const String& expr) {
+ String& src = String::Handle(String::New("() => "));
+ src = String::Concat(src, expr);
+ src = String::Concat(src, Symbols::Semicolon());
+ Script& script = Script::Handle();
+ script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag);
+ // In order to tokenize the source, we need to get the key to mangle
+ // private names from the library from which the object's class
+ // originates.
+ const Library& lib = Library::Handle(cls.library());
+ ASSERT(!lib.IsNull());
+ const String& lib_key = String::Handle(lib.private_key());
+ script.Tokenize(lib_key);
+ const String& src_class_name = String::Handle(Symbols::New(":internal"));
+ const Class& src_class = Class::Handle(
+ Class::New(src_class_name, script, Scanner::kDummyTokenIndex));
+ src_class.set_is_finalized();
+ src_class.set_library(lib);
+ return PatchClass::New(cls, src_class);
+}
+
+
+RawObject* Compiler::Evaluate(const Instance& obj, const String& expr) {
hausner 2013/08/14 23:54:09 Should this functionality be here in class Compile
Ivan Posva 2013/08/19 21:32:18 Could you add Evaluate on the Instance C++ class?
hausner 2013/08/19 22:47:38 Done.
+ const Class& obj_cls = Class::Handle(obj.clazz());
+ const PatchClass& temp_class =
+ PatchClass::Handle(MakeTempPatchClass(obj_cls, expr));
+ const String& eval_func_name = String::Handle(Symbols::New(":eval"));
+ const Function& eval_func =
+ Function::Handle(Function::New(eval_func_name,
+ RawFunction::kRegularFunction,
+ false, // Not static.
+ false, // Not const.
+ false, // Not abstract.
+ false, // Not external.
+ temp_class,
+ 0));
+ eval_func.set_result_type(Type::Handle(Type::DynamicType()));
+ eval_func.set_num_fixed_parameters(1);
+ eval_func.SetNumOptionalParameters(0, true);
+ eval_func.set_is_optimizable(false);
+
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, obj);
+ const Object& result =
+ Object::Handle(DartEntry::InvokeFunction(eval_func, args));
+ return result.raw();
+}
+
+
RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) {
Isolate* isolate = Isolate::Current();
LongJump* base = isolate->long_jump_base();

Powered by Google App Engine
This is Rietveld 408576698