| 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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 // LetDeclaration | 1139 // LetDeclaration |
| 1130 // ConstDeclaration | 1140 // ConstDeclaration |
| 1131 // ModuleDeclaration | 1141 // ModuleDeclaration |
| 1132 // ImportDeclaration | 1142 // ImportDeclaration |
| 1133 // ExportDeclaration | 1143 // ExportDeclaration |
| 1134 // GeneratorDeclaration | 1144 // GeneratorDeclaration |
| 1135 | 1145 |
| 1136 switch (peek()) { | 1146 switch (peek()) { |
| 1137 case Token::FUNCTION: | 1147 case Token::FUNCTION: |
| 1138 return ParseFunctionDeclaration(NULL, ok); | 1148 return ParseFunctionDeclaration(NULL, ok); |
| 1149 case Token::CLASS: |
| 1150 return ParseClassDeclaration(NULL, ok); |
| 1139 case Token::IMPORT: | 1151 case Token::IMPORT: |
| 1140 return ParseImportDeclaration(ok); | 1152 return ParseImportDeclaration(ok); |
| 1141 case Token::EXPORT: | 1153 case Token::EXPORT: |
| 1142 return ParseExportDeclaration(ok); | 1154 return ParseExportDeclaration(ok); |
| 1143 case Token::CONST: | 1155 case Token::CONST: |
| 1144 return ParseVariableStatement(kModuleElement, NULL, ok); | 1156 return ParseVariableStatement(kModuleElement, NULL, ok); |
| 1145 case Token::LET: | 1157 case Token::LET: |
| 1146 DCHECK(allow_harmony_scoping()); | 1158 DCHECK(allow_harmony_scoping()); |
| 1147 if (strict_mode() == STRICT) { | 1159 if (strict_mode() == STRICT) { |
| 1148 return ParseVariableStatement(kModuleElement, NULL, ok); | 1160 return ParseVariableStatement(kModuleElement, NULL, ok); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 } else { | 1480 } else { |
| 1469 result = ParseModuleDeclaration(&names, CHECK_OK); | 1481 result = ParseModuleDeclaration(&names, CHECK_OK); |
| 1470 } | 1482 } |
| 1471 break; | 1483 break; |
| 1472 } | 1484 } |
| 1473 | 1485 |
| 1474 case Token::FUNCTION: | 1486 case Token::FUNCTION: |
| 1475 result = ParseFunctionDeclaration(&names, CHECK_OK); | 1487 result = ParseFunctionDeclaration(&names, CHECK_OK); |
| 1476 break; | 1488 break; |
| 1477 | 1489 |
| 1490 case Token::CLASS: |
| 1491 result = ParseClassDeclaration(&names, CHECK_OK); |
| 1492 break; |
| 1493 |
| 1478 case Token::VAR: | 1494 case Token::VAR: |
| 1479 case Token::LET: | 1495 case Token::LET: |
| 1480 case Token::CONST: | 1496 case Token::CONST: |
| 1481 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); | 1497 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); |
| 1482 break; | 1498 break; |
| 1483 | 1499 |
| 1484 default: | 1500 default: |
| 1485 *ok = false; | 1501 *ok = false; |
| 1486 ReportUnexpectedToken(scanner()->current_token()); | 1502 ReportUnexpectedToken(scanner()->current_token()); |
| 1487 return NULL; | 1503 return NULL; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 // (Ecma 262 5th Edition, clause 14): | 1546 // (Ecma 262 5th Edition, clause 14): |
| 1531 // SourceElement: | 1547 // SourceElement: |
| 1532 // Statement | 1548 // Statement |
| 1533 // FunctionDeclaration | 1549 // FunctionDeclaration |
| 1534 // | 1550 // |
| 1535 // In harmony mode we allow additionally the following productions | 1551 // In harmony mode we allow additionally the following productions |
| 1536 // BlockElement (aka SourceElement): | 1552 // BlockElement (aka SourceElement): |
| 1537 // LetDeclaration | 1553 // LetDeclaration |
| 1538 // ConstDeclaration | 1554 // ConstDeclaration |
| 1539 // GeneratorDeclaration | 1555 // GeneratorDeclaration |
| 1556 // ClassDeclaration |
| 1540 | 1557 |
| 1541 switch (peek()) { | 1558 switch (peek()) { |
| 1542 case Token::FUNCTION: | 1559 case Token::FUNCTION: |
| 1543 return ParseFunctionDeclaration(NULL, ok); | 1560 return ParseFunctionDeclaration(NULL, ok); |
| 1561 case Token::CLASS: |
| 1562 return ParseClassDeclaration(NULL, ok); |
| 1544 case Token::CONST: | 1563 case Token::CONST: |
| 1545 return ParseVariableStatement(kModuleElement, NULL, ok); | 1564 return ParseVariableStatement(kModuleElement, NULL, ok); |
| 1546 case Token::LET: | 1565 case Token::LET: |
| 1547 DCHECK(allow_harmony_scoping()); | 1566 DCHECK(allow_harmony_scoping()); |
| 1548 if (strict_mode() == STRICT) { | 1567 if (strict_mode() == STRICT) { |
| 1549 return ParseVariableStatement(kModuleElement, NULL, ok); | 1568 return ParseVariableStatement(kModuleElement, NULL, ok); |
| 1550 } | 1569 } |
| 1551 // Fall through. | 1570 // Fall through. |
| 1552 default: | 1571 default: |
| 1553 return ParseStatement(labels, ok); | 1572 return ParseStatement(labels, ok); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 // Statement: | 1664 // Statement: |
| 1646 // GeneratorDeclaration | 1665 // GeneratorDeclaration |
| 1647 if (strict_mode() == STRICT) { | 1666 if (strict_mode() == STRICT) { |
| 1648 ReportMessageAt(scanner()->peek_location(), "strict_function"); | 1667 ReportMessageAt(scanner()->peek_location(), "strict_function"); |
| 1649 *ok = false; | 1668 *ok = false; |
| 1650 return NULL; | 1669 return NULL; |
| 1651 } | 1670 } |
| 1652 return ParseFunctionDeclaration(NULL, ok); | 1671 return ParseFunctionDeclaration(NULL, ok); |
| 1653 } | 1672 } |
| 1654 | 1673 |
| 1674 case Token::CLASS: |
| 1675 return ParseClassDeclaration(NULL, ok); |
| 1676 |
| 1655 case Token::DEBUGGER: | 1677 case Token::DEBUGGER: |
| 1656 return ParseDebuggerStatement(ok); | 1678 return ParseDebuggerStatement(ok); |
| 1657 | 1679 |
| 1658 case Token::VAR: | 1680 case Token::VAR: |
| 1659 case Token::CONST: | 1681 case Token::CONST: |
| 1660 return ParseVariableStatement(kStatement, NULL, ok); | 1682 return ParseVariableStatement(kStatement, NULL, ok); |
| 1661 | 1683 |
| 1662 case Token::LET: | 1684 case Token::LET: |
| 1663 DCHECK(allow_harmony_scoping()); | 1685 DCHECK(allow_harmony_scoping()); |
| 1664 if (strict_mode() == STRICT) { | 1686 if (strict_mode() == STRICT) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 scope_->is_function_scope()) ? LET : VAR; | 1935 scope_->is_function_scope()) ? LET : VAR; |
| 1914 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); | 1936 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); |
| 1915 Declaration* declaration = | 1937 Declaration* declaration = |
| 1916 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 1938 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
| 1917 Declare(declaration, true, CHECK_OK); | 1939 Declare(declaration, true, CHECK_OK); |
| 1918 if (names) names->Add(name, zone()); | 1940 if (names) names->Add(name, zone()); |
| 1919 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1941 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| 1920 } | 1942 } |
| 1921 | 1943 |
| 1922 | 1944 |
| 1945 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 1946 bool* ok) { |
| 1947 // ClassDeclaration :: |
| 1948 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' |
| 1949 // |
| 1950 // A ClassDeclaration |
| 1951 // |
| 1952 // class C { ... } |
| 1953 // |
| 1954 // has the same semantics as: |
| 1955 // |
| 1956 // let C = class C { ... }; |
| 1957 // |
| 1958 // so rewrite it as such. |
| 1959 |
| 1960 Expect(Token::CLASS, CHECK_OK); |
| 1961 int pos = position(); |
| 1962 bool is_strict_reserved = false; |
| 1963 const AstRawString* name = |
| 1964 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 1965 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
| 1966 is_strict_reserved, pos, CHECK_OK); |
| 1967 |
| 1968 Block* block = factory()->NewBlock(NULL, 1, true, pos); |
| 1969 VariableMode mode = LET; |
| 1970 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); |
| 1971 Declaration* declaration = |
| 1972 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); |
| 1973 Declare(declaration, true, CHECK_OK); |
| 1974 |
| 1975 Token::Value init_op = Token::INIT_LET; |
| 1976 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
| 1977 block->AddStatement( |
| 1978 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
| 1979 zone()); |
| 1980 |
| 1981 if (names) names->Add(name, zone()); |
| 1982 return block; |
| 1983 } |
| 1984 |
| 1985 |
| 1923 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 1986 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| 1924 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 1987 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
| 1925 return ParseScopedBlock(labels, ok); | 1988 return ParseScopedBlock(labels, ok); |
| 1926 } | 1989 } |
| 1927 | 1990 |
| 1928 // Block :: | 1991 // Block :: |
| 1929 // '{' Statement* '}' | 1992 // '{' Statement* '}' |
| 1930 | 1993 |
| 1931 // Note that a Block does not introduce a new execution scope! | 1994 // Note that a Block does not introduce a new execution scope! |
| 1932 // (ECMA-262, 3rd, 12.2) | 1995 // (ECMA-262, 3rd, 12.2) |
| (...skipping 2950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4883 | 4946 |
| 4884 // We cannot internalize on a background thread; a foreground task will take | 4947 // We cannot internalize on a background thread; a foreground task will take |
| 4885 // care of calling Parser::Internalize just before compilation. | 4948 // care of calling Parser::Internalize just before compilation. |
| 4886 | 4949 |
| 4887 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 4950 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4888 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 4951 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 4889 log_ = NULL; | 4952 log_ = NULL; |
| 4890 } | 4953 } |
| 4891 } | 4954 } |
| 4892 } } // namespace v8::internal | 4955 } } // namespace v8::internal |
| OLD | NEW |