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 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 | 1048 |
1049 // Parses an identifier that is valid for the current scope, in particular it | 1049 // Parses an identifier that is valid for the current scope, in particular it |
1050 // fails on strict mode future reserved keywords in a strict scope. If | 1050 // fails on strict mode future reserved keywords in a strict scope. If |
1051 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 1051 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
1052 // "arguments" as identifier even in strict mode (this is needed in cases like | 1052 // "arguments" as identifier even in strict mode (this is needed in cases like |
1053 // "var foo = eval;"). | 1053 // "var foo = eval;"). |
1054 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); | 1054 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); |
1055 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 1055 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
1056 bool* ok); | 1056 bool* ok); |
1057 // Parses an identifier or a strict mode future reserved word, and indicate | 1057 // Parses an identifier or a strict mode future reserved word, and indicate |
1058 // whether it is strict mode future reserved. Allows passing in is_generator | 1058 // whether it is strict mode future reserved. Allows passing in function_kind |
1059 // for the case of parsing the identifier in a function expression, where the | 1059 // for the case of parsing the identifier in a function expression, where the |
1060 // relevant "is_generator" bit is of the function being parsed, not the | 1060 // relevant "function_kind" bit is of the function being parsed, not the |
1061 // containing | 1061 // containing function. |
1062 // function. | 1062 IdentifierT ParseIdentifierOrStrictReservedWord(FunctionKind function_kind, |
1063 IdentifierT ParseIdentifierOrStrictReservedWord(bool is_generator, | |
1064 bool* is_strict_reserved, | 1063 bool* is_strict_reserved, |
1065 bool* ok); | 1064 bool* ok); |
1066 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, | 1065 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, |
1067 bool* ok) { | 1066 bool* ok) { |
1068 return ParseIdentifierOrStrictReservedWord(this->is_generator(), | 1067 return ParseIdentifierOrStrictReservedWord(function_state_->kind(), |
1069 is_strict_reserved, ok); | 1068 is_strict_reserved, ok); |
1070 } | 1069 } |
1071 | 1070 |
1072 IdentifierT ParseIdentifierName(bool* ok); | 1071 IdentifierT ParseIdentifierName(bool* ok); |
1073 | 1072 |
1074 ExpressionT ParseRegExpLiteral(bool* ok); | 1073 ExpressionT ParseRegExpLiteral(bool* ok); |
1075 | 1074 |
1076 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 1075 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
1077 bool* is_async, bool* ok); | 1076 bool* is_async, bool* ok); |
1078 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 1077 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
1079 bool* ok) { | 1078 bool* ok) { |
1080 bool is_async; | 1079 bool is_async; |
1081 return ParsePrimaryExpression(classifier, &is_async, ok); | 1080 return ParsePrimaryExpression(classifier, &is_async, ok); |
1082 } | 1081 } |
1083 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 1082 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
1084 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, | 1083 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, |
1085 bool* ok); | 1084 bool* ok); |
1086 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); | 1085 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); |
1087 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 1086 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
1088 bool* is_await, bool* is_computed_name, | 1087 bool* is_computed_name, |
1089 ExpressionClassifier* classifier, bool* ok); | 1088 ExpressionClassifier* classifier, bool* ok); |
1090 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 1089 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
1091 ObjectLiteralPropertyT ParsePropertyDefinition( | 1090 ObjectLiteralPropertyT ParsePropertyDefinition( |
1092 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1091 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
1093 MethodKind kind, bool* is_computed_name, bool* has_seen_constructor, | 1092 MethodKind kind, bool* is_computed_name, bool* has_seen_constructor, |
1094 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 1093 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
1095 typename Traits::Type::ExpressionList ParseArguments( | 1094 typename Traits::Type::ExpressionList ParseArguments( |
1096 Scanner::Location* first_spread_pos, bool maybe_arrow, | 1095 Scanner::Location* first_spread_pos, bool maybe_arrow, |
1097 ExpressionClassifier* classifier, bool* ok); | 1096 ExpressionClassifier* classifier, bool* ok); |
1098 typename Traits::Type::ExpressionList ParseArguments( | 1097 typename Traits::Type::ExpressionList ParseArguments( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 return result; | 1407 return result; |
1409 } | 1408 } |
1410 | 1409 |
1411 | 1410 |
1412 template <class Traits> | 1411 template <class Traits> |
1413 typename ParserBase<Traits>::IdentifierT | 1412 typename ParserBase<Traits>::IdentifierT |
1414 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 1413 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
1415 bool* ok) { | 1414 bool* ok) { |
1416 Token::Value next = Next(); | 1415 Token::Value next = Next(); |
1417 if (next == Token::IDENTIFIER || next == Token::ASYNC || | 1416 if (next == Token::IDENTIFIER || next == Token::ASYNC || |
1418 (next == Token::AWAIT && !parsing_module_)) { | 1417 (next == Token::AWAIT && !parsing_module_ && !is_async_function())) { |
1419 IdentifierT name = this->GetSymbol(scanner()); | 1418 IdentifierT name = this->GetSymbol(scanner()); |
1420 // When this function is used to read a formal parameter, we don't always | 1419 // When this function is used to read a formal parameter, we don't always |
1421 // know whether the function is going to be strict or sloppy. Indeed for | 1420 // know whether the function is going to be strict or sloppy. Indeed for |
1422 // arrow functions we don't always know that the identifier we are reading | 1421 // arrow functions we don't always know that the identifier we are reading |
1423 // is actually a formal parameter. Therefore besides the errors that we | 1422 // is actually a formal parameter. Therefore besides the errors that we |
1424 // must detect because we know we're in strict mode, we also record any | 1423 // must detect because we know we're in strict mode, we also record any |
1425 // error that we might make in the future once we know the language mode. | 1424 // error that we might make in the future once we know the language mode. |
1426 if (this->IsEval(name)) { | 1425 if (this->IsEvalOrArguments(name)) { |
1427 classifier->RecordStrictModeFormalParameterError( | 1426 classifier->RecordStrictModeFormalParameterError( |
1428 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1427 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1429 if (is_strict(language_mode())) { | 1428 if (is_strict(language_mode())) { |
1430 classifier->RecordBindingPatternError( | 1429 classifier->RecordBindingPatternError( |
1431 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1430 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1432 } | 1431 } |
1433 } | 1432 } else if (next == Token::AWAIT) { |
1434 if (this->IsArguments(name)) { | |
1435 classifier->RecordStrictModeFormalParameterError( | |
1436 scanner()->location(), MessageTemplate::kStrictEvalArguments); | |
1437 if (is_strict(language_mode())) { | |
1438 classifier->RecordBindingPatternError( | |
1439 scanner()->location(), MessageTemplate::kStrictEvalArguments); | |
1440 } | |
1441 } | |
1442 if (this->IsAwait(name)) { | |
1443 if (is_async_function()) { | |
1444 classifier->RecordPatternError( | |
1445 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); | |
1446 } | |
1447 classifier->RecordAsyncArrowFormalParametersError( | 1433 classifier->RecordAsyncArrowFormalParametersError( |
1448 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); | 1434 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); |
1449 } | 1435 } |
1450 | 1436 |
1451 if (classifier->duplicate_finder() != nullptr && | 1437 if (classifier->duplicate_finder() != nullptr && |
1452 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1438 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
1453 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1439 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
1454 } | 1440 } |
1455 return name; | 1441 return name; |
1456 } else if (is_sloppy(language_mode()) && | 1442 } else if (is_sloppy(language_mode()) && |
(...skipping 16 matching lines...) Expand all Loading... | |
1473 MessageTemplate::kLetInLexicalBinding); | 1459 MessageTemplate::kLetInLexicalBinding); |
1474 } | 1460 } |
1475 return this->GetSymbol(scanner()); | 1461 return this->GetSymbol(scanner()); |
1476 } else { | 1462 } else { |
1477 this->ReportUnexpectedToken(next); | 1463 this->ReportUnexpectedToken(next); |
1478 *ok = false; | 1464 *ok = false; |
1479 return Traits::EmptyIdentifier(); | 1465 return Traits::EmptyIdentifier(); |
1480 } | 1466 } |
1481 } | 1467 } |
1482 | 1468 |
1483 | |
1484 template <class Traits> | 1469 template <class Traits> |
1485 typename ParserBase<Traits>::IdentifierT | 1470 typename ParserBase<Traits>::IdentifierT |
1486 ParserBase<Traits>::ParseIdentifierOrStrictReservedWord( | 1471 ParserBase<Traits>::ParseIdentifierOrStrictReservedWord( |
1487 bool is_generator, bool* is_strict_reserved, bool* ok) { | 1472 FunctionKind function_kind, bool* is_strict_reserved, bool* ok) { |
1488 Token::Value next = Next(); | 1473 Token::Value next = Next(); |
1489 if (next == Token::IDENTIFIER || (next == Token::AWAIT && !parsing_module_) || | 1474 if (next == Token::IDENTIFIER || (next == Token::AWAIT && !parsing_module_ && |
1475 !IsAsyncFunction(function_kind)) || | |
1490 next == Token::ASYNC) { | 1476 next == Token::ASYNC) { |
1491 *is_strict_reserved = false; | 1477 *is_strict_reserved = false; |
1492 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 1478 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || |
1493 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { | 1479 next == Token::STATIC || |
1480 (next == Token::YIELD && !IsGeneratorFunction(function_kind))) { | |
1494 *is_strict_reserved = true; | 1481 *is_strict_reserved = true; |
1495 } else { | 1482 } else { |
1496 ReportUnexpectedToken(next); | 1483 ReportUnexpectedToken(next); |
1497 *ok = false; | 1484 *ok = false; |
1498 return Traits::EmptyIdentifier(); | 1485 return Traits::EmptyIdentifier(); |
1499 } | 1486 } |
1500 | 1487 |
1501 return this->GetSymbol(scanner()); | 1488 return this->GetSymbol(scanner()); |
1502 } | 1489 } |
1503 | 1490 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1873 // parsing (this is OK, as it is an implementation limitation). | 1860 // parsing (this is OK, as it is an implementation limitation). |
1874 ReportMessage(MessageTemplate::kTooManySpreads); | 1861 ReportMessage(MessageTemplate::kTooManySpreads); |
1875 return this->EmptyExpression(); | 1862 return this->EmptyExpression(); |
1876 } | 1863 } |
1877 } | 1864 } |
1878 return result; | 1865 return result; |
1879 } | 1866 } |
1880 | 1867 |
1881 template <class Traits> | 1868 template <class Traits> |
1882 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( | 1869 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
1883 IdentifierT* name, bool* is_get, bool* is_set, bool* is_await, | 1870 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name, |
1884 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { | 1871 ExpressionClassifier* classifier, bool* ok) { |
1885 Token::Value token = peek(); | 1872 Token::Value token = peek(); |
1886 int pos = peek_position(); | 1873 int pos = peek_position(); |
1887 | 1874 |
1888 // For non computed property names we normalize the name a bit: | 1875 // For non computed property names we normalize the name a bit: |
1889 // | 1876 // |
1890 // "12" -> 12 | 1877 // "12" -> 12 |
1891 // 12.3 -> "12.3" | 1878 // 12.3 -> "12.3" |
1892 // 12.30 -> "12.3" | 1879 // 12.30 -> "12.3" |
1893 // identifier -> "identifier" | 1880 // identifier -> "identifier" |
1894 // | 1881 // |
(...skipping 24 matching lines...) Expand all Loading... | |
1919 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); | 1906 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); |
1920 classifier->Accumulate(&computed_name_classifier, | 1907 classifier->Accumulate(&computed_name_classifier, |
1921 ExpressionClassifier::ExpressionProductions); | 1908 ExpressionClassifier::ExpressionProductions); |
1922 Expect(Token::RBRACK, CHECK_OK); | 1909 Expect(Token::RBRACK, CHECK_OK); |
1923 return expression; | 1910 return expression; |
1924 } | 1911 } |
1925 | 1912 |
1926 default: | 1913 default: |
1927 *name = ParseIdentifierName(CHECK_OK); | 1914 *name = ParseIdentifierName(CHECK_OK); |
1928 scanner()->IsGetOrSet(is_get, is_set); | 1915 scanner()->IsGetOrSet(is_get, is_set); |
1929 if (this->IsAwait(*name)) { | |
1930 *is_await = true; | |
1931 } | |
1932 break; | 1916 break; |
1933 } | 1917 } |
1934 | 1918 |
1935 uint32_t index; | 1919 uint32_t index; |
1936 return this->IsArrayIndex(*name, &index) | 1920 return this->IsArrayIndex(*name, &index) |
1937 ? factory()->NewNumberLiteral(index, pos) | 1921 ? factory()->NewNumberLiteral(index, pos) |
1938 : factory()->NewStringLiteral(*name, pos); | 1922 : factory()->NewStringLiteral(*name, pos); |
1939 } | 1923 } |
1940 | 1924 |
1941 template <class Traits> | 1925 template <class Traits> |
1942 typename ParserBase<Traits>::ObjectLiteralPropertyT | 1926 typename ParserBase<Traits>::ObjectLiteralPropertyT |
1943 ParserBase<Traits>::ParsePropertyDefinition( | 1927 ParserBase<Traits>::ParsePropertyDefinition( |
1944 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1928 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
1945 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, | 1929 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, |
1946 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { | 1930 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { |
1947 DCHECK(!in_class || IsStaticMethod(method_kind) || | 1931 DCHECK(!in_class || IsStaticMethod(method_kind) || |
1948 has_seen_constructor != nullptr); | 1932 has_seen_constructor != nullptr); |
1949 bool is_get = false; | 1933 bool is_get = false; |
1950 bool is_set = false; | 1934 bool is_set = false; |
1951 bool is_await = false; | |
1952 bool is_generator = Check(Token::MUL); | 1935 bool is_generator = Check(Token::MUL); |
1953 bool is_async = false; | 1936 bool is_async = false; |
1954 const bool is_static = IsStaticMethod(method_kind); | 1937 const bool is_static = IsStaticMethod(method_kind); |
1955 | 1938 |
1956 Token::Value name_token = peek(); | 1939 Token::Value name_token = peek(); |
1957 | 1940 |
1958 if (is_generator) { | 1941 if (is_generator) { |
1959 method_kind |= MethodKind::kGenerator; | 1942 method_kind |= MethodKind::kGenerator; |
1960 } else if (allow_harmony_async_await() && name_token == Token::ASYNC && | 1943 } else if (allow_harmony_async_await() && name_token == Token::ASYNC && |
1961 !scanner()->HasAnyLineTerminatorAfterNext() && | 1944 !scanner()->HasAnyLineTerminatorAfterNext() && |
1962 PeekAhead() != Token::LPAREN && PeekAhead()) { | 1945 PeekAhead() != Token::LPAREN && PeekAhead()) { |
1963 is_async = true; | 1946 is_async = true; |
1964 } | 1947 } |
1965 | 1948 |
1966 int next_beg_pos = scanner()->peek_location().beg_pos; | 1949 int next_beg_pos = scanner()->peek_location().beg_pos; |
1967 int next_end_pos = scanner()->peek_location().end_pos; | 1950 int next_end_pos = scanner()->peek_location().end_pos; |
1968 ExpressionT name_expression = ParsePropertyName( | 1951 ExpressionT name_expression = |
1969 name, &is_get, &is_set, &is_await, is_computed_name, classifier, | 1952 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier, |
1970 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1953 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1971 | 1954 |
1972 if (fni_ != nullptr && !*is_computed_name) { | 1955 if (fni_ != nullptr && !*is_computed_name) { |
1973 this->PushLiteralName(fni_, *name); | 1956 this->PushLiteralName(fni_, *name); |
1974 } | 1957 } |
1975 | 1958 |
1976 if (!in_class && !is_generator) { | 1959 if (!in_class && !is_generator) { |
1977 DCHECK(!IsStaticMethod(method_kind)); | 1960 DCHECK(!IsStaticMethod(method_kind)); |
1978 if (peek() == Token::COLON) { | 1961 if (peek() == Token::COLON) { |
1979 // PropertyDefinition | 1962 // PropertyDefinition |
1980 // PropertyName ':' AssignmentExpression | 1963 // PropertyName ':' AssignmentExpression |
1981 if (!*is_computed_name) { | 1964 if (!*is_computed_name) { |
1982 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal, | 1965 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal, |
1983 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1966 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1984 } | 1967 } |
1985 Consume(Token::COLON); | 1968 Consume(Token::COLON); |
1986 int beg_pos = peek_position(); | 1969 int beg_pos = peek_position(); |
1987 ExpressionT value = this->ParseAssignmentExpression( | 1970 ExpressionT value = this->ParseAssignmentExpression( |
1988 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1971 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1989 CheckDestructuringElement(value, classifier, beg_pos, | 1972 CheckDestructuringElement(value, classifier, beg_pos, |
1990 scanner()->location().end_pos); | 1973 scanner()->location().end_pos); |
1991 | 1974 |
1992 return factory()->NewObjectLiteralProperty(name_expression, value, | 1975 return factory()->NewObjectLiteralProperty(name_expression, value, |
1993 is_static, *is_computed_name); | 1976 is_static, *is_computed_name); |
1994 } | 1977 } |
1995 | 1978 |
1996 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), | 1979 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), |
1997 parsing_module_) && | 1980 parsing_module_ || is_async_function()) && |
adamk
2016/08/20 01:00:54
To be clear, this is the bugfix, everything else i
| |
1998 (peek() == Token::COMMA || peek() == Token::RBRACE || | 1981 (peek() == Token::COMMA || peek() == Token::RBRACE || |
1999 peek() == Token::ASSIGN)) { | 1982 peek() == Token::ASSIGN)) { |
2000 // PropertyDefinition | 1983 // PropertyDefinition |
2001 // IdentifierReference | 1984 // IdentifierReference |
2002 // CoverInitializedName | 1985 // CoverInitializedName |
2003 // | 1986 // |
2004 // CoverInitializedName | 1987 // CoverInitializedName |
2005 // IdentifierReference Initializer? | 1988 // IdentifierReference Initializer? |
2006 if (classifier->duplicate_finder() != nullptr && | 1989 if (classifier->duplicate_finder() != nullptr && |
2007 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1990 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
2008 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1991 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
2009 } | 1992 } |
2010 | 1993 |
2011 if (this->IsEvalOrArguments(*name) && is_strict(language_mode())) { | 1994 if (this->IsEvalOrArguments(*name) && is_strict(language_mode())) { |
2012 classifier->RecordBindingPatternError( | 1995 classifier->RecordBindingPatternError( |
2013 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1996 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
2014 } | 1997 } |
2015 | 1998 |
2016 if (name_token == Token::LET) { | 1999 if (name_token == Token::LET) { |
2017 classifier->RecordLetPatternError( | 2000 classifier->RecordLetPatternError( |
2018 scanner()->location(), MessageTemplate::kLetInLexicalBinding); | 2001 scanner()->location(), MessageTemplate::kLetInLexicalBinding); |
2019 } | 2002 } |
2020 if (is_await) { | 2003 if (name_token == Token::AWAIT) { |
2021 if (is_async_function()) { | 2004 DCHECK(!is_async_function()); |
2022 classifier->RecordPatternError( | 2005 classifier->RecordAsyncArrowFormalParametersError( |
2023 Scanner::Location(next_beg_pos, next_end_pos), | 2006 Scanner::Location(next_beg_pos, next_end_pos), |
2024 MessageTemplate::kAwaitBindingIdentifier); | 2007 MessageTemplate::kAwaitBindingIdentifier); |
2025 } else { | |
2026 classifier->RecordAsyncArrowFormalParametersError( | |
2027 Scanner::Location(next_beg_pos, next_end_pos), | |
2028 MessageTemplate::kAwaitBindingIdentifier); | |
2029 } | |
2030 } | 2008 } |
2031 ExpressionT lhs = | 2009 ExpressionT lhs = |
2032 this->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos); | 2010 this->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos); |
2033 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 2011 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
2034 | 2012 |
2035 ExpressionT value; | 2013 ExpressionT value; |
2036 if (peek() == Token::ASSIGN) { | 2014 if (peek() == Token::ASSIGN) { |
2037 Consume(Token::ASSIGN); | 2015 Consume(Token::ASSIGN); |
2038 ExpressionClassifier rhs_classifier(this); | 2016 ExpressionClassifier rhs_classifier(this); |
2039 ExpressionT rhs = this->ParseAssignmentExpression( | 2017 ExpressionT rhs = this->ParseAssignmentExpression( |
(...skipping 22 matching lines...) Expand all Loading... | |
2062 // Method definitions are never valid in patterns. | 2040 // Method definitions are never valid in patterns. |
2063 classifier->RecordPatternError( | 2041 classifier->RecordPatternError( |
2064 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 2042 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
2065 MessageTemplate::kInvalidDestructuringTarget); | 2043 MessageTemplate::kInvalidDestructuringTarget); |
2066 | 2044 |
2067 if (is_async && !IsSpecialMethod(method_kind)) { | 2045 if (is_async && !IsSpecialMethod(method_kind)) { |
2068 DCHECK(!is_get); | 2046 DCHECK(!is_get); |
2069 DCHECK(!is_set); | 2047 DCHECK(!is_set); |
2070 bool dont_care; | 2048 bool dont_care; |
2071 name_expression = ParsePropertyName( | 2049 name_expression = ParsePropertyName( |
2072 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, | 2050 name, &dont_care, &dont_care, is_computed_name, classifier, |
2073 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2051 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2074 method_kind |= MethodKind::kAsync; | 2052 method_kind |= MethodKind::kAsync; |
2075 } | 2053 } |
2076 | 2054 |
2077 if (is_generator || peek() == Token::LPAREN) { | 2055 if (is_generator || peek() == Token::LPAREN) { |
2078 // MethodDefinition | 2056 // MethodDefinition |
2079 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2057 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
2080 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2058 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
2081 if (!*is_computed_name) { | 2059 if (!*is_computed_name) { |
2082 checker->CheckProperty(name_token, kMethodProperty, method_kind, | 2060 checker->CheckProperty(name_token, kMethodProperty, method_kind, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2118 | 2096 |
2119 if (is_get || is_set) { | 2097 if (is_get || is_set) { |
2120 // MethodDefinition (Accessors) | 2098 // MethodDefinition (Accessors) |
2121 // get PropertyName '(' ')' '{' FunctionBody '}' | 2099 // get PropertyName '(' ')' '{' FunctionBody '}' |
2122 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 2100 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
2123 *name = this->EmptyIdentifier(); | 2101 *name = this->EmptyIdentifier(); |
2124 bool dont_care = false; | 2102 bool dont_care = false; |
2125 name_token = peek(); | 2103 name_token = peek(); |
2126 | 2104 |
2127 name_expression = ParsePropertyName( | 2105 name_expression = ParsePropertyName( |
2128 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, | 2106 name, &dont_care, &dont_care, is_computed_name, classifier, |
2129 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2107 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2130 | 2108 |
2131 if (!*is_computed_name) { | 2109 if (!*is_computed_name) { |
2132 checker->CheckProperty(name_token, kAccessorProperty, method_kind, | 2110 checker->CheckProperty(name_token, kAccessorProperty, method_kind, |
2133 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2111 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2134 } | 2112 } |
2135 | 2113 |
2136 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 2114 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
2137 *name, scanner()->location(), kSkipFunctionNameCheck, | 2115 *name, scanner()->location(), kSkipFunctionNameCheck, |
2138 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, | 2116 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3094 // TODO(neis): allow escaping into closures? | 3072 // TODO(neis): allow escaping into closures? |
3095 ReportMessageAt(scanner()->location(), | 3073 ReportMessageAt(scanner()->location(), |
3096 MessageTemplate::kUnexpectedFunctionSent); | 3074 MessageTemplate::kUnexpectedFunctionSent); |
3097 *ok = false; | 3075 *ok = false; |
3098 return this->EmptyExpression(); | 3076 return this->EmptyExpression(); |
3099 } | 3077 } |
3100 | 3078 |
3101 return this->FunctionSentExpression(factory(), pos); | 3079 return this->FunctionSentExpression(factory(), pos); |
3102 } | 3080 } |
3103 | 3081 |
3104 bool is_generator = Check(Token::MUL); | 3082 FunctionKind function_kind = Check(Token::MUL) |
3083 ? FunctionKind::kGeneratorFunction | |
3084 : FunctionKind::kNormalFunction; | |
3105 IdentifierT name = this->EmptyIdentifier(); | 3085 IdentifierT name = this->EmptyIdentifier(); |
3106 bool is_strict_reserved_name = false; | 3086 bool is_strict_reserved_name = false; |
3107 Scanner::Location function_name_location = Scanner::Location::invalid(); | 3087 Scanner::Location function_name_location = Scanner::Location::invalid(); |
3108 FunctionLiteral::FunctionType function_type = | 3088 FunctionLiteral::FunctionType function_type = |
3109 FunctionLiteral::kAnonymousExpression; | 3089 FunctionLiteral::kAnonymousExpression; |
3110 if (peek_any_identifier()) { | 3090 if (peek_any_identifier()) { |
3111 name = ParseIdentifierOrStrictReservedWord( | 3091 name = ParseIdentifierOrStrictReservedWord( |
3112 is_generator, &is_strict_reserved_name, CHECK_OK); | 3092 function_kind, &is_strict_reserved_name, CHECK_OK); |
3113 function_name_location = scanner()->location(); | 3093 function_name_location = scanner()->location(); |
3114 function_type = FunctionLiteral::kNamedExpression; | 3094 function_type = FunctionLiteral::kNamedExpression; |
3115 } | 3095 } |
3116 result = this->ParseFunctionLiteral( | 3096 result = this->ParseFunctionLiteral( |
3117 name, function_name_location, | 3097 name, function_name_location, |
3118 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 3098 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
3119 : kFunctionNameValidityUnknown, | 3099 : kFunctionNameValidityUnknown, |
3120 is_generator ? FunctionKind::kGeneratorFunction | 3100 function_kind, function_token_position, function_type, language_mode(), |
3121 : FunctionKind::kNormalFunction, | 3101 CHECK_OK); |
3122 function_token_position, function_type, language_mode(), CHECK_OK); | |
3123 } else if (peek() == Token::SUPER) { | 3102 } else if (peek() == Token::SUPER) { |
3124 const bool is_new = false; | 3103 const bool is_new = false; |
3125 result = ParseSuperExpression(is_new, CHECK_OK); | 3104 result = ParseSuperExpression(is_new, CHECK_OK); |
3126 } else { | 3105 } else { |
3127 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); | 3106 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); |
3128 } | 3107 } |
3129 | 3108 |
3130 result = | 3109 result = |
3131 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); | 3110 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); |
3132 return result; | 3111 return result; |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3753 has_seen_constructor_ = true; | 3732 has_seen_constructor_ = true; |
3754 return; | 3733 return; |
3755 } | 3734 } |
3756 } | 3735 } |
3757 | 3736 |
3758 | 3737 |
3759 } // namespace internal | 3738 } // namespace internal |
3760 } // namespace v8 | 3739 } // namespace v8 |
3761 | 3740 |
3762 #endif // V8_PARSING_PARSER_BASE_H | 3741 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |