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

Unified Diff: runtime/vm/object.cc

Issue 23067006: 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 26326)
+++ runtime/vm/object.cc (working copy)
@@ -9931,6 +9931,58 @@
}
+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* Instance::Evaluate(const String& expr) const {
+ const Class& cls = Class::Handle(clazz());
+ const PatchClass& temp_class =
+ PatchClass::Handle(MakeTempPatchClass(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, *this);
+ const Object& result =
+ Object::Handle(DartEntry::InvokeFunction(eval_func, args));
+ return result.raw();
+}
+
+
+
bool Instance::Equals(const Instance& other) const {
if (this->raw() == other.raw()) {
return true; // "===".
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698