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/parser.h" | 5 #include "src/parser.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 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 // GeneratorDeclaration :: | 2220 // GeneratorDeclaration :: |
2221 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 2221 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
2222 // '{' FunctionBody '}' | 2222 // '{' FunctionBody '}' |
2223 Expect(Token::FUNCTION, CHECK_OK); | 2223 Expect(Token::FUNCTION, CHECK_OK); |
2224 int pos = position(); | 2224 int pos = position(); |
2225 bool is_generator = Check(Token::MUL); | 2225 bool is_generator = Check(Token::MUL); |
2226 bool is_strict_reserved = false; | 2226 bool is_strict_reserved = false; |
2227 const AstRawString* name = ParseIdentifierOrStrictReservedWord( | 2227 const AstRawString* name = ParseIdentifierOrStrictReservedWord( |
2228 &is_strict_reserved, CHECK_OK); | 2228 &is_strict_reserved, CHECK_OK); |
2229 | 2229 |
2230 if (fni_ != NULL) { | 2230 FuncNameInferrer::State fni_state(fni_); |
2231 fni_->Enter(); | 2231 if (fni_ != NULL) fni_->PushEnclosingName(name); |
2232 fni_->PushEnclosingName(name); | |
2233 } | |
2234 FunctionLiteral* fun = ParseFunctionLiteral( | 2232 FunctionLiteral* fun = ParseFunctionLiteral( |
2235 name, scanner()->location(), | 2233 name, scanner()->location(), |
2236 is_strict_reserved ? kFunctionNameIsStrictReserved | 2234 is_strict_reserved ? kFunctionNameIsStrictReserved |
2237 : kFunctionNameValidityUnknown, | 2235 : kFunctionNameValidityUnknown, |
2238 is_generator ? FunctionKind::kGeneratorFunction | 2236 is_generator ? FunctionKind::kGeneratorFunction |
2239 : FunctionKind::kNormalFunction, | 2237 : FunctionKind::kNormalFunction, |
2240 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, | 2238 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, |
2241 language_mode(), CHECK_OK); | 2239 language_mode(), CHECK_OK); |
2242 if (fni_ != NULL) fni_->Leave(); | |
2243 | 2240 |
2244 // Even if we're not at the top-level of the global or a function | 2241 // Even if we're not at the top-level of the global or a function |
2245 // scope, we treat it as such and introduce the function with its | 2242 // scope, we treat it as such and introduce the function with its |
2246 // initial value upon entering the corresponding scope. | 2243 // initial value upon entering the corresponding scope. |
2247 // In ES6, a function behaves as a lexical binding, except in | 2244 // In ES6, a function behaves as a lexical binding, except in |
2248 // a script scope, or the initial scope of eval or another function. | 2245 // a script scope, or the initial scope of eval or another function. |
2249 VariableMode mode = | 2246 VariableMode mode = |
2250 is_strong(language_mode()) | 2247 is_strong(language_mode()) |
2251 ? CONST | 2248 ? CONST |
2252 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) && | 2249 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) && |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 parsing_result->descriptor.declaration_scope = | 2506 parsing_result->descriptor.declaration_scope = |
2510 DeclarationScope(parsing_result->descriptor.mode); | 2507 DeclarationScope(parsing_result->descriptor.mode); |
2511 parsing_result->descriptor.scope = scope_; | 2508 parsing_result->descriptor.scope = scope_; |
2512 parsing_result->descriptor.hoist_scope = nullptr; | 2509 parsing_result->descriptor.hoist_scope = nullptr; |
2513 | 2510 |
2514 | 2511 |
2515 bool first_declaration = true; | 2512 bool first_declaration = true; |
2516 int bindings_start = peek_position(); | 2513 int bindings_start = peek_position(); |
2517 bool is_for_iteration_variable; | 2514 bool is_for_iteration_variable; |
2518 do { | 2515 do { |
2519 if (fni_ != NULL) fni_->Enter(); | 2516 FuncNameInferrer::State fni_state(fni_); |
2520 | 2517 |
2521 // Parse name. | 2518 // Parse name. |
2522 if (!first_declaration) Consume(Token::COMMA); | 2519 if (!first_declaration) Consume(Token::COMMA); |
2523 | 2520 |
2524 Expression* pattern; | 2521 Expression* pattern; |
2525 { | 2522 { |
2526 ExpressionClassifier pattern_classifier; | 2523 ExpressionClassifier pattern_classifier; |
2527 Token::Value next = peek(); | 2524 Token::Value next = peek(); |
2528 pattern = ParsePrimaryExpression(&pattern_classifier, ok); | 2525 pattern = ParsePrimaryExpression(&pattern_classifier, ok); |
2529 if (!*ok) return; | 2526 if (!*ok) return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 } else { | 2581 } else { |
2585 // End position of the initializer is after the variable. | 2582 // End position of the initializer is after the variable. |
2586 initializer_position = position(); | 2583 initializer_position = position(); |
2587 } | 2584 } |
2588 | 2585 |
2589 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. | 2586 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. |
2590 if (value == NULL && parsing_result->descriptor.needs_init) { | 2587 if (value == NULL && parsing_result->descriptor.needs_init) { |
2591 value = GetLiteralUndefined(position()); | 2588 value = GetLiteralUndefined(position()); |
2592 } | 2589 } |
2593 | 2590 |
2594 if (single_name && fni_ != NULL) fni_->Leave(); | |
2595 parsing_result->declarations.Add(DeclarationParsingResult::Declaration( | 2591 parsing_result->declarations.Add(DeclarationParsingResult::Declaration( |
2596 pattern, initializer_position, value)); | 2592 pattern, initializer_position, value)); |
2597 first_declaration = false; | 2593 first_declaration = false; |
2598 } while (peek() == Token::COMMA); | 2594 } while (peek() == Token::COMMA); |
2599 | 2595 |
2600 parsing_result->bindings_loc = | 2596 parsing_result->bindings_loc = |
2601 Scanner::Location(bindings_start, scanner()->location().end_pos); | 2597 Scanner::Location(bindings_start, scanner()->location().end_pos); |
2602 } | 2598 } |
2603 | 2599 |
2604 | 2600 |
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4806 ClassLiteralChecker checker(this); | 4802 ClassLiteralChecker checker(this); |
4807 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 4803 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
4808 FunctionLiteral* constructor = NULL; | 4804 FunctionLiteral* constructor = NULL; |
4809 bool has_seen_constructor = false; | 4805 bool has_seen_constructor = false; |
4810 | 4806 |
4811 Expect(Token::LBRACE, CHECK_OK); | 4807 Expect(Token::LBRACE, CHECK_OK); |
4812 | 4808 |
4813 const bool has_extends = extends != nullptr; | 4809 const bool has_extends = extends != nullptr; |
4814 while (peek() != Token::RBRACE) { | 4810 while (peek() != Token::RBRACE) { |
4815 if (Check(Token::SEMICOLON)) continue; | 4811 if (Check(Token::SEMICOLON)) continue; |
4816 if (fni_ != NULL) fni_->Enter(); | 4812 FuncNameInferrer::State fni_state(fni_); |
4817 const bool in_class = true; | 4813 const bool in_class = true; |
4818 const bool is_static = false; | 4814 const bool is_static = false; |
4819 bool is_computed_name = false; // Classes do not care about computed | 4815 bool is_computed_name = false; // Classes do not care about computed |
4820 // property names here. | 4816 // property names here. |
4821 ExpressionClassifier classifier; | 4817 ExpressionClassifier classifier; |
4822 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4818 ObjectLiteral::Property* property = ParsePropertyDefinition( |
4823 &checker, in_class, has_extends, is_static, &is_computed_name, | 4819 &checker, in_class, has_extends, is_static, &is_computed_name, |
4824 &has_seen_constructor, &classifier, CHECK_OK); | 4820 &has_seen_constructor, &classifier, CHECK_OK); |
4825 ValidateExpression(&classifier, CHECK_OK); | 4821 ValidateExpression(&classifier, CHECK_OK); |
4826 | 4822 |
4827 if (has_seen_constructor && constructor == NULL) { | 4823 if (has_seen_constructor && constructor == NULL) { |
4828 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4824 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4829 DCHECK_NOT_NULL(constructor); | 4825 DCHECK_NOT_NULL(constructor); |
4830 } else { | 4826 } else { |
4831 properties->Add(property, zone()); | 4827 properties->Add(property, zone()); |
4832 } | 4828 } |
4833 | 4829 |
4834 if (fni_ != NULL) { | 4830 if (fni_ != NULL) fni_->Infer(); |
4835 fni_->Infer(); | |
4836 fni_->Leave(); | |
4837 } | |
4838 } | 4831 } |
4839 | 4832 |
4840 Expect(Token::RBRACE, CHECK_OK); | 4833 Expect(Token::RBRACE, CHECK_OK); |
4841 int end_pos = scanner()->location().end_pos; | 4834 int end_pos = scanner()->location().end_pos; |
4842 | 4835 |
4843 if (constructor == NULL) { | 4836 if (constructor == NULL) { |
4844 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, | 4837 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, |
4845 block_scope->language_mode()); | 4838 block_scope->language_mode()); |
4846 } | 4839 } |
4847 | 4840 |
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6289 | 6282 |
6290 Expression* Parser::SpreadCallNew(Expression* function, | 6283 Expression* Parser::SpreadCallNew(Expression* function, |
6291 ZoneList<v8::internal::Expression*>* args, | 6284 ZoneList<v8::internal::Expression*>* args, |
6292 int pos) { | 6285 int pos) { |
6293 args->InsertAt(0, function, zone()); | 6286 args->InsertAt(0, function, zone()); |
6294 | 6287 |
6295 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6288 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6296 } | 6289 } |
6297 } // namespace internal | 6290 } // namespace internal |
6298 } // namespace v8 | 6291 } // namespace v8 |
OLD | NEW |