| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 | 28 |
| 29 #include "v8.h" | 29 #include "v8.h" |
| 30 | 30 |
| 31 #include "liveedit.h" | 31 #include "liveedit.h" |
| 32 #include "compiler.h" | 32 #include "compiler.h" |
| 33 #include "oprofile-agent.h" | 33 #include "oprofile-agent.h" |
| 34 #include "scopes.h" | 34 #include "scopes.h" |
| 35 #include "scopeinfo.h" |
| 35 #include "global-handles.h" | 36 #include "global-handles.h" |
| 36 #include "debug.h" | 37 #include "debug.h" |
| 37 #include "memory.h" | 38 #include "memory.h" |
| 38 | 39 |
| 39 namespace v8 { | 40 namespace v8 { |
| 40 namespace internal { | 41 namespace internal { |
| 41 | 42 |
| 42 | 43 |
| 43 #ifdef ENABLE_DEBUGGER_SUPPORT | 44 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 44 | 45 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 494 } |
| 494 void SetInitialProperties(Handle<String> name, int start_position, | 495 void SetInitialProperties(Handle<String> name, int start_position, |
| 495 int end_position, int param_num, int parent_index) { | 496 int end_position, int param_num, int parent_index) { |
| 496 HandleScope scope; | 497 HandleScope scope; |
| 497 this->SetField(kFunctionNameOffset_, name); | 498 this->SetField(kFunctionNameOffset_, name); |
| 498 this->SetSmiValueField(kStartPositionOffset_, start_position); | 499 this->SetSmiValueField(kStartPositionOffset_, start_position); |
| 499 this->SetSmiValueField(kEndPositionOffset_, end_position); | 500 this->SetSmiValueField(kEndPositionOffset_, end_position); |
| 500 this->SetSmiValueField(kParamNumOffset_, param_num); | 501 this->SetSmiValueField(kParamNumOffset_, param_num); |
| 501 this->SetSmiValueField(kParentIndexOffset_, parent_index); | 502 this->SetSmiValueField(kParentIndexOffset_, parent_index); |
| 502 } | 503 } |
| 503 void SetFunctionCode(Handle<Code> function_code) { | 504 void SetFunctionCode(Handle<Code> function_code, |
| 504 Handle<JSValue> wrapper = WrapInJSValue(*function_code); | 505 Handle<Object> code_scope_info) { |
| 505 this->SetField(kCodeOffset_, wrapper); | 506 Handle<JSValue> code_wrapper = WrapInJSValue(*function_code); |
| 507 this->SetField(kCodeOffset_, code_wrapper); |
| 508 |
| 509 Handle<JSValue> scope_wrapper = WrapInJSValue(*code_scope_info); |
| 510 this->SetField(kCodeScopeInfoOffset_, scope_wrapper); |
| 506 } | 511 } |
| 507 void SetScopeInfo(Handle<Object> scope_info_array) { | 512 void SetOuterScopeInfo(Handle<Object> scope_info_array) { |
| 508 this->SetField(kScopeInfoOffset_, scope_info_array); | 513 this->SetField(kOuterScopeInfoOffset_, scope_info_array); |
| 509 } | 514 } |
| 510 void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info) { | 515 void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info) { |
| 511 Handle<JSValue> info_holder = WrapInJSValue(*info); | 516 Handle<JSValue> info_holder = WrapInJSValue(*info); |
| 512 this->SetField(kSharedFunctionInfoOffset_, info_holder); | 517 this->SetField(kSharedFunctionInfoOffset_, info_holder); |
| 513 } | 518 } |
| 514 int GetParentIndex() { | 519 int GetParentIndex() { |
| 515 return this->GetSmiValueField(kParentIndexOffset_); | 520 return this->GetSmiValueField(kParentIndexOffset_); |
| 516 } | 521 } |
| 517 Handle<Code> GetFunctionCode() { | 522 Handle<Code> GetFunctionCode() { |
| 518 Handle<Object> raw_result = UnwrapJSValue(Handle<JSValue>( | 523 Handle<Object> raw_result = UnwrapJSValue(Handle<JSValue>( |
| 519 JSValue::cast(this->GetField(kCodeOffset_)))); | 524 JSValue::cast(this->GetField(kCodeOffset_)))); |
| 520 return Handle<Code>::cast(raw_result); | 525 return Handle<Code>::cast(raw_result); |
| 521 } | 526 } |
| 527 Handle<Object> GetCodeScopeInfo() { |
| 528 Handle<Object> raw_result = UnwrapJSValue(Handle<JSValue>( |
| 529 JSValue::cast(this->GetField(kCodeScopeInfoOffset_)))); |
| 530 return raw_result; |
| 531 } |
| 522 int GetStartPosition() { | 532 int GetStartPosition() { |
| 523 return this->GetSmiValueField(kStartPositionOffset_); | 533 return this->GetSmiValueField(kStartPositionOffset_); |
| 524 } | 534 } |
| 525 int GetEndPosition() { | 535 int GetEndPosition() { |
| 526 return this->GetSmiValueField(kEndPositionOffset_); | 536 return this->GetSmiValueField(kEndPositionOffset_); |
| 527 } | 537 } |
| 528 | 538 |
| 529 private: | 539 private: |
| 530 static const int kFunctionNameOffset_ = 0; | 540 static const int kFunctionNameOffset_ = 0; |
| 531 static const int kStartPositionOffset_ = 1; | 541 static const int kStartPositionOffset_ = 1; |
| 532 static const int kEndPositionOffset_ = 2; | 542 static const int kEndPositionOffset_ = 2; |
| 533 static const int kParamNumOffset_ = 3; | 543 static const int kParamNumOffset_ = 3; |
| 534 static const int kCodeOffset_ = 4; | 544 static const int kCodeOffset_ = 4; |
| 535 static const int kScopeInfoOffset_ = 5; | 545 static const int kCodeScopeInfoOffset_ = 5; |
| 536 static const int kParentIndexOffset_ = 6; | 546 static const int kOuterScopeInfoOffset_ = 6; |
| 537 static const int kSharedFunctionInfoOffset_ = 7; | 547 static const int kParentIndexOffset_ = 7; |
| 538 static const int kSize_ = 8; | 548 static const int kSharedFunctionInfoOffset_ = 8; |
| 549 static const int kSize_ = 9; |
| 539 | 550 |
| 540 friend class JSArrayBasedStruct<FunctionInfoWrapper>; | 551 friend class JSArrayBasedStruct<FunctionInfoWrapper>; |
| 541 }; | 552 }; |
| 542 | 553 |
| 543 // Wraps SharedFunctionInfo along with some of its fields for passing it | 554 // Wraps SharedFunctionInfo along with some of its fields for passing it |
| 544 // back to JavaScript. SharedFunctionInfo object itself is additionally | 555 // back to JavaScript. SharedFunctionInfo object itself is additionally |
| 545 // wrapped into BlindReference for sanitizing reasons. | 556 // wrapped into BlindReference for sanitizing reasons. |
| 546 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { | 557 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { |
| 547 public: | 558 public: |
| 548 static bool IsInstance(Handle<JSArray> array) { | 559 static bool IsInstance(Handle<JSArray> array) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 675 |
| 665 return *scope_info_list; | 676 return *scope_info_list; |
| 666 } | 677 } |
| 667 | 678 |
| 668 public: | 679 public: |
| 669 // Saves only function code, because for a script function we | 680 // Saves only function code, because for a script function we |
| 670 // may never create a SharedFunctionInfo object. | 681 // may never create a SharedFunctionInfo object. |
| 671 void FunctionCode(Handle<Code> function_code) { | 682 void FunctionCode(Handle<Code> function_code) { |
| 672 FunctionInfoWrapper info = | 683 FunctionInfoWrapper info = |
| 673 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); | 684 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); |
| 674 info.SetFunctionCode(function_code); | 685 info.SetFunctionCode(function_code, Handle<Object>(Heap::null_value())); |
| 675 } | 686 } |
| 676 | 687 |
| 677 // Saves full information about a function: its code, its scope info | 688 // Saves full information about a function: its code, its scope info |
| 678 // and a SharedFunctionInfo object. | 689 // and a SharedFunctionInfo object. |
| 679 void FunctionInfo(Handle<SharedFunctionInfo> shared, Scope* scope) { | 690 void FunctionInfo(Handle<SharedFunctionInfo> shared, Scope* scope) { |
| 680 if (!shared->IsSharedFunctionInfo()) { | 691 if (!shared->IsSharedFunctionInfo()) { |
| 681 return; | 692 return; |
| 682 } | 693 } |
| 683 FunctionInfoWrapper info = | 694 FunctionInfoWrapper info = |
| 684 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); | 695 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); |
| 685 info.SetFunctionCode(Handle<Code>(shared->code())); | 696 info.SetFunctionCode(Handle<Code>(shared->code()), |
| 697 Handle<Object>(shared->scope_info())); |
| 686 info.SetSharedFunctionInfo(shared); | 698 info.SetSharedFunctionInfo(shared); |
| 687 | 699 |
| 688 Handle<Object> scope_info_list(SerializeFunctionScope(scope)); | 700 Handle<Object> scope_info_list(SerializeFunctionScope(scope)); |
| 689 info.SetScopeInfo(scope_info_list); | 701 info.SetOuterScopeInfo(scope_info_list); |
| 690 } | 702 } |
| 691 | 703 |
| 692 Handle<JSArray> GetResult() { | 704 Handle<JSArray> GetResult() { |
| 693 return result_; | 705 return result_; |
| 694 } | 706 } |
| 695 | 707 |
| 696 private: | 708 private: |
| 697 Handle<JSArray> result_; | 709 Handle<JSArray> result_; |
| 698 int len_; | 710 int len_; |
| 699 int current_parent_index_; | 711 int current_parent_index_; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 } | 860 } |
| 849 | 861 |
| 850 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 862 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
| 851 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 863 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
| 852 | 864 |
| 853 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 865 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 854 | 866 |
| 855 if (IsJSFunctionCode(shared_info->code())) { | 867 if (IsJSFunctionCode(shared_info->code())) { |
| 856 ReplaceCodeObject(shared_info->code(), | 868 ReplaceCodeObject(shared_info->code(), |
| 857 *(compile_info_wrapper.GetFunctionCode())); | 869 *(compile_info_wrapper.GetFunctionCode())); |
| 870 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); |
| 871 if (code_scope_info->IsFixedArray()) { |
| 872 shared_info->set_scope_info(SerializedScopeInfo::cast(*code_scope_info)); |
| 873 } |
| 858 } | 874 } |
| 859 | 875 |
| 860 if (shared_info->debug_info()->IsDebugInfo()) { | 876 if (shared_info->debug_info()->IsDebugInfo()) { |
| 861 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); | 877 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); |
| 862 Handle<Code> new_original_code = | 878 Handle<Code> new_original_code = |
| 863 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); | 879 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); |
| 864 debug_info->set_original_code(*new_original_code); | 880 debug_info->set_original_code(*new_original_code); |
| 865 } | 881 } |
| 866 | 882 |
| 867 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); | 883 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 | 1494 |
| 1479 bool LiveEditFunctionTracker::IsActive() { | 1495 bool LiveEditFunctionTracker::IsActive() { |
| 1480 return false; | 1496 return false; |
| 1481 } | 1497 } |
| 1482 | 1498 |
| 1483 #endif // ENABLE_DEBUGGER_SUPPORT | 1499 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1484 | 1500 |
| 1485 | 1501 |
| 1486 | 1502 |
| 1487 } } // namespace v8::internal | 1503 } } // namespace v8::internal |
| OLD | NEW |