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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/debug/debug.h" | 10 #include "src/debug/debug.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 Handle<Script> script(Script::cast(shared_info->script())); | 94 Handle<Script> script(Script::cast(shared_info->script())); |
95 info.reset(new ParseInfo(&zone, script)); | 95 info.reset(new ParseInfo(&zone, script)); |
96 if (scope_info->scope_type() == EVAL_SCOPE) { | 96 if (scope_info->scope_type() == EVAL_SCOPE) { |
97 info->set_eval(); | 97 info->set_eval(); |
98 if (!function->context()->IsNativeContext()) { | 98 if (!function->context()->IsNativeContext()) { |
99 info->set_outer_scope_info(handle(function->context()->scope_info())); | 99 info->set_outer_scope_info(handle(function->context()->scope_info())); |
100 } | 100 } |
101 // Language mode may be inherited from the eval caller. | 101 // Language mode may be inherited from the eval caller. |
102 // Retrieve it from shared function info. | 102 // Retrieve it from shared function info. |
103 info->set_language_mode(shared_info->language_mode()); | 103 info->set_language_mode(shared_info->language_mode()); |
| 104 } else if (scope_info->scope_type() == MODULE_SCOPE) { |
| 105 info->set_module(); |
104 } else { | 106 } else { |
105 DCHECK(scope_info->scope_type() == SCRIPT_SCOPE); | 107 DCHECK(scope_info->scope_type() == SCRIPT_SCOPE); |
106 } | 108 } |
107 } else { | 109 } else { |
108 // Inner function. | 110 // Inner function. |
109 info.reset(new ParseInfo(&zone, shared_info)); | 111 info.reset(new ParseInfo(&zone, shared_info)); |
110 } | 112 } |
111 if (Parser::ParseStatic(info.get()) && Rewriter::Rewrite(info.get())) { | 113 if (Parser::ParseStatic(info.get()) && Rewriter::Rewrite(info.get())) { |
112 DeclarationScope* scope = info->literal()->scope(); | 114 DeclarationScope* scope = info->literal()->scope(); |
113 if (!ignore_nested_scopes || collect_non_locals) { | 115 if (!ignore_nested_scopes || collect_non_locals) { |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return inner_scope; | 603 return inner_scope; |
602 } | 604 } |
603 | 605 |
604 | 606 |
605 // Create a plain JSObject which materializes the module scope for the specified | 607 // Create a plain JSObject which materializes the module scope for the specified |
606 // module context. | 608 // module context. |
607 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { | 609 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { |
608 Handle<Context> context = CurrentContext(); | 610 Handle<Context> context = CurrentContext(); |
609 DCHECK(context->IsModuleContext()); | 611 DCHECK(context->IsModuleContext()); |
610 Handle<ScopeInfo> scope_info(context->scope_info()); | 612 Handle<ScopeInfo> scope_info(context->scope_info()); |
611 | |
612 // Allocate and initialize a JSObject with all the members of the debugged | |
613 // module. | |
614 Handle<JSObject> module_scope = | 613 Handle<JSObject> module_scope = |
615 isolate_->factory()->NewJSObjectWithNullProto(); | 614 isolate_->factory()->NewJSObjectWithNullProto(); |
616 | |
617 // Fill all context locals. | |
618 CopyContextLocalsToScopeObject(scope_info, context, module_scope); | 615 CopyContextLocalsToScopeObject(scope_info, context, module_scope); |
619 | 616 CopyModuleVarsToScopeObject(scope_info, context, module_scope); |
620 // TODO(neis): Also collect stack locals as well as imports and exports. | |
621 | |
622 return module_scope; | 617 return module_scope; |
623 } | 618 } |
624 | 619 |
625 bool ScopeIterator::SetParameterValue(Handle<ScopeInfo> scope_info, | 620 bool ScopeIterator::SetParameterValue(Handle<ScopeInfo> scope_info, |
626 JavaScriptFrame* frame, | 621 JavaScriptFrame* frame, |
627 Handle<String> parameter_name, | 622 Handle<String> parameter_name, |
628 Handle<Object> new_value) { | 623 Handle<Object> new_value) { |
629 // Setting stack locals of optimized frames is not supported. | 624 // Setting stack locals of optimized frames is not supported. |
630 if (frame->is_optimized()) return false; | 625 if (frame->is_optimized()) return false; |
631 HandleScope scope(isolate_); | 626 HandleScope scope(isolate_); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 Handle<Object> value = Handle<Object>(context->get(context_index), isolate); | 777 Handle<Object> value = Handle<Object>(context->get(context_index), isolate); |
783 // Reflect variables under TDZ as undefined in scope object. | 778 // Reflect variables under TDZ as undefined in scope object. |
784 if (value->IsTheHole(isolate)) continue; | 779 if (value->IsTheHole(isolate)) continue; |
785 // This should always succeed. | 780 // This should always succeed. |
786 // TODO(verwaest): Use AddDataProperty instead. | 781 // TODO(verwaest): Use AddDataProperty instead. |
787 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) | 782 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) |
788 .Check(); | 783 .Check(); |
789 } | 784 } |
790 } | 785 } |
791 | 786 |
| 787 void ScopeIterator::CopyModuleVarsToScopeObject(Handle<ScopeInfo> scope_info, |
| 788 Handle<Context> context, |
| 789 Handle<JSObject> scope_object) { |
| 790 Isolate* isolate = scope_info->GetIsolate(); |
| 791 |
| 792 int module_variable_count = |
| 793 Smi::cast(scope_info->get(scope_info->ModuleVariableCountIndex())) |
| 794 ->value(); |
| 795 for (int i = 0; i < module_variable_count; ++i) { |
| 796 Handle<String> local_name; |
| 797 bool is_export; |
| 798 { |
| 799 String* name; |
| 800 int index; |
| 801 scope_info->ModuleVariable(i, &name, &index); |
| 802 CHECK(!ScopeInfo::VariableIsSynthetic(name)); |
| 803 local_name = handle(name, isolate); |
| 804 is_export = index == Variable::kModuleExportIndex; |
| 805 } |
| 806 |
| 807 Handle<Object> value; |
| 808 if (is_export) { |
| 809 value = |
| 810 Module::LoadExport(handle(context->module(), isolate), local_name); |
| 811 } else { |
| 812 Handle<ModuleInfo> module_info(scope_info->ModuleDescriptorInfo(), |
| 813 isolate); |
| 814 Handle<ModuleInfoEntry> entry = |
| 815 ModuleInfo::LookupRegularImport(module_info, local_name); |
| 816 Handle<String> import_name(String::cast(entry->import_name()), isolate); |
| 817 int module_request = Smi::cast(entry->module_request())->value(); |
| 818 value = Module::LoadImport(handle(context->module(), isolate), |
| 819 import_name, module_request); |
| 820 } |
| 821 |
| 822 // Reflect variables under TDZ as undefined in scope object. |
| 823 if (value->IsTheHole(isolate)) continue; |
| 824 // This should always succeed. |
| 825 // TODO(verwaest): Use AddDataProperty instead. |
| 826 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, local_name, value, |
| 827 NONE) |
| 828 .Check(); |
| 829 } |
| 830 } |
| 831 |
792 void ScopeIterator::CopyContextExtensionToScopeObject( | 832 void ScopeIterator::CopyContextExtensionToScopeObject( |
793 Handle<Context> context, Handle<JSObject> scope_object, | 833 Handle<Context> context, Handle<JSObject> scope_object, |
794 KeyCollectionMode mode) { | 834 KeyCollectionMode mode) { |
795 if (context->extension_object() == nullptr) return; | 835 if (context->extension_object() == nullptr) return; |
796 Handle<JSObject> extension(context->extension_object()); | 836 Handle<JSObject> extension(context->extension_object()); |
797 Handle<FixedArray> keys = | 837 Handle<FixedArray> keys = |
798 KeyAccumulator::GetKeys(extension, mode, ENUMERABLE_STRINGS) | 838 KeyAccumulator::GetKeys(extension, mode, ENUMERABLE_STRINGS) |
799 .ToHandleChecked(); | 839 .ToHandleChecked(); |
800 | 840 |
801 for (int i = 0; i < keys->length(); i++) { | 841 for (int i = 0; i < keys->length(); i++) { |
(...skipping 29 matching lines...) Expand all Loading... |
831 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 871 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
832 if (beg_pos <= position && position < end_pos) { | 872 if (beg_pos <= position && position < end_pos) { |
833 GetNestedScopeChain(isolate, inner_scope, position); | 873 GetNestedScopeChain(isolate, inner_scope, position); |
834 return; | 874 return; |
835 } | 875 } |
836 } | 876 } |
837 } | 877 } |
838 | 878 |
839 } // namespace internal | 879 } // namespace internal |
840 } // namespace v8 | 880 } // namespace v8 |
OLD | NEW |