| 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/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/compiler/ast-loop-assignment-analyzer.h" | 9 #include "src/compiler/ast-loop-assignment-analyzer.h" |
| 10 #include "src/compiler/control-builders.h" | 10 #include "src/compiler/control-builders.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 485 } |
| 486 | 486 |
| 487 | 487 |
| 488 Node* AstGraphBuilder::GetFunctionClosureForContext() { | 488 Node* AstGraphBuilder::GetFunctionClosureForContext() { |
| 489 Scope* closure_scope = current_scope()->ClosureScope(); | 489 Scope* closure_scope = current_scope()->ClosureScope(); |
| 490 if (closure_scope->is_script_scope() || | 490 if (closure_scope->is_script_scope() || |
| 491 closure_scope->is_module_scope()) { | 491 closure_scope->is_module_scope()) { |
| 492 // Contexts nested in the native context have a canonical empty function as | 492 // Contexts nested in the native context have a canonical empty function as |
| 493 // their closure, not the anonymous closure containing the global code. | 493 // their closure, not the anonymous closure containing the global code. |
| 494 return BuildLoadNativeContextField(Context::CLOSURE_INDEX); | 494 return BuildLoadNativeContextField(Context::CLOSURE_INDEX); |
| 495 } else if (closure_scope->is_eval_scope()) { |
| 496 // Contexts nested inside eval code have the same closure as the context |
| 497 // calling eval, not the anonymous closure containing the eval code. |
| 498 const Operator* op = |
| 499 javascript()->LoadContext(0, Context::CLOSURE_INDEX, false); |
| 500 return NewNode(op, current_context()); |
| 495 } else { | 501 } else { |
| 496 DCHECK(closure_scope->is_function_scope()); | 502 DCHECK(closure_scope->is_function_scope()); |
| 497 return GetFunctionClosure(); | 503 return GetFunctionClosure(); |
| 498 } | 504 } |
| 499 } | 505 } |
| 500 | 506 |
| 501 | 507 |
| 502 Node* AstGraphBuilder::GetFunctionClosure() { | 508 Node* AstGraphBuilder::GetFunctionClosure() { |
| 503 if (!function_closure_.is_set()) { | 509 if (!function_closure_.is_set()) { |
| 504 int index = Linkage::kJSCallClosureParamIndex; | 510 int index = Linkage::kJSCallClosureParamIndex; |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 } | 1108 } |
| 1103 break; | 1109 break; |
| 1104 case VariableLocation::CONTEXT: | 1110 case VariableLocation::CONTEXT: |
| 1105 if (hole_init) { | 1111 if (hole_init) { |
| 1106 Node* value = jsgraph()->TheHoleConstant(); | 1112 Node* value = jsgraph()->TheHoleConstant(); |
| 1107 const Operator* op = javascript()->StoreContext(0, variable->index()); | 1113 const Operator* op = javascript()->StoreContext(0, variable->index()); |
| 1108 NewNode(op, current_context(), value); | 1114 NewNode(op, current_context(), value); |
| 1109 } | 1115 } |
| 1110 break; | 1116 break; |
| 1111 case VariableLocation::LOOKUP: | 1117 case VariableLocation::LOOKUP: |
| 1112 UNIMPLEMENTED(); | 1118 // TODO(mstarzinger): Implement this case. |
| 1119 SetStackOverflow(); |
| 1120 break; |
| 1113 } | 1121 } |
| 1114 } | 1122 } |
| 1115 | 1123 |
| 1116 | 1124 |
| 1117 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 1125 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
| 1118 Variable* variable = decl->proxy()->var(); | 1126 Variable* variable = decl->proxy()->var(); |
| 1119 switch (variable->location()) { | 1127 switch (variable->location()) { |
| 1120 case VariableLocation::GLOBAL: | 1128 case VariableLocation::GLOBAL: |
| 1121 case VariableLocation::UNALLOCATED: { | 1129 case VariableLocation::UNALLOCATED: { |
| 1122 Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo( | 1130 Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1135 break; | 1143 break; |
| 1136 } | 1144 } |
| 1137 case VariableLocation::CONTEXT: { | 1145 case VariableLocation::CONTEXT: { |
| 1138 VisitForValue(decl->fun()); | 1146 VisitForValue(decl->fun()); |
| 1139 Node* value = environment()->Pop(); | 1147 Node* value = environment()->Pop(); |
| 1140 const Operator* op = javascript()->StoreContext(0, variable->index()); | 1148 const Operator* op = javascript()->StoreContext(0, variable->index()); |
| 1141 NewNode(op, current_context(), value); | 1149 NewNode(op, current_context(), value); |
| 1142 break; | 1150 break; |
| 1143 } | 1151 } |
| 1144 case VariableLocation::LOOKUP: | 1152 case VariableLocation::LOOKUP: |
| 1145 UNIMPLEMENTED(); | 1153 // TODO(mstarzinger): Implement this case. |
| 1154 SetStackOverflow(); |
| 1155 break; |
| 1146 } | 1156 } |
| 1147 } | 1157 } |
| 1148 | 1158 |
| 1149 | 1159 |
| 1150 void AstGraphBuilder::VisitImportDeclaration(ImportDeclaration* decl) { | 1160 void AstGraphBuilder::VisitImportDeclaration(ImportDeclaration* decl) { |
| 1151 UNREACHABLE(); | 1161 UNREACHABLE(); |
| 1152 } | 1162 } |
| 1153 | 1163 |
| 1154 | 1164 |
| 1155 void AstGraphBuilder::VisitExportDeclaration(ExportDeclaration* decl) { | 1165 void AstGraphBuilder::VisitExportDeclaration(ExportDeclaration* decl) { |
| (...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3178 DCHECK_EQ(0, scope->ContextChainLength(variable->scope())); | 3188 DCHECK_EQ(0, scope->ContextChainLength(variable->scope())); |
| 3179 const Operator* op = javascript()->StoreContext(0, variable->index()); | 3189 const Operator* op = javascript()->StoreContext(0, variable->index()); |
| 3180 NewNode(op, local_context, parameter); | 3190 NewNode(op, local_context, parameter); |
| 3181 } | 3191 } |
| 3182 | 3192 |
| 3183 return local_context; | 3193 return local_context; |
| 3184 } | 3194 } |
| 3185 | 3195 |
| 3186 | 3196 |
| 3187 Node* AstGraphBuilder::BuildLocalFunctionContext(Scope* scope) { | 3197 Node* AstGraphBuilder::BuildLocalFunctionContext(Scope* scope) { |
| 3188 DCHECK(scope->is_function_scope()); | 3198 DCHECK(scope->is_function_scope() || scope->is_eval_scope()); |
| 3189 | 3199 |
| 3190 // Allocate a new local context. | 3200 // Allocate a new local context. |
| 3191 int slot_count = scope->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 3201 int slot_count = scope->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 3192 const Operator* op = javascript()->CreateFunctionContext(slot_count); | 3202 const Operator* op = javascript()->CreateFunctionContext(slot_count); |
| 3193 Node* local_context = NewNode(op, GetFunctionClosure()); | 3203 Node* local_context = NewNode(op, GetFunctionClosure()); |
| 3194 | 3204 |
| 3195 return local_context; | 3205 return local_context; |
| 3196 } | 3206 } |
| 3197 | 3207 |
| 3198 | 3208 |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4335 // Phi does not exist yet, introduce one. | 4345 // Phi does not exist yet, introduce one. |
| 4336 value = NewPhi(inputs, value, control); | 4346 value = NewPhi(inputs, value, control); |
| 4337 value->ReplaceInput(inputs - 1, other); | 4347 value->ReplaceInput(inputs - 1, other); |
| 4338 } | 4348 } |
| 4339 return value; | 4349 return value; |
| 4340 } | 4350 } |
| 4341 | 4351 |
| 4342 } // namespace compiler | 4352 } // namespace compiler |
| 4343 } // namespace internal | 4353 } // namespace internal |
| 4344 } // namespace v8 | 4354 } // namespace v8 |
| OLD | NEW |