OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 2921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2932 descriptor.scope = scope(); | 2932 descriptor.scope = scope(); |
2933 descriptor.hoist_scope = nullptr; | 2933 descriptor.hoist_scope = nullptr; |
2934 descriptor.mode = LET; | 2934 descriptor.mode = LET; |
2935 descriptor.declaration_pos = parameter.pattern->position(); | 2935 descriptor.declaration_pos = parameter.pattern->position(); |
2936 // The position that will be used by the AssignmentExpression | 2936 // The position that will be used by the AssignmentExpression |
2937 // which copies from the temp parameter to the pattern. | 2937 // which copies from the temp parameter to the pattern. |
2938 // | 2938 // |
2939 // TODO(adamk): Should this be kNoSourcePosition, since | 2939 // TODO(adamk): Should this be kNoSourcePosition, since |
2940 // it's just copying from a temp var to the real param var? | 2940 // it's just copying from a temp var to the real param var? |
2941 descriptor.initialization_pos = parameter.pattern->position(); | 2941 descriptor.initialization_pos = parameter.pattern->position(); |
2942 // The initializer position which will end up in, | |
2943 // Variable::initializer_position(), used for hole check elimination. | |
2944 int initializer_position = parameter.pattern->position(); | |
2945 Expression* initial_value = | 2942 Expression* initial_value = |
2946 factory()->NewVariableProxy(parameters.scope->parameter(i)); | 2943 factory()->NewVariableProxy(parameters.scope->parameter(i)); |
2947 if (parameter.initializer != nullptr) { | 2944 if (parameter.initializer != nullptr) { |
2948 // IS_UNDEFINED($param) ? initializer : $param | 2945 // IS_UNDEFINED($param) ? initializer : $param |
2949 | 2946 |
2950 // Ensure initializer is rewritten | 2947 // Ensure initializer is rewritten |
2951 RewriteParameterInitializer(parameter.initializer, scope()); | 2948 RewriteParameterInitializer(parameter.initializer, scope()); |
2952 | 2949 |
2953 auto condition = factory()->NewCompareOperation( | 2950 auto condition = factory()->NewCompareOperation( |
2954 Token::EQ_STRICT, | 2951 Token::EQ_STRICT, |
2955 factory()->NewVariableProxy(parameters.scope->parameter(i)), | 2952 factory()->NewVariableProxy(parameters.scope->parameter(i)), |
2956 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); | 2953 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); |
2957 initial_value = factory()->NewConditional( | 2954 initial_value = factory()->NewConditional( |
2958 condition, parameter.initializer, initial_value, kNoSourcePosition); | 2955 condition, parameter.initializer, initial_value, kNoSourcePosition); |
2959 descriptor.initialization_pos = parameter.initializer->position(); | 2956 descriptor.initialization_pos = parameter.initializer->position(); |
2960 initializer_position = parameter.initializer_end_position; | |
2961 } | 2957 } |
2962 | 2958 |
2963 Scope* param_scope = scope(); | 2959 Scope* param_scope = scope(); |
2964 Block* param_block = init_block; | 2960 Block* param_block = init_block; |
2965 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) { | 2961 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) { |
2966 param_scope = NewVarblockScope(); | 2962 param_scope = NewVarblockScope(); |
2967 param_scope->set_start_position(descriptor.initialization_pos); | 2963 param_scope->set_start_position(descriptor.initialization_pos); |
2968 param_scope->set_end_position(parameter.initializer_end_position); | 2964 param_scope->set_end_position(parameter.initializer_end_position); |
2969 param_scope->RecordEvalCall(); | 2965 param_scope->RecordEvalCall(); |
2970 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 2966 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
2971 param_block->set_scope(param_scope); | 2967 param_block->set_scope(param_scope); |
2972 descriptor.hoist_scope = scope(); | 2968 descriptor.hoist_scope = scope(); |
2973 // Pass the appropriate scope in so that PatternRewriter can appropriately | 2969 // Pass the appropriate scope in so that PatternRewriter can appropriately |
2974 // rewrite inner initializers of the pattern to param_scope | 2970 // rewrite inner initializers of the pattern to param_scope |
2975 descriptor.scope = param_scope; | 2971 descriptor.scope = param_scope; |
2976 // Rewrite the outer initializer to point to param_scope | 2972 // Rewrite the outer initializer to point to param_scope |
2977 ReparentParameterExpressionScope(stack_limit(), initial_value, | 2973 ReparentParameterExpressionScope(stack_limit(), initial_value, |
2978 param_scope); | 2974 param_scope); |
2979 } | 2975 } |
2980 | 2976 |
2981 BlockState block_state(&scope_state_, param_scope); | 2977 BlockState block_state(&scope_state_, param_scope); |
2982 DeclarationParsingResult::Declaration decl( | 2978 DeclarationParsingResult::Declaration decl( |
2983 parameter.pattern, initializer_position, initial_value); | 2979 parameter.pattern, parameter.initializer_end_position, initial_value); |
2984 PatternRewriter::DeclareAndInitializeVariables( | 2980 PatternRewriter::DeclareAndInitializeVariables( |
2985 this, param_block, &descriptor, &decl, nullptr, CHECK_OK); | 2981 this, param_block, &descriptor, &decl, nullptr, CHECK_OK); |
2986 | 2982 |
2987 if (param_block != init_block) { | 2983 if (param_block != init_block) { |
2988 param_scope = block_state.FinalizedBlockScope(); | 2984 param_scope = block_state.FinalizedBlockScope(); |
2989 if (param_scope != nullptr) { | 2985 if (param_scope != nullptr) { |
2990 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 2986 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
2991 } | 2987 } |
2992 init_block->statements()->Add(param_block, zone()); | 2988 init_block->statements()->Add(param_block, zone()); |
2993 } | 2989 } |
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5446 | 5442 |
5447 return final_loop; | 5443 return final_loop; |
5448 } | 5444 } |
5449 | 5445 |
5450 #undef CHECK_OK | 5446 #undef CHECK_OK |
5451 #undef CHECK_OK_VOID | 5447 #undef CHECK_OK_VOID |
5452 #undef CHECK_FAILED | 5448 #undef CHECK_FAILED |
5453 | 5449 |
5454 } // namespace internal | 5450 } // namespace internal |
5455 } // namespace v8 | 5451 } // namespace v8 |
OLD | NEW |