| 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 #include "src/debug/liveedit.h" | 5 #include "src/debug/liveedit.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/compilation-cache.h" | 9 #include "src/compilation-cache.h" |
| 10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(shared)); | 597 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(shared)); |
| 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 void FunctionInfoWrapper::SetInitialProperties( |
| 608 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, | 608 Handle<String> name, int start_position, int end_position, int param_num, |
| 609 int start_position, | 609 int literal_count, int parent_index, int function_literal_id) { |
| 610 int end_position, int param_num, | |
| 611 int literal_count, | |
| 612 int parent_index) { | |
| 613 HandleScope scope(isolate()); | 610 HandleScope scope(isolate()); |
| 614 this->SetField(kFunctionNameOffset_, name); | 611 this->SetField(kFunctionNameOffset_, name); |
| 615 this->SetSmiValueField(kStartPositionOffset_, start_position); | 612 this->SetSmiValueField(kStartPositionOffset_, start_position); |
| 616 this->SetSmiValueField(kEndPositionOffset_, end_position); | 613 this->SetSmiValueField(kEndPositionOffset_, end_position); |
| 617 this->SetSmiValueField(kParamNumOffset_, param_num); | 614 this->SetSmiValueField(kParamNumOffset_, param_num); |
| 618 this->SetSmiValueField(kLiteralNumOffset_, literal_count); | 615 this->SetSmiValueField(kLiteralNumOffset_, literal_count); |
| 619 this->SetSmiValueField(kParentIndexOffset_, parent_index); | 616 this->SetSmiValueField(kParentIndexOffset_, parent_index); |
| 617 this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id); |
| 620 } | 618 } |
| 621 | 619 |
| 622 void FunctionInfoWrapper::SetSharedFunctionInfo( | 620 void FunctionInfoWrapper::SetSharedFunctionInfo( |
| 623 Handle<SharedFunctionInfo> info) { | 621 Handle<SharedFunctionInfo> info) { |
| 624 Handle<JSValue> info_holder = WrapInJSValue(info); | 622 Handle<JSValue> info_holder = WrapInJSValue(info); |
| 625 this->SetField(kSharedFunctionInfoOffset_, info_holder); | 623 this->SetField(kSharedFunctionInfoOffset_, info_holder); |
| 626 } | 624 } |
| 627 | 625 |
| 628 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() { | 626 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() { |
| 629 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); | 627 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 Handle<Script> copy = isolate->factory()->NewScript(original_source); | 1164 Handle<Script> copy = isolate->factory()->NewScript(original_source); |
| 1167 | 1165 |
| 1168 copy->set_name(original->name()); | 1166 copy->set_name(original->name()); |
| 1169 copy->set_line_offset(original->line_offset()); | 1167 copy->set_line_offset(original->line_offset()); |
| 1170 copy->set_column_offset(original->column_offset()); | 1168 copy->set_column_offset(original->column_offset()); |
| 1171 copy->set_type(original->type()); | 1169 copy->set_type(original->type()); |
| 1172 copy->set_context_data(original->context_data()); | 1170 copy->set_context_data(original->context_data()); |
| 1173 copy->set_eval_from_shared(original->eval_from_shared()); | 1171 copy->set_eval_from_shared(original->eval_from_shared()); |
| 1174 copy->set_eval_from_position(original->eval_from_position()); | 1172 copy->set_eval_from_position(original->eval_from_position()); |
| 1175 | 1173 |
| 1174 Handle<FixedArray> infos(isolate->factory()->NewFixedArrayWithSmis( |
| 1175 original->shared_function_infos()->length(), 0)); |
| 1176 copy->set_shared_function_infos(*infos); |
| 1177 |
| 1176 // Copy all the flags, but clear compilation state. | 1178 // Copy all the flags, but clear compilation state. |
| 1177 copy->set_flags(original->flags()); | 1179 copy->set_flags(original->flags()); |
| 1178 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); | 1180 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); |
| 1179 | 1181 |
| 1180 return copy; | 1182 return copy; |
| 1181 } | 1183 } |
| 1182 | 1184 |
| 1183 | |
| 1184 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, | 1185 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, |
| 1186 int max_function_literal_id, |
| 1185 Handle<String> new_source, | 1187 Handle<String> new_source, |
| 1186 Handle<Object> old_script_name) { | 1188 Handle<Object> old_script_name) { |
| 1187 Isolate* isolate = original_script->GetIsolate(); | 1189 Isolate* isolate = original_script->GetIsolate(); |
| 1188 Handle<Object> old_script_object; | 1190 Handle<Object> old_script_object; |
| 1189 if (old_script_name->IsString()) { | 1191 if (old_script_name->IsString()) { |
| 1190 Handle<Script> old_script = CreateScriptCopy(original_script); | 1192 Handle<Script> old_script = CreateScriptCopy(original_script); |
| 1191 old_script->set_name(String::cast(*old_script_name)); | 1193 old_script->set_name(String::cast(*old_script_name)); |
| 1192 old_script_object = old_script; | 1194 old_script_object = old_script; |
| 1193 isolate->debug()->OnAfterCompile(old_script); | 1195 isolate->debug()->OnAfterCompile(old_script); |
| 1194 } else { | 1196 } else { |
| 1195 old_script_object = isolate->factory()->null_value(); | 1197 old_script_object = isolate->factory()->null_value(); |
| 1196 } | 1198 } |
| 1197 | 1199 |
| 1198 original_script->set_source(*new_source); | 1200 original_script->set_source(*new_source); |
| 1199 | 1201 |
| 1200 // Drop line ends so that they will be recalculated. | 1202 // Drop line ends so that they will be recalculated. |
| 1201 original_script->set_line_ends(isolate->heap()->undefined_value()); | 1203 original_script->set_line_ends(isolate->heap()->undefined_value()); |
| 1202 | 1204 |
| 1205 Handle<FixedArray> infos(isolate->factory()->NewFixedArrayWithSmis( |
| 1206 max_function_literal_id + 1, 0)); |
| 1207 original_script->set_shared_function_infos(*infos); |
| 1208 |
| 1203 return old_script_object; | 1209 return old_script_object; |
| 1204 } | 1210 } |
| 1205 | 1211 |
| 1206 | 1212 |
| 1207 | 1213 |
| 1208 void LiveEdit::ReplaceRefToNestedFunction( | 1214 void LiveEdit::ReplaceRefToNestedFunction( |
| 1209 Handle<JSValue> parent_function_wrapper, | 1215 Handle<JSValue> parent_function_wrapper, |
| 1210 Handle<JSValue> orig_function_wrapper, | 1216 Handle<JSValue> orig_function_wrapper, |
| 1211 Handle<JSValue> subst_function_wrapper) { | 1217 Handle<JSValue> subst_function_wrapper) { |
| 1212 | 1218 |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 script_ = script; | 1855 script_ = script; |
| 1850 zone_ = zone; | 1856 zone_ = zone; |
| 1851 } | 1857 } |
| 1852 | 1858 |
| 1853 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { | 1859 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { |
| 1854 // FunctionStarted is called in pre-order. | 1860 // FunctionStarted is called in pre-order. |
| 1855 FunctionStarted(node); | 1861 FunctionStarted(node); |
| 1856 // Recurse using the regular traversal. | 1862 // Recurse using the regular traversal. |
| 1857 AstTraversalVisitor::VisitFunctionLiteral(node); | 1863 AstTraversalVisitor::VisitFunctionLiteral(node); |
| 1858 // FunctionDone are called in post-order. | 1864 // FunctionDone are called in post-order. |
| 1859 // TODO(jgruber): If required, replace the (linear cost) | |
| 1860 // FindSharedFunctionInfo call with a more efficient implementation. | |
| 1861 Handle<SharedFunctionInfo> info = | 1865 Handle<SharedFunctionInfo> info = |
| 1862 script_->FindSharedFunctionInfo(node).ToHandleChecked(); | 1866 script_->FindSharedFunctionInfo(node).ToHandleChecked(); |
| 1863 FunctionDone(info, node->scope()); | 1867 FunctionDone(info, node->scope()); |
| 1864 } | 1868 } |
| 1865 | 1869 |
| 1866 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { | 1870 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { |
| 1867 HandleScope handle_scope(isolate_); | 1871 HandleScope handle_scope(isolate_); |
| 1868 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); | 1872 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); |
| 1869 info.SetInitialProperties(fun->name(), fun->start_position(), | 1873 info.SetInitialProperties(fun->name(), fun->start_position(), |
| 1870 fun->end_position(), fun->parameter_count(), | 1874 fun->end_position(), fun->parameter_count(), |
| 1871 fun->materialized_literal_count(), | 1875 fun->materialized_literal_count(), |
| 1872 current_parent_index_); | 1876 current_parent_index_, fun->function_literal_id()); |
| 1873 current_parent_index_ = len_; | 1877 current_parent_index_ = len_; |
| 1874 SetElementSloppy(result_, len_, info.GetJSArray()); | 1878 SetElementSloppy(result_, len_, info.GetJSArray()); |
| 1875 len_++; | 1879 len_++; |
| 1876 } | 1880 } |
| 1877 | 1881 |
| 1878 // Saves full information about a function: its code, its scope info | 1882 // Saves full information about a function: its code, its scope info |
| 1879 // and a SharedFunctionInfo object. | 1883 // and a SharedFunctionInfo object. |
| 1880 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, | 1884 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, |
| 1881 Scope* scope) { | 1885 Scope* scope) { |
| 1882 HandleScope handle_scope(isolate_); | 1886 HandleScope handle_scope(isolate_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 scope_info_length++; | 1919 scope_info_length++; |
| 1916 | 1920 |
| 1917 current_scope = current_scope->outer_scope(); | 1921 current_scope = current_scope->outer_scope(); |
| 1918 } | 1922 } |
| 1919 | 1923 |
| 1920 return scope_info_list; | 1924 return scope_info_list; |
| 1921 } | 1925 } |
| 1922 | 1926 |
| 1923 } // namespace internal | 1927 } // namespace internal |
| 1924 } // namespace v8 | 1928 } // namespace v8 |
| OLD | NEW |