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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 2375793002: Reland: [modules] Properly initialize declared variables. (Closed)
Patch Set: Update CompilerHints. Created 4 years, 2 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
« no previous file with comments | « src/globals.h ('k') | src/objects.h » ('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 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/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/compile-time-value.h" 7 #include "src/ast/compile-time-value.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/compilation-info.h" 10 #include "src/compilation-info.h"
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 925
926 Register name = register_allocator()->NewRegister(); 926 Register name = register_allocator()->NewRegister();
927 927
928 builder() 928 builder()
929 ->LoadLiteral(variable->name()) 929 ->LoadLiteral(variable->name())
930 .StoreAccumulatorInRegister(name) 930 .StoreAccumulatorInRegister(name)
931 .CallRuntime(Runtime::kDeclareEvalVar, name, 1); 931 .CallRuntime(Runtime::kDeclareEvalVar, name, 1);
932 break; 932 break;
933 } 933 }
934 case VariableLocation::MODULE: 934 case VariableLocation::MODULE:
935 // Nothing to do here. 935 if (variable->IsExport() && variable->binding_needs_init()) {
936 builder()->LoadTheHole();
937 VisitVariableAssignment(variable, Token::INIT,
938 FeedbackVectorSlot::Invalid());
939 }
940 // Nothing to do for imports.
936 break; 941 break;
937 } 942 }
938 } 943 }
939 944
940 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { 945 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) {
941 Variable* variable = decl->proxy()->var(); 946 Variable* variable = decl->proxy()->var();
942 DCHECK(variable->mode() == LET || variable->mode() == VAR); 947 DCHECK(variable->mode() == LET || variable->mode() == VAR);
943 switch (variable->location()) { 948 switch (variable->location()) {
944 case VariableLocation::UNALLOCATED: { 949 case VariableLocation::UNALLOCATED: {
945 FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot(); 950 FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot();
(...skipping 19 matching lines...) Expand all
965 Register name = register_allocator()->NextConsecutiveRegister(); 970 Register name = register_allocator()->NextConsecutiveRegister();
966 Register literal = register_allocator()->NextConsecutiveRegister(); 971 Register literal = register_allocator()->NextConsecutiveRegister();
967 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); 972 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name);
968 973
969 VisitForAccumulatorValue(decl->fun()); 974 VisitForAccumulatorValue(decl->fun());
970 builder()->StoreAccumulatorInRegister(literal).CallRuntime( 975 builder()->StoreAccumulatorInRegister(literal).CallRuntime(
971 Runtime::kDeclareEvalFunction, name, 2); 976 Runtime::kDeclareEvalFunction, name, 2);
972 break; 977 break;
973 } 978 }
974 case VariableLocation::MODULE: 979 case VariableLocation::MODULE:
975 DCHECK(variable->mode() == LET); 980 DCHECK_EQ(variable->mode(), LET);
981 DCHECK(variable->IsExport());
976 VisitForAccumulatorValue(decl->fun()); 982 VisitForAccumulatorValue(decl->fun());
977 VisitVariableAssignment(variable, Token::INIT, 983 VisitVariableAssignment(variable, Token::INIT,
978 FeedbackVectorSlot::Invalid()); 984 FeedbackVectorSlot::Invalid());
979 break; 985 break;
980 } 986 }
981 } 987 }
982 988
983 void BytecodeGenerator::VisitDeclarations( 989 void BytecodeGenerator::VisitDeclarations(
984 ZoneList<Declaration*>* declarations) { 990 ZoneList<Declaration*>* declarations) {
985 RegisterAllocationScope register_scope(this); 991 RegisterAllocationScope register_scope(this);
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 Register import_name = register_allocator()->NextConsecutiveRegister(); 2017 Register import_name = register_allocator()->NextConsecutiveRegister();
2012 Register module_request = 2018 Register module_request =
2013 register_allocator()->NextConsecutiveRegister(); 2019 register_allocator()->NextConsecutiveRegister();
2014 builder() 2020 builder()
2015 ->LoadLiteral(it->second->import_name->string()) 2021 ->LoadLiteral(it->second->import_name->string())
2016 .StoreAccumulatorInRegister(import_name) 2022 .StoreAccumulatorInRegister(import_name)
2017 .LoadLiteral(Smi::FromInt(it->second->module_request)) 2023 .LoadLiteral(Smi::FromInt(it->second->module_request))
2018 .StoreAccumulatorInRegister(module_request) 2024 .StoreAccumulatorInRegister(module_request)
2019 .CallRuntime(Runtime::kLoadModuleImport, import_name, 2); 2025 .CallRuntime(Runtime::kLoadModuleImport, import_name, 2);
2020 } 2026 }
2027 BuildHoleCheckForVariableLoad(variable);
2021 break; 2028 break;
2022 } 2029 }
2023 } 2030 }
2024 execution_result()->SetResultInAccumulator(); 2031 execution_result()->SetResultInAccumulator();
2025 } 2032 }
2026 2033
2027 void BytecodeGenerator::VisitVariableLoadForAccumulatorValue( 2034 void BytecodeGenerator::VisitVariableLoadForAccumulatorValue(
2028 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) { 2035 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) {
2029 AccumulatorResultScope accumulator_result(this); 2036 AccumulatorResultScope accumulator_result(this);
2030 VisitVariableLoad(variable, slot, typeof_mode); 2037 VisitVariableLoad(variable, slot, typeof_mode);
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3463 return execution_context()->scope()->language_mode(); 3470 return execution_context()->scope()->language_mode();
3464 } 3471 }
3465 3472
3466 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 3473 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
3467 return TypeFeedbackVector::GetIndex(slot); 3474 return TypeFeedbackVector::GetIndex(slot);
3468 } 3475 }
3469 3476
3470 } // namespace interpreter 3477 } // namespace interpreter
3471 } // namespace internal 3478 } // namespace internal
3472 } // namespace v8 3479 } // namespace v8
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698