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 "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 4106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4117 bool is_rest = expr->IsSpread(); | 4117 bool is_rest = expr->IsSpread(); |
4118 if (is_rest) { | 4118 if (is_rest) { |
4119 expr = expr->AsSpread()->expression(); | 4119 expr = expr->AsSpread()->expression(); |
4120 parameters->has_rest = true; | 4120 parameters->has_rest = true; |
4121 } | 4121 } |
4122 if (parameters->is_simple) { | 4122 if (parameters->is_simple) { |
4123 parameters->is_simple = !is_rest && expr->IsVariableProxy(); | 4123 parameters->is_simple = !is_rest && expr->IsVariableProxy(); |
4124 } | 4124 } |
4125 | 4125 |
4126 Expression* initializer = nullptr; | 4126 Expression* initializer = nullptr; |
4127 if (expr->IsVariableProxy()) { | 4127 if (expr->IsAssignment()) { |
4128 // When the formal parameter was originally seen, it was parsed as a | |
4129 // VariableProxy and recorded as unresolved in the scope. Here we undo that | |
4130 // parse-time side-effect for parameters that are single-names (not | |
4131 // patterns; for patterns that happens uniformly in | |
4132 // PatternRewriter::VisitVariableProxy). | |
4133 parser_->scope()->RemoveUnresolved(expr->AsVariableProxy()); | |
4134 } else if (expr->IsAssignment()) { | |
4135 Assignment* assignment = expr->AsAssignment(); | 4128 Assignment* assignment = expr->AsAssignment(); |
4136 DCHECK(!assignment->is_compound()); | 4129 DCHECK(!assignment->is_compound()); |
4137 initializer = assignment->value(); | 4130 initializer = assignment->value(); |
4138 expr = assignment->target(); | 4131 expr = assignment->target(); |
4139 | |
4140 // TODO(adamk): Only call this if necessary. | |
4141 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, | |
4142 parser_->scope(), parameters->scope); | |
4143 } | 4132 } |
4144 | 4133 |
4145 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 4134 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); |
4146 } | 4135 } |
4147 | 4136 |
4148 void ParserTraits::ParseAsyncArrowSingleExpressionBody( | 4137 void ParserTraits::ParseAsyncArrowSingleExpressionBody( |
4149 ZoneList<Statement*>* body, bool accept_IN, | 4138 ZoneList<Statement*>* body, bool accept_IN, |
4150 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 4139 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
4151 parser_->DesugarAsyncFunctionBody( | 4140 parser_->DesugarAsyncFunctionBody( |
4152 parser_->ast_value_factory()->empty_string(), parser_->scope(), body, | 4141 parser_->ast_value_factory()->empty_string(), parser_->scope(), body, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4212 Block* block = ParseBlock(nullptr, false, CHECK_OK); | 4201 Block* block = ParseBlock(nullptr, false, CHECK_OK); |
4213 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4202 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
4214 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 4203 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { |
4215 *ok = false; | 4204 *ok = false; |
4216 return nullptr; | 4205 return nullptr; |
4217 } | 4206 } |
4218 block->set_scope(block->scope()->FinalizeBlockScope()); | 4207 block->set_scope(block->scope()->FinalizeBlockScope()); |
4219 return expr; | 4208 return expr; |
4220 } | 4209 } |
4221 | 4210 |
4222 | |
4223 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4211 void ParserTraits::ParseArrowFunctionFormalParameterList( |
4224 ParserFormalParameters* parameters, Expression* expr, | 4212 ParserFormalParameters* parameters, Expression* expr, |
4225 const Scanner::Location& params_loc, | 4213 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
4226 Scanner::Location* duplicate_loc, bool* ok) { | 4214 Scope::Snapshot& scope_snapshot, bool* ok) { |
4227 if (expr->IsEmptyParentheses()) return; | 4215 if (expr->IsEmptyParentheses()) return; |
4228 | 4216 |
4229 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, | 4217 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, |
4230 CHECK_OK_VOID); | 4218 CHECK_OK_VOID); |
4231 | 4219 |
| 4220 scope_snapshot.Reparent(parameters->scope); |
| 4221 |
4232 if (parameters->Arity() > Code::kMaxArguments) { | 4222 if (parameters->Arity() > Code::kMaxArguments) { |
4233 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 4223 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
4234 *ok = false; | 4224 *ok = false; |
4235 return; | 4225 return; |
4236 } | 4226 } |
4237 | 4227 |
4238 Type::ExpressionClassifier classifier(parser_); | 4228 Type::ExpressionClassifier classifier(parser_); |
4239 if (!parameters->is_simple) { | 4229 if (!parameters->is_simple) { |
4240 classifier.RecordNonSimpleParameter(); | 4230 classifier.RecordNonSimpleParameter(); |
4241 } | 4231 } |
(...skipping 2833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7075 node->Print(Isolate::Current()); | 7065 node->Print(Isolate::Current()); |
7076 } | 7066 } |
7077 #endif // DEBUG | 7067 #endif // DEBUG |
7078 | 7068 |
7079 #undef CHECK_OK | 7069 #undef CHECK_OK |
7080 #undef CHECK_OK_VOID | 7070 #undef CHECK_OK_VOID |
7081 #undef CHECK_FAILED | 7071 #undef CHECK_FAILED |
7082 | 7072 |
7083 } // namespace internal | 7073 } // namespace internal |
7084 } // namespace v8 | 7074 } // namespace v8 |
OLD | NEW |