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/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 Loading... | |
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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 // LetDeclaration | 1130 // LetDeclaration |
1121 // ConstDeclaration | 1131 // ConstDeclaration |
1122 // ModuleDeclaration | 1132 // ModuleDeclaration |
1123 // ImportDeclaration | 1133 // ImportDeclaration |
1124 // ExportDeclaration | 1134 // ExportDeclaration |
1125 // GeneratorDeclaration | 1135 // GeneratorDeclaration |
1126 | 1136 |
1127 switch (peek()) { | 1137 switch (peek()) { |
1128 case Token::FUNCTION: | 1138 case Token::FUNCTION: |
1129 return ParseFunctionDeclaration(NULL, ok); | 1139 return ParseFunctionDeclaration(NULL, ok); |
1140 case Token::CLASS: | |
1141 return ParseClassDeclaration(NULL, ok); | |
1130 case Token::IMPORT: | 1142 case Token::IMPORT: |
1131 return ParseImportDeclaration(ok); | 1143 return ParseImportDeclaration(ok); |
1132 case Token::EXPORT: | 1144 case Token::EXPORT: |
1133 return ParseExportDeclaration(ok); | 1145 return ParseExportDeclaration(ok); |
1134 case Token::CONST: | 1146 case Token::CONST: |
1135 return ParseVariableStatement(kModuleElement, NULL, ok); | 1147 return ParseVariableStatement(kModuleElement, NULL, ok); |
1136 case Token::LET: | 1148 case Token::LET: |
1137 DCHECK(allow_harmony_scoping()); | 1149 DCHECK(allow_harmony_scoping()); |
1138 if (strict_mode() == STRICT) { | 1150 if (strict_mode() == STRICT) { |
1139 return ParseVariableStatement(kModuleElement, NULL, ok); | 1151 return ParseVariableStatement(kModuleElement, NULL, ok); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 } else { | 1471 } else { |
1460 result = ParseModuleDeclaration(&names, CHECK_OK); | 1472 result = ParseModuleDeclaration(&names, CHECK_OK); |
1461 } | 1473 } |
1462 break; | 1474 break; |
1463 } | 1475 } |
1464 | 1476 |
1465 case Token::FUNCTION: | 1477 case Token::FUNCTION: |
1466 result = ParseFunctionDeclaration(&names, CHECK_OK); | 1478 result = ParseFunctionDeclaration(&names, CHECK_OK); |
1467 break; | 1479 break; |
1468 | 1480 |
1481 case Token::CLASS: | |
1482 result = ParseClassDeclaration(&names, CHECK_OK); | |
1483 break; | |
1484 | |
1469 case Token::VAR: | 1485 case Token::VAR: |
1470 case Token::LET: | 1486 case Token::LET: |
1471 case Token::CONST: | 1487 case Token::CONST: |
1472 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); | 1488 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); |
1473 break; | 1489 break; |
1474 | 1490 |
1475 default: | 1491 default: |
1476 *ok = false; | 1492 *ok = false; |
1477 ReportUnexpectedToken(scanner()->current_token()); | 1493 ReportUnexpectedToken(scanner()->current_token()); |
1478 return NULL; | 1494 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 // (Ecma 262 5th Edition, clause 14): | 1537 // (Ecma 262 5th Edition, clause 14): |
1522 // SourceElement: | 1538 // SourceElement: |
1523 // Statement | 1539 // Statement |
1524 // FunctionDeclaration | 1540 // FunctionDeclaration |
1525 // | 1541 // |
1526 // In harmony mode we allow additionally the following productions | 1542 // In harmony mode we allow additionally the following productions |
1527 // BlockElement (aka SourceElement): | 1543 // BlockElement (aka SourceElement): |
1528 // LetDeclaration | 1544 // LetDeclaration |
1529 // ConstDeclaration | 1545 // ConstDeclaration |
1530 // GeneratorDeclaration | 1546 // GeneratorDeclaration |
1547 // ClassDeclaration | |
1531 | 1548 |
1532 switch (peek()) { | 1549 switch (peek()) { |
1533 case Token::FUNCTION: | 1550 case Token::FUNCTION: |
1534 return ParseFunctionDeclaration(NULL, ok); | 1551 return ParseFunctionDeclaration(NULL, ok); |
1552 case Token::CLASS: | |
1553 return ParseClassDeclaration(NULL, ok); | |
1535 case Token::CONST: | 1554 case Token::CONST: |
1536 return ParseVariableStatement(kModuleElement, NULL, ok); | 1555 return ParseVariableStatement(kModuleElement, NULL, ok); |
1537 case Token::LET: | 1556 case Token::LET: |
1538 DCHECK(allow_harmony_scoping()); | 1557 DCHECK(allow_harmony_scoping()); |
1539 if (strict_mode() == STRICT) { | 1558 if (strict_mode() == STRICT) { |
1540 return ParseVariableStatement(kModuleElement, NULL, ok); | 1559 return ParseVariableStatement(kModuleElement, NULL, ok); |
1541 } | 1560 } |
1542 // Fall through. | 1561 // Fall through. |
1543 default: | 1562 default: |
1544 return ParseStatement(labels, ok); | 1563 return ParseStatement(labels, ok); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1636 // Statement: | 1655 // Statement: |
1637 // GeneratorDeclaration | 1656 // GeneratorDeclaration |
1638 if (strict_mode() == STRICT) { | 1657 if (strict_mode() == STRICT) { |
1639 ReportMessageAt(scanner()->peek_location(), "strict_function"); | 1658 ReportMessageAt(scanner()->peek_location(), "strict_function"); |
1640 *ok = false; | 1659 *ok = false; |
1641 return NULL; | 1660 return NULL; |
1642 } | 1661 } |
1643 return ParseFunctionDeclaration(NULL, ok); | 1662 return ParseFunctionDeclaration(NULL, ok); |
1644 } | 1663 } |
1645 | 1664 |
1665 case Token::CLASS: | |
1666 return ParseClassDeclaration(NULL, ok); | |
1667 | |
1646 case Token::DEBUGGER: | 1668 case Token::DEBUGGER: |
1647 return ParseDebuggerStatement(ok); | 1669 return ParseDebuggerStatement(ok); |
1648 | 1670 |
1649 case Token::VAR: | 1671 case Token::VAR: |
1650 case Token::CONST: | 1672 case Token::CONST: |
1651 return ParseVariableStatement(kStatement, NULL, ok); | 1673 return ParseVariableStatement(kStatement, NULL, ok); |
1652 | 1674 |
1653 case Token::LET: | 1675 case Token::LET: |
1654 DCHECK(allow_harmony_scoping()); | 1676 DCHECK(allow_harmony_scoping()); |
1655 if (strict_mode() == STRICT) { | 1677 if (strict_mode() == STRICT) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1904 scope_->is_function_scope()) ? LET : VAR; | 1926 scope_->is_function_scope()) ? LET : VAR; |
1905 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); | 1927 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); |
1906 Declaration* declaration = | 1928 Declaration* declaration = |
1907 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 1929 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
1908 Declare(declaration, true, CHECK_OK); | 1930 Declare(declaration, true, CHECK_OK); |
1909 if (names) names->Add(name, zone()); | 1931 if (names) names->Add(name, zone()); |
1910 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1932 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
1911 } | 1933 } |
1912 | 1934 |
1913 | 1935 |
1936 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, | |
1937 bool* ok) { | |
1938 // ClassDeclaration :: | |
1939 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' | |
1940 // | |
1941 // A ClassDeclaration | |
1942 // | |
1943 // class C { ... } | |
1944 // | |
1945 // has the same semantics as: | |
1946 // | |
1947 // let C = class C { ... }; | |
1948 // | |
1949 // so rewrite it as such. | |
1950 | |
1951 Expect(Token::CLASS, CHECK_OK); | |
1952 int pos = position(); | |
1953 bool is_strict_reserved = false; | |
1954 const AstRawString* name = | |
1955 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | |
1956 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | |
1957 is_strict_reserved, pos, CHECK_OK); | |
1958 | |
1959 Block* block = factory()->NewBlock(NULL, 1, true, pos); | |
1960 VariableMode mode = LET; | |
1961 Interface* interface = Interface::NewValue(); | |
rossberg
2014/09/15 12:32:48
Nit: inline into call
arv (Not doing code reviews)
2014/09/15 15:12:32
Done.
| |
1962 VariableProxy* proxy = NewUnresolved(name, mode, interface); | |
1963 Declaration* declaration = | |
1964 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); | |
1965 Declare(declaration, true, CHECK_OK); | |
1966 | |
1967 Token::Value init_op = Token::INIT_LET; | |
1968 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | |
1969 block->AddStatement( | |
1970 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | |
1971 zone()); | |
1972 | |
1973 if (names) names->Add(name, zone()); | |
1974 return block; | |
1975 } | |
1976 | |
1977 | |
1914 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 1978 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
1915 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 1979 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
1916 return ParseScopedBlock(labels, ok); | 1980 return ParseScopedBlock(labels, ok); |
1917 } | 1981 } |
1918 | 1982 |
1919 // Block :: | 1983 // Block :: |
1920 // '{' Statement* '}' | 1984 // '{' Statement* '}' |
1921 | 1985 |
1922 // Note that a Block does not introduce a new execution scope! | 1986 // Note that a Block does not introduce a new execution scope! |
1923 // (ECMA-262, 3rd, 12.2) | 1987 // (ECMA-262, 3rd, 12.2) |
(...skipping 2917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4841 DCHECK(ast_value_factory_->IsInternalized()); | 4905 DCHECK(ast_value_factory_->IsInternalized()); |
4842 // info takes ownership of ast_value_factory_. | 4906 // info takes ownership of ast_value_factory_. |
4843 if (info()->ast_value_factory() == NULL) { | 4907 if (info()->ast_value_factory() == NULL) { |
4844 info()->SetAstValueFactory(ast_value_factory_); | 4908 info()->SetAstValueFactory(ast_value_factory_); |
4845 } | 4909 } |
4846 ast_value_factory_ = NULL; | 4910 ast_value_factory_ = NULL; |
4847 return (result != NULL); | 4911 return (result != NULL); |
4848 } | 4912 } |
4849 | 4913 |
4850 } } // namespace v8::internal | 4914 } } // namespace v8::internal |
OLD | NEW |