OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include "src/v8.h" | 6 #include "src/v8.h" |
7 | 7 |
8 #include "src/liveedit.h" | 8 #include "src/liveedit.h" |
9 | 9 |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 } | 598 } |
599 | 599 |
600 | 600 |
601 static int GetArrayLength(Handle<JSArray> array) { | 601 static int GetArrayLength(Handle<JSArray> array) { |
602 Object* length = array->length(); | 602 Object* length = array->length(); |
603 CHECK(length->IsSmi()); | 603 CHECK(length->IsSmi()); |
604 return Smi::cast(length)->value(); | 604 return Smi::cast(length)->value(); |
605 } | 605 } |
606 | 606 |
607 | 607 |
608 void FunctionInfoWrapper::SetInitialProperties( | 608 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, |
609 Handle<String> name, int start_position, int end_position, int param_num, | 609 int start_position, |
610 int literal_count, int slot_count, int ic_slot_count, int parent_index) { | 610 int end_position, int param_num, |
| 611 int literal_count, |
| 612 int parent_index) { |
611 HandleScope scope(isolate()); | 613 HandleScope scope(isolate()); |
612 this->SetField(kFunctionNameOffset_, name); | 614 this->SetField(kFunctionNameOffset_, name); |
613 this->SetSmiValueField(kStartPositionOffset_, start_position); | 615 this->SetSmiValueField(kStartPositionOffset_, start_position); |
614 this->SetSmiValueField(kEndPositionOffset_, end_position); | 616 this->SetSmiValueField(kEndPositionOffset_, end_position); |
615 this->SetSmiValueField(kParamNumOffset_, param_num); | 617 this->SetSmiValueField(kParamNumOffset_, param_num); |
616 this->SetSmiValueField(kLiteralNumOffset_, literal_count); | 618 this->SetSmiValueField(kLiteralNumOffset_, literal_count); |
617 this->SetSmiValueField(kSlotNumOffset_, slot_count); | |
618 this->SetSmiValueField(kICSlotNumOffset_, ic_slot_count); | |
619 this->SetSmiValueField(kParentIndexOffset_, parent_index); | 619 this->SetSmiValueField(kParentIndexOffset_, parent_index); |
620 } | 620 } |
621 | 621 |
622 | 622 |
623 void FunctionInfoWrapper::SetFunctionCode(Handle<Code> function_code, | 623 void FunctionInfoWrapper::SetFunctionCode(Handle<Code> function_code, |
624 Handle<HeapObject> code_scope_info) { | 624 Handle<HeapObject> code_scope_info) { |
625 Handle<JSValue> code_wrapper = WrapInJSValue(function_code); | 625 Handle<JSValue> code_wrapper = WrapInJSValue(function_code); |
626 this->SetField(kCodeOffset_, code_wrapper); | 626 this->SetField(kCodeOffset_, code_wrapper); |
627 | 627 |
628 Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info); | 628 Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info); |
(...skipping 10 matching lines...) Expand all Loading... |
639 | 639 |
640 Handle<Code> FunctionInfoWrapper::GetFunctionCode() { | 640 Handle<Code> FunctionInfoWrapper::GetFunctionCode() { |
641 Handle<Object> element = this->GetField(kCodeOffset_); | 641 Handle<Object> element = this->GetField(kCodeOffset_); |
642 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | 642 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); |
643 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | 643 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); |
644 CHECK(raw_result->IsCode()); | 644 CHECK(raw_result->IsCode()); |
645 return Handle<Code>::cast(raw_result); | 645 return Handle<Code>::cast(raw_result); |
646 } | 646 } |
647 | 647 |
648 | 648 |
649 Handle<TypeFeedbackVector> FunctionInfoWrapper::GetFeedbackVector() { | 649 MaybeHandle<TypeFeedbackVector> FunctionInfoWrapper::GetFeedbackVector() { |
650 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); | 650 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); |
651 Handle<TypeFeedbackVector> result; | |
652 if (element->IsJSValue()) { | 651 if (element->IsJSValue()) { |
653 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | 652 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); |
654 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | 653 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); |
655 Handle<SharedFunctionInfo> shared = | 654 Handle<SharedFunctionInfo> shared = |
656 Handle<SharedFunctionInfo>::cast(raw_result); | 655 Handle<SharedFunctionInfo>::cast(raw_result); |
657 result = Handle<TypeFeedbackVector>(shared->feedback_vector(), isolate()); | 656 return Handle<TypeFeedbackVector>(shared->feedback_vector(), isolate()); |
658 CHECK_EQ(result->Slots(), GetSlotCount()); | |
659 CHECK_EQ(result->ICSlots(), GetICSlotCount()); | |
660 } else { | 657 } else { |
661 // Scripts may never have a SharedFunctionInfo created, so | 658 // Scripts may never have a SharedFunctionInfo created. |
662 // create a type feedback vector here. | 659 return MaybeHandle<TypeFeedbackVector>(); |
663 int slot_count = GetSlotCount(); | |
664 int ic_slot_count = GetICSlotCount(); | |
665 result = | |
666 isolate()->factory()->NewTypeFeedbackVector(slot_count, ic_slot_count); | |
667 } | 660 } |
668 return result; | |
669 } | 661 } |
670 | 662 |
671 | 663 |
672 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { | 664 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { |
673 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); | 665 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); |
674 return UnwrapJSValue(Handle<JSValue>::cast(element)); | 666 return UnwrapJSValue(Handle<JSValue>::cast(element)); |
675 } | 667 } |
676 | 668 |
677 | 669 |
678 void SharedInfoWrapper::SetProperties(Handle<String> name, | 670 void SharedInfoWrapper::SetProperties(Handle<String> name, |
(...skipping 20 matching lines...) Expand all Loading... |
699 public: | 691 public: |
700 explicit FunctionInfoListener(Isolate* isolate) { | 692 explicit FunctionInfoListener(Isolate* isolate) { |
701 current_parent_index_ = -1; | 693 current_parent_index_ = -1; |
702 len_ = 0; | 694 len_ = 0; |
703 result_ = isolate->factory()->NewJSArray(10); | 695 result_ = isolate->factory()->NewJSArray(10); |
704 } | 696 } |
705 | 697 |
706 void FunctionStarted(FunctionLiteral* fun) { | 698 void FunctionStarted(FunctionLiteral* fun) { |
707 HandleScope scope(isolate()); | 699 HandleScope scope(isolate()); |
708 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate()); | 700 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate()); |
709 info.SetInitialProperties( | 701 info.SetInitialProperties(fun->name(), fun->start_position(), |
710 fun->name(), fun->start_position(), fun->end_position(), | 702 fun->end_position(), fun->parameter_count(), |
711 fun->parameter_count(), fun->materialized_literal_count(), | 703 fun->materialized_literal_count(), |
712 fun->slot_count(), fun->ic_slot_count(), current_parent_index_); | 704 current_parent_index_); |
713 current_parent_index_ = len_; | 705 current_parent_index_ = len_; |
714 SetElementSloppy(result_, len_, info.GetJSArray()); | 706 SetElementSloppy(result_, len_, info.GetJSArray()); |
715 len_++; | 707 len_++; |
716 } | 708 } |
717 | 709 |
718 void FunctionDone() { | 710 void FunctionDone() { |
719 HandleScope scope(isolate()); | 711 HandleScope scope(isolate()); |
720 FunctionInfoWrapper info = | 712 FunctionInfoWrapper info = |
721 FunctionInfoWrapper::cast( | 713 FunctionInfoWrapper::cast( |
722 *Object::GetElement( | 714 *Object::GetElement( |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1186 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
1195 | 1187 |
1196 if (IsJSFunctionCode(shared_info->code())) { | 1188 if (IsJSFunctionCode(shared_info->code())) { |
1197 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); | 1189 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); |
1198 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); | 1190 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); |
1199 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); | 1191 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); |
1200 if (code_scope_info->IsFixedArray()) { | 1192 if (code_scope_info->IsFixedArray()) { |
1201 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); | 1193 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); |
1202 } | 1194 } |
1203 shared_info->DisableOptimization(kLiveEdit); | 1195 shared_info->DisableOptimization(kLiveEdit); |
1204 // Update the type feedback vector | 1196 // Update the type feedback vector, if needed. |
1205 Handle<TypeFeedbackVector> feedback_vector = | 1197 MaybeHandle<TypeFeedbackVector> feedback_vector = |
1206 compile_info_wrapper.GetFeedbackVector(); | 1198 compile_info_wrapper.GetFeedbackVector(); |
1207 shared_info->set_feedback_vector(*feedback_vector); | 1199 if (!feedback_vector.is_null()) { |
| 1200 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); |
| 1201 } |
1208 } | 1202 } |
1209 | 1203 |
1210 if (shared_info->debug_info()->IsDebugInfo()) { | 1204 if (shared_info->debug_info()->IsDebugInfo()) { |
1211 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); | 1205 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); |
1212 Handle<Code> new_original_code = | 1206 Handle<Code> new_original_code = |
1213 isolate->factory()->CopyCode(compile_info_wrapper.GetFunctionCode()); | 1207 isolate->factory()->CopyCode(compile_info_wrapper.GetFunctionCode()); |
1214 debug_info->set_original_code(*new_original_code); | 1208 debug_info->set_original_code(*new_original_code); |
1215 } | 1209 } |
1216 | 1210 |
1217 int start_position = compile_info_wrapper.GetStartPosition(); | 1211 int start_position = compile_info_wrapper.GetStartPosition(); |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { | 2071 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { |
2078 isolate_->active_function_info_listener()->FunctionCode(code); | 2072 isolate_->active_function_info_listener()->FunctionCode(code); |
2079 } | 2073 } |
2080 | 2074 |
2081 | 2075 |
2082 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 2076 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
2083 return isolate->active_function_info_listener() != NULL; | 2077 return isolate->active_function_info_listener() != NULL; |
2084 } | 2078 } |
2085 | 2079 |
2086 } } // namespace v8::internal | 2080 } } // namespace v8::internal |
OLD | NEW |