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 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 // GeneratorDeclaration :: | 2235 // GeneratorDeclaration :: |
2236 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 2236 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
2237 // '{' FunctionBody '}' | 2237 // '{' FunctionBody '}' |
2238 Expect(Token::FUNCTION, CHECK_OK); | 2238 Expect(Token::FUNCTION, CHECK_OK); |
2239 int pos = position(); | 2239 int pos = position(); |
2240 bool is_generator = Check(Token::MUL); | 2240 bool is_generator = Check(Token::MUL); |
2241 bool is_strict_reserved = false; | 2241 bool is_strict_reserved = false; |
2242 const AstRawString* name = ParseIdentifierOrStrictReservedWord( | 2242 const AstRawString* name = ParseIdentifierOrStrictReservedWord( |
2243 &is_strict_reserved, CHECK_OK); | 2243 &is_strict_reserved, CHECK_OK); |
2244 | 2244 |
2245 if (fni_ != NULL) { | 2245 FuncNameInferrer::State fni_state(fni_); |
2246 fni_->Enter(); | 2246 if (fni_ != NULL) fni_->PushEnclosingName(name); |
2247 fni_->PushEnclosingName(name); | |
2248 } | |
2249 FunctionLiteral* fun = ParseFunctionLiteral( | 2247 FunctionLiteral* fun = ParseFunctionLiteral( |
2250 name, scanner()->location(), | 2248 name, scanner()->location(), |
2251 is_strict_reserved ? kFunctionNameIsStrictReserved | 2249 is_strict_reserved ? kFunctionNameIsStrictReserved |
2252 : kFunctionNameValidityUnknown, | 2250 : kFunctionNameValidityUnknown, |
2253 is_generator ? FunctionKind::kGeneratorFunction | 2251 is_generator ? FunctionKind::kGeneratorFunction |
2254 : FunctionKind::kNormalFunction, | 2252 : FunctionKind::kNormalFunction, |
2255 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, | 2253 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, |
2256 language_mode(), CHECK_OK); | 2254 language_mode(), CHECK_OK); |
2257 if (fni_ != NULL) fni_->Leave(); | |
2258 | 2255 |
2259 // Even if we're not at the top-level of the global or a function | 2256 // Even if we're not at the top-level of the global or a function |
2260 // scope, we treat it as such and introduce the function with its | 2257 // scope, we treat it as such and introduce the function with its |
2261 // initial value upon entering the corresponding scope. | 2258 // initial value upon entering the corresponding scope. |
2262 // In ES6, a function behaves as a lexical binding, except in | 2259 // In ES6, a function behaves as a lexical binding, except in |
2263 // a script scope, or the initial scope of eval or another function. | 2260 // a script scope, or the initial scope of eval or another function. |
2264 VariableMode mode = | 2261 VariableMode mode = |
2265 is_strong(language_mode()) | 2262 is_strong(language_mode()) |
2266 ? CONST | 2263 ? CONST |
2267 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) && | 2264 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) && |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 parsing_result->descriptor.declaration_scope = | 2521 parsing_result->descriptor.declaration_scope = |
2525 DeclarationScope(parsing_result->descriptor.mode); | 2522 DeclarationScope(parsing_result->descriptor.mode); |
2526 parsing_result->descriptor.scope = scope_; | 2523 parsing_result->descriptor.scope = scope_; |
2527 parsing_result->descriptor.hoist_scope = nullptr; | 2524 parsing_result->descriptor.hoist_scope = nullptr; |
2528 | 2525 |
2529 | 2526 |
2530 bool first_declaration = true; | 2527 bool first_declaration = true; |
2531 int bindings_start = peek_position(); | 2528 int bindings_start = peek_position(); |
2532 bool is_for_iteration_variable; | 2529 bool is_for_iteration_variable; |
2533 do { | 2530 do { |
2534 if (fni_ != NULL) fni_->Enter(); | 2531 FuncNameInferrer::State fni_state(fni_); |
2535 | 2532 |
2536 // Parse name. | 2533 // Parse name. |
2537 if (!first_declaration) Consume(Token::COMMA); | 2534 if (!first_declaration) Consume(Token::COMMA); |
2538 | 2535 |
2539 Expression* pattern; | 2536 Expression* pattern; |
2540 int decl_pos = peek_position(); | 2537 int decl_pos = peek_position(); |
2541 { | 2538 { |
2542 ExpressionClassifier pattern_classifier; | 2539 ExpressionClassifier pattern_classifier; |
2543 Token::Value next = peek(); | 2540 Token::Value next = peek(); |
2544 pattern = ParsePrimaryExpression(&pattern_classifier, ok); | 2541 pattern = ParsePrimaryExpression(&pattern_classifier, ok); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2614 } | 2611 } |
2615 // End position of the initializer is after the variable. | 2612 // End position of the initializer is after the variable. |
2616 initializer_position = position(); | 2613 initializer_position = position(); |
2617 } | 2614 } |
2618 | 2615 |
2619 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. | 2616 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. |
2620 if (value == NULL && parsing_result->descriptor.needs_init) { | 2617 if (value == NULL && parsing_result->descriptor.needs_init) { |
2621 value = GetLiteralUndefined(position()); | 2618 value = GetLiteralUndefined(position()); |
2622 } | 2619 } |
2623 | 2620 |
2624 if (single_name && fni_ != NULL) fni_->Leave(); | |
2625 parsing_result->declarations.Add(DeclarationParsingResult::Declaration( | 2621 parsing_result->declarations.Add(DeclarationParsingResult::Declaration( |
2626 pattern, initializer_position, value)); | 2622 pattern, initializer_position, value)); |
2627 first_declaration = false; | 2623 first_declaration = false; |
2628 } while (peek() == Token::COMMA); | 2624 } while (peek() == Token::COMMA); |
2629 | 2625 |
2630 parsing_result->bindings_loc = | 2626 parsing_result->bindings_loc = |
2631 Scanner::Location(bindings_start, scanner()->location().end_pos); | 2627 Scanner::Location(bindings_start, scanner()->location().end_pos); |
2632 } | 2628 } |
2633 | 2629 |
2634 | 2630 |
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4926 ClassLiteralChecker checker(this); | 4922 ClassLiteralChecker checker(this); |
4927 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 4923 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
4928 FunctionLiteral* constructor = NULL; | 4924 FunctionLiteral* constructor = NULL; |
4929 bool has_seen_constructor = false; | 4925 bool has_seen_constructor = false; |
4930 | 4926 |
4931 Expect(Token::LBRACE, CHECK_OK); | 4927 Expect(Token::LBRACE, CHECK_OK); |
4932 | 4928 |
4933 const bool has_extends = extends != nullptr; | 4929 const bool has_extends = extends != nullptr; |
4934 while (peek() != Token::RBRACE) { | 4930 while (peek() != Token::RBRACE) { |
4935 if (Check(Token::SEMICOLON)) continue; | 4931 if (Check(Token::SEMICOLON)) continue; |
4936 if (fni_ != NULL) fni_->Enter(); | 4932 FuncNameInferrer::State fni_state(fni_); |
4937 const bool in_class = true; | 4933 const bool in_class = true; |
4938 const bool is_static = false; | 4934 const bool is_static = false; |
4939 bool is_computed_name = false; // Classes do not care about computed | 4935 bool is_computed_name = false; // Classes do not care about computed |
4940 // property names here. | 4936 // property names here. |
4941 ExpressionClassifier classifier; | 4937 ExpressionClassifier classifier; |
4942 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4938 ObjectLiteral::Property* property = ParsePropertyDefinition( |
4943 &checker, in_class, has_extends, is_static, &is_computed_name, | 4939 &checker, in_class, has_extends, is_static, &is_computed_name, |
4944 &has_seen_constructor, &classifier, CHECK_OK); | 4940 &has_seen_constructor, &classifier, CHECK_OK); |
4945 ValidateExpression(&classifier, CHECK_OK); | 4941 ValidateExpression(&classifier, CHECK_OK); |
4946 | 4942 |
4947 if (has_seen_constructor && constructor == NULL) { | 4943 if (has_seen_constructor && constructor == NULL) { |
4948 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4944 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4949 DCHECK_NOT_NULL(constructor); | 4945 DCHECK_NOT_NULL(constructor); |
4950 } else { | 4946 } else { |
4951 properties->Add(property, zone()); | 4947 properties->Add(property, zone()); |
4952 } | 4948 } |
4953 | 4949 |
4954 if (fni_ != NULL) { | 4950 if (fni_ != NULL) fni_->Infer(); |
4955 fni_->Infer(); | |
4956 fni_->Leave(); | |
4957 } | |
4958 } | 4951 } |
4959 | 4952 |
4960 Expect(Token::RBRACE, CHECK_OK); | 4953 Expect(Token::RBRACE, CHECK_OK); |
4961 int end_pos = scanner()->location().end_pos; | 4954 int end_pos = scanner()->location().end_pos; |
4962 | 4955 |
4963 if (constructor == NULL) { | 4956 if (constructor == NULL) { |
4964 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, | 4957 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, |
4965 block_scope->language_mode()); | 4958 block_scope->language_mode()); |
4966 } | 4959 } |
4967 | 4960 |
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6453 } | 6446 } |
6454 | 6447 |
6455 | 6448 |
6456 void Parser::RaiseLanguageMode(LanguageMode mode) { | 6449 void Parser::RaiseLanguageMode(LanguageMode mode) { |
6457 SetLanguageMode(scope_, | 6450 SetLanguageMode(scope_, |
6458 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 6451 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
6459 } | 6452 } |
6460 | 6453 |
6461 } // namespace internal | 6454 } // namespace internal |
6462 } // namespace v8 | 6455 } // namespace v8 |
OLD | NEW |