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

Side by Side Diff: src/compiler/ast-graph-builder.cc

Issue 749633002: harmony-scoping: make assignment to 'const' a late error. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/ast-loop-assignment-analyzer.h" 8 #include "src/compiler/ast-loop-assignment-analyzer.h"
9 #include "src/compiler/control-builders.h" 9 #include "src/compiler/control-builders.h"
10 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 Node* global = BuildLoadGlobalObject(); 2006 Node* global = BuildLoadGlobalObject();
2007 Unique<Name> name = MakeUnique(variable->name()); 2007 Unique<Name> name = MakeUnique(variable->name());
2008 const Operator* op = javascript()->StoreNamed(strict_mode(), name); 2008 const Operator* op = javascript()->StoreNamed(strict_mode(), name);
2009 Node* store = NewNode(op, global, value); 2009 Node* store = NewNode(op, global, value);
2010 PrepareFrameState(store, bailout_id, combine); 2010 PrepareFrameState(store, bailout_id, combine);
2011 return store; 2011 return store;
2012 } 2012 }
2013 case Variable::PARAMETER: 2013 case Variable::PARAMETER:
2014 case Variable::LOCAL: 2014 case Variable::LOCAL:
2015 // Local var, const, or let variable. 2015 // Local var, const, or let variable.
2016 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { 2016 if (variable->IsSignallingAssignmentToConst(op, strict_mode())) {
rossberg 2014/11/25 15:23:36 I'm not sure I like this factorisation, since it b
Michael Starzinger 2014/11/25 15:48:35 Acknowledged. I would slightly prefer writing down
Dmitry Lomov (no reviews) 2014/11/25 15:51:01 I'd prefer to share logic with the backends. Michi
rossberg 2014/11/25 16:25:02 Well, sharing the logic would make sense if we did
Dmitry Lomov (no reviews) 2014/11/25 17:22:31 Yes I am quite sure there is a benefit in introduc
rossberg 2014/11/25 18:02:47 My point was: you could argue the same for a gazil
Dmitry Lomov (no reviews) 2014/11/25 18:37:26 Ok, if you honestly believe this is better.
2017 return BuildThrowConstAssignError(bailout_id);
2018 } else if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) {
2017 // Perform an initialization check for legacy const variables. 2019 // Perform an initialization check for legacy const variables.
2018 Node* current = environment()->Lookup(variable); 2020 Node* current = environment()->Lookup(variable);
2019 if (current->op() != the_hole->op()) { 2021 if (current->op() != the_hole->op()) {
2020 value = BuildHoleCheckSilent(current, value, current); 2022 value = BuildHoleCheckSilent(current, value, current);
2021 } 2023 }
2022 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { 2024 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
2023 // Non-initializing assignments to legacy const is ignored. 2025 // Non-initializing assignments to legacy const is ignored.
2024 return value; 2026 return value;
2025 } else if (mode == LET && op != Token::INIT_LET) { 2027 } else if (mode == LET && op != Token::INIT_LET) {
2026 // Perform an initialization check for let declared variables. 2028 // Perform an initialization check for let declared variables.
2027 // Also note that the dynamic hole-check is only done to ensure that 2029 // Also note that the dynamic hole-check is only done to ensure that
2028 // this does not break in the presence of do-expressions within the 2030 // this does not break in the presence of do-expressions within the
2029 // temporal dead zone of a let declared variable. 2031 // temporal dead zone of a let declared variable.
2030 Node* current = environment()->Lookup(variable); 2032 Node* current = environment()->Lookup(variable);
2031 if (current->op() == the_hole->op()) { 2033 if (current->op() == the_hole->op()) {
2032 value = BuildThrowReferenceError(variable, bailout_id); 2034 value = BuildThrowReferenceError(variable, bailout_id);
2033 } else if (value->opcode() == IrOpcode::kPhi) { 2035 } else if (value->opcode() == IrOpcode::kPhi) {
2034 value = BuildHoleCheckThrow(current, variable, value, bailout_id); 2036 value = BuildHoleCheckThrow(current, variable, value, bailout_id);
2035 } 2037 }
2036 } else if (mode == CONST && op != Token::INIT_CONST) {
2037 // All assignments to const variables are early errors.
2038 UNREACHABLE();
2039 } 2038 }
2040 environment()->Bind(variable, value); 2039 environment()->Bind(variable, value);
2041 return value; 2040 return value;
2042 case Variable::CONTEXT: { 2041 case Variable::CONTEXT: {
2043 // Context variable (potentially up the context chain). 2042 // Context variable (potentially up the context chain).
2044 int depth = current_scope()->ContextChainLength(variable->scope()); 2043 int depth = current_scope()->ContextChainLength(variable->scope());
2045 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { 2044 if (variable->IsSignallingAssignmentToConst(op, strict_mode())) {
rossberg 2014/11/25 15:23:36 Same here.
2045 return BuildThrowConstAssignError(bailout_id);
2046 } else if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) {
2046 // Perform an initialization check for legacy const variables. 2047 // Perform an initialization check for legacy const variables.
2047 const Operator* op = 2048 const Operator* op =
2048 javascript()->LoadContext(depth, variable->index(), false); 2049 javascript()->LoadContext(depth, variable->index(), false);
2049 Node* current = NewNode(op, current_context()); 2050 Node* current = NewNode(op, current_context());
2050 value = BuildHoleCheckSilent(current, value, current); 2051 value = BuildHoleCheckSilent(current, value, current);
2051 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { 2052 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
2052 // Non-initializing assignments to legacy const is ignored. 2053 // Non-initializing assignments to legacy const is ignored.
2053 return value; 2054 return value;
2054 } else if (mode == LET && op != Token::INIT_LET) { 2055 } else if (mode == LET && op != Token::INIT_LET) {
2055 // Perform an initialization check for let declared variables. 2056 // Perform an initialization check for let declared variables.
2056 const Operator* op = 2057 const Operator* op =
2057 javascript()->LoadContext(depth, variable->index(), false); 2058 javascript()->LoadContext(depth, variable->index(), false);
2058 Node* current = NewNode(op, current_context()); 2059 Node* current = NewNode(op, current_context());
2059 value = BuildHoleCheckThrow(current, variable, value, bailout_id); 2060 value = BuildHoleCheckThrow(current, variable, value, bailout_id);
2060 } else if (mode == CONST && op != Token::INIT_CONST) {
2061 // All assignments to const variables are early errors.
2062 UNREACHABLE();
2063 } 2061 }
2064 const Operator* op = javascript()->StoreContext(depth, variable->index()); 2062 const Operator* op = javascript()->StoreContext(depth, variable->index());
2065 return NewNode(op, current_context(), value); 2063 return NewNode(op, current_context(), value);
2066 } 2064 }
2067 case Variable::LOOKUP: { 2065 case Variable::LOOKUP: {
2068 // Dynamic lookup of context variable (anywhere in the chain). 2066 // Dynamic lookup of context variable (anywhere in the chain).
2069 Node* name = jsgraph()->Constant(variable->name()); 2067 Node* name = jsgraph()->Constant(variable->name());
2070 Node* strict = jsgraph()->Constant(strict_mode()); 2068 Node* strict = jsgraph()->Constant(strict_mode());
2071 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for 2069 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for
2072 // initializations of const declarations. 2070 // initializations of const declarations.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 // TODO(mstarzinger): Should be unified with the VisitThrow implementation. 2144 // TODO(mstarzinger): Should be unified with the VisitThrow implementation.
2147 Node* variable_name = jsgraph()->Constant(variable->name()); 2145 Node* variable_name = jsgraph()->Constant(variable->name());
2148 const Operator* op = 2146 const Operator* op =
2149 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1); 2147 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1);
2150 Node* call = NewNode(op, variable_name); 2148 Node* call = NewNode(op, variable_name);
2151 PrepareFrameState(call, bailout_id); 2149 PrepareFrameState(call, bailout_id);
2152 return call; 2150 return call;
2153 } 2151 }
2154 2152
2155 2153
2154 Node* AstGraphBuilder::BuildThrowConstAssignError(BailoutId bailout_id) {
2155 // TODO(mstarzinger): Should be unified with the VisitThrow implementation.
2156 const Operator* op =
2157 javascript()->CallRuntime(Runtime::kThrowConstAssignError, 0);
2158 Node* call = NewNode(op);
2159 PrepareFrameState(call, bailout_id);
2160 return call;
2161 }
2162
2163
2156 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) { 2164 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) {
2157 const Operator* js_op; 2165 const Operator* js_op;
2158 switch (op) { 2166 switch (op) {
2159 case Token::BIT_OR: 2167 case Token::BIT_OR:
2160 js_op = javascript()->BitwiseOr(); 2168 js_op = javascript()->BitwiseOr();
2161 break; 2169 break;
2162 case Token::BIT_AND: 2170 case Token::BIT_AND:
2163 js_op = javascript()->BitwiseAnd(); 2171 js_op = javascript()->BitwiseAnd();
2164 break; 2172 break;
2165 case Token::BIT_XOR: 2173 case Token::BIT_XOR:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2236
2229 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( 2237 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop(
2230 IterationStatement* stmt) { 2238 IterationStatement* stmt) {
2231 if (loop_assignment_analysis_ == NULL) return NULL; 2239 if (loop_assignment_analysis_ == NULL) return NULL;
2232 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); 2240 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt);
2233 } 2241 }
2234 2242
2235 } // namespace compiler 2243 } // namespace compiler
2236 } // namespace internal 2244 } // namespace internal
2237 } // namespace v8 2245 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/hydrogen.cc » ('j') | src/variables.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698