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

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: Comment update Created 6 years 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/compiler/ast-graph-builder.h ('k') | src/full-codegen.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 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 2002 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) {
2017 // Perform an initialization check for legacy const variables. 2017 // Perform an initialization check for legacy const variables.
2018 Node* current = environment()->Lookup(variable); 2018 Node* current = environment()->Lookup(variable);
2019 if (current->op() != the_hole->op()) { 2019 if (current->op() != the_hole->op()) {
2020 value = BuildHoleCheckSilent(current, value, current); 2020 value = BuildHoleCheckSilent(current, value, current);
2021 } 2021 }
2022 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { 2022 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
2023 // Non-initializing assignments to legacy const is ignored. 2023 // Non-initializing assignments to legacy const is
2024 // - exception in strict mode.
2025 // - ignored in sloppy mode.
2026 if (strict_mode() == STRICT) {
2027 return BuildThrowConstAssignError(bailout_id);
2028 }
2024 return value; 2029 return value;
2025 } else if (mode == LET && op != Token::INIT_LET) { 2030 } else if (mode == LET && op != Token::INIT_LET) {
2026 // Perform an initialization check for let declared variables. 2031 // Perform an initialization check for let declared variables.
2027 // Also note that the dynamic hole-check is only done to ensure that 2032 // 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 2033 // this does not break in the presence of do-expressions within the
2029 // temporal dead zone of a let declared variable. 2034 // temporal dead zone of a let declared variable.
2030 Node* current = environment()->Lookup(variable); 2035 Node* current = environment()->Lookup(variable);
2031 if (current->op() == the_hole->op()) { 2036 if (current->op() == the_hole->op()) {
2032 value = BuildThrowReferenceError(variable, bailout_id); 2037 value = BuildThrowReferenceError(variable, bailout_id);
2033 } else if (value->opcode() == IrOpcode::kPhi) { 2038 } else if (value->opcode() == IrOpcode::kPhi) {
2034 value = BuildHoleCheckThrow(current, variable, value, bailout_id); 2039 value = BuildHoleCheckThrow(current, variable, value, bailout_id);
2035 } 2040 }
2036 } else if (mode == CONST && op != Token::INIT_CONST) { 2041 } else if (mode == CONST && op != Token::INIT_CONST) {
2037 // All assignments to const variables are early errors. 2042 // Non-initializing assignments to const is exception in all modes.
2038 UNREACHABLE(); 2043 return BuildThrowConstAssignError(bailout_id);
2039 } 2044 }
2040 environment()->Bind(variable, value); 2045 environment()->Bind(variable, value);
2041 return value; 2046 return value;
2042 case Variable::CONTEXT: { 2047 case Variable::CONTEXT: {
2043 // Context variable (potentially up the context chain). 2048 // Context variable (potentially up the context chain).
2044 int depth = current_scope()->ContextChainLength(variable->scope()); 2049 int depth = current_scope()->ContextChainLength(variable->scope());
2045 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { 2050 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) {
2046 // Perform an initialization check for legacy const variables. 2051 // Perform an initialization check for legacy const variables.
2047 const Operator* op = 2052 const Operator* op =
2048 javascript()->LoadContext(depth, variable->index(), false); 2053 javascript()->LoadContext(depth, variable->index(), false);
2049 Node* current = NewNode(op, current_context()); 2054 Node* current = NewNode(op, current_context());
2050 value = BuildHoleCheckSilent(current, value, current); 2055 value = BuildHoleCheckSilent(current, value, current);
2051 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { 2056 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
2052 // Non-initializing assignments to legacy const is ignored. 2057 // Non-initializing assignments to legacy const is
2058 // - exception in strict mode.
2059 // - ignored in sloppy mode.
2060 if (strict_mode() == STRICT) {
2061 return BuildThrowConstAssignError(bailout_id);
2062 }
2053 return value; 2063 return value;
2054 } else if (mode == LET && op != Token::INIT_LET) { 2064 } else if (mode == LET && op != Token::INIT_LET) {
2055 // Perform an initialization check for let declared variables. 2065 // Perform an initialization check for let declared variables.
2056 const Operator* op = 2066 const Operator* op =
2057 javascript()->LoadContext(depth, variable->index(), false); 2067 javascript()->LoadContext(depth, variable->index(), false);
2058 Node* current = NewNode(op, current_context()); 2068 Node* current = NewNode(op, current_context());
2059 value = BuildHoleCheckThrow(current, variable, value, bailout_id); 2069 value = BuildHoleCheckThrow(current, variable, value, bailout_id);
2060 } else if (mode == CONST && op != Token::INIT_CONST) { 2070 } else if (mode == CONST && op != Token::INIT_CONST) {
2061 // All assignments to const variables are early errors. 2071 // Non-initializing assignments to const is exception in all modes.
2062 UNREACHABLE(); 2072 return BuildThrowConstAssignError(bailout_id);
2063 } 2073 }
2064 const Operator* op = javascript()->StoreContext(depth, variable->index()); 2074 const Operator* op = javascript()->StoreContext(depth, variable->index());
2065 return NewNode(op, current_context(), value); 2075 return NewNode(op, current_context(), value);
2066 } 2076 }
2067 case Variable::LOOKUP: { 2077 case Variable::LOOKUP: {
2068 // Dynamic lookup of context variable (anywhere in the chain). 2078 // Dynamic lookup of context variable (anywhere in the chain).
2069 Node* name = jsgraph()->Constant(variable->name()); 2079 Node* name = jsgraph()->Constant(variable->name());
2070 Node* strict = jsgraph()->Constant(strict_mode()); 2080 Node* strict = jsgraph()->Constant(strict_mode());
2071 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for 2081 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for
2072 // initializations of const declarations. 2082 // 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. 2156 // TODO(mstarzinger): Should be unified with the VisitThrow implementation.
2147 Node* variable_name = jsgraph()->Constant(variable->name()); 2157 Node* variable_name = jsgraph()->Constant(variable->name());
2148 const Operator* op = 2158 const Operator* op =
2149 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1); 2159 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1);
2150 Node* call = NewNode(op, variable_name); 2160 Node* call = NewNode(op, variable_name);
2151 PrepareFrameState(call, bailout_id); 2161 PrepareFrameState(call, bailout_id);
2152 return call; 2162 return call;
2153 } 2163 }
2154 2164
2155 2165
2166 Node* AstGraphBuilder::BuildThrowConstAssignError(BailoutId bailout_id) {
2167 // TODO(mstarzinger): Should be unified with the VisitThrow implementation.
2168 const Operator* op =
2169 javascript()->CallRuntime(Runtime::kThrowConstAssignError, 0);
2170 Node* call = NewNode(op);
2171 PrepareFrameState(call, bailout_id);
2172 return call;
2173 }
2174
2175
2156 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) { 2176 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) {
2157 const Operator* js_op; 2177 const Operator* js_op;
2158 switch (op) { 2178 switch (op) {
2159 case Token::BIT_OR: 2179 case Token::BIT_OR:
2160 js_op = javascript()->BitwiseOr(); 2180 js_op = javascript()->BitwiseOr();
2161 break; 2181 break;
2162 case Token::BIT_AND: 2182 case Token::BIT_AND:
2163 js_op = javascript()->BitwiseAnd(); 2183 js_op = javascript()->BitwiseAnd();
2164 break; 2184 break;
2165 case Token::BIT_XOR: 2185 case Token::BIT_XOR:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2248
2229 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( 2249 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop(
2230 IterationStatement* stmt) { 2250 IterationStatement* stmt) {
2231 if (loop_assignment_analysis_ == NULL) return NULL; 2251 if (loop_assignment_analysis_ == NULL) return NULL;
2232 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); 2252 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt);
2233 } 2253 }
2234 2254
2235 } // namespace compiler 2255 } // namespace compiler
2236 } // namespace internal 2256 } // namespace internal
2237 } // namespace v8 2257 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/full-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698