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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1960 if (mode == CONST_LEGACY && op == Token::INIT) { | 1960 if (mode == CONST_LEGACY && op == Token::INIT) { |
1961 // Perform an intialization check for legacy constants. | 1961 // Perform an intialization check for legacy constants. |
1962 builder() | 1962 builder() |
1963 ->JumpIfNotHole(&end_label) | 1963 ->JumpIfNotHole(&end_label) |
1964 .MoveRegister(value_temp, destination) | 1964 .MoveRegister(value_temp, destination) |
1965 .Bind(&end_label) | 1965 .Bind(&end_label) |
1966 .LoadAccumulatorWithRegister(value_temp); | 1966 .LoadAccumulatorWithRegister(value_temp); |
1967 // Break here because the value should not be stored unconditionally. | 1967 // Break here because the value should not be stored unconditionally. |
1968 break; | 1968 break; |
1969 } else if (mode == CONST_LEGACY && op != Token::INIT) { | 1969 } else if (mode == CONST_LEGACY && op != Token::INIT) { |
1970 DCHECK(!is_strict(language_mode())); | 1970 if (is_strict(language_mode())) { |
1971 // Ensure accumulator is in the correct state. | 1971 builder()->CallRuntime(Runtime::kThrowConstAssignError, Register(), |
1972 builder()->LoadAccumulatorWithRegister(value_temp); | 1972 0); |
1973 // Break here, non-initializing assignments to legacy constants are | 1973 } else { |
1974 // ignored. | 1974 // Ensure accumulator is in the correct state. |
1975 builder()->LoadAccumulatorWithRegister(value_temp); | |
1976 } | |
1977 // Non-initializing assignments to legacy constants are ignored | |
1978 // in sloppy mode. Break here to avoid storing into variable. | |
1975 break; | 1979 break; |
1976 } else { | 1980 } else { |
1977 BuildHoleCheckForVariableAssignment(variable, op); | 1981 BuildHoleCheckForVariableAssignment(variable, op); |
1978 builder()->LoadAccumulatorWithRegister(value_temp); | 1982 builder()->LoadAccumulatorWithRegister(value_temp); |
1979 } | 1983 } |
1980 } | 1984 } |
1981 | 1985 |
1982 builder()->StoreAccumulatorInRegister(destination); | 1986 builder()->StoreAccumulatorInRegister(destination); |
1983 break; | 1987 break; |
1984 } | 1988 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2027 builder() | 2031 builder() |
2028 ->JumpIfNotHole(&end_label) | 2032 ->JumpIfNotHole(&end_label) |
2029 .LoadAccumulatorWithRegister(value_temp) | 2033 .LoadAccumulatorWithRegister(value_temp) |
2030 .StoreContextSlot(context_reg, variable->index()) | 2034 .StoreContextSlot(context_reg, variable->index()) |
2031 .Bind(&end_label); | 2035 .Bind(&end_label); |
2032 builder()->LoadAccumulatorWithRegister(value_temp); | 2036 builder()->LoadAccumulatorWithRegister(value_temp); |
2033 // Break here because the value should not be stored unconditionally. | 2037 // Break here because the value should not be stored unconditionally. |
2034 // The above code performs the store conditionally. | 2038 // The above code performs the store conditionally. |
2035 break; | 2039 break; |
2036 } else if (mode == CONST_LEGACY && op != Token::INIT) { | 2040 } else if (mode == CONST_LEGACY && op != Token::INIT) { |
2037 DCHECK(!is_strict(language_mode())); | 2041 if (is_strict(language_mode())) { |
2038 // Ensure accumulator is in the correct state. | 2042 builder()->CallRuntime(Runtime::kThrowConstAssignError, Register(), |
2039 builder()->LoadAccumulatorWithRegister(value_temp); | 2043 0); |
2040 // Break here, non-initializing assignments to legacy constants are | 2044 } else { |
2041 // ignored. | 2045 // Ensure accumulator is in the correct state. |
2046 builder()->LoadAccumulatorWithRegister(value_temp); | |
2047 } | |
2048 // Non-initializing assignments to legacy constants are ignored | |
2049 // in sloppy mode. Break hear to avoid storing into variable. | |
rmcilroy
2016/04/05 08:44:21
/s/hear/here
mythria
2016/04/11 10:10:05
Done.
| |
2042 break; | 2050 break; |
2043 } else { | 2051 } else { |
2044 BuildHoleCheckForVariableAssignment(variable, op); | 2052 BuildHoleCheckForVariableAssignment(variable, op); |
2045 builder()->LoadAccumulatorWithRegister(value_temp); | 2053 builder()->LoadAccumulatorWithRegister(value_temp); |
2046 } | 2054 } |
2047 } | 2055 } |
2048 | 2056 |
2049 builder()->StoreContextSlot(context_reg, variable->index()); | 2057 builder()->StoreContextSlot(context_reg, variable->index()); |
2050 break; | 2058 break; |
2051 } | 2059 } |
2052 case VariableLocation::LOOKUP: { | 2060 case VariableLocation::LOOKUP: { |
2053 if (mode == CONST_LEGACY && op == Token::INIT) { | 2061 if (mode == CONST_LEGACY && op == Token::INIT) { |
2054 register_allocator()->PrepareForConsecutiveAllocations(3); | 2062 register_allocator()->PrepareForConsecutiveAllocations(3); |
2055 Register value = register_allocator()->NextConsecutiveRegister(); | 2063 Register value = register_allocator()->NextConsecutiveRegister(); |
2056 Register context = register_allocator()->NextConsecutiveRegister(); | 2064 Register context = register_allocator()->NextConsecutiveRegister(); |
2057 Register name = register_allocator()->NextConsecutiveRegister(); | 2065 Register name = register_allocator()->NextConsecutiveRegister(); |
2058 | 2066 |
2059 // InitializeLegacyConstLookupSlot runtime call returns the 'value' | 2067 // InitializeLegacyConstLookupSlot runtime call returns the 'value' |
2060 // passed to it. So, accumulator will have its original contents when | 2068 // passed to it. So, accumulator will have its original contents when |
2061 // runtime call returns. | 2069 // runtime call returns. |
2062 builder() | 2070 builder() |
2063 ->StoreAccumulatorInRegister(value) | 2071 ->StoreAccumulatorInRegister(value) |
2064 .MoveRegister(execution_context()->reg(), context) | 2072 .MoveRegister(execution_context()->reg(), context) |
2065 .LoadLiteral(variable->name()) | 2073 .LoadLiteral(variable->name()) |
2066 .StoreAccumulatorInRegister(name) | 2074 .StoreAccumulatorInRegister(name) |
2067 .CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, value, 3); | 2075 .CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, value, 3); |
2068 } else if (mode == CONST_LEGACY && op != Token::INIT) { | 2076 } else if (mode == CONST_LEGACY && op != Token::INIT) { |
2069 // Non-intializing assignments to legacy constants are ignored. | 2077 // Non-intializing assignments to legacy constants are ignored in sloppy |
2070 DCHECK(!is_strict(language_mode())); | 2078 // mode and throws TypeError in strict mode. |
2079 if (is_strict(language_mode())) { | |
Michael Starzinger
2016/04/04 12:02:24
nit: The Runtime_StoreLookupSlot_[Strict|Sloppy] m
mythria
2016/04/11 10:10:05
Done.
| |
2080 builder()->CallRuntime(Runtime::kThrowConstAssignError, Register(), | |
2081 0); | |
2082 } | |
2071 } else { | 2083 } else { |
2072 builder()->StoreLookupSlot(variable->name(), language_mode()); | 2084 builder()->StoreLookupSlot(variable->name(), language_mode()); |
2073 } | 2085 } |
2074 break; | 2086 break; |
2075 } | 2087 } |
2076 } | 2088 } |
2077 } | 2089 } |
2078 | 2090 |
2079 | 2091 |
2080 void BytecodeGenerator::VisitAssignment(Assignment* expr) { | 2092 void BytecodeGenerator::VisitAssignment(Assignment* expr) { |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3147 } | 3159 } |
3148 | 3160 |
3149 | 3161 |
3150 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3162 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3151 return info()->feedback_vector()->GetIndex(slot); | 3163 return info()->feedback_vector()->GetIndex(slot); |
3152 } | 3164 } |
3153 | 3165 |
3154 } // namespace interpreter | 3166 } // namespace interpreter |
3155 } // namespace internal | 3167 } // namespace internal |
3156 } // namespace v8 | 3168 } // namespace v8 |
OLD | NEW |