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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1195 // NewUnresolved references in current scope. Entrer arrow function | 1195 // NewUnresolved references in current scope. Entrer arrow function |
1196 // scope for formal parameter parsing. | 1196 // scope for formal parameter parsing. |
1197 BlockState block_state(&scope_, scope); | 1197 BlockState block_state(&scope_, scope); |
1198 if (Check(Token::LPAREN)) { | 1198 if (Check(Token::LPAREN)) { |
1199 // '(' StrictFormalParameters ')' | 1199 // '(' StrictFormalParameters ')' |
1200 ParseFormalParameterList(&formals, &formals_classifier, &ok); | 1200 ParseFormalParameterList(&formals, &formals_classifier, &ok); |
1201 if (ok) ok = Check(Token::RPAREN); | 1201 if (ok) ok = Check(Token::RPAREN); |
1202 } else { | 1202 } else { |
1203 // BindingIdentifier | 1203 // BindingIdentifier |
1204 const bool is_rest = false; | 1204 const bool is_rest = false; |
1205 ParseFormalParameter(is_rest, &formals, &formals_classifier, &ok); | 1205 ParseFormalParameter(is_rest, &formals, &formals_classifier, &ok); |
adamk
2015/08/03 18:43:51
Check ok before declaring?
rossberg
2015/08/04 15:31:19
Done.
| |
1206 DeclareFormalParameter( | |
1207 formals.scope, formals.at(0), formals.is_simple, | |
1208 &formals_classifier); | |
1206 } | 1209 } |
1207 } | 1210 } |
1208 | 1211 |
1209 if (ok) { | 1212 if (ok) { |
1210 checkpoint.Restore(&formals.materialized_literals_count); | 1213 checkpoint.Restore(&formals.materialized_literals_count); |
1211 Expression* expression = | 1214 Expression* expression = |
1212 ParseArrowFunctionLiteral(formals, formals_classifier, &ok); | 1215 ParseArrowFunctionLiteral(formals, formals_classifier, &ok); |
1213 if (ok) { | 1216 if (ok) { |
1214 // Scanning must end at the same position that was recorded | 1217 // Scanning must end at the same position that was recorded |
1215 // previously. If not, parsing has been interrupted due to a stack | 1218 // previously. If not, parsing has been interrupted due to a stack |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2209 language_mode(), CHECK_OK); | 2212 language_mode(), CHECK_OK); |
2210 // Even if we're not at the top-level of the global or a function | 2213 // Even if we're not at the top-level of the global or a function |
2211 // scope, we treat it as such and introduce the function with its | 2214 // scope, we treat it as such and introduce the function with its |
2212 // initial value upon entering the corresponding scope. | 2215 // initial value upon entering the corresponding scope. |
2213 // In ES6, a function behaves as a lexical binding, except in | 2216 // In ES6, a function behaves as a lexical binding, except in |
2214 // a script scope, or the initial scope of eval or another function. | 2217 // a script scope, or the initial scope of eval or another function. |
2215 VariableMode mode = | 2218 VariableMode mode = |
2216 is_strong(language_mode()) | 2219 is_strong(language_mode()) |
2217 ? CONST | 2220 ? CONST |
2218 : (is_strict(language_mode()) || allow_harmony_sloppy()) && | 2221 : (is_strict(language_mode()) || allow_harmony_sloppy()) && |
2219 !(scope_->is_script_scope() || scope_->is_eval_scope() || | 2222 !scope_->is_declaration_scope() ? LET : VAR; |
adamk
2015/08/03 18:43:51
This looks unrelated to the rest of the change; ma
rossberg
2015/08/04 15:31:19
You are right, I overlooked this one when splittin
adamk
2015/08/04 17:25:03
Given that the rest of this change is needed to ex
| |
2220 scope_->is_function_scope()) | |
2221 ? LET | |
2222 : VAR; | |
2223 VariableProxy* proxy = NewUnresolved(name, mode); | 2223 VariableProxy* proxy = NewUnresolved(name, mode); |
2224 Declaration* declaration = | 2224 Declaration* declaration = |
2225 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 2225 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
2226 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2226 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
2227 if (names) names->Add(name, zone()); | 2227 if (names) names->Add(name, zone()); |
2228 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 2228 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
2229 } | 2229 } |
2230 | 2230 |
2231 | 2231 |
2232 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 2232 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3895 if (expr->IsVariableProxy()) { | 3895 if (expr->IsVariableProxy()) { |
3896 // When the formal parameter was originally seen, it was parsed as a | 3896 // When the formal parameter was originally seen, it was parsed as a |
3897 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3897 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3898 // parse-time side-effect for parameters that are single-names (not | 3898 // parse-time side-effect for parameters that are single-names (not |
3899 // patterns; for patterns that happens uniformly in | 3899 // patterns; for patterns that happens uniformly in |
3900 // PatternRewriter::VisitVariableProxy). | 3900 // PatternRewriter::VisitVariableProxy). |
3901 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3901 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3902 } | 3902 } |
3903 | 3903 |
3904 ++parameters->arity; | 3904 ++parameters->arity; |
3905 ExpressionClassifier classifier; | 3905 AddFormalParameter(parameters, expr, is_rest); |
3906 DeclareFormalParameter(parameters, expr, is_rest, &classifier); | 3906 } |
3907 if (!duplicate_loc->IsValid()) { | 3907 |
3908 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 3908 |
3909 void ParserTraits::ParseArrowFunctionFormalParameterList( | |
3910 ParserFormalParameters* parameters, Expression* expr, | |
3911 const Scanner::Location& params_loc, | |
3912 Scanner::Location* duplicate_loc, bool* ok) { | |
3913 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, | |
3914 duplicate_loc, ok); | |
3915 if (!*ok) return; | |
3916 | |
3917 for (int i = 0; i < parameters->arity; ++i) { | |
adamk
2015/08/03 18:43:51
Seems scary to use arity for this instead of the p
| |
3918 auto parameter = parameters->at(i); | |
3919 ExpressionClassifier classifier; | |
3920 DeclareFormalParameter( | |
3921 parameters->scope, parameter, parameters->is_simple, &classifier); | |
3922 if (!duplicate_loc->IsValid()) { | |
3923 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | |
3924 } | |
3909 } | 3925 } |
3910 } | 3926 } |
3911 | 3927 |
3912 | 3928 |
3913 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { | 3929 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { |
3914 if (parser_->function_state_->materialized_literal_count() > 0) { | 3930 if (parser_->function_state_->materialized_literal_count() > 0) { |
3915 AstLiteralReindexer reindexer; | 3931 AstLiteralReindexer reindexer; |
3916 | 3932 |
3917 for (const auto p : parameters.params) { | 3933 for (const auto p : parameters.params) { |
3918 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); | 3934 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4310 | 4326 |
4311 | 4327 |
4312 Block* Parser::BuildParameterInitializationBlock( | 4328 Block* Parser::BuildParameterInitializationBlock( |
4313 const ParserFormalParameters& parameters, bool* ok) { | 4329 const ParserFormalParameters& parameters, bool* ok) { |
4314 DCHECK(!parameters.is_simple); | 4330 DCHECK(!parameters.is_simple); |
4315 DCHECK(scope_->is_function_scope()); | 4331 DCHECK(scope_->is_function_scope()); |
4316 Block* init_block = | 4332 Block* init_block = |
4317 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4333 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4318 for (int i = 0; i < parameters.params.length(); ++i) { | 4334 for (int i = 0; i < parameters.params.length(); ++i) { |
4319 auto parameter = parameters.params[i]; | 4335 auto parameter = parameters.params[i]; |
4320 if (parameter.pattern == nullptr) continue; | 4336 // TODO(caitp,rossberg): Remove special handling for rest once desugared. |
4337 if (parameter.is_rest) break; | |
4321 DeclarationDescriptor descriptor; | 4338 DeclarationDescriptor descriptor; |
4322 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4339 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4323 descriptor.parser = this; | 4340 descriptor.parser = this; |
4324 descriptor.declaration_scope = scope_; | 4341 descriptor.declaration_scope = scope_; |
4325 descriptor.scope = scope_; | 4342 descriptor.scope = scope_; |
4326 descriptor.mode = LET; | 4343 descriptor.mode = LET; |
4327 descriptor.is_const = false; | 4344 descriptor.is_const = false; |
4328 descriptor.needs_init = true; | 4345 descriptor.needs_init = true; |
4329 descriptor.declaration_pos = parameter.pattern->position(); | 4346 descriptor.declaration_pos = parameter.pattern->position(); |
4330 descriptor.initialization_pos = parameter.pattern->position(); | 4347 descriptor.initialization_pos = parameter.pattern->position(); |
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5986 Expression* Parser::SpreadCallNew(Expression* function, | 6003 Expression* Parser::SpreadCallNew(Expression* function, |
5987 ZoneList<v8::internal::Expression*>* args, | 6004 ZoneList<v8::internal::Expression*>* args, |
5988 int pos) { | 6005 int pos) { |
5989 args->InsertAt(0, function, zone()); | 6006 args->InsertAt(0, function, zone()); |
5990 | 6007 |
5991 return factory()->NewCallRuntime( | 6008 return factory()->NewCallRuntime( |
5992 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6009 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5993 } | 6010 } |
5994 } // namespace internal | 6011 } // namespace internal |
5995 } // namespace v8 | 6012 } // namespace v8 |
OLD | NEW |