OLD | NEW |
---|---|
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 Loading... | |
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 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) { |
rossberg
2014/11/26 08:31:46
Why not merge this case with the above?
Dmitry Lomov (no reviews)
2014/11/26 08:52:32
And extract the condition into IsNonInitializingAs
Dmitry Lomov (no reviews)
2014/11/26 10:30:56
Actually, I realized that we also decided that non
| |
2037 // All assignments to const variables are early errors. | 2042 // Non-initializing assignments to const is |
2038 UNREACHABLE(); | 2043 // - exception in strict mode. |
2044 // - ignored in sloppy mode. | |
2045 if (strict_mode() == STRICT) { | |
2046 return BuildThrowConstAssignError(bailout_id); | |
2047 } | |
2048 return value; | |
2039 } | 2049 } |
2040 environment()->Bind(variable, value); | 2050 environment()->Bind(variable, value); |
2041 return value; | 2051 return value; |
2042 case Variable::CONTEXT: { | 2052 case Variable::CONTEXT: { |
2043 // Context variable (potentially up the context chain). | 2053 // Context variable (potentially up the context chain). |
2044 int depth = current_scope()->ContextChainLength(variable->scope()); | 2054 int depth = current_scope()->ContextChainLength(variable->scope()); |
2045 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { | 2055 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { |
2046 // Perform an initialization check for legacy const variables. | 2056 // Perform an initialization check for legacy const variables. |
2047 const Operator* op = | 2057 const Operator* op = |
2048 javascript()->LoadContext(depth, variable->index(), false); | 2058 javascript()->LoadContext(depth, variable->index(), false); |
2049 Node* current = NewNode(op, current_context()); | 2059 Node* current = NewNode(op, current_context()); |
2050 value = BuildHoleCheckSilent(current, value, current); | 2060 value = BuildHoleCheckSilent(current, value, current); |
2051 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { | 2061 } else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) { |
2052 // Non-initializing assignments to legacy const is ignored. | 2062 // Non-initializing assignments to const is |
2063 // - exception in strict mode. | |
2064 // - ignored in sloppy mode. | |
2065 if (strict_mode() == STRICT) { | |
2066 return BuildThrowConstAssignError(bailout_id); | |
2067 } | |
2053 return value; | 2068 return value; |
2054 } else if (mode == LET && op != Token::INIT_LET) { | 2069 } else if (mode == LET && op != Token::INIT_LET) { |
2055 // Perform an initialization check for let declared variables. | 2070 // Perform an initialization check for let declared variables. |
2056 const Operator* op = | 2071 const Operator* op = |
2057 javascript()->LoadContext(depth, variable->index(), false); | 2072 javascript()->LoadContext(depth, variable->index(), false); |
2058 Node* current = NewNode(op, current_context()); | 2073 Node* current = NewNode(op, current_context()); |
2059 value = BuildHoleCheckThrow(current, variable, value, bailout_id); | 2074 value = BuildHoleCheckThrow(current, variable, value, bailout_id); |
2060 } else if (mode == CONST && op != Token::INIT_CONST) { | 2075 } else if (mode == CONST && op != Token::INIT_CONST) { |
rossberg
2014/11/26 08:31:46
Same here.
| |
2061 // All assignments to const variables are early errors. | 2076 // Non-initializing assignments to const is |
2062 UNREACHABLE(); | 2077 // - exception in strict mode. |
2078 // - ignored in sloppy mode. | |
2079 if (strict_mode() == STRICT) { | |
2080 return BuildThrowConstAssignError(bailout_id); | |
2081 } | |
2082 return value; | |
2063 } | 2083 } |
2064 const Operator* op = javascript()->StoreContext(depth, variable->index()); | 2084 const Operator* op = javascript()->StoreContext(depth, variable->index()); |
2065 return NewNode(op, current_context(), value); | 2085 return NewNode(op, current_context(), value); |
2066 } | 2086 } |
2067 case Variable::LOOKUP: { | 2087 case Variable::LOOKUP: { |
2068 // Dynamic lookup of context variable (anywhere in the chain). | 2088 // Dynamic lookup of context variable (anywhere in the chain). |
2069 Node* name = jsgraph()->Constant(variable->name()); | 2089 Node* name = jsgraph()->Constant(variable->name()); |
2070 Node* strict = jsgraph()->Constant(strict_mode()); | 2090 Node* strict = jsgraph()->Constant(strict_mode()); |
2071 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for | 2091 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for |
2072 // initializations of const declarations. | 2092 // initializations of const declarations. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2146 // TODO(mstarzinger): Should be unified with the VisitThrow implementation. | 2166 // TODO(mstarzinger): Should be unified with the VisitThrow implementation. |
2147 Node* variable_name = jsgraph()->Constant(variable->name()); | 2167 Node* variable_name = jsgraph()->Constant(variable->name()); |
2148 const Operator* op = | 2168 const Operator* op = |
2149 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1); | 2169 javascript()->CallRuntime(Runtime::kThrowReferenceError, 1); |
2150 Node* call = NewNode(op, variable_name); | 2170 Node* call = NewNode(op, variable_name); |
2151 PrepareFrameState(call, bailout_id); | 2171 PrepareFrameState(call, bailout_id); |
2152 return call; | 2172 return call; |
2153 } | 2173 } |
2154 | 2174 |
2155 | 2175 |
2176 Node* AstGraphBuilder::BuildThrowConstAssignError(BailoutId bailout_id) { | |
2177 // TODO(mstarzinger): Should be unified with the VisitThrow implementation. | |
2178 const Operator* op = | |
2179 javascript()->CallRuntime(Runtime::kThrowConstAssignError, 0); | |
2180 Node* call = NewNode(op); | |
2181 PrepareFrameState(call, bailout_id); | |
2182 return call; | |
2183 } | |
2184 | |
2185 | |
2156 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) { | 2186 Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) { |
2157 const Operator* js_op; | 2187 const Operator* js_op; |
2158 switch (op) { | 2188 switch (op) { |
2159 case Token::BIT_OR: | 2189 case Token::BIT_OR: |
2160 js_op = javascript()->BitwiseOr(); | 2190 js_op = javascript()->BitwiseOr(); |
2161 break; | 2191 break; |
2162 case Token::BIT_AND: | 2192 case Token::BIT_AND: |
2163 js_op = javascript()->BitwiseAnd(); | 2193 js_op = javascript()->BitwiseAnd(); |
2164 break; | 2194 break; |
2165 case Token::BIT_XOR: | 2195 case Token::BIT_XOR: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2228 | 2258 |
2229 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( | 2259 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( |
2230 IterationStatement* stmt) { | 2260 IterationStatement* stmt) { |
2231 if (loop_assignment_analysis_ == NULL) return NULL; | 2261 if (loop_assignment_analysis_ == NULL) return NULL; |
2232 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); | 2262 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); |
2233 } | 2263 } |
2234 | 2264 |
2235 } // namespace compiler | 2265 } // namespace compiler |
2236 } // namespace internal | 2266 } // namespace internal |
2237 } // namespace v8 | 2267 } // namespace v8 |
OLD | NEW |