| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/debug-scopes.h" | 5 #include "src/debug/debug-scopes.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
| 11 #include "src/globals.h" | 11 #include "src/globals.h" |
| 12 #include "src/isolate-inl.h" | 12 #include "src/isolate-inl.h" |
| 13 #include "src/parsing/parser.h" | 13 #include "src/parsing/parser.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, | 18 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, |
| 19 ScopeIterator::Option option) | 19 ScopeIterator::Option option) |
| 20 : isolate_(isolate), | 20 : isolate_(isolate), |
| 21 frame_inspector_(frame_inspector), | 21 frame_inspector_(frame_inspector), |
| 22 nested_scope_chain_(4), | 22 nested_scope_chain_(4), |
| 23 seen_script_scope_(false), | 23 seen_script_scope_(false), |
| 24 failed_(false) { | 24 failed_(false) { |
| 25 if (!frame_inspector->GetContext()->IsContext() || | 25 if (!frame_inspector->GetContext()->IsContext()) { |
| 26 !frame_inspector->GetFunction()->IsJSFunction()) { | |
| 27 // Optimized frame, context or function cannot be materialized. Give up. | 26 // Optimized frame, context or function cannot be materialized. Give up. |
| 28 return; | 27 return; |
| 29 } | 28 } |
| 30 | 29 |
| 31 context_ = Handle<Context>::cast(frame_inspector->GetContext()); | 30 context_ = Handle<Context>::cast(frame_inspector->GetContext()); |
| 32 | 31 |
| 33 // Catch the case when the debugger stops in an internal function. | 32 // Catch the case when the debugger stops in an internal function. |
| 34 Handle<JSFunction> function = GetFunction(); | 33 Handle<JSFunction> function = GetFunction(); |
| 35 Handle<SharedFunctionInfo> shared_info(function->shared()); | 34 Handle<SharedFunctionInfo> shared_info(function->shared()); |
| 36 Handle<ScopeInfo> scope_info(shared_info->scope_info()); | 35 Handle<ScopeInfo> scope_info(shared_info->scope_info()); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 606 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
| 608 if (String::Equals(handle(scope_info->ParameterName(i)), parameter_name)) { | 607 if (String::Equals(handle(scope_info->ParameterName(i)), parameter_name)) { |
| 609 frame->SetParameterValue(i, *new_value); | 608 frame->SetParameterValue(i, *new_value); |
| 610 return true; | 609 return true; |
| 611 } | 610 } |
| 612 } | 611 } |
| 613 return false; | 612 return false; |
| 614 } | 613 } |
| 615 | 614 |
| 616 bool ScopeIterator::SetStackVariableValue(Handle<ScopeInfo> scope_info, | 615 bool ScopeIterator::SetStackVariableValue(Handle<ScopeInfo> scope_info, |
| 617 JavaScriptFrame* frame, | |
| 618 Handle<String> variable_name, | 616 Handle<String> variable_name, |
| 619 Handle<Object> new_value) { | 617 Handle<Object> new_value) { |
| 618 JavaScriptFrame* frame = GetFrame(); |
| 620 // Setting stack locals of optimized frames is not supported. | 619 // Setting stack locals of optimized frames is not supported. |
| 621 if (frame->is_optimized()) return false; | 620 if (frame->is_optimized()) return false; |
| 622 HandleScope scope(isolate_); | 621 HandleScope scope(isolate_); |
| 623 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 622 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 624 if (String::Equals(handle(scope_info->StackLocalName(i)), variable_name)) { | 623 if (String::Equals(handle(scope_info->StackLocalName(i)), variable_name)) { |
| 625 frame->SetExpression(scope_info->StackLocalIndex(i), *new_value); | 624 frame->SetExpression(scope_info->StackLocalIndex(i), *new_value); |
| 626 return true; | 625 return true; |
| 627 } | 626 } |
| 628 } | 627 } |
| 629 return false; | 628 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 664 |
| 666 bool ScopeIterator::SetLocalVariableValue(Handle<String> variable_name, | 665 bool ScopeIterator::SetLocalVariableValue(Handle<String> variable_name, |
| 667 Handle<Object> new_value) { | 666 Handle<Object> new_value) { |
| 668 JavaScriptFrame* frame = GetFrame(); | 667 JavaScriptFrame* frame = GetFrame(); |
| 669 Handle<ScopeInfo> scope_info(frame->function()->shared()->scope_info()); | 668 Handle<ScopeInfo> scope_info(frame->function()->shared()->scope_info()); |
| 670 | 669 |
| 671 // Parameter might be shadowed in context. Don't stop here. | 670 // Parameter might be shadowed in context. Don't stop here. |
| 672 bool result = SetParameterValue(scope_info, frame, variable_name, new_value); | 671 bool result = SetParameterValue(scope_info, frame, variable_name, new_value); |
| 673 | 672 |
| 674 // Stack locals. | 673 // Stack locals. |
| 675 if (SetStackVariableValue(scope_info, frame, variable_name, new_value)) { | 674 if (SetStackVariableValue(scope_info, variable_name, new_value)) { |
| 676 return true; | 675 return true; |
| 677 } | 676 } |
| 678 | 677 |
| 679 if (scope_info->HasContext() && | 678 if (scope_info->HasContext() && |
| 680 SetContextVariableValue(scope_info, CurrentContext(), variable_name, | 679 SetContextVariableValue(scope_info, CurrentContext(), variable_name, |
| 681 new_value)) { | 680 new_value)) { |
| 682 return true; | 681 return true; |
| 683 } | 682 } |
| 684 | 683 |
| 685 return result; | 684 return result; |
| 686 } | 685 } |
| 687 | 686 |
| 688 bool ScopeIterator::SetInnerScopeVariableValue(Handle<String> variable_name, | 687 bool ScopeIterator::SetInnerScopeVariableValue(Handle<String> variable_name, |
| 689 Handle<Object> new_value) { | 688 Handle<Object> new_value) { |
| 690 Handle<ScopeInfo> scope_info = CurrentScopeInfo(); | 689 Handle<ScopeInfo> scope_info = CurrentScopeInfo(); |
| 691 DCHECK(scope_info->scope_type() == BLOCK_SCOPE || | 690 DCHECK(scope_info->scope_type() == BLOCK_SCOPE || |
| 692 scope_info->scope_type() == EVAL_SCOPE); | 691 scope_info->scope_type() == EVAL_SCOPE); |
| 693 JavaScriptFrame* frame = GetFrame(); | |
| 694 | 692 |
| 695 // Setting stack locals of optimized frames is not supported. | 693 // Setting stack locals of optimized frames is not supported. |
| 696 if (SetStackVariableValue(scope_info, frame, variable_name, new_value)) { | 694 if (SetStackVariableValue(scope_info, variable_name, new_value)) { |
| 697 return true; | 695 return true; |
| 698 } | 696 } |
| 699 | 697 |
| 700 if (HasContext() && SetContextVariableValue(scope_info, CurrentContext(), | 698 if (HasContext() && SetContextVariableValue(scope_info, CurrentContext(), |
| 701 variable_name, new_value)) { | 699 variable_name, new_value)) { |
| 702 return true; | 700 return true; |
| 703 } | 701 } |
| 704 | 702 |
| 705 return false; | 703 return false; |
| 706 } | 704 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 800 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
| 803 if (beg_pos <= position && position < end_pos) { | 801 if (beg_pos <= position && position < end_pos) { |
| 804 GetNestedScopeChain(isolate, inner_scope, position); | 802 GetNestedScopeChain(isolate, inner_scope, position); |
| 805 return; | 803 return; |
| 806 } | 804 } |
| 807 } | 805 } |
| 808 } | 806 } |
| 809 | 807 |
| 810 } // namespace internal | 808 } // namespace internal |
| 811 } // namespace v8 | 809 } // namespace v8 |
| OLD | NEW |