| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { | 396 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { |
| 397 return IsEval(identifier) || IsArguments(identifier); | 397 return IsEval(identifier) || IsArguments(identifier); |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { | 400 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { |
| 401 return identifier == parser_->ast_value_factory()->undefined_string(); | 401 return identifier == parser_->ast_value_factory()->undefined_string(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 bool ParserTraits::IsAwait(const AstRawString* identifier) const { | |
| 405 return identifier == parser_->ast_value_factory()->await_string(); | |
| 406 } | |
| 407 | |
| 408 bool ParserTraits::IsPrototype(const AstRawString* identifier) const { | 404 bool ParserTraits::IsPrototype(const AstRawString* identifier) const { |
| 409 return identifier == parser_->ast_value_factory()->prototype_string(); | 405 return identifier == parser_->ast_value_factory()->prototype_string(); |
| 410 } | 406 } |
| 411 | 407 |
| 412 | 408 |
| 413 bool ParserTraits::IsConstructor(const AstRawString* identifier) const { | 409 bool ParserTraits::IsConstructor(const AstRawString* identifier) const { |
| 414 return identifier == parser_->ast_value_factory()->constructor_string(); | 410 return identifier == parser_->ast_value_factory()->constructor_string(); |
| 415 } | 411 } |
| 416 | 412 |
| 417 | 413 |
| (...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 name_validity = kSkipFunctionNameCheck; | 2168 name_validity = kSkipFunctionNameCheck; |
| 2173 variable_name = ast_value_factory()->star_default_star_string(); | 2169 variable_name = ast_value_factory()->star_default_star_string(); |
| 2174 } else { | 2170 } else { |
| 2175 bool is_strict_reserved; | 2171 bool is_strict_reserved; |
| 2176 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2172 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 2177 name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved | 2173 name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved |
| 2178 : kFunctionNameValidityUnknown; | 2174 : kFunctionNameValidityUnknown; |
| 2179 variable_name = name; | 2175 variable_name = name; |
| 2180 } | 2176 } |
| 2181 | 2177 |
| 2182 if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) { | |
| 2183 ReportMessageAt(scanner()->location(), | |
| 2184 MessageTemplate::kAwaitBindingIdentifier); | |
| 2185 *ok = false; | |
| 2186 return nullptr; | |
| 2187 } | |
| 2188 | |
| 2189 FuncNameInferrer::State fni_state(fni_); | 2178 FuncNameInferrer::State fni_state(fni_); |
| 2190 if (fni_ != NULL) fni_->PushEnclosingName(name); | 2179 if (fni_ != NULL) fni_->PushEnclosingName(name); |
| 2191 FunctionLiteral* fun = ParseFunctionLiteral( | 2180 FunctionLiteral* fun = ParseFunctionLiteral( |
| 2192 name, scanner()->location(), name_validity, | 2181 name, scanner()->location(), name_validity, |
| 2193 is_generator ? FunctionKind::kGeneratorFunction | 2182 is_generator ? FunctionKind::kGeneratorFunction |
| 2194 : is_async ? FunctionKind::kAsyncFunction | 2183 : is_async ? FunctionKind::kAsyncFunction |
| 2195 : FunctionKind::kNormalFunction, | 2184 : FunctionKind::kNormalFunction, |
| 2196 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 2185 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
| 2197 | 2186 |
| 2198 // In ES6, a function behaves as a lexical binding, except in | 2187 // In ES6, a function behaves as a lexical binding, except in |
| (...skipping 2284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4483 // ( FormalParameters[Await] ) { AsyncFunctionBody } | 4472 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
| 4484 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); | 4473 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); |
| 4485 int pos = position(); | 4474 int pos = position(); |
| 4486 Expect(Token::FUNCTION, CHECK_OK); | 4475 Expect(Token::FUNCTION, CHECK_OK); |
| 4487 bool is_strict_reserved = false; | 4476 bool is_strict_reserved = false; |
| 4488 const AstRawString* name = nullptr; | 4477 const AstRawString* name = nullptr; |
| 4489 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; | 4478 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; |
| 4490 | 4479 |
| 4491 if (peek_any_identifier()) { | 4480 if (peek_any_identifier()) { |
| 4492 type = FunctionLiteral::kNamedExpression; | 4481 type = FunctionLiteral::kNamedExpression; |
| 4493 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 4482 name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction, |
| 4494 if (this->IsAwait(name)) { | 4483 &is_strict_reserved, CHECK_OK); |
| 4495 ReportMessageAt(scanner()->location(), | |
| 4496 MessageTemplate::kAwaitBindingIdentifier); | |
| 4497 *ok = false; | |
| 4498 return nullptr; | |
| 4499 } | |
| 4500 } | 4484 } |
| 4501 return ParseFunctionLiteral(name, scanner()->location(), | 4485 return ParseFunctionLiteral(name, scanner()->location(), |
| 4502 is_strict_reserved ? kFunctionNameIsStrictReserved | 4486 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 4503 : kFunctionNameValidityUnknown, | 4487 : kFunctionNameValidityUnknown, |
| 4504 FunctionKind::kAsyncFunction, pos, type, | 4488 FunctionKind::kAsyncFunction, pos, type, |
| 4505 language_mode(), CHECK_OK); | 4489 language_mode(), CHECK_OK); |
| 4506 } | 4490 } |
| 4507 | 4491 |
| 4508 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, | 4492 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, |
| 4509 int* expected_property_count, bool* ok, | 4493 int* expected_property_count, bool* ok, |
| (...skipping 2512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7022 node->Print(Isolate::Current()); | 7006 node->Print(Isolate::Current()); |
| 7023 } | 7007 } |
| 7024 #endif // DEBUG | 7008 #endif // DEBUG |
| 7025 | 7009 |
| 7026 #undef CHECK_OK | 7010 #undef CHECK_OK |
| 7027 #undef CHECK_OK_VOID | 7011 #undef CHECK_OK_VOID |
| 7028 #undef CHECK_FAILED | 7012 #undef CHECK_FAILED |
| 7029 | 7013 |
| 7030 } // namespace internal | 7014 } // namespace internal |
| 7031 } // namespace v8 | 7015 } // namespace v8 |
| OLD | NEW |