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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1704 // Statement: | 1704 // Statement: |
1705 // GeneratorDeclaration | 1705 // GeneratorDeclaration |
1706 if (strict_mode() == STRICT) { | 1706 if (strict_mode() == STRICT) { |
1707 ReportMessageAt(scanner()->peek_location(), "strict_function"); | 1707 ReportMessageAt(scanner()->peek_location(), "strict_function"); |
1708 *ok = false; | 1708 *ok = false; |
1709 return NULL; | 1709 return NULL; |
1710 } | 1710 } |
1711 return ParseFunctionDeclaration(NULL, ok); | 1711 return ParseFunctionDeclaration(NULL, ok); |
1712 } | 1712 } |
1713 | 1713 |
1714 case Token::CLASS: | |
1715 return ParseClassDeclaration(NULL, ok); | |
1716 | |
1717 case Token::DEBUGGER: | 1714 case Token::DEBUGGER: |
1718 return ParseDebuggerStatement(ok); | 1715 return ParseDebuggerStatement(ok); |
1719 | 1716 |
1720 case Token::VAR: | 1717 case Token::VAR: |
1721 case Token::CONST: | |
1722 return ParseVariableStatement(kStatement, NULL, ok); | 1718 return ParseVariableStatement(kStatement, NULL, ok); |
1723 | 1719 |
1724 case Token::LET: | 1720 case Token::CONST: |
1725 DCHECK(allow_harmony_scoping()); | 1721 // In ES6 CONST is not allowed as a Statement , only as a |
1726 if (strict_mode() == STRICT) { | 1722 // LexicalDeclaration, however we continue to allow it in sloppy mode for |
1723 // backwards compatibility. | |
1724 if (strict_mode() == SLOPPY) { | |
1727 return ParseVariableStatement(kStatement, NULL, ok); | 1725 return ParseVariableStatement(kStatement, NULL, ok); |
1728 } | 1726 } |
1729 // Fall through. | 1727 |
1728 // Fall through. | |
1730 default: | 1729 default: |
1731 return ParseExpressionOrLabelledStatement(labels, ok); | 1730 return ParseExpressionOrLabelledStatement(labels, ok); |
1732 } | 1731 } |
1733 } | 1732 } |
1734 | 1733 |
1735 | 1734 |
1736 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1735 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
1737 VariableMode mode, Interface* interface) { | 1736 VariableMode mode, Interface* interface) { |
1738 // If we are inside a function, a declaration of a var/const variable is a | 1737 // If we are inside a function, a declaration of a var/const variable is a |
1739 // truly local variable, and the scope of the variable is always the function | 1738 // truly local variable, and the scope of the variable is always the function |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2143 // existing pages. Therefore we keep allowing const with the old | 2142 // existing pages. Therefore we keep allowing const with the old |
2144 // non-harmony semantics in sloppy mode. | 2143 // non-harmony semantics in sloppy mode. |
2145 Consume(Token::CONST); | 2144 Consume(Token::CONST); |
2146 switch (strict_mode()) { | 2145 switch (strict_mode()) { |
2147 case SLOPPY: | 2146 case SLOPPY: |
2148 mode = CONST_LEGACY; | 2147 mode = CONST_LEGACY; |
2149 init_op = Token::INIT_CONST_LEGACY; | 2148 init_op = Token::INIT_CONST_LEGACY; |
2150 break; | 2149 break; |
2151 case STRICT: | 2150 case STRICT: |
2152 if (allow_harmony_scoping()) { | 2151 if (allow_harmony_scoping()) { |
2153 if (var_context == kStatement) { | 2152 if (var_context == kStatement) { |
adamk
2015/01/23 20:11:39
I believe this code is now unreachable...
| |
2154 // In strict mode 'const' declarations are only allowed in source | 2153 // In strict mode 'const' declarations are only allowed in source |
2155 // element positions. | 2154 // element positions. |
2156 ReportMessage("unprotected_const"); | 2155 ReportMessage("unprotected_const"); |
2157 *ok = false; | 2156 *ok = false; |
2158 return NULL; | 2157 return NULL; |
2159 } | 2158 } |
2160 mode = CONST; | 2159 mode = CONST; |
2161 init_op = Token::INIT_CONST; | 2160 init_op = Token::INIT_CONST; |
2162 } else { | 2161 } else { |
2163 ReportMessage("strict_const"); | 2162 ReportMessage("strict_const"); |
2164 *ok = false; | 2163 *ok = false; |
2165 return NULL; | 2164 return NULL; |
2166 } | 2165 } |
2167 } | 2166 } |
2168 is_const = true; | 2167 is_const = true; |
2169 needs_init = true; | 2168 needs_init = true; |
2170 } else if (peek() == Token::LET && strict_mode() == STRICT) { | 2169 } else if (peek() == Token::LET && strict_mode() == STRICT) { |
2171 DCHECK(allow_harmony_scoping()); | 2170 DCHECK(allow_harmony_scoping()); |
2172 Consume(Token::LET); | 2171 Consume(Token::LET); |
2173 if (var_context == kStatement) { | 2172 if (var_context == kStatement) { |
adamk
2015/01/23 20:11:39
...as is this.
| |
2174 // Let declarations are only allowed in source element positions. | 2173 // Let declarations are only allowed in source element positions. |
2175 ReportMessage("unprotected_let"); | 2174 ReportMessage("unprotected_let"); |
2176 *ok = false; | 2175 *ok = false; |
2177 return NULL; | 2176 return NULL; |
2178 } | 2177 } |
2179 mode = LET; | 2178 mode = LET; |
2180 needs_init = true; | 2179 needs_init = true; |
2181 init_op = Token::INIT_LET; | 2180 init_op = Token::INIT_LET; |
2182 } else { | 2181 } else { |
2183 UNREACHABLE(); // by current callers | 2182 UNREACHABLE(); // by current callers |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2431 } | 2430 } |
2432 return false; | 2431 return false; |
2433 } | 2432 } |
2434 | 2433 |
2435 | 2434 |
2436 Statement* Parser::ParseExpressionOrLabelledStatement( | 2435 Statement* Parser::ParseExpressionOrLabelledStatement( |
2437 ZoneList<const AstRawString*>* labels, bool* ok) { | 2436 ZoneList<const AstRawString*>* labels, bool* ok) { |
2438 // ExpressionStatement | LabelledStatement :: | 2437 // ExpressionStatement | LabelledStatement :: |
2439 // Expression ';' | 2438 // Expression ';' |
2440 // Identifier ':' Statement | 2439 // Identifier ':' Statement |
2440 // | |
2441 // ExpressionStatement[Yield] : | |
2442 // [lookahead ∉ {{, function, class, let [}] Expression[In, ?Yield] ; | |
2443 | |
2444 switch (peek()) { | |
2445 case Token::FUNCTION: | |
2446 case Token::LBRACE: | |
2447 UNREACHABLE(); // Always handled by the callers. | |
2448 case Token::CLASS: | |
2449 ReportUnexpectedToken(Next()); | |
2450 *ok = false; | |
2451 return nullptr; | |
adamk
2015/01/23 20:11:39
Nit: the rest of the code in this file still uses
| |
2452 | |
2453 // TODO(arv): Handle `let [` | |
2454 // https://code.google.com/p/v8/issues/detail?id=3847 | |
2455 | |
2456 default: | |
2457 break; | |
2458 } | |
2459 | |
2441 int pos = peek_position(); | 2460 int pos = peek_position(); |
2442 bool starts_with_idenfifier = peek_any_identifier(); | 2461 bool starts_with_idenfifier = peek_any_identifier(); |
2443 Expression* expr = ParseExpression(true, CHECK_OK); | 2462 Expression* expr = ParseExpression(true, CHECK_OK); |
2444 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && | 2463 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && |
2445 expr->AsVariableProxy() != NULL && | 2464 expr->AsVariableProxy() != NULL && |
2446 !expr->AsVariableProxy()->is_this()) { | 2465 !expr->AsVariableProxy()->is_this()) { |
2447 // Expression is a single identifier, and not, e.g., a parenthesized | 2466 // Expression is a single identifier, and not, e.g., a parenthesized |
2448 // identifier. | 2467 // identifier. |
2449 VariableProxy* var = expr->AsVariableProxy(); | 2468 VariableProxy* var = expr->AsVariableProxy(); |
2450 const AstRawString* label = var->raw_name(); | 2469 const AstRawString* label = var->raw_name(); |
(...skipping 2894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5345 } else { | 5364 } else { |
5346 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5365 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5347 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5366 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5348 raw_string->length()); | 5367 raw_string->length()); |
5349 } | 5368 } |
5350 } | 5369 } |
5351 | 5370 |
5352 return running_hash; | 5371 return running_hash; |
5353 } | 5372 } |
5354 } } // namespace v8::internal | 5373 } } // namespace v8::internal |
OLD | NEW |