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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 9913 matching lines...) Expand 10 before | Expand all | Expand 10 after
9924 return "UnwindError"; 9924 return "UnwindError";
9925 } 9925 }
9926 9926
9927 9927
9928 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { 9928 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const {
9929 stream->OpenObject(); 9929 stream->OpenObject();
9930 stream->CloseObject(); 9930 stream->CloseObject();
9931 } 9931 }
9932 9932
9933 9933
9934 static RawPatchClass* MakeTempPatchClass(const Class& cls,
9935 const String& expr) {
9936 String& src = String::Handle(String::New("() => "));
9937 src = String::Concat(src, expr);
9938 src = String::Concat(src, Symbols::Semicolon());
9939 Script& script = Script::Handle();
9940 script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag);
9941 // In order to tokenize the source, we need to get the key to mangle
9942 // private names from the library from which the object's class
9943 // originates.
9944 const Library& lib = Library::Handle(cls.library());
9945 ASSERT(!lib.IsNull());
9946 const String& lib_key = String::Handle(lib.private_key());
9947 script.Tokenize(lib_key);
9948
9949 const String& src_class_name = String::Handle(Symbols::New(":internal"));
9950 const Class& src_class = Class::Handle(
9951 Class::New(src_class_name, script, Scanner::kDummyTokenIndex));
9952 src_class.set_is_finalized();
9953 src_class.set_library(lib);
9954 return PatchClass::New(cls, src_class);
9955 }
9956
9957
9958 RawObject* Instance::Evaluate(const String& expr) const {
9959 const Class& cls = Class::Handle(clazz());
9960 const PatchClass& temp_class =
9961 PatchClass::Handle(MakeTempPatchClass(cls, expr));
9962 const String& eval_func_name = String::Handle(Symbols::New(":eval"));
9963 const Function& eval_func =
9964 Function::Handle(Function::New(eval_func_name,
9965 RawFunction::kRegularFunction,
9966 false, // Not static.
9967 false, // Not const.
9968 false, // Not abstract.
9969 false, // Not external.
9970 temp_class,
9971 0));
9972 eval_func.set_result_type(Type::Handle(Type::DynamicType()));
9973 eval_func.set_num_fixed_parameters(1);
9974 eval_func.SetNumOptionalParameters(0, true);
9975 eval_func.set_is_optimizable(false);
9976
9977 const Array& args = Array::Handle(Array::New(1));
9978 args.SetAt(0, *this);
9979 const Object& result =
9980 Object::Handle(DartEntry::InvokeFunction(eval_func, args));
9981 return result.raw();
9982 }
9983
9984
9985
9934 bool Instance::Equals(const Instance& other) const { 9986 bool Instance::Equals(const Instance& other) const {
9935 if (this->raw() == other.raw()) { 9987 if (this->raw() == other.raw()) {
9936 return true; // "===". 9988 return true; // "===".
9937 } 9989 }
9938 9990
9939 if (other.IsNull() || (this->clazz() != other.clazz())) { 9991 if (other.IsNull() || (this->clazz() != other.clazz())) {
9940 return false; 9992 return false;
9941 } 9993 }
9942 9994
9943 { 9995 {
(...skipping 4661 matching lines...) Expand 10 before | Expand all | Expand 10 after
14605 } 14657 }
14606 14658
14607 14659
14608 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14660 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14609 stream->OpenObject(); 14661 stream->OpenObject();
14610 stream->CloseObject(); 14662 stream->CloseObject();
14611 } 14663 }
14612 14664
14613 14665
14614 } // namespace dart 14666 } // namespace dart
OLDNEW
« 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