Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: src/parser.cc

Issue 561913002: Class syntax parsing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add early error checks for static prototype and get/set constructor Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 AstNode::IdGen saved_ast_node_id_gen_; 359 AstNode::IdGen saved_ast_node_id_gen_;
360 }; 360 };
361 361
362 362
363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { 363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
364 return identifier == parser_->ast_value_factory_->eval_string() || 364 return identifier == parser_->ast_value_factory_->eval_string() ||
365 identifier == parser_->ast_value_factory_->arguments_string(); 365 identifier == parser_->ast_value_factory_->arguments_string();
366 } 366 }
367 367
368 368
369 bool ParserTraits::IsPrototype(const AstRawString* identifier) const {
370 return identifier == parser_->ast_value_factory_->prototype_string();
371 }
372
373
374 bool ParserTraits::IsConstructor(const AstRawString* identifier) const {
375 return identifier == parser_->ast_value_factory_->constructor_string();
376 }
377
378
369 bool ParserTraits::IsThisProperty(Expression* expression) { 379 bool ParserTraits::IsThisProperty(Expression* expression) {
370 DCHECK(expression != NULL); 380 DCHECK(expression != NULL);
371 Property* property = expression->AsProperty(); 381 Property* property = expression->AsProperty();
372 return property != NULL && 382 return property != NULL &&
373 property->obj()->AsVariableProxy() != NULL && 383 property->obj()->AsVariableProxy() != NULL &&
374 property->obj()->AsVariableProxy()->is_this(); 384 property->obj()->AsVariableProxy()->is_this();
375 } 385 }
376 386
377 387
378 bool ParserTraits::IsIdentifier(Expression* expression) { 388 bool ParserTraits::IsIdentifier(Expression* expression) {
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 // FunctionDeclaration 1126 // FunctionDeclaration
1117 // 1127 //
1118 // In harmony mode we allow additionally the following productions 1128 // In harmony mode we allow additionally the following productions
1119 // ModuleElement: 1129 // ModuleElement:
1120 // LetDeclaration 1130 // LetDeclaration
1121 // ConstDeclaration 1131 // ConstDeclaration
1122 // ModuleDeclaration 1132 // ModuleDeclaration
1123 // ImportDeclaration 1133 // ImportDeclaration
1124 // ExportDeclaration 1134 // ExportDeclaration
1125 // GeneratorDeclaration 1135 // GeneratorDeclaration
1136 // ClassDeclaration
1126 1137
1127 switch (peek()) { 1138 switch (peek()) {
1128 case Token::FUNCTION: 1139 case Token::FUNCTION:
1129 return ParseFunctionDeclaration(NULL, ok); 1140 return ParseFunctionDeclaration(NULL, ok);
1141 case Token::CLASS:
1142 return ParseClassDeclaration(NULL, ok);
1130 case Token::IMPORT: 1143 case Token::IMPORT:
1131 return ParseImportDeclaration(ok); 1144 return ParseImportDeclaration(ok);
1132 case Token::EXPORT: 1145 case Token::EXPORT:
1133 return ParseExportDeclaration(ok); 1146 return ParseExportDeclaration(ok);
1134 case Token::CONST: 1147 case Token::CONST:
1135 return ParseVariableStatement(kModuleElement, NULL, ok); 1148 return ParseVariableStatement(kModuleElement, NULL, ok);
1136 case Token::LET: 1149 case Token::LET:
1137 DCHECK(allow_harmony_scoping()); 1150 DCHECK(allow_harmony_scoping());
1138 if (strict_mode() == STRICT) { 1151 if (strict_mode() == STRICT) {
1139 return ParseVariableStatement(kModuleElement, NULL, ok); 1152 return ParseVariableStatement(kModuleElement, NULL, ok);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 } else { 1472 } else {
1460 result = ParseModuleDeclaration(&names, CHECK_OK); 1473 result = ParseModuleDeclaration(&names, CHECK_OK);
1461 } 1474 }
1462 break; 1475 break;
1463 } 1476 }
1464 1477
1465 case Token::FUNCTION: 1478 case Token::FUNCTION:
1466 result = ParseFunctionDeclaration(&names, CHECK_OK); 1479 result = ParseFunctionDeclaration(&names, CHECK_OK);
1467 break; 1480 break;
1468 1481
1482 case Token::CLASS:
1483 result = ParseClassDeclaration(&names, CHECK_OK);
1484 break;
1485
1469 case Token::VAR: 1486 case Token::VAR:
1470 case Token::LET: 1487 case Token::LET:
1471 case Token::CONST: 1488 case Token::CONST:
1472 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); 1489 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK);
1473 break; 1490 break;
1474 1491
1475 default: 1492 default:
1476 *ok = false; 1493 *ok = false;
1477 ReportUnexpectedToken(scanner()->current_token()); 1494 ReportUnexpectedToken(scanner()->current_token());
1478 return NULL; 1495 return NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 // (Ecma 262 5th Edition, clause 14): 1538 // (Ecma 262 5th Edition, clause 14):
1522 // SourceElement: 1539 // SourceElement:
1523 // Statement 1540 // Statement
1524 // FunctionDeclaration 1541 // FunctionDeclaration
1525 // 1542 //
1526 // In harmony mode we allow additionally the following productions 1543 // In harmony mode we allow additionally the following productions
1527 // BlockElement (aka SourceElement): 1544 // BlockElement (aka SourceElement):
1528 // LetDeclaration 1545 // LetDeclaration
1529 // ConstDeclaration 1546 // ConstDeclaration
1530 // GeneratorDeclaration 1547 // GeneratorDeclaration
1548 // ClassDeclaration
1531 1549
1532 switch (peek()) { 1550 switch (peek()) {
1533 case Token::FUNCTION: 1551 case Token::FUNCTION:
1534 return ParseFunctionDeclaration(NULL, ok); 1552 return ParseFunctionDeclaration(NULL, ok);
1553 case Token::CLASS:
1554 return ParseClassDeclaration(NULL, ok);
1535 case Token::CONST: 1555 case Token::CONST:
1536 return ParseVariableStatement(kModuleElement, NULL, ok); 1556 return ParseVariableStatement(kModuleElement, NULL, ok);
1537 case Token::LET: 1557 case Token::LET:
1538 DCHECK(allow_harmony_scoping()); 1558 DCHECK(allow_harmony_scoping());
1539 if (strict_mode() == STRICT) { 1559 if (strict_mode() == STRICT) {
1540 return ParseVariableStatement(kModuleElement, NULL, ok); 1560 return ParseVariableStatement(kModuleElement, NULL, ok);
1541 } 1561 }
1542 // Fall through. 1562 // Fall through.
1543 default: 1563 default:
1544 return ParseStatement(labels, ok); 1564 return ParseStatement(labels, ok);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 // Statement: 1656 // Statement:
1637 // GeneratorDeclaration 1657 // GeneratorDeclaration
1638 if (strict_mode() == STRICT) { 1658 if (strict_mode() == STRICT) {
1639 ReportMessageAt(scanner()->peek_location(), "strict_function"); 1659 ReportMessageAt(scanner()->peek_location(), "strict_function");
1640 *ok = false; 1660 *ok = false;
1641 return NULL; 1661 return NULL;
1642 } 1662 }
1643 return ParseFunctionDeclaration(NULL, ok); 1663 return ParseFunctionDeclaration(NULL, ok);
1644 } 1664 }
1645 1665
1666 case Token::CLASS:
1667 return ParseClassDeclaration(NULL, ok);
1668
1646 case Token::DEBUGGER: 1669 case Token::DEBUGGER:
1647 return ParseDebuggerStatement(ok); 1670 return ParseDebuggerStatement(ok);
1648 1671
1649 case Token::VAR: 1672 case Token::VAR:
1650 case Token::CONST: 1673 case Token::CONST:
1651 return ParseVariableStatement(kStatement, NULL, ok); 1674 return ParseVariableStatement(kStatement, NULL, ok);
1652 1675
1653 case Token::LET: 1676 case Token::LET:
1654 DCHECK(allow_harmony_scoping()); 1677 DCHECK(allow_harmony_scoping());
1655 if (strict_mode() == STRICT) { 1678 if (strict_mode() == STRICT) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 scope_->is_function_scope()) ? LET : VAR; 1927 scope_->is_function_scope()) ? LET : VAR;
1905 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); 1928 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
1906 Declaration* declaration = 1929 Declaration* declaration =
1907 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 1930 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
1908 Declare(declaration, true, CHECK_OK); 1931 Declare(declaration, true, CHECK_OK);
1909 if (names) names->Add(name, zone()); 1932 if (names) names->Add(name, zone());
1910 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1933 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1911 } 1934 }
1912 1935
1913 1936
1937 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
1938 bool* ok) {
1939 // ClassDeclaration ::
1940 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
1941 Expect(Token::CLASS, CHECK_OK);
1942 int pos = position();
1943 bool is_strict_reserved = false;
1944 const AstRawString* name =
1945 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
1946 ClassLiteral* lit = ParseClassLiteral(name, scanner()->location(),
1947 is_strict_reserved, pos, CHECK_OK);
1948 VariableMode mode = LET;
1949 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
1950 Declaration* declaration =
1951 factory()->NewClassDeclaration(proxy, lit, scope_, pos);
1952 Declare(declaration, true, CHECK_OK);
1953 if (names) names->Add(name, zone());
1954 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1955 }
1956
1957
1914 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { 1958 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) {
1915 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1959 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1916 return ParseScopedBlock(labels, ok); 1960 return ParseScopedBlock(labels, ok);
1917 } 1961 }
1918 1962
1919 // Block :: 1963 // Block ::
1920 // '{' Statement* '}' 1964 // '{' Statement* '}'
1921 1965
1922 // Note that a Block does not introduce a new execution scope! 1966 // Note that a Block does not introduce a new execution scope!
1923 // (ECMA-262, 3rd, 12.2) 1967 // (ECMA-262, 3rd, 12.2)
(...skipping 2917 matching lines...) Expand 10 before | Expand all | Expand 10 after
4841 DCHECK(ast_value_factory_->IsInternalized()); 4885 DCHECK(ast_value_factory_->IsInternalized());
4842 // info takes ownership of ast_value_factory_. 4886 // info takes ownership of ast_value_factory_.
4843 if (info()->ast_value_factory() == NULL) { 4887 if (info()->ast_value_factory() == NULL) {
4844 info()->SetAstValueFactory(ast_value_factory_); 4888 info()->SetAstValueFactory(ast_value_factory_);
4845 } 4889 }
4846 ast_value_factory_ = NULL; 4890 ast_value_factory_ = NULL;
4847 return (result != NULL); 4891 return (result != NULL);
4848 } 4892 }
4849 4893
4850 } } // namespace v8::internal 4894 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698