| OLD | NEW |
| 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 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 } | 2044 } |
| 2045 SetFields(new_list); | 2045 SetFields(new_list); |
| 2046 | 2046 |
| 2047 // The functions and fields in the patch class are no longer needed. | 2047 // The functions and fields in the patch class are no longer needed. |
| 2048 patch.SetFunctions(Object::empty_array()); | 2048 patch.SetFunctions(Object::empty_array()); |
| 2049 patch.SetFields(Object::empty_array()); | 2049 patch.SetFields(Object::empty_array()); |
| 2050 return true; | 2050 return true; |
| 2051 } | 2051 } |
| 2052 | 2052 |
| 2053 | 2053 |
| 2054 static RawPatchClass* MakeTempPatchClass(const Class& cls, |
| 2055 const String& expr) { |
| 2056 String& src = String::Handle(String::New("() => ")); |
| 2057 src = String::Concat(src, expr); |
| 2058 src = String::Concat(src, Symbols::Semicolon()); |
| 2059 Script& script = Script::Handle(); |
| 2060 script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag); |
| 2061 // In order to tokenize the source, we need to get the key to mangle |
| 2062 // private names from the library from which the object's class |
| 2063 // originates. |
| 2064 const Library& lib = Library::Handle(cls.library()); |
| 2065 ASSERT(!lib.IsNull()); |
| 2066 const String& lib_key = String::Handle(lib.private_key()); |
| 2067 script.Tokenize(lib_key); |
| 2068 |
| 2069 const String& src_class_name = String::Handle(Symbols::New(":internal")); |
| 2070 const Class& src_class = Class::Handle( |
| 2071 Class::New(src_class_name, script, Scanner::kDummyTokenIndex)); |
| 2072 src_class.set_is_finalized(); |
| 2073 src_class.set_library(lib); |
| 2074 return PatchClass::New(cls, src_class); |
| 2075 } |
| 2076 |
| 2077 |
| 2078 RawObject* Class::Evaluate(const String& expr) const { |
| 2079 const PatchClass& temp_class = |
| 2080 PatchClass::Handle(MakeTempPatchClass(*this, expr)); |
| 2081 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 2082 const Function& eval_func = |
| 2083 Function::Handle(Function::New(eval_func_name, |
| 2084 RawFunction::kRegularFunction, |
| 2085 true, // Static. |
| 2086 false, // Not const. |
| 2087 false, // Not abstract. |
| 2088 false, // Not external. |
| 2089 temp_class, |
| 2090 0)); |
| 2091 eval_func.set_result_type(Type::Handle(Type::DynamicType())); |
| 2092 eval_func.set_num_fixed_parameters(0); |
| 2093 eval_func.SetNumOptionalParameters(0, true); |
| 2094 eval_func.set_is_optimizable(false); |
| 2095 |
| 2096 const Array& args = Array::Handle(Array::New(0)); |
| 2097 const Object& result = |
| 2098 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); |
| 2099 return result.raw(); |
| 2100 } |
| 2101 |
| 2102 |
| 2054 // Ensure that top level parsing of the class has been done. | 2103 // Ensure that top level parsing of the class has been done. |
| 2055 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { | 2104 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { |
| 2056 // Finalized classes have already been parsed. | 2105 // Finalized classes have already been parsed. |
| 2057 if (is_finalized()) { | 2106 if (is_finalized()) { |
| 2058 return Error::null(); | 2107 return Error::null(); |
| 2059 } | 2108 } |
| 2060 ASSERT(isolate != NULL); | 2109 ASSERT(isolate != NULL); |
| 2061 const Error& error = Error::Handle(isolate, Compiler::CompileClass(*this)); | 2110 const Error& error = Error::Handle(isolate, Compiler::CompileClass(*this)); |
| 2062 if (!error.IsNull() && (isolate->long_jump_base() != NULL)) { | 2111 if (!error.IsNull() && (isolate->long_jump_base() != NULL)) { |
| 2063 isolate->long_jump_base()->Jump(1, error); | 2112 isolate->long_jump_base()->Jump(1, error); |
| (...skipping 7941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10005 return "UnwindError"; | 10054 return "UnwindError"; |
| 10006 } | 10055 } |
| 10007 | 10056 |
| 10008 | 10057 |
| 10009 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 10058 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 10010 stream->OpenObject(); | 10059 stream->OpenObject(); |
| 10011 stream->CloseObject(); | 10060 stream->CloseObject(); |
| 10012 } | 10061 } |
| 10013 | 10062 |
| 10014 | 10063 |
| 10015 static RawPatchClass* MakeTempPatchClass(const Class& cls, | |
| 10016 const String& expr) { | |
| 10017 String& src = String::Handle(String::New("() => ")); | |
| 10018 src = String::Concat(src, expr); | |
| 10019 src = String::Concat(src, Symbols::Semicolon()); | |
| 10020 Script& script = Script::Handle(); | |
| 10021 script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag); | |
| 10022 // In order to tokenize the source, we need to get the key to mangle | |
| 10023 // private names from the library from which the object's class | |
| 10024 // originates. | |
| 10025 const Library& lib = Library::Handle(cls.library()); | |
| 10026 ASSERT(!lib.IsNull()); | |
| 10027 const String& lib_key = String::Handle(lib.private_key()); | |
| 10028 script.Tokenize(lib_key); | |
| 10029 | |
| 10030 const String& src_class_name = String::Handle(Symbols::New(":internal")); | |
| 10031 const Class& src_class = Class::Handle( | |
| 10032 Class::New(src_class_name, script, Scanner::kDummyTokenIndex)); | |
| 10033 src_class.set_is_finalized(); | |
| 10034 src_class.set_library(lib); | |
| 10035 return PatchClass::New(cls, src_class); | |
| 10036 } | |
| 10037 | |
| 10038 | |
| 10039 RawObject* Instance::Evaluate(const String& expr) const { | 10064 RawObject* Instance::Evaluate(const String& expr) const { |
| 10040 const Class& cls = Class::Handle(clazz()); | 10065 const Class& cls = Class::Handle(clazz()); |
| 10041 const PatchClass& temp_class = | 10066 const PatchClass& temp_class = |
| 10042 PatchClass::Handle(MakeTempPatchClass(cls, expr)); | 10067 PatchClass::Handle(MakeTempPatchClass(cls, expr)); |
| 10043 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | 10068 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 10044 const Function& eval_func = | 10069 const Function& eval_func = |
| 10045 Function::Handle(Function::New(eval_func_name, | 10070 Function::Handle(Function::New(eval_func_name, |
| 10046 RawFunction::kRegularFunction, | 10071 RawFunction::kRegularFunction, |
| 10047 false, // Not static. | 10072 false, // Not static. |
| 10048 false, // Not const. | 10073 false, // Not const. |
| (...skipping 4725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14774 } | 14799 } |
| 14775 | 14800 |
| 14776 | 14801 |
| 14777 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14802 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14778 stream->OpenObject(); | 14803 stream->OpenObject(); |
| 14779 stream->CloseObject(); | 14804 stream->CloseObject(); |
| 14780 } | 14805 } |
| 14781 | 14806 |
| 14782 | 14807 |
| 14783 } // namespace dart | 14808 } // namespace dart |
| OLD | NEW |