| 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 4104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4115   bool is_rest = expr->IsSpread(); | 4115   bool is_rest = expr->IsSpread(); | 
| 4116   if (is_rest) { | 4116   if (is_rest) { | 
| 4117     expr = expr->AsSpread()->expression(); | 4117     expr = expr->AsSpread()->expression(); | 
| 4118     parameters->has_rest = true; | 4118     parameters->has_rest = true; | 
| 4119   } | 4119   } | 
| 4120   if (parameters->is_simple) { | 4120   if (parameters->is_simple) { | 
| 4121     parameters->is_simple = !is_rest && expr->IsVariableProxy(); | 4121     parameters->is_simple = !is_rest && expr->IsVariableProxy(); | 
| 4122   } | 4122   } | 
| 4123 | 4123 | 
| 4124   Expression* initializer = nullptr; | 4124   Expression* initializer = nullptr; | 
| 4125   if (expr->IsVariableProxy()) { | 4125   if (expr->IsAssignment()) { | 
| 4126     // When the formal parameter was originally seen, it was parsed as a |  | 
| 4127     // VariableProxy and recorded as unresolved in the scope.  Here we undo that |  | 
| 4128     // parse-time side-effect for parameters that are single-names (not |  | 
| 4129     // patterns; for patterns that happens uniformly in |  | 
| 4130     // PatternRewriter::VisitVariableProxy). |  | 
| 4131     parser_->scope()->RemoveUnresolved(expr->AsVariableProxy()); |  | 
| 4132   } else if (expr->IsAssignment()) { |  | 
| 4133     Assignment* assignment = expr->AsAssignment(); | 4126     Assignment* assignment = expr->AsAssignment(); | 
| 4134     DCHECK(!assignment->is_compound()); | 4127     DCHECK(!assignment->is_compound()); | 
| 4135     initializer = assignment->value(); | 4128     initializer = assignment->value(); | 
| 4136     expr = assignment->target(); | 4129     expr = assignment->target(); | 
| 4137 |  | 
| 4138     // TODO(adamk): Only call this if necessary. |  | 
| 4139     RewriteParameterInitializerScope(parser_->stack_limit(), initializer, |  | 
| 4140                                      parser_->scope(), parameters->scope); |  | 
| 4141   } | 4130   } | 
| 4142 | 4131 | 
| 4143   AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 4132   AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 
| 4144 } | 4133 } | 
| 4145 | 4134 | 
| 4146 void ParserTraits::ParseAsyncArrowSingleExpressionBody( | 4135 void ParserTraits::ParseAsyncArrowSingleExpressionBody( | 
| 4147     ZoneList<Statement*>* body, bool accept_IN, | 4136     ZoneList<Statement*>* body, bool accept_IN, | 
| 4148     Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 4137     Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 
| 4149   parser_->DesugarAsyncFunctionBody( | 4138   parser_->DesugarAsyncFunctionBody( | 
| 4150       parser_->ast_value_factory()->empty_string(), parser_->scope(), body, | 4139       parser_->ast_value_factory()->empty_string(), parser_->scope(), body, | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4210   Block* block = ParseBlock(nullptr, false, CHECK_OK); | 4199   Block* block = ParseBlock(nullptr, false, CHECK_OK); | 
| 4211   DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4200   DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 
| 4212   if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 4201   if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 
| 4213     *ok = false; | 4202     *ok = false; | 
| 4214     return nullptr; | 4203     return nullptr; | 
| 4215   } | 4204   } | 
| 4216   block->set_scope(block->scope()->FinalizeBlockScope()); | 4205   block->set_scope(block->scope()->FinalizeBlockScope()); | 
| 4217   return expr; | 4206   return expr; | 
| 4218 } | 4207 } | 
| 4219 | 4208 | 
| 4220 |  | 
| 4221 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4209 void ParserTraits::ParseArrowFunctionFormalParameterList( | 
| 4222     ParserFormalParameters* parameters, Expression* expr, | 4210     ParserFormalParameters* parameters, Expression* expr, | 
| 4223     const Scanner::Location& params_loc, | 4211     const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 
| 4224     Scanner::Location* duplicate_loc, bool* ok) { | 4212     const Scope::Snapshot& scope_snapshot, bool* ok) { | 
| 4225   if (expr->IsEmptyParentheses()) return; | 4213   if (expr->IsEmptyParentheses()) return; | 
| 4226 | 4214 | 
| 4227   ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, | 4215   ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, | 
| 4228                                      CHECK_OK_VOID); | 4216                                      CHECK_OK_VOID); | 
| 4229 | 4217 | 
|  | 4218   scope_snapshot.Reparent(parameters->scope); | 
|  | 4219 | 
| 4230   if (parameters->Arity() > Code::kMaxArguments) { | 4220   if (parameters->Arity() > Code::kMaxArguments) { | 
| 4231     ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 4221     ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 
| 4232     *ok = false; | 4222     *ok = false; | 
| 4233     return; | 4223     return; | 
| 4234   } | 4224   } | 
| 4235 | 4225 | 
| 4236   Type::ExpressionClassifier classifier(parser_); | 4226   Type::ExpressionClassifier classifier(parser_); | 
| 4237   if (!parameters->is_simple) { | 4227   if (!parameters->is_simple) { | 
| 4238     classifier.RecordNonSimpleParameter(); | 4228     classifier.RecordNonSimpleParameter(); | 
| 4239   } | 4229   } | 
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4708       param_scope->set_start_position(descriptor.initialization_pos); | 4698       param_scope->set_start_position(descriptor.initialization_pos); | 
| 4709       param_scope->set_end_position(parameter.initializer_end_position); | 4699       param_scope->set_end_position(parameter.initializer_end_position); | 
| 4710       param_scope->RecordEvalCall(); | 4700       param_scope->RecordEvalCall(); | 
| 4711       param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 4701       param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 
| 4712       param_block->set_scope(param_scope); | 4702       param_block->set_scope(param_scope); | 
| 4713       descriptor.hoist_scope = scope(); | 4703       descriptor.hoist_scope = scope(); | 
| 4714       // Pass the appropriate scope in so that PatternRewriter can appropriately | 4704       // Pass the appropriate scope in so that PatternRewriter can appropriately | 
| 4715       // rewrite inner initializers of the pattern to param_scope | 4705       // rewrite inner initializers of the pattern to param_scope | 
| 4716       descriptor.scope = param_scope; | 4706       descriptor.scope = param_scope; | 
| 4717       // Rewrite the outer initializer to point to param_scope | 4707       // Rewrite the outer initializer to point to param_scope | 
| 4718       RewriteParameterInitializerScope(stack_limit(), initial_value, scope(), | 4708       ReparentParameterExpressionScope(stack_limit(), initial_value, | 
| 4719                                        param_scope); | 4709                                        param_scope); | 
| 4720     } | 4710     } | 
| 4721 | 4711 | 
| 4722     { | 4712     { | 
| 4723       BlockState block_state(&scope_state_, param_scope); | 4713       BlockState block_state(&scope_state_, param_scope); | 
| 4724       DeclarationParsingResult::Declaration decl( | 4714       DeclarationParsingResult::Declaration decl( | 
| 4725           parameter.pattern, initializer_position, initial_value); | 4715           parameter.pattern, initializer_position, initial_value); | 
| 4726       PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 4716       PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 
| 4727                                                      &decl, nullptr, CHECK_OK); | 4717                                                      &decl, nullptr, CHECK_OK); | 
| 4728     } | 4718     } | 
| (...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7071   node->Print(Isolate::Current()); | 7061   node->Print(Isolate::Current()); | 
| 7072 } | 7062 } | 
| 7073 #endif  // DEBUG | 7063 #endif  // DEBUG | 
| 7074 | 7064 | 
| 7075 #undef CHECK_OK | 7065 #undef CHECK_OK | 
| 7076 #undef CHECK_OK_VOID | 7066 #undef CHECK_OK_VOID | 
| 7077 #undef CHECK_FAILED | 7067 #undef CHECK_FAILED | 
| 7078 | 7068 | 
| 7079 }  // namespace internal | 7069 }  // namespace internal | 
| 7080 }  // namespace v8 | 7070 }  // namespace v8 | 
| OLD | NEW | 
|---|