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

Side by Side Diff: src/liveedit.cc

Issue 227483007: Handlify LiveEdit. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | « src/liveedit.h ('k') | src/runtime.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 628 }
629 629
630 630
631 static int GetArrayLength(Handle<JSArray> array) { 631 static int GetArrayLength(Handle<JSArray> array) {
632 Object* length = array->length(); 632 Object* length = array->length();
633 CHECK(length->IsSmi()); 633 CHECK(length->IsSmi());
634 return Smi::cast(length)->value(); 634 return Smi::cast(length)->value();
635 } 635 }
636 636
637 637
638 // Simple helper class that creates more or less typed structures over 638 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name,
639 // JSArray object. This is an adhoc method of passing structures from C++ 639 int start_position,
640 // to JavaScript. 640 int end_position,
641 template<typename S> 641 int param_num,
642 class JSArrayBasedStruct { 642 int literal_count,
643 public: 643 int parent_index) {
644 static S Create(Isolate* isolate) { 644 HandleScope scope(isolate());
645 Factory* factory = isolate->factory(); 645 this->SetField(kFunctionNameOffset_, name);
646 Handle<JSArray> array = factory->NewJSArray(S::kSize_); 646 this->SetSmiValueField(kStartPositionOffset_, start_position);
647 return S(array); 647 this->SetSmiValueField(kEndPositionOffset_, end_position);
648 } 648 this->SetSmiValueField(kParamNumOffset_, param_num);
649 static S cast(Object* object) { 649 this->SetSmiValueField(kLiteralNumOffset_, literal_count);
650 JSArray* array = JSArray::cast(object); 650 this->SetSmiValueField(kParentIndexOffset_, parent_index);
651 Handle<JSArray> array_handle(array); 651 }
652 return S(array_handle);
653 }
654 explicit JSArrayBasedStruct(Handle<JSArray> array) : array_(array) {
655 }
656 Handle<JSArray> GetJSArray() {
657 return array_;
658 }
659 Isolate* isolate() const {
660 return array_->GetIsolate();
661 }
662
663 protected:
664 void SetField(int field_position, Handle<Object> value) {
665 SetElementSloppy(array_, field_position, value);
666 }
667 void SetSmiValueField(int field_position, int value) {
668 SetElementSloppy(array_,
669 field_position,
670 Handle<Smi>(Smi::FromInt(value), isolate()));
671 }
672 Handle<Object> GetField(int field_position) {
673 return Object::GetElementNoExceptionThrown(
674 isolate(), array_, field_position);
675 }
676 int GetSmiValueField(int field_position) {
677 Handle<Object> res = GetField(field_position);
678 return Handle<Smi>::cast(res)->value();
679 }
680
681 private:
682 Handle<JSArray> array_;
683 };
684 652
685 653
686 // Represents some function compilation details. This structure will be used 654 void FunctionInfoWrapper::SetFunctionCode(Handle<Code> function_code,
687 // from JavaScript. It contains Code object, which is kept wrapped 655 Handle<HeapObject> code_scope_info) {
688 // into a BlindReference for sanitizing reasons. 656 Handle<JSValue> code_wrapper = WrapInJSValue(function_code);
689 class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { 657 this->SetField(kCodeOffset_, code_wrapper);
690 public:
691 explicit FunctionInfoWrapper(Handle<JSArray> array)
692 : JSArrayBasedStruct<FunctionInfoWrapper>(array) {
693 }
694 void SetInitialProperties(Handle<String> name, int start_position,
695 int end_position, int param_num,
696 int literal_count, int parent_index) {
697 HandleScope scope(isolate());
698 this->SetField(kFunctionNameOffset_, name);
699 this->SetSmiValueField(kStartPositionOffset_, start_position);
700 this->SetSmiValueField(kEndPositionOffset_, end_position);
701 this->SetSmiValueField(kParamNumOffset_, param_num);
702 this->SetSmiValueField(kLiteralNumOffset_, literal_count);
703 this->SetSmiValueField(kParentIndexOffset_, parent_index);
704 }
705 void SetFunctionCode(Handle<Code> function_code,
706 Handle<HeapObject> code_scope_info) {
707 Handle<JSValue> code_wrapper = WrapInJSValue(function_code);
708 this->SetField(kCodeOffset_, code_wrapper);
709 658
710 Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info); 659 Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info);
711 this->SetField(kCodeScopeInfoOffset_, scope_wrapper); 660 this->SetField(kCodeScopeInfoOffset_, scope_wrapper);
712 } 661 }
713 void SetFunctionScopeInfo(Handle<Object> scope_info_array) {
714 this->SetField(kFunctionScopeInfoOffset_, scope_info_array);
715 }
716 void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info) {
717 Handle<JSValue> info_holder = WrapInJSValue(info);
718 this->SetField(kSharedFunctionInfoOffset_, info_holder);
719 }
720 int GetLiteralCount() {
721 return this->GetSmiValueField(kLiteralNumOffset_);
722 }
723 int GetParentIndex() {
724 return this->GetSmiValueField(kParentIndexOffset_);
725 }
726 Handle<Code> GetFunctionCode() {
727 Handle<Object> element = this->GetField(kCodeOffset_);
728 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
729 Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
730 CHECK(raw_result->IsCode());
731 return Handle<Code>::cast(raw_result);
732 }
733 Handle<Object> GetCodeScopeInfo() {
734 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_);
735 return UnwrapJSValue(Handle<JSValue>::cast(element));
736 }
737 int GetStartPosition() {
738 return this->GetSmiValueField(kStartPositionOffset_);
739 }
740 int GetEndPosition() {
741 return this->GetSmiValueField(kEndPositionOffset_);
742 }
743
744 private:
745 static const int kFunctionNameOffset_ = 0;
746 static const int kStartPositionOffset_ = 1;
747 static const int kEndPositionOffset_ = 2;
748 static const int kParamNumOffset_ = 3;
749 static const int kCodeOffset_ = 4;
750 static const int kCodeScopeInfoOffset_ = 5;
751 static const int kFunctionScopeInfoOffset_ = 6;
752 static const int kParentIndexOffset_ = 7;
753 static const int kSharedFunctionInfoOffset_ = 8;
754 static const int kLiteralNumOffset_ = 9;
755 static const int kSize_ = 10;
756
757 friend class JSArrayBasedStruct<FunctionInfoWrapper>;
758 };
759 662
760 663
761 // Wraps SharedFunctionInfo along with some of its fields for passing it 664 void FunctionInfoWrapper::SetSharedFunctionInfo(
762 // back to JavaScript. SharedFunctionInfo object itself is additionally 665 Handle<SharedFunctionInfo> info) {
763 // wrapped into BlindReference for sanitizing reasons. 666 Handle<JSValue> info_holder = WrapInJSValue(info);
764 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { 667 this->SetField(kSharedFunctionInfoOffset_, info_holder);
765 public: 668 }
766 static bool IsInstance(Handle<JSArray> array) {
767 return array->length() == Smi::FromInt(kSize_) &&
768 Object::GetElementNoExceptionThrown(
769 array->GetIsolate(), array, kSharedInfoOffset_)->IsJSValue();
770 }
771 669
772 explicit SharedInfoWrapper(Handle<JSArray> array)
773 : JSArrayBasedStruct<SharedInfoWrapper>(array) {
774 }
775 670
776 void SetProperties(Handle<String> name, int start_position, int end_position, 671 Handle<Code> FunctionInfoWrapper::GetFunctionCode() {
777 Handle<SharedFunctionInfo> info) { 672 Handle<Object> element = this->GetField(kCodeOffset_);
778 HandleScope scope(isolate()); 673 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
779 this->SetField(kFunctionNameOffset_, name); 674 Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
780 Handle<JSValue> info_holder = WrapInJSValue(info); 675 CHECK(raw_result->IsCode());
781 this->SetField(kSharedInfoOffset_, info_holder); 676 return Handle<Code>::cast(raw_result);
782 this->SetSmiValueField(kStartPositionOffset_, start_position); 677 }
783 this->SetSmiValueField(kEndPositionOffset_, end_position);
784 }
785 Handle<SharedFunctionInfo> GetInfo() {
786 Handle<Object> element = this->GetField(kSharedInfoOffset_);
787 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
788 return UnwrapSharedFunctionInfoFromJSValue(value_wrapper);
789 }
790 678
791 private:
792 static const int kFunctionNameOffset_ = 0;
793 static const int kStartPositionOffset_ = 1;
794 static const int kEndPositionOffset_ = 2;
795 static const int kSharedInfoOffset_ = 3;
796 static const int kSize_ = 4;
797 679
798 friend class JSArrayBasedStruct<SharedInfoWrapper>; 680 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() {
799 }; 681 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_);
682 return UnwrapJSValue(Handle<JSValue>::cast(element));
683 }
684
685
686 void SharedInfoWrapper::SetProperties(Handle<String> name,
687 int start_position,
688 int end_position,
689 Handle<SharedFunctionInfo> info) {
690 HandleScope scope(isolate());
691 this->SetField(kFunctionNameOffset_, name);
692 Handle<JSValue> info_holder = WrapInJSValue(info);
693 this->SetField(kSharedInfoOffset_, info_holder);
694 this->SetSmiValueField(kStartPositionOffset_, start_position);
695 this->SetSmiValueField(kEndPositionOffset_, end_position);
696 }
697
698
699 Handle<SharedFunctionInfo> SharedInfoWrapper::GetInfo() {
700 Handle<Object> element = this->GetField(kSharedInfoOffset_);
701 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
702 return UnwrapSharedFunctionInfoFromJSValue(value_wrapper);
703 }
800 704
801 705
802 class FunctionInfoListener { 706 class FunctionInfoListener {
803 public: 707 public:
804 explicit FunctionInfoListener(Isolate* isolate) { 708 explicit FunctionInfoListener(Isolate* isolate) {
805 current_parent_index_ = -1; 709 current_parent_index_ = -1;
806 len_ = 0; 710 len_ = 0;
807 result_ = isolate->factory()->NewJSArray(10); 711 result_ = isolate->factory()->NewJSArray(10);
808 } 712 }
809 713
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 return; 751 return;
848 } 752 }
849 FunctionInfoWrapper info = 753 FunctionInfoWrapper info =
850 FunctionInfoWrapper::cast( 754 FunctionInfoWrapper::cast(
851 *Object::GetElementNoExceptionThrown( 755 *Object::GetElementNoExceptionThrown(
852 isolate(), result_, current_parent_index_)); 756 isolate(), result_, current_parent_index_));
853 info.SetFunctionCode(Handle<Code>(shared->code()), 757 info.SetFunctionCode(Handle<Code>(shared->code()),
854 Handle<HeapObject>(shared->scope_info())); 758 Handle<HeapObject>(shared->scope_info()));
855 info.SetSharedFunctionInfo(shared); 759 info.SetSharedFunctionInfo(shared);
856 760
857 Handle<Object> scope_info_list(SerializeFunctionScope(scope, zone), 761 Handle<Object> scope_info_list = SerializeFunctionScope(scope, zone);
858 isolate());
859 info.SetFunctionScopeInfo(scope_info_list); 762 info.SetFunctionScopeInfo(scope_info_list);
860 } 763 }
861 764
862 Handle<JSArray> GetResult() { return result_; } 765 Handle<JSArray> GetResult() { return result_; }
863 766
864 private: 767 private:
865 Isolate* isolate() const { return result_->GetIsolate(); } 768 Isolate* isolate() const { return result_->GetIsolate(); }
866 769
867 Object* SerializeFunctionScope(Scope* scope, Zone* zone) { 770 Handle<Object> SerializeFunctionScope(Scope* scope, Zone* zone) {
868 HandleScope handle_scope(isolate());
869
870 Handle<JSArray> scope_info_list = isolate()->factory()->NewJSArray(10); 771 Handle<JSArray> scope_info_list = isolate()->factory()->NewJSArray(10);
871 int scope_info_length = 0; 772 int scope_info_length = 0;
872 773
873 // Saves some description of scope. It stores name and indexes of 774 // Saves some description of scope. It stores name and indexes of
874 // variables in the whole scope chain. Null-named slots delimit 775 // variables in the whole scope chain. Null-named slots delimit
875 // scopes of this chain. 776 // scopes of this chain.
876 Scope* current_scope = scope; 777 Scope* current_scope = scope;
877 while (current_scope != NULL) { 778 while (current_scope != NULL) {
779 HandleScope handle_scope(isolate());
878 ZoneList<Variable*> stack_list(current_scope->StackLocalCount(), zone); 780 ZoneList<Variable*> stack_list(current_scope->StackLocalCount(), zone);
879 ZoneList<Variable*> context_list( 781 ZoneList<Variable*> context_list(
880 current_scope->ContextLocalCount(), zone); 782 current_scope->ContextLocalCount(), zone);
881 current_scope->CollectStackAndContextLocals(&stack_list, &context_list); 783 current_scope->CollectStackAndContextLocals(&stack_list, &context_list);
882 context_list.Sort(&Variable::CompareIndex); 784 context_list.Sort(&Variable::CompareIndex);
883 785
884 for (int i = 0; i < context_list.length(); i++) { 786 for (int i = 0; i < context_list.length(); i++) {
885 SetElementSloppy(scope_info_list, 787 SetElementSloppy(scope_info_list,
886 scope_info_length, 788 scope_info_length,
887 context_list[i]->name()); 789 context_list[i]->name());
888 scope_info_length++; 790 scope_info_length++;
889 SetElementSloppy( 791 SetElementSloppy(
890 scope_info_list, 792 scope_info_list,
891 scope_info_length, 793 scope_info_length,
892 Handle<Smi>(Smi::FromInt(context_list[i]->index()), isolate())); 794 Handle<Smi>(Smi::FromInt(context_list[i]->index()), isolate()));
893 scope_info_length++; 795 scope_info_length++;
894 } 796 }
895 SetElementSloppy(scope_info_list, 797 SetElementSloppy(scope_info_list,
896 scope_info_length, 798 scope_info_length,
897 Handle<Object>(isolate()->heap()->null_value(), 799 Handle<Object>(isolate()->heap()->null_value(),
898 isolate())); 800 isolate()));
899 scope_info_length++; 801 scope_info_length++;
900 802
901 current_scope = current_scope->outer_scope(); 803 current_scope = current_scope->outer_scope();
902 } 804 }
903 805
904 return *scope_info_list; 806 return scope_info_list;
905 } 807 }
906 808
907 Handle<JSArray> result_; 809 Handle<JSArray> result_;
908 int len_; 810 int len_;
909 int current_parent_index_; 811 int current_parent_index_;
910 }; 812 };
911 813
912 814
913 JSArray* LiveEdit::GatherCompileInfo(Handle<Script> script, 815 MaybeHandle<JSArray> LiveEdit::GatherCompileInfo(Handle<Script> script,
914 Handle<String> source) { 816 Handle<String> source) {
915 Isolate* isolate = script->GetIsolate(); 817 Isolate* isolate = script->GetIsolate();
916 818
917 FunctionInfoListener listener(isolate); 819 FunctionInfoListener listener(isolate);
918 Handle<Object> original_source = 820 Handle<Object> original_source =
919 Handle<Object>(script->source(), isolate); 821 Handle<Object>(script->source(), isolate);
920 script->set_source(*source); 822 script->set_source(*source);
921 isolate->set_active_function_info_listener(&listener); 823 isolate->set_active_function_info_listener(&listener);
922 824
923 { 825 {
924 // Creating verbose TryCatch from public API is currently the only way to 826 // Creating verbose TryCatch from public API is currently the only way to
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 JSReceiver::SetProperty( 864 JSReceiver::SetProperty(
963 rethrow_exception, script_obj_key, script_obj, NONE, SLOPPY).Assert(); 865 rethrow_exception, script_obj_key, script_obj, NONE, SLOPPY).Assert();
964 } 866 }
965 } 867 }
966 868
967 // A logical 'finally' section. 869 // A logical 'finally' section.
968 isolate->set_active_function_info_listener(NULL); 870 isolate->set_active_function_info_listener(NULL);
969 script->set_source(*original_source); 871 script->set_source(*original_source);
970 872
971 if (rethrow_exception.is_null()) { 873 if (rethrow_exception.is_null()) {
972 return *(listener.GetResult()); 874 return listener.GetResult();
973 } else { 875 } else {
974 isolate->Throw(*rethrow_exception); 876 return isolate->Throw<JSArray>(rethrow_exception);
975 return 0;
976 } 877 }
977 } 878 }
978 879
979 880
980 void LiveEdit::WrapSharedFunctionInfos(Handle<JSArray> array) { 881 void LiveEdit::WrapSharedFunctionInfos(Handle<JSArray> array) {
981 Isolate* isolate = array->GetIsolate(); 882 Isolate* isolate = array->GetIsolate();
982 HandleScope scope(isolate); 883 HandleScope scope(isolate);
983 int len = GetArrayLength(array); 884 int len = GetArrayLength(array);
984 for (int i = 0; i < len; i++) { 885 for (int i = 0; i < len; i++) {
985 Handle<SharedFunctionInfo> info( 886 Handle<SharedFunctionInfo> info(
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 // TODO(titzer): need to traverse all optimized code to find OSR code here. 1155 // TODO(titzer): need to traverse all optimized code to find OSR code here.
1255 Deoptimizer::VisitAllOptimizedFunctions(function_info->GetIsolate(), &marker); 1156 Deoptimizer::VisitAllOptimizedFunctions(function_info->GetIsolate(), &marker);
1256 1157
1257 if (marker.found_) { 1158 if (marker.found_) {
1258 // Only go through with the deoptimization if something was found. 1159 // Only go through with the deoptimization if something was found.
1259 Deoptimizer::DeoptimizeMarkedCode(function_info->GetIsolate()); 1160 Deoptimizer::DeoptimizeMarkedCode(function_info->GetIsolate());
1260 } 1161 }
1261 } 1162 }
1262 1163
1263 1164
1264 MaybeObject* LiveEdit::ReplaceFunctionCode( 1165 void LiveEdit::ReplaceFunctionCode(
1265 Handle<JSArray> new_compile_info_array, 1166 Handle<JSArray> new_compile_info_array,
1266 Handle<JSArray> shared_info_array) { 1167 Handle<JSArray> shared_info_array) {
1267 Isolate* isolate = new_compile_info_array->GetIsolate(); 1168 Isolate* isolate = new_compile_info_array->GetIsolate();
1268 HandleScope scope(isolate);
1269
1270 if (!SharedInfoWrapper::IsInstance(shared_info_array)) {
1271 return isolate->ThrowIllegalOperation();
1272 }
1273 1169
1274 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); 1170 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array);
1275 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1171 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1276 1172
1277 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1173 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1278 1174
1279 isolate->heap()->EnsureHeapIsIterable(); 1175 isolate->heap()->EnsureHeapIsIterable();
1280 1176
1281 if (IsJSFunctionCode(shared_info->code())) { 1177 if (IsJSFunctionCode(shared_info->code())) {
1282 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); 1178 Handle<Code> code = compile_info_wrapper.GetFunctionCode();
(...skipping 17 matching lines...) Expand all
1300 shared_info->set_start_position(start_position); 1196 shared_info->set_start_position(start_position);
1301 shared_info->set_end_position(end_position); 1197 shared_info->set_end_position(end_position);
1302 1198
1303 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, isolate); 1199 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, isolate);
1304 1200
1305 shared_info->set_construct_stub( 1201 shared_info->set_construct_stub(
1306 isolate->builtins()->builtin(Builtins::kJSConstructStubGeneric)); 1202 isolate->builtins()->builtin(Builtins::kJSConstructStubGeneric));
1307 1203
1308 DeoptimizeDependentFunctions(*shared_info); 1204 DeoptimizeDependentFunctions(*shared_info);
1309 isolate->compilation_cache()->Remove(shared_info); 1205 isolate->compilation_cache()->Remove(shared_info);
1310
1311 return isolate->heap()->undefined_value();
1312 } 1206 }
1313 1207
1314 1208
1315 MaybeObject* LiveEdit::FunctionSourceUpdated( 1209 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) {
1316 Handle<JSArray> shared_info_array) {
1317 Isolate* isolate = shared_info_array->GetIsolate();
1318 HandleScope scope(isolate);
1319
1320 if (!SharedInfoWrapper::IsInstance(shared_info_array)) {
1321 return isolate->ThrowIllegalOperation();
1322 }
1323
1324 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1210 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1325 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1211 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1326 1212
1327 DeoptimizeDependentFunctions(*shared_info); 1213 DeoptimizeDependentFunctions(*shared_info);
1328 isolate->compilation_cache()->Remove(shared_info); 1214 shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info);
1329
1330 return isolate->heap()->undefined_value();
1331 } 1215 }
1332 1216
1333 1217
1334 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, 1218 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper,
1335 Handle<Object> script_handle) { 1219 Handle<Object> script_handle) {
1336 Handle<SharedFunctionInfo> shared_info = 1220 Handle<SharedFunctionInfo> shared_info =
1337 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); 1221 UnwrapSharedFunctionInfoFromJSValue(function_wrapper);
1338 CHECK(script_handle->IsScript() || script_handle->IsUndefined()); 1222 CHECK(script_handle->IsScript() || script_handle->IsUndefined());
1339 shared_info->set_script(*script_handle); 1223 shared_info->set_script(*script_handle);
1340 1224
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 } else { 1381 } else {
1498 // Relocation info section now has different size. We cannot simply 1382 // Relocation info section now has different size. We cannot simply
1499 // rewrite it inside code object. Instead we have to create a new 1383 // rewrite it inside code object. Instead we have to create a new
1500 // code object. 1384 // code object.
1501 Handle<Code> result(isolate->factory()->CopyCode(code, buffer)); 1385 Handle<Code> result(isolate->factory()->CopyCode(code, buffer));
1502 return result; 1386 return result;
1503 } 1387 }
1504 } 1388 }
1505 1389
1506 1390
1507 MaybeObject* LiveEdit::PatchFunctionPositions( 1391 void LiveEdit::PatchFunctionPositions(Handle<JSArray> shared_info_array,
1508 Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array) { 1392 Handle<JSArray> position_change_array) {
1509 if (!SharedInfoWrapper::IsInstance(shared_info_array)) {
1510 return shared_info_array->GetIsolate()->ThrowIllegalOperation();
1511 }
1512
1513 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1393 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1514 Handle<SharedFunctionInfo> info = shared_info_wrapper.GetInfo(); 1394 Handle<SharedFunctionInfo> info = shared_info_wrapper.GetInfo();
1515 1395
1516 int old_function_start = info->start_position(); 1396 int old_function_start = info->start_position();
1517 int new_function_start = TranslatePosition(old_function_start, 1397 int new_function_start = TranslatePosition(old_function_start,
1518 position_change_array); 1398 position_change_array);
1519 int new_function_end = TranslatePosition(info->end_position(), 1399 int new_function_end = TranslatePosition(info->end_position(),
1520 position_change_array); 1400 position_change_array);
1521 int new_function_token_pos = 1401 int new_function_token_pos =
1522 TranslatePosition(info->function_token_position(), position_change_array); 1402 TranslatePosition(info->function_token_position(), position_change_array);
(...skipping 10 matching lines...) Expand all
1533 position_change_array); 1413 position_change_array);
1534 if (*patched_code != info->code()) { 1414 if (*patched_code != info->code()) {
1535 // Replace all references to the code across the heap. In particular, 1415 // Replace all references to the code across the heap. In particular,
1536 // some stubs may refer to this code and this code may be being executed 1416 // some stubs may refer to this code and this code may be being executed
1537 // on stack (it is safe to substitute the code object on stack, because 1417 // on stack (it is safe to substitute the code object on stack, because
1538 // we only change the structure of rinfo and leave instructions 1418 // we only change the structure of rinfo and leave instructions
1539 // untouched). 1419 // untouched).
1540 ReplaceCodeObject(Handle<Code>(info->code()), patched_code); 1420 ReplaceCodeObject(Handle<Code>(info->code()), patched_code);
1541 } 1421 }
1542 } 1422 }
1543
1544 return info->GetIsolate()->heap()->undefined_value();
1545 } 1423 }
1546 1424
1547 1425
1548 static Handle<Script> CreateScriptCopy(Handle<Script> original) { 1426 static Handle<Script> CreateScriptCopy(Handle<Script> original) {
1549 Isolate* isolate = original->GetIsolate(); 1427 Isolate* isolate = original->GetIsolate();
1550 1428
1551 Handle<String> original_source(String::cast(original->source())); 1429 Handle<String> original_source(String::cast(original->source()));
1552 Handle<Script> copy = isolate->factory()->NewScript(original_source); 1430 Handle<Script> copy = isolate->factory()->NewScript(original_source);
1553 1431
1554 copy->set_name(original->name()); 1432 copy->set_name(original->name());
1555 copy->set_line_offset(original->line_offset()); 1433 copy->set_line_offset(original->line_offset());
1556 copy->set_column_offset(original->column_offset()); 1434 copy->set_column_offset(original->column_offset());
1557 copy->set_type(original->type()); 1435 copy->set_type(original->type());
1558 copy->set_context_data(original->context_data()); 1436 copy->set_context_data(original->context_data());
1559 copy->set_eval_from_shared(original->eval_from_shared()); 1437 copy->set_eval_from_shared(original->eval_from_shared());
1560 copy->set_eval_from_instructions_offset( 1438 copy->set_eval_from_instructions_offset(
1561 original->eval_from_instructions_offset()); 1439 original->eval_from_instructions_offset());
1562 1440
1563 // Copy all the flags, but clear compilation state. 1441 // Copy all the flags, but clear compilation state.
1564 copy->set_flags(original->flags()); 1442 copy->set_flags(original->flags());
1565 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); 1443 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL);
1566 1444
1567 return copy; 1445 return copy;
1568 } 1446 }
1569 1447
1570 1448
1571 Object* LiveEdit::ChangeScriptSource(Handle<Script> original_script, 1449 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script,
1572 Handle<String> new_source, 1450 Handle<String> new_source,
1573 Handle<Object> old_script_name) { 1451 Handle<Object> old_script_name) {
1574 Isolate* isolate = original_script->GetIsolate(); 1452 Isolate* isolate = original_script->GetIsolate();
1575 Handle<Object> old_script_object; 1453 Handle<Object> old_script_object;
1576 if (old_script_name->IsString()) { 1454 if (old_script_name->IsString()) {
1577 Handle<Script> old_script = CreateScriptCopy(original_script); 1455 Handle<Script> old_script = CreateScriptCopy(original_script);
1578 old_script->set_name(String::cast(*old_script_name)); 1456 old_script->set_name(String::cast(*old_script_name));
1579 old_script_object = old_script; 1457 old_script_object = old_script;
1580 isolate->debugger()->OnAfterCompile( 1458 isolate->debugger()->OnAfterCompile(
1581 old_script, Debugger::SEND_WHEN_DEBUGGING); 1459 old_script, Debugger::SEND_WHEN_DEBUGGING);
1582 } else { 1460 } else {
1583 old_script_object = isolate->factory()->null_value(); 1461 old_script_object = isolate->factory()->null_value();
1584 } 1462 }
1585 1463
1586 original_script->set_source(*new_source); 1464 original_script->set_source(*new_source);
1587 1465
1588 // Drop line ends so that they will be recalculated. 1466 // Drop line ends so that they will be recalculated.
1589 original_script->set_line_ends(isolate->heap()->undefined_value()); 1467 original_script->set_line_ends(isolate->heap()->undefined_value());
1590 1468
1591 return *old_script_object; 1469 return old_script_object;
1592 } 1470 }
1593 1471
1594 1472
1595 1473
1596 void LiveEdit::ReplaceRefToNestedFunction( 1474 void LiveEdit::ReplaceRefToNestedFunction(
1597 Handle<JSValue> parent_function_wrapper, 1475 Handle<JSValue> parent_function_wrapper,
1598 Handle<JSValue> orig_function_wrapper, 1476 Handle<JSValue> orig_function_wrapper,
1599 Handle<JSValue> subst_function_wrapper) { 1477 Handle<JSValue> subst_function_wrapper) {
1600 1478
1601 Handle<SharedFunctionInfo> parent_shared = 1479 Handle<SharedFunctionInfo> parent_shared =
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 2005
2128 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { 2006 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) {
2129 return false; 2007 return false;
2130 } 2008 }
2131 2009
2132 #endif // ENABLE_DEBUGGER_SUPPORT 2010 #endif // ENABLE_DEBUGGER_SUPPORT
2133 2011
2134 2012
2135 2013
2136 } } // namespace v8::internal 2014 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698