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

Side by Side Diff: runtime/vm/object.cc

Issue 2489723003: Run field initializers for new instance fields after a reload (Closed)
Patch Set: Created 4 years, 1 month 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
« runtime/vm/isolate_reload_test.cc ('K') | « runtime/vm/object.h ('k') | no next file » | 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/become.h" 10 #include "vm/become.h"
(...skipping 3041 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 piece ^= formal_params.At(i); 3052 piece ^= formal_params.At(i);
3053 src_pieces.Add(piece); 3053 src_pieces.Add(piece);
3054 } 3054 }
3055 src_pieces.Add(Symbols::RParenArrow()); 3055 src_pieces.Add(Symbols::RParenArrow());
3056 src_pieces.Add(expr); 3056 src_pieces.Add(expr);
3057 src_pieces.Add(Symbols::Semicolon()); 3057 src_pieces.Add(Symbols::Semicolon());
3058 return String::ConcatAll(Array::Handle(Array::MakeArray(src_pieces))); 3058 return String::ConcatAll(Array::Handle(Array::MakeArray(src_pieces)));
3059 } 3059 }
3060 3060
3061 3061
3062 static RawFunction* EvaluateHelper(const Class& cls, 3062 RawFunction* Function::EvaluateHelper(const Class& cls,
3063 const String& expr, 3063 const String& expr,
3064 const Array& param_names, 3064 const Array& param_names,
3065 bool is_static) { 3065 bool is_static) {
3066 const String& func_src = 3066 const String& func_src =
3067 String::Handle(BuildClosureSource(param_names, expr)); 3067 String::Handle(BuildClosureSource(param_names, expr));
3068 Script& script = Script::Handle(); 3068 Script& script = Script::Handle();
3069 script = Script::New(Symbols::EvalSourceUri(), 3069 script = Script::New(Symbols::EvalSourceUri(),
3070 func_src, 3070 func_src,
3071 RawScript::kEvaluateTag); 3071 RawScript::kEvaluateTag);
3072 // In order to tokenize the source, we need to get the key to mangle 3072 // In order to tokenize the source, we need to get the key to mangle
3073 // private names from the library from which the class originates. 3073 // private names from the library from which the class originates.
3074 const Library& lib = Library::Handle(cls.library()); 3074 const Library& lib = Library::Handle(cls.library());
3075 ASSERT(!lib.IsNull()); 3075 ASSERT(!lib.IsNull());
(...skipping 16 matching lines...) Expand all
3092 const Array& param_values) const { 3092 const Array& param_values) const {
3093 ASSERT(Thread::Current()->IsMutatorThread()); 3093 ASSERT(Thread::Current()->IsMutatorThread());
3094 if (id() < kInstanceCid) { 3094 if (id() < kInstanceCid) {
3095 const Instance& exception = Instance::Handle(String::New( 3095 const Instance& exception = Instance::Handle(String::New(
3096 "Cannot evaluate against a VM internal class")); 3096 "Cannot evaluate against a VM internal class"));
3097 const Instance& stacktrace = Instance::Handle(); 3097 const Instance& stacktrace = Instance::Handle();
3098 return UnhandledException::New(exception, stacktrace); 3098 return UnhandledException::New(exception, stacktrace);
3099 } 3099 }
3100 3100
3101 const Function& eval_func = 3101 const Function& eval_func =
3102 Function::Handle(EvaluateHelper(*this, expr, param_names, true)); 3102 Function::Handle(
3103 Function::EvaluateHelper(*this, expr, param_names, true));
3103 const Object& result = 3104 const Object& result =
3104 Object::Handle(DartEntry::InvokeFunction(eval_func, param_values)); 3105 Object::Handle(DartEntry::InvokeFunction(eval_func, param_values));
3105 return result.raw(); 3106 return result.raw();
3106 } 3107 }
3107 3108
3108 3109
3109 // Ensure that top level parsing of the class has been done. 3110 // Ensure that top level parsing of the class has been done.
3110 RawError* Class::EnsureIsFinalized(Thread* thread) const { 3111 RawError* Class::EnsureIsFinalized(Thread* thread) const {
3111 // Finalized classes have already been parsed. 3112 // Finalized classes have already been parsed.
3112 if (is_finalized()) { 3113 if (is_finalized()) {
(...skipping 4527 matching lines...) Expand 10 before | Expand all | Expand 10 after
7640 } 7641 }
7641 ASSERT(original.IsOriginal()); 7642 ASSERT(original.IsOriginal());
7642 Field& clone = Field::Handle(); 7643 Field& clone = Field::Handle();
7643 clone ^= Object::Clone(*this, Heap::kOld); 7644 clone ^= Object::Clone(*this, Heap::kOld);
7644 clone.SetOriginal(original); 7645 clone.SetOriginal(original);
7645 clone.set_kernel_field(original.kernel_field()); 7646 clone.set_kernel_field(original.kernel_field());
7646 return clone.raw(); 7647 return clone.raw();
7647 } 7648 }
7648 7649
7649 7650
7651 RawString* Field::InitializingExpression() const {
rmacnak 2016/11/09 00:36:32 Copying the initializer like this means any stackt
7652 Thread* thread = Thread::Current();
7653 Zone* zone = thread->zone();
7654 const class Script& scr = Script::Handle(zone, Script());
7655 ASSERT(!scr.IsNull());
7656 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens());
7657 if (tkns.IsNull()) {
7658 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
7659 return String::null();
7660 }
7661 TokenStream::Iterator tkit(zone,
7662 tkns,
7663 token_pos());
7664 ASSERT(Token::IsIdentifier(tkit.CurrentTokenKind()));
7665 #if defined(DEBUG)
7666 const String& literal = String::Handle(zone, tkit.CurrentLiteral());
7667 ASSERT(literal.raw() == name());
7668 #endif
7669 tkit.Advance();
7670 if (tkit.CurrentTokenKind() != Token::kASSIGN) {
7671 return String::null();
7672 }
7673 tkit.Advance();
7674 const TokenPosition start_of_expression = tkit.CurrentPosition();
7675 while (tkit.CurrentTokenKind() != Token::kSEMICOLON) {
7676 tkit.Advance();
7677 }
7678 const TokenPosition end_of_expression = tkit.CurrentPosition();
7679 return scr.GetSnippet(start_of_expression, end_of_expression);
7680 }
7681
7682
7650 RawString* Field::UserVisibleName() const { 7683 RawString* Field::UserVisibleName() const {
7651 if (FLAG_show_internal_names) { 7684 if (FLAG_show_internal_names) {
7652 return name(); 7685 return name();
7653 } 7686 }
7654 return String::ScrubName(String::Handle(name())); 7687 return String::ScrubName(String::Handle(name()));
7655 } 7688 }
7656 7689
7657 7690
7658 intptr_t Field::guarded_list_length() const { 7691 intptr_t Field::guarded_list_length() const {
7659 return Smi::Value(raw_ptr()->guarded_list_length_); 7692 return Smi::Value(raw_ptr()->guarded_list_length_);
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
9108 return String::SubString(src, 9141 return String::SubString(src,
9109 line_start_idx, 9142 line_start_idx,
9110 last_char_idx - line_start_idx + 1, 9143 last_char_idx - line_start_idx + 1,
9111 space); 9144 space);
9112 } else { 9145 } else {
9113 return Symbols::Empty().raw(); 9146 return Symbols::Empty().raw();
9114 } 9147 }
9115 } 9148 }
9116 9149
9117 9150
9151 RawString* Script::GetSnippet(TokenPosition from, TokenPosition to) const {
9152 intptr_t from_line;
9153 intptr_t from_column;
9154 intptr_t to_line;
9155 intptr_t to_column;
9156 GetTokenLocation(from, &from_line, &from_column);
9157 GetTokenLocation(to, &to_line, &to_column);
9158 return GetSnippet(from_line, from_column,
9159 to_line, to_column);
9160 }
9161
9162
9118 RawString* Script::GetSnippet(intptr_t from_line, 9163 RawString* Script::GetSnippet(intptr_t from_line,
9119 intptr_t from_column, 9164 intptr_t from_column,
9120 intptr_t to_line, 9165 intptr_t to_line,
9121 intptr_t to_column) const { 9166 intptr_t to_column) const {
9122 const String& src = String::Handle(Source()); 9167 const String& src = String::Handle(Source());
9123 if (src.IsNull()) { 9168 if (src.IsNull()) {
9124 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); 9169 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
9125 return Symbols::OptimizedOut().raw(); 9170 return Symbols::OptimizedOut().raw();
9126 } 9171 }
9127 intptr_t length = src.Length(); 9172 intptr_t length = src.Length();
(...skipping 6330 matching lines...) Expand 10 before | Expand all | Expand 10 after
15458 const char* UnwindError::ToCString() const { 15503 const char* UnwindError::ToCString() const {
15459 return "UnwindError"; 15504 return "UnwindError";
15460 } 15505 }
15461 15506
15462 15507
15463 RawObject* Instance::Evaluate(const Class& method_cls, 15508 RawObject* Instance::Evaluate(const Class& method_cls,
15464 const String& expr, 15509 const String& expr,
15465 const Array& param_names, 15510 const Array& param_names,
15466 const Array& param_values) const { 15511 const Array& param_values) const {
15467 const Function& eval_func = 15512 const Function& eval_func =
15468 Function::Handle(EvaluateHelper(method_cls, expr, param_names, false)); 15513 Function::Handle(
15514 Function::EvaluateHelper(method_cls, expr, param_names, false));
15469 const Array& args = Array::Handle(Array::New(1 + param_values.Length())); 15515 const Array& args = Array::Handle(Array::New(1 + param_values.Length()));
15470 PassiveObject& param = PassiveObject::Handle(); 15516 PassiveObject& param = PassiveObject::Handle();
15471 args.SetAt(0, *this); 15517 args.SetAt(0, *this);
15472 for (intptr_t i = 0; i < param_values.Length(); i++) { 15518 for (intptr_t i = 0; i < param_values.Length(); i++) {
15473 param = param_values.At(i); 15519 param = param_values.At(i);
15474 args.SetAt(i + 1, param); 15520 args.SetAt(i + 1, param);
15475 } 15521 }
15476 return DartEntry::InvokeFunction(eval_func, args); 15522 return DartEntry::InvokeFunction(eval_func, args);
15477 } 15523 }
15478 15524
(...skipping 7556 matching lines...) Expand 10 before | Expand all | Expand 10 after
23035 return UserTag::null(); 23081 return UserTag::null();
23036 } 23082 }
23037 23083
23038 23084
23039 const char* UserTag::ToCString() const { 23085 const char* UserTag::ToCString() const {
23040 const String& tag_label = String::Handle(label()); 23086 const String& tag_label = String::Handle(label());
23041 return tag_label.ToCString(); 23087 return tag_label.ToCString();
23042 } 23088 }
23043 23089
23044 } // namespace dart 23090 } // namespace dart
OLDNEW
« runtime/vm/isolate_reload_test.cc ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698