OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 474 } |
475 | 475 |
476 ~BlockState() { parser_->top_scope_ = outer_scope_; } | 476 ~BlockState() { parser_->top_scope_ = outer_scope_; } |
477 | 477 |
478 private: | 478 private: |
479 Parser* parser_; | 479 Parser* parser_; |
480 Scope* outer_scope_; | 480 Scope* outer_scope_; |
481 }; | 481 }; |
482 | 482 |
483 | 483 |
484 class Parser::FunctionState BASE_EMBEDDED { | |
485 public: | |
486 FunctionState(Parser* parser, Scope* scope, Isolate* isolate); | |
487 ~FunctionState(); | |
488 | |
489 int NextMaterializedLiteralIndex() { | |
490 return next_materialized_literal_index_++; | |
491 } | |
492 int materialized_literal_count() { | |
493 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | |
494 } | |
495 | |
496 int NextHandlerIndex() { return next_handler_index_++; } | |
497 int handler_count() { return next_handler_index_; } | |
498 | |
499 void SetThisPropertyAssignmentInfo( | |
500 bool only_simple_this_property_assignments, | |
501 Handle<FixedArray> this_property_assignments) { | |
502 only_simple_this_property_assignments_ = | |
503 only_simple_this_property_assignments; | |
504 this_property_assignments_ = this_property_assignments; | |
505 } | |
506 bool only_simple_this_property_assignments() { | |
507 return only_simple_this_property_assignments_; | |
508 } | |
509 Handle<FixedArray> this_property_assignments() { | |
510 return this_property_assignments_; | |
511 } | |
512 | |
513 void AddProperty() { expected_property_count_++; } | |
514 int expected_property_count() { return expected_property_count_; } | |
515 | |
516 private: | |
517 // Used to assign an index to each literal that needs materialization in | |
518 // the function. Includes regexp literals, and boilerplate for object and | |
519 // array literals. | |
520 int next_materialized_literal_index_; | |
521 | |
522 // Used to assign a per-function index to try and catch handlers. | |
523 int next_handler_index_; | |
524 | |
525 // Properties count estimation. | |
526 int expected_property_count_; | |
527 | |
528 // Keeps track of assignments to properties of this. Used for | |
529 // optimizing constructors. | |
530 bool only_simple_this_property_assignments_; | |
531 Handle<FixedArray> this_property_assignments_; | |
532 | |
533 Parser* parser_; | |
534 FunctionState* outer_function_state_; | |
535 Scope* outer_scope_; | |
536 unsigned saved_ast_node_id_; | |
537 }; | |
538 | |
539 | |
540 Parser::FunctionState::FunctionState(Parser* parser, | 484 Parser::FunctionState::FunctionState(Parser* parser, |
541 Scope* scope, | 485 Scope* scope, |
542 Isolate* isolate) | 486 Isolate* isolate) |
543 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 487 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
544 next_handler_index_(0), | 488 next_handler_index_(0), |
545 expected_property_count_(0), | 489 expected_property_count_(0), |
546 only_simple_this_property_assignments_(false), | 490 only_simple_this_property_assignments_(false), |
547 this_property_assignments_(isolate->factory()->empty_fixed_array()), | 491 this_property_assignments_(isolate->factory()->empty_fixed_array()), |
548 parser_(parser), | 492 parser_(parser), |
549 outer_function_state_(parser->current_function_state_), | 493 outer_function_state_(parser->current_function_state_), |
550 outer_scope_(parser->top_scope_), | 494 outer_scope_(parser->top_scope_), |
551 saved_ast_node_id_(isolate->ast_node_id()) { | 495 saved_ast_node_id_(isolate->ast_node_id()), |
| 496 factory_(isolate) { |
552 parser->top_scope_ = scope; | 497 parser->top_scope_ = scope; |
553 parser->current_function_state_ = this; | 498 parser->current_function_state_ = this; |
554 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1); | 499 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1); |
555 } | 500 } |
556 | 501 |
557 | 502 |
558 Parser::FunctionState::~FunctionState() { | 503 Parser::FunctionState::~FunctionState() { |
559 parser_->top_scope_ = outer_scope_; | 504 parser_->top_scope_ = outer_scope_; |
560 parser_->current_function_state_ = outer_function_state_; | 505 parser_->current_function_state_ = outer_function_state_; |
561 parser_->isolate()->set_ast_node_id(saved_ast_node_id_); | 506 parser_->isolate()->set_ast_node_id(saved_ast_node_id_); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 ParseSourceElements(body, Token::EOS, &ok); | 612 ParseSourceElements(body, Token::EOS, &ok); |
668 if (ok && !top_scope_->is_classic_mode()) { | 613 if (ok && !top_scope_->is_classic_mode()) { |
669 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 614 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
670 } | 615 } |
671 | 616 |
672 if (ok && is_extended_mode()) { | 617 if (ok && is_extended_mode()) { |
673 CheckConflictingVarDeclarations(scope, &ok); | 618 CheckConflictingVarDeclarations(scope, &ok); |
674 } | 619 } |
675 | 620 |
676 if (ok) { | 621 if (ok) { |
677 result = new(zone()) FunctionLiteral( | 622 result = factory()->NewFunctionLiteral( |
678 isolate(), | |
679 no_name, | 623 no_name, |
680 top_scope_, | 624 top_scope_, |
681 body, | 625 body, |
682 function_state.materialized_literal_count(), | 626 function_state.materialized_literal_count(), |
683 function_state.expected_property_count(), | 627 function_state.expected_property_count(), |
684 function_state.handler_count(), | 628 function_state.handler_count(), |
685 function_state.only_simple_this_property_assignments(), | 629 function_state.only_simple_this_property_assignments(), |
686 function_state.this_property_assignments(), | 630 function_state.this_property_assignments(), |
687 0, | 631 0, |
| 632 false, // Does not have duplicate parameters. |
688 FunctionLiteral::ANONYMOUS_EXPRESSION, | 633 FunctionLiteral::ANONYMOUS_EXPRESSION, |
689 false); // Does not have duplicate parameters. | 634 false); // Top-level literal doesn't count for the AST's properties. |
| 635 result->set_ast_properties(factory()->visitor()->ast_properties()); |
690 } else if (stack_overflow_) { | 636 } else if (stack_overflow_) { |
691 isolate()->StackOverflow(); | 637 isolate()->StackOverflow(); |
692 } | 638 } |
693 } | 639 } |
694 | 640 |
695 // Make sure the target stack is empty. | 641 // Make sure the target stack is empty. |
696 ASSERT(target_stack_ == NULL); | 642 ASSERT(target_stack_ == NULL); |
697 | 643 |
698 // If there was a syntax error we have to get rid of the AST | 644 // If there was a syntax error we have to get rid of the AST |
699 // and it is not safe to do so before the scope has been deleted. | 645 // and it is not safe to do so before the scope has been deleted. |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 return ParseBlock(labels, ok); | 1213 return ParseBlock(labels, ok); |
1268 | 1214 |
1269 case Token::CONST: // fall through | 1215 case Token::CONST: // fall through |
1270 case Token::LET: | 1216 case Token::LET: |
1271 case Token::VAR: | 1217 case Token::VAR: |
1272 stmt = ParseVariableStatement(kStatement, ok); | 1218 stmt = ParseVariableStatement(kStatement, ok); |
1273 break; | 1219 break; |
1274 | 1220 |
1275 case Token::SEMICOLON: | 1221 case Token::SEMICOLON: |
1276 Next(); | 1222 Next(); |
1277 return EmptyStatement(); | 1223 return factory()->NewEmptyStatement(); |
1278 | 1224 |
1279 case Token::IF: | 1225 case Token::IF: |
1280 stmt = ParseIfStatement(labels, ok); | 1226 stmt = ParseIfStatement(labels, ok); |
1281 break; | 1227 break; |
1282 | 1228 |
1283 case Token::DO: | 1229 case Token::DO: |
1284 stmt = ParseDoWhileStatement(labels, ok); | 1230 stmt = ParseDoWhileStatement(labels, ok); |
1285 break; | 1231 break; |
1286 | 1232 |
1287 case Token::WHILE: | 1233 case Token::WHILE: |
(...skipping 27 matching lines...) Expand all Loading... |
1315 case Token::THROW: | 1261 case Token::THROW: |
1316 stmt = ParseThrowStatement(ok); | 1262 stmt = ParseThrowStatement(ok); |
1317 break; | 1263 break; |
1318 | 1264 |
1319 case Token::TRY: { | 1265 case Token::TRY: { |
1320 // NOTE: It is somewhat complicated to have labels on | 1266 // NOTE: It is somewhat complicated to have labels on |
1321 // try-statements. When breaking out of a try-finally statement, | 1267 // try-statements. When breaking out of a try-finally statement, |
1322 // one must take great care not to treat it as a | 1268 // one must take great care not to treat it as a |
1323 // fall-through. It is much easier just to wrap the entire | 1269 // fall-through. It is much easier just to wrap the entire |
1324 // try-statement in a statement block and put the labels there | 1270 // try-statement in a statement block and put the labels there |
1325 Block* result = new(zone()) Block(isolate(), labels, 1, false); | 1271 Block* result = factory()->NewBlock(labels, 1, false); |
1326 Target target(&this->target_stack_, result); | 1272 Target target(&this->target_stack_, result); |
1327 TryStatement* statement = ParseTryStatement(CHECK_OK); | 1273 TryStatement* statement = ParseTryStatement(CHECK_OK); |
1328 if (statement) { | 1274 if (statement) { |
1329 statement->set_statement_pos(statement_pos); | 1275 statement->set_statement_pos(statement_pos); |
1330 } | 1276 } |
1331 if (result) result->AddStatement(statement); | 1277 if (result) result->AddStatement(statement); |
1332 return result; | 1278 return result; |
1333 } | 1279 } |
1334 | 1280 |
1335 case Token::FUNCTION: { | 1281 case Token::FUNCTION: { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 // parameters) if the proxy is needed or not. The proxy will be | 1393 // parameters) if the proxy is needed or not. The proxy will be |
1448 // bound during variable resolution time unless it was pre-bound | 1394 // bound during variable resolution time unless it was pre-bound |
1449 // below. | 1395 // below. |
1450 // | 1396 // |
1451 // WARNING: This will lead to multiple declaration nodes for the | 1397 // WARNING: This will lead to multiple declaration nodes for the |
1452 // same variable if it is declared several times. This is not a | 1398 // same variable if it is declared several times. This is not a |
1453 // semantic issue as long as we keep the source order, but it may be | 1399 // semantic issue as long as we keep the source order, but it may be |
1454 // a performance issue since it may lead to repeated | 1400 // a performance issue since it may lead to repeated |
1455 // Runtime::DeclareContextSlot() calls. | 1401 // Runtime::DeclareContextSlot() calls. |
1456 VariableProxy* proxy = declaration_scope->NewUnresolved( | 1402 VariableProxy* proxy = declaration_scope->NewUnresolved( |
1457 name, scanner().location().beg_pos); | 1403 factory(), name, scanner().location().beg_pos); |
1458 declaration_scope->AddDeclaration( | 1404 declaration_scope->AddDeclaration( |
1459 new(zone()) Declaration(proxy, mode, fun, top_scope_)); | 1405 factory()->NewDeclaration(proxy, mode, fun, top_scope_)); |
1460 | 1406 |
1461 if ((mode == CONST || mode == CONST_HARMONY) && | 1407 if ((mode == CONST || mode == CONST_HARMONY) && |
1462 declaration_scope->is_global_scope()) { | 1408 declaration_scope->is_global_scope()) { |
1463 // For global const variables we bind the proxy to a variable. | 1409 // For global const variables we bind the proxy to a variable. |
1464 ASSERT(resolve); // should be set by all callers | 1410 ASSERT(resolve); // should be set by all callers |
1465 Variable::Kind kind = Variable::NORMAL; | 1411 Variable::Kind kind = Variable::NORMAL; |
1466 var = new(zone()) Variable(declaration_scope, | 1412 var = new(zone()) Variable(declaration_scope, |
1467 name, | 1413 name, |
1468 mode, | 1414 mode, |
1469 true, | 1415 true, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 | 1503 |
1558 // Copy the function data to the shared function info. | 1504 // Copy the function data to the shared function info. |
1559 shared->set_function_data(fun->shared()->function_data()); | 1505 shared->set_function_data(fun->shared()->function_data()); |
1560 int parameters = fun->shared()->formal_parameter_count(); | 1506 int parameters = fun->shared()->formal_parameter_count(); |
1561 shared->set_formal_parameter_count(parameters); | 1507 shared->set_formal_parameter_count(parameters); |
1562 | 1508 |
1563 // TODO(1240846): It's weird that native function declarations are | 1509 // TODO(1240846): It's weird that native function declarations are |
1564 // introduced dynamically when we meet their declarations, whereas | 1510 // introduced dynamically when we meet their declarations, whereas |
1565 // other functions are set up when entering the surrounding scope. | 1511 // other functions are set up when entering the surrounding scope. |
1566 SharedFunctionInfoLiteral* lit = | 1512 SharedFunctionInfoLiteral* lit = |
1567 new(zone()) SharedFunctionInfoLiteral(isolate(), shared); | 1513 factory()->NewSharedFunctionInfoLiteral(shared); |
1568 VariableProxy* var = Declare(name, VAR, NULL, true, CHECK_OK); | 1514 VariableProxy* var = Declare(name, VAR, NULL, true, CHECK_OK); |
1569 return new(zone()) ExpressionStatement(new(zone()) Assignment( | 1515 return factory()->NewExpressionStatement( |
1570 isolate(), Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); | 1516 factory()->NewAssignment( |
| 1517 Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); |
1571 } | 1518 } |
1572 | 1519 |
1573 | 1520 |
1574 Statement* Parser::ParseFunctionDeclaration(bool* ok) { | 1521 Statement* Parser::ParseFunctionDeclaration(bool* ok) { |
1575 // FunctionDeclaration :: | 1522 // FunctionDeclaration :: |
1576 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 1523 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
1577 Expect(Token::FUNCTION, CHECK_OK); | 1524 Expect(Token::FUNCTION, CHECK_OK); |
1578 int function_token_position = scanner().location().beg_pos; | 1525 int function_token_position = scanner().location().beg_pos; |
1579 bool is_strict_reserved = false; | 1526 bool is_strict_reserved = false; |
1580 Handle<String> name = ParseIdentifierOrStrictReservedWord( | 1527 Handle<String> name = ParseIdentifierOrStrictReservedWord( |
1581 &is_strict_reserved, CHECK_OK); | 1528 &is_strict_reserved, CHECK_OK); |
1582 FunctionLiteral* fun = ParseFunctionLiteral(name, | 1529 FunctionLiteral* fun = ParseFunctionLiteral(name, |
1583 is_strict_reserved, | 1530 is_strict_reserved, |
1584 function_token_position, | 1531 function_token_position, |
1585 FunctionLiteral::DECLARATION, | 1532 FunctionLiteral::DECLARATION, |
1586 CHECK_OK); | 1533 CHECK_OK); |
1587 // Even if we're not at the top-level of the global or a function | 1534 // Even if we're not at the top-level of the global or a function |
1588 // scope, we treat is as such and introduce the function with it's | 1535 // scope, we treat is as such and introduce the function with it's |
1589 // initial value upon entering the corresponding scope. | 1536 // initial value upon entering the corresponding scope. |
1590 VariableMode mode = is_extended_mode() ? LET : VAR; | 1537 VariableMode mode = is_extended_mode() ? LET : VAR; |
1591 Declare(name, mode, fun, true, CHECK_OK); | 1538 Declare(name, mode, fun, true, CHECK_OK); |
1592 return EmptyStatement(); | 1539 return factory()->NewEmptyStatement(); |
1593 } | 1540 } |
1594 | 1541 |
1595 | 1542 |
1596 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { | 1543 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { |
1597 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); | 1544 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); |
1598 | 1545 |
1599 // Block :: | 1546 // Block :: |
1600 // '{' Statement* '}' | 1547 // '{' Statement* '}' |
1601 | 1548 |
1602 // Note that a Block does not introduce a new execution scope! | 1549 // Note that a Block does not introduce a new execution scope! |
1603 // (ECMA-262, 3rd, 12.2) | 1550 // (ECMA-262, 3rd, 12.2) |
1604 // | 1551 // |
1605 // Construct block expecting 16 statements. | 1552 // Construct block expecting 16 statements. |
1606 Block* result = new(zone()) Block(isolate(), labels, 16, false); | 1553 Block* result = factory()->NewBlock(labels, 16, false); |
1607 Target target(&this->target_stack_, result); | 1554 Target target(&this->target_stack_, result); |
1608 Expect(Token::LBRACE, CHECK_OK); | 1555 Expect(Token::LBRACE, CHECK_OK); |
1609 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1556 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
1610 while (peek() != Token::RBRACE) { | 1557 while (peek() != Token::RBRACE) { |
1611 Statement* stat = ParseStatement(NULL, CHECK_OK); | 1558 Statement* stat = ParseStatement(NULL, CHECK_OK); |
1612 if (stat && !stat->IsEmpty()) { | 1559 if (stat && !stat->IsEmpty()) { |
1613 result->AddStatement(stat); | 1560 result->AddStatement(stat); |
1614 block_finder.Update(stat); | 1561 block_finder.Update(stat); |
1615 } | 1562 } |
1616 } | 1563 } |
1617 Expect(Token::RBRACE, CHECK_OK); | 1564 Expect(Token::RBRACE, CHECK_OK); |
1618 return result; | 1565 return result; |
1619 } | 1566 } |
1620 | 1567 |
1621 | 1568 |
1622 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { | 1569 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
1623 // The harmony mode uses source elements instead of statements. | 1570 // The harmony mode uses source elements instead of statements. |
1624 // | 1571 // |
1625 // Block :: | 1572 // Block :: |
1626 // '{' SourceElement* '}' | 1573 // '{' SourceElement* '}' |
1627 | 1574 |
1628 // Construct block expecting 16 statements. | 1575 // Construct block expecting 16 statements. |
1629 Block* body = new(zone()) Block(isolate(), labels, 16, false); | 1576 Block* body = factory()->NewBlock(labels, 16, false); |
1630 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); | 1577 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); |
1631 | 1578 |
1632 // Parse the statements and collect escaping labels. | 1579 // Parse the statements and collect escaping labels. |
1633 Expect(Token::LBRACE, CHECK_OK); | 1580 Expect(Token::LBRACE, CHECK_OK); |
1634 block_scope->set_start_position(scanner().location().beg_pos); | 1581 block_scope->set_start_position(scanner().location().beg_pos); |
1635 { BlockState block_state(this, block_scope); | 1582 { BlockState block_state(this, block_scope); |
1636 TargetCollector collector; | 1583 TargetCollector collector; |
1637 Target target(&this->target_stack_, &collector); | 1584 Target target(&this->target_stack_, &collector); |
1638 Target target_body(&this->target_stack_, body); | 1585 Target target_body(&this->target_stack_, body); |
1639 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1586 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 // Scope declaration, and rewrite the source-level initialization into an | 1726 // Scope declaration, and rewrite the source-level initialization into an |
1780 // assignment statement. We use a block to collect multiple assignments. | 1727 // assignment statement. We use a block to collect multiple assignments. |
1781 // | 1728 // |
1782 // We mark the block as initializer block because we don't want the | 1729 // We mark the block as initializer block because we don't want the |
1783 // rewriter to add a '.result' assignment to such a block (to get compliant | 1730 // rewriter to add a '.result' assignment to such a block (to get compliant |
1784 // behavior for code such as print(eval('var x = 7')), and for cosmetic | 1731 // behavior for code such as print(eval('var x = 7')), and for cosmetic |
1785 // reasons when pretty-printing. Also, unless an assignment (initialization) | 1732 // reasons when pretty-printing. Also, unless an assignment (initialization) |
1786 // is inside an initializer block, it is ignored. | 1733 // is inside an initializer block, it is ignored. |
1787 // | 1734 // |
1788 // Create new block with one expected declaration. | 1735 // Create new block with one expected declaration. |
1789 Block* block = new(zone()) Block(isolate(), NULL, 1, true); | 1736 Block* block = factory()->NewBlock(NULL, 1, true); |
1790 int nvars = 0; // the number of variables declared | 1737 int nvars = 0; // the number of variables declared |
1791 Handle<String> name; | 1738 Handle<String> name; |
1792 do { | 1739 do { |
1793 if (fni_ != NULL) fni_->Enter(); | 1740 if (fni_ != NULL) fni_->Enter(); |
1794 | 1741 |
1795 // Parse variable name. | 1742 // Parse variable name. |
1796 if (nvars > 0) Consume(Token::COMMA); | 1743 if (nvars > 0) Consume(Token::COMMA); |
1797 name = ParseIdentifier(CHECK_OK); | 1744 name = ParseIdentifier(CHECK_OK); |
1798 if (fni_ != NULL) fni_->PushVariableName(name); | 1745 if (fni_ != NULL) fni_->PushVariableName(name); |
1799 | 1746 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 // variable defined in the global object and not in any | 1847 // variable defined in the global object and not in any |
1901 // prototype. This way, global variable declarations can shadow | 1848 // prototype. This way, global variable declarations can shadow |
1902 // properties in the prototype chain, but only after the variable | 1849 // properties in the prototype chain, but only after the variable |
1903 // declaration statement has been executed. This is important in | 1850 // declaration statement has been executed. This is important in |
1904 // browsers where the global object (window) has lots of | 1851 // browsers where the global object (window) has lots of |
1905 // properties defined in prototype objects. | 1852 // properties defined in prototype objects. |
1906 if (initialization_scope->is_global_scope()) { | 1853 if (initialization_scope->is_global_scope()) { |
1907 // Compute the arguments for the runtime call. | 1854 // Compute the arguments for the runtime call. |
1908 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3); | 1855 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3); |
1909 // We have at least 1 parameter. | 1856 // We have at least 1 parameter. |
1910 arguments->Add(NewLiteral(name)); | 1857 arguments->Add(factory()->NewLiteral(name)); |
1911 CallRuntime* initialize; | 1858 CallRuntime* initialize; |
1912 | 1859 |
1913 if (is_const) { | 1860 if (is_const) { |
1914 arguments->Add(value); | 1861 arguments->Add(value); |
1915 value = NULL; // zap the value to avoid the unnecessary assignment | 1862 value = NULL; // zap the value to avoid the unnecessary assignment |
1916 | 1863 |
1917 // Construct the call to Runtime_InitializeConstGlobal | 1864 // Construct the call to Runtime_InitializeConstGlobal |
1918 // and add it to the initialization statement block. | 1865 // and add it to the initialization statement block. |
1919 // Note that the function does different things depending on | 1866 // Note that the function does different things depending on |
1920 // the number of arguments (1 or 2). | 1867 // the number of arguments (1 or 2). |
1921 initialize = | 1868 initialize = factory()->NewCallRuntime( |
1922 new(zone()) CallRuntime( | 1869 isolate()->factory()->InitializeConstGlobal_symbol(), |
1923 isolate(), | 1870 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), |
1924 isolate()->factory()->InitializeConstGlobal_symbol(), | 1871 arguments); |
1925 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), | |
1926 arguments); | |
1927 } else { | 1872 } else { |
1928 // Add strict mode. | 1873 // Add strict mode. |
1929 // We may want to pass singleton to avoid Literal allocations. | 1874 // We may want to pass singleton to avoid Literal allocations. |
1930 LanguageMode language_mode = initialization_scope->language_mode(); | 1875 LanguageMode language_mode = initialization_scope->language_mode(); |
1931 arguments->Add(NewNumberLiteral(language_mode)); | 1876 arguments->Add(factory()->NewNumberLiteral(language_mode)); |
1932 | 1877 |
1933 // Be careful not to assign a value to the global variable if | 1878 // Be careful not to assign a value to the global variable if |
1934 // we're in a with. The initialization value should not | 1879 // we're in a with. The initialization value should not |
1935 // necessarily be stored in the global object in that case, | 1880 // necessarily be stored in the global object in that case, |
1936 // which is why we need to generate a separate assignment node. | 1881 // which is why we need to generate a separate assignment node. |
1937 if (value != NULL && !inside_with()) { | 1882 if (value != NULL && !inside_with()) { |
1938 arguments->Add(value); | 1883 arguments->Add(value); |
1939 value = NULL; // zap the value to avoid the unnecessary assignment | 1884 value = NULL; // zap the value to avoid the unnecessary assignment |
1940 } | 1885 } |
1941 | 1886 |
1942 // Construct the call to Runtime_InitializeVarGlobal | 1887 // Construct the call to Runtime_InitializeVarGlobal |
1943 // and add it to the initialization statement block. | 1888 // and add it to the initialization statement block. |
1944 // Note that the function does different things depending on | 1889 // Note that the function does different things depending on |
1945 // the number of arguments (2 or 3). | 1890 // the number of arguments (2 or 3). |
1946 initialize = | 1891 initialize = factory()->NewCallRuntime( |
1947 new(zone()) CallRuntime( | 1892 isolate()->factory()->InitializeVarGlobal_symbol(), |
1948 isolate(), | 1893 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), |
1949 isolate()->factory()->InitializeVarGlobal_symbol(), | 1894 arguments); |
1950 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), | |
1951 arguments); | |
1952 } | 1895 } |
1953 | 1896 |
1954 block->AddStatement(new(zone()) ExpressionStatement(initialize)); | 1897 block->AddStatement(factory()->NewExpressionStatement(initialize)); |
1955 } else if (needs_init) { | 1898 } else if (needs_init) { |
1956 // Constant initializations always assign to the declared constant which | 1899 // Constant initializations always assign to the declared constant which |
1957 // is always at the function scope level. This is only relevant for | 1900 // is always at the function scope level. This is only relevant for |
1958 // dynamically looked-up variables and constants (the start context for | 1901 // dynamically looked-up variables and constants (the start context for |
1959 // constant lookups is always the function context, while it is the top | 1902 // constant lookups is always the function context, while it is the top |
1960 // context for var declared variables). Sigh... | 1903 // context for var declared variables). Sigh... |
1961 // For 'let' and 'const' declared variables in harmony mode the | 1904 // For 'let' and 'const' declared variables in harmony mode the |
1962 // initialization also always assigns to the declared variable. | 1905 // initialization also always assigns to the declared variable. |
1963 ASSERT(proxy != NULL); | 1906 ASSERT(proxy != NULL); |
1964 ASSERT(proxy->var() != NULL); | 1907 ASSERT(proxy->var() != NULL); |
1965 ASSERT(value != NULL); | 1908 ASSERT(value != NULL); |
1966 Assignment* assignment = | 1909 Assignment* assignment = |
1967 new(zone()) Assignment(isolate(), init_op, proxy, value, position); | 1910 factory()->NewAssignment(init_op, proxy, value, position); |
1968 block->AddStatement(new(zone()) ExpressionStatement(assignment)); | 1911 block->AddStatement(factory()->NewExpressionStatement(assignment)); |
1969 value = NULL; | 1912 value = NULL; |
1970 } | 1913 } |
1971 | 1914 |
1972 // Add an assignment node to the initialization statement block if we still | 1915 // Add an assignment node to the initialization statement block if we still |
1973 // have a pending initialization value. | 1916 // have a pending initialization value. |
1974 if (value != NULL) { | 1917 if (value != NULL) { |
1975 ASSERT(mode == VAR); | 1918 ASSERT(mode == VAR); |
1976 // 'var' initializations are simply assignments (with all the consequences | 1919 // 'var' initializations are simply assignments (with all the consequences |
1977 // if they are inside a 'with' statement - they may change a 'with' object | 1920 // if they are inside a 'with' statement - they may change a 'with' object |
1978 // property). | 1921 // property). |
1979 VariableProxy* proxy = initialization_scope->NewUnresolved(name); | 1922 VariableProxy* proxy = |
| 1923 initialization_scope->NewUnresolved(factory(), name); |
1980 Assignment* assignment = | 1924 Assignment* assignment = |
1981 new(zone()) Assignment(isolate(), init_op, proxy, value, position); | 1925 factory()->NewAssignment(init_op, proxy, value, position); |
1982 block->AddStatement(new(zone()) ExpressionStatement(assignment)); | 1926 block->AddStatement(factory()->NewExpressionStatement(assignment)); |
1983 } | 1927 } |
1984 | 1928 |
1985 if (fni_ != NULL) fni_->Leave(); | 1929 if (fni_ != NULL) fni_->Leave(); |
1986 } while (peek() == Token::COMMA); | 1930 } while (peek() == Token::COMMA); |
1987 | 1931 |
1988 // If there was a single non-const declaration, return it in the output | 1932 // If there was a single non-const declaration, return it in the output |
1989 // parameter for possible use by for/in. | 1933 // parameter for possible use by for/in. |
1990 if (nvars == 1 && !is_const) { | 1934 if (nvars == 1 && !is_const) { |
1991 *out = name; | 1935 *out = name; |
1992 } | 1936 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2052 expr != NULL && | 1996 expr != NULL && |
2053 expr->AsVariableProxy() != NULL && | 1997 expr->AsVariableProxy() != NULL && |
2054 expr->AsVariableProxy()->name()->Equals( | 1998 expr->AsVariableProxy()->name()->Equals( |
2055 isolate()->heap()->native_symbol()) && | 1999 isolate()->heap()->native_symbol()) && |
2056 !scanner().literal_contains_escapes()) { | 2000 !scanner().literal_contains_escapes()) { |
2057 return ParseNativeDeclaration(ok); | 2001 return ParseNativeDeclaration(ok); |
2058 } | 2002 } |
2059 | 2003 |
2060 // Parsed expression statement. | 2004 // Parsed expression statement. |
2061 ExpectSemicolon(CHECK_OK); | 2005 ExpectSemicolon(CHECK_OK); |
2062 return new(zone()) ExpressionStatement(expr); | 2006 return factory()->NewExpressionStatement(expr); |
2063 } | 2007 } |
2064 | 2008 |
2065 | 2009 |
2066 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { | 2010 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { |
2067 // IfStatement :: | 2011 // IfStatement :: |
2068 // 'if' '(' Expression ')' Statement ('else' Statement)? | 2012 // 'if' '(' Expression ')' Statement ('else' Statement)? |
2069 | 2013 |
2070 Expect(Token::IF, CHECK_OK); | 2014 Expect(Token::IF, CHECK_OK); |
2071 Expect(Token::LPAREN, CHECK_OK); | 2015 Expect(Token::LPAREN, CHECK_OK); |
2072 Expression* condition = ParseExpression(true, CHECK_OK); | 2016 Expression* condition = ParseExpression(true, CHECK_OK); |
2073 Expect(Token::RPAREN, CHECK_OK); | 2017 Expect(Token::RPAREN, CHECK_OK); |
2074 Statement* then_statement = ParseStatement(labels, CHECK_OK); | 2018 Statement* then_statement = ParseStatement(labels, CHECK_OK); |
2075 Statement* else_statement = NULL; | 2019 Statement* else_statement = NULL; |
2076 if (peek() == Token::ELSE) { | 2020 if (peek() == Token::ELSE) { |
2077 Next(); | 2021 Next(); |
2078 else_statement = ParseStatement(labels, CHECK_OK); | 2022 else_statement = ParseStatement(labels, CHECK_OK); |
2079 } else { | 2023 } else { |
2080 else_statement = EmptyStatement(); | 2024 else_statement = factory()->NewEmptyStatement(); |
2081 } | 2025 } |
2082 return new(zone()) IfStatement( | 2026 return factory()->NewIfStatement(condition, then_statement, else_statement); |
2083 isolate(), condition, then_statement, else_statement); | |
2084 } | 2027 } |
2085 | 2028 |
2086 | 2029 |
2087 Statement* Parser::ParseContinueStatement(bool* ok) { | 2030 Statement* Parser::ParseContinueStatement(bool* ok) { |
2088 // ContinueStatement :: | 2031 // ContinueStatement :: |
2089 // 'continue' Identifier? ';' | 2032 // 'continue' Identifier? ';' |
2090 | 2033 |
2091 Expect(Token::CONTINUE, CHECK_OK); | 2034 Expect(Token::CONTINUE, CHECK_OK); |
2092 Handle<String> label = Handle<String>::null(); | 2035 Handle<String> label = Handle<String>::null(); |
2093 Token::Value tok = peek(); | 2036 Token::Value tok = peek(); |
2094 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 2037 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
2095 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 2038 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
2096 label = ParseIdentifier(CHECK_OK); | 2039 label = ParseIdentifier(CHECK_OK); |
2097 } | 2040 } |
2098 IterationStatement* target = NULL; | 2041 IterationStatement* target = NULL; |
2099 target = LookupContinueTarget(label, CHECK_OK); | 2042 target = LookupContinueTarget(label, CHECK_OK); |
2100 if (target == NULL) { | 2043 if (target == NULL) { |
2101 // Illegal continue statement. | 2044 // Illegal continue statement. |
2102 const char* message = "illegal_continue"; | 2045 const char* message = "illegal_continue"; |
2103 Vector<Handle<String> > args; | 2046 Vector<Handle<String> > args; |
2104 if (!label.is_null()) { | 2047 if (!label.is_null()) { |
2105 message = "unknown_label"; | 2048 message = "unknown_label"; |
2106 args = Vector<Handle<String> >(&label, 1); | 2049 args = Vector<Handle<String> >(&label, 1); |
2107 } | 2050 } |
2108 ReportMessageAt(scanner().location(), message, args); | 2051 ReportMessageAt(scanner().location(), message, args); |
2109 *ok = false; | 2052 *ok = false; |
2110 return NULL; | 2053 return NULL; |
2111 } | 2054 } |
2112 ExpectSemicolon(CHECK_OK); | 2055 ExpectSemicolon(CHECK_OK); |
2113 return new(zone()) ContinueStatement(target); | 2056 return factory()->NewContinueStatement(target); |
2114 } | 2057 } |
2115 | 2058 |
2116 | 2059 |
2117 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { | 2060 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
2118 // BreakStatement :: | 2061 // BreakStatement :: |
2119 // 'break' Identifier? ';' | 2062 // 'break' Identifier? ';' |
2120 | 2063 |
2121 Expect(Token::BREAK, CHECK_OK); | 2064 Expect(Token::BREAK, CHECK_OK); |
2122 Handle<String> label; | 2065 Handle<String> label; |
2123 Token::Value tok = peek(); | 2066 Token::Value tok = peek(); |
2124 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 2067 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
2125 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 2068 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
2126 label = ParseIdentifier(CHECK_OK); | 2069 label = ParseIdentifier(CHECK_OK); |
2127 } | 2070 } |
2128 // Parse labeled break statements that target themselves into | 2071 // Parse labeled break statements that target themselves into |
2129 // empty statements, e.g. 'l1: l2: l3: break l2;' | 2072 // empty statements, e.g. 'l1: l2: l3: break l2;' |
2130 if (!label.is_null() && ContainsLabel(labels, label)) { | 2073 if (!label.is_null() && ContainsLabel(labels, label)) { |
2131 return EmptyStatement(); | 2074 return factory()->NewEmptyStatement(); |
2132 } | 2075 } |
2133 BreakableStatement* target = NULL; | 2076 BreakableStatement* target = NULL; |
2134 target = LookupBreakTarget(label, CHECK_OK); | 2077 target = LookupBreakTarget(label, CHECK_OK); |
2135 if (target == NULL) { | 2078 if (target == NULL) { |
2136 // Illegal break statement. | 2079 // Illegal break statement. |
2137 const char* message = "illegal_break"; | 2080 const char* message = "illegal_break"; |
2138 Vector<Handle<String> > args; | 2081 Vector<Handle<String> > args; |
2139 if (!label.is_null()) { | 2082 if (!label.is_null()) { |
2140 message = "unknown_label"; | 2083 message = "unknown_label"; |
2141 args = Vector<Handle<String> >(&label, 1); | 2084 args = Vector<Handle<String> >(&label, 1); |
2142 } | 2085 } |
2143 ReportMessageAt(scanner().location(), message, args); | 2086 ReportMessageAt(scanner().location(), message, args); |
2144 *ok = false; | 2087 *ok = false; |
2145 return NULL; | 2088 return NULL; |
2146 } | 2089 } |
2147 ExpectSemicolon(CHECK_OK); | 2090 ExpectSemicolon(CHECK_OK); |
2148 return new(zone()) BreakStatement(target); | 2091 return factory()->NewBreakStatement(target); |
2149 } | 2092 } |
2150 | 2093 |
2151 | 2094 |
2152 Statement* Parser::ParseReturnStatement(bool* ok) { | 2095 Statement* Parser::ParseReturnStatement(bool* ok) { |
2153 // ReturnStatement :: | 2096 // ReturnStatement :: |
2154 // 'return' Expression? ';' | 2097 // 'return' Expression? ';' |
2155 | 2098 |
2156 // Consume the return token. It is necessary to do the before | 2099 // Consume the return token. It is necessary to do the before |
2157 // reporting any errors on it, because of the way errors are | 2100 // reporting any errors on it, because of the way errors are |
2158 // reported (underlining). | 2101 // reported (underlining). |
2159 Expect(Token::RETURN, CHECK_OK); | 2102 Expect(Token::RETURN, CHECK_OK); |
2160 | 2103 |
2161 Token::Value tok = peek(); | 2104 Token::Value tok = peek(); |
2162 Statement* result; | 2105 Statement* result; |
2163 if (scanner().HasAnyLineTerminatorBeforeNext() || | 2106 if (scanner().HasAnyLineTerminatorBeforeNext() || |
2164 tok == Token::SEMICOLON || | 2107 tok == Token::SEMICOLON || |
2165 tok == Token::RBRACE || | 2108 tok == Token::RBRACE || |
2166 tok == Token::EOS) { | 2109 tok == Token::EOS) { |
2167 ExpectSemicolon(CHECK_OK); | 2110 ExpectSemicolon(CHECK_OK); |
2168 result = new(zone()) ReturnStatement(GetLiteralUndefined()); | 2111 result = factory()->NewReturnStatement(GetLiteralUndefined()); |
2169 } else { | 2112 } else { |
2170 Expression* expr = ParseExpression(true, CHECK_OK); | 2113 Expression* expr = ParseExpression(true, CHECK_OK); |
2171 ExpectSemicolon(CHECK_OK); | 2114 ExpectSemicolon(CHECK_OK); |
2172 result = new(zone()) ReturnStatement(expr); | 2115 result = factory()->NewReturnStatement(expr); |
2173 } | 2116 } |
2174 | 2117 |
2175 // An ECMAScript program is considered syntactically incorrect if it | 2118 // An ECMAScript program is considered syntactically incorrect if it |
2176 // contains a return statement that is not within the body of a | 2119 // contains a return statement that is not within the body of a |
2177 // function. See ECMA-262, section 12.9, page 67. | 2120 // function. See ECMA-262, section 12.9, page 67. |
2178 // | 2121 // |
2179 // To be consistent with KJS we report the syntax error at runtime. | 2122 // To be consistent with KJS we report the syntax error at runtime. |
2180 Scope* declaration_scope = top_scope_->DeclarationScope(); | 2123 Scope* declaration_scope = top_scope_->DeclarationScope(); |
2181 if (declaration_scope->is_global_scope() || | 2124 if (declaration_scope->is_global_scope() || |
2182 declaration_scope->is_eval_scope()) { | 2125 declaration_scope->is_eval_scope()) { |
2183 Handle<String> type = isolate()->factory()->illegal_return_symbol(); | 2126 Handle<String> type = isolate()->factory()->illegal_return_symbol(); |
2184 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 2127 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
2185 return new(zone()) ExpressionStatement(throw_error); | 2128 return factory()->NewExpressionStatement(throw_error); |
2186 } | 2129 } |
2187 return result; | 2130 return result; |
2188 } | 2131 } |
2189 | 2132 |
2190 | 2133 |
2191 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 2134 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
2192 // WithStatement :: | 2135 // WithStatement :: |
2193 // 'with' '(' Expression ')' Statement | 2136 // 'with' '(' Expression ')' Statement |
2194 | 2137 |
2195 Expect(Token::WITH, CHECK_OK); | 2138 Expect(Token::WITH, CHECK_OK); |
2196 | 2139 |
2197 if (!top_scope_->is_classic_mode()) { | 2140 if (!top_scope_->is_classic_mode()) { |
2198 ReportMessage("strict_mode_with", Vector<const char*>::empty()); | 2141 ReportMessage("strict_mode_with", Vector<const char*>::empty()); |
2199 *ok = false; | 2142 *ok = false; |
2200 return NULL; | 2143 return NULL; |
2201 } | 2144 } |
2202 | 2145 |
2203 Expect(Token::LPAREN, CHECK_OK); | 2146 Expect(Token::LPAREN, CHECK_OK); |
2204 Expression* expr = ParseExpression(true, CHECK_OK); | 2147 Expression* expr = ParseExpression(true, CHECK_OK); |
2205 Expect(Token::RPAREN, CHECK_OK); | 2148 Expect(Token::RPAREN, CHECK_OK); |
2206 | 2149 |
2207 top_scope_->DeclarationScope()->RecordWithStatement(); | 2150 top_scope_->DeclarationScope()->RecordWithStatement(); |
2208 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); | 2151 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); |
2209 Statement* stmt; | 2152 Statement* stmt; |
2210 { BlockState block_state(this, with_scope); | 2153 { BlockState block_state(this, with_scope); |
2211 with_scope->set_start_position(scanner().peek_location().beg_pos); | 2154 with_scope->set_start_position(scanner().peek_location().beg_pos); |
2212 stmt = ParseStatement(labels, CHECK_OK); | 2155 stmt = ParseStatement(labels, CHECK_OK); |
2213 with_scope->set_end_position(scanner().location().end_pos); | 2156 with_scope->set_end_position(scanner().location().end_pos); |
2214 } | 2157 } |
2215 return new(zone()) WithStatement(expr, stmt); | 2158 return factory()->NewWithStatement(expr, stmt); |
2216 } | 2159 } |
2217 | 2160 |
2218 | 2161 |
2219 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 2162 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
2220 // CaseClause :: | 2163 // CaseClause :: |
2221 // 'case' Expression ':' Statement* | 2164 // 'case' Expression ':' Statement* |
2222 // 'default' ':' Statement* | 2165 // 'default' ':' Statement* |
2223 | 2166 |
2224 Expression* label = NULL; // NULL expression indicates default case | 2167 Expression* label = NULL; // NULL expression indicates default case |
2225 if (peek() == Token::CASE) { | 2168 if (peek() == Token::CASE) { |
(...skipping 21 matching lines...) Expand all Loading... |
2247 | 2190 |
2248 return new(zone()) CaseClause(isolate(), label, statements, pos); | 2191 return new(zone()) CaseClause(isolate(), label, statements, pos); |
2249 } | 2192 } |
2250 | 2193 |
2251 | 2194 |
2252 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, | 2195 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, |
2253 bool* ok) { | 2196 bool* ok) { |
2254 // SwitchStatement :: | 2197 // SwitchStatement :: |
2255 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 2198 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
2256 | 2199 |
2257 SwitchStatement* statement = new(zone()) SwitchStatement(isolate(), labels); | 2200 SwitchStatement* statement = factory()->NewSwitchStatement(labels); |
2258 Target target(&this->target_stack_, statement); | 2201 Target target(&this->target_stack_, statement); |
2259 | 2202 |
2260 Expect(Token::SWITCH, CHECK_OK); | 2203 Expect(Token::SWITCH, CHECK_OK); |
2261 Expect(Token::LPAREN, CHECK_OK); | 2204 Expect(Token::LPAREN, CHECK_OK); |
2262 Expression* tag = ParseExpression(true, CHECK_OK); | 2205 Expression* tag = ParseExpression(true, CHECK_OK); |
2263 Expect(Token::RPAREN, CHECK_OK); | 2206 Expect(Token::RPAREN, CHECK_OK); |
2264 | 2207 |
2265 bool default_seen = false; | 2208 bool default_seen = false; |
2266 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4); | 2209 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4); |
2267 Expect(Token::LBRACE, CHECK_OK); | 2210 Expect(Token::LBRACE, CHECK_OK); |
(...skipping 15 matching lines...) Expand all Loading... |
2283 Expect(Token::THROW, CHECK_OK); | 2226 Expect(Token::THROW, CHECK_OK); |
2284 int pos = scanner().location().beg_pos; | 2227 int pos = scanner().location().beg_pos; |
2285 if (scanner().HasAnyLineTerminatorBeforeNext()) { | 2228 if (scanner().HasAnyLineTerminatorBeforeNext()) { |
2286 ReportMessage("newline_after_throw", Vector<const char*>::empty()); | 2229 ReportMessage("newline_after_throw", Vector<const char*>::empty()); |
2287 *ok = false; | 2230 *ok = false; |
2288 return NULL; | 2231 return NULL; |
2289 } | 2232 } |
2290 Expression* exception = ParseExpression(true, CHECK_OK); | 2233 Expression* exception = ParseExpression(true, CHECK_OK); |
2291 ExpectSemicolon(CHECK_OK); | 2234 ExpectSemicolon(CHECK_OK); |
2292 | 2235 |
2293 return new(zone()) ExpressionStatement( | 2236 return factory()->NewExpressionStatement(factory()->NewThrow(exception, pos)); |
2294 new(zone()) Throw(isolate(), exception, pos)); | |
2295 } | 2237 } |
2296 | 2238 |
2297 | 2239 |
2298 TryStatement* Parser::ParseTryStatement(bool* ok) { | 2240 TryStatement* Parser::ParseTryStatement(bool* ok) { |
2299 // TryStatement :: | 2241 // TryStatement :: |
2300 // 'try' Block Catch | 2242 // 'try' Block Catch |
2301 // 'try' Block Finally | 2243 // 'try' Block Finally |
2302 // 'try' Block Catch Finally | 2244 // 'try' Block Catch Finally |
2303 // | 2245 // |
2304 // Catch :: | 2246 // Catch :: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2371 | 2313 |
2372 // Simplify the AST nodes by converting: | 2314 // Simplify the AST nodes by converting: |
2373 // 'try B0 catch B1 finally B2' | 2315 // 'try B0 catch B1 finally B2' |
2374 // to: | 2316 // to: |
2375 // 'try { try B0 catch B1 } finally B2' | 2317 // 'try { try B0 catch B1 } finally B2' |
2376 | 2318 |
2377 if (catch_block != NULL && finally_block != NULL) { | 2319 if (catch_block != NULL && finally_block != NULL) { |
2378 // If we have both, create an inner try/catch. | 2320 // If we have both, create an inner try/catch. |
2379 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2321 ASSERT(catch_scope != NULL && catch_variable != NULL); |
2380 int index = current_function_state_->NextHandlerIndex(); | 2322 int index = current_function_state_->NextHandlerIndex(); |
2381 TryCatchStatement* statement = new(zone()) TryCatchStatement(index, | 2323 TryCatchStatement* statement = factory()->NewTryCatchStatement( |
2382 try_block, | 2324 index, try_block, catch_scope, catch_variable, catch_block); |
2383 catch_scope, | |
2384 catch_variable, | |
2385 catch_block); | |
2386 statement->set_escaping_targets(try_collector.targets()); | 2325 statement->set_escaping_targets(try_collector.targets()); |
2387 try_block = new(zone()) Block(isolate(), NULL, 1, false); | 2326 try_block = factory()->NewBlock(NULL, 1, false); |
2388 try_block->AddStatement(statement); | 2327 try_block->AddStatement(statement); |
2389 catch_block = NULL; // Clear to indicate it's been handled. | 2328 catch_block = NULL; // Clear to indicate it's been handled. |
2390 } | 2329 } |
2391 | 2330 |
2392 TryStatement* result = NULL; | 2331 TryStatement* result = NULL; |
2393 if (catch_block != NULL) { | 2332 if (catch_block != NULL) { |
2394 ASSERT(finally_block == NULL); | 2333 ASSERT(finally_block == NULL); |
2395 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2334 ASSERT(catch_scope != NULL && catch_variable != NULL); |
2396 int index = current_function_state_->NextHandlerIndex(); | 2335 int index = current_function_state_->NextHandlerIndex(); |
2397 result = new(zone()) TryCatchStatement(index, | 2336 result = factory()->NewTryCatchStatement( |
2398 try_block, | 2337 index, try_block, catch_scope, catch_variable, catch_block); |
2399 catch_scope, | |
2400 catch_variable, | |
2401 catch_block); | |
2402 } else { | 2338 } else { |
2403 ASSERT(finally_block != NULL); | 2339 ASSERT(finally_block != NULL); |
2404 int index = current_function_state_->NextHandlerIndex(); | 2340 int index = current_function_state_->NextHandlerIndex(); |
2405 result = new(zone()) TryFinallyStatement(index, | 2341 result = factory()->NewTryFinallyStatement(index, try_block, finally_block); |
2406 try_block, | |
2407 finally_block); | |
2408 // Combine the jump targets of the try block and the possible catch block. | 2342 // Combine the jump targets of the try block and the possible catch block. |
2409 try_collector.targets()->AddAll(*catch_collector.targets()); | 2343 try_collector.targets()->AddAll(*catch_collector.targets()); |
2410 } | 2344 } |
2411 | 2345 |
2412 result->set_escaping_targets(try_collector.targets()); | 2346 result->set_escaping_targets(try_collector.targets()); |
2413 return result; | 2347 return result; |
2414 } | 2348 } |
2415 | 2349 |
2416 | 2350 |
2417 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, | 2351 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, |
2418 bool* ok) { | 2352 bool* ok) { |
2419 // DoStatement :: | 2353 // DoStatement :: |
2420 // 'do' Statement 'while' '(' Expression ')' ';' | 2354 // 'do' Statement 'while' '(' Expression ')' ';' |
2421 | 2355 |
2422 DoWhileStatement* loop = new(zone()) DoWhileStatement(isolate(), labels); | 2356 DoWhileStatement* loop = factory()->NewDoWhileStatement(labels); |
2423 Target target(&this->target_stack_, loop); | 2357 Target target(&this->target_stack_, loop); |
2424 | 2358 |
2425 Expect(Token::DO, CHECK_OK); | 2359 Expect(Token::DO, CHECK_OK); |
2426 Statement* body = ParseStatement(NULL, CHECK_OK); | 2360 Statement* body = ParseStatement(NULL, CHECK_OK); |
2427 Expect(Token::WHILE, CHECK_OK); | 2361 Expect(Token::WHILE, CHECK_OK); |
2428 Expect(Token::LPAREN, CHECK_OK); | 2362 Expect(Token::LPAREN, CHECK_OK); |
2429 | 2363 |
2430 if (loop != NULL) { | 2364 if (loop != NULL) { |
2431 int position = scanner().location().beg_pos; | 2365 int position = scanner().location().beg_pos; |
2432 loop->set_condition_position(position); | 2366 loop->set_condition_position(position); |
(...skipping 10 matching lines...) Expand all Loading... |
2443 | 2377 |
2444 if (loop != NULL) loop->Initialize(cond, body); | 2378 if (loop != NULL) loop->Initialize(cond, body); |
2445 return loop; | 2379 return loop; |
2446 } | 2380 } |
2447 | 2381 |
2448 | 2382 |
2449 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { | 2383 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { |
2450 // WhileStatement :: | 2384 // WhileStatement :: |
2451 // 'while' '(' Expression ')' Statement | 2385 // 'while' '(' Expression ')' Statement |
2452 | 2386 |
2453 WhileStatement* loop = new(zone()) WhileStatement(isolate(), labels); | 2387 WhileStatement* loop = factory()->NewWhileStatement(labels); |
2454 Target target(&this->target_stack_, loop); | 2388 Target target(&this->target_stack_, loop); |
2455 | 2389 |
2456 Expect(Token::WHILE, CHECK_OK); | 2390 Expect(Token::WHILE, CHECK_OK); |
2457 Expect(Token::LPAREN, CHECK_OK); | 2391 Expect(Token::LPAREN, CHECK_OK); |
2458 Expression* cond = ParseExpression(true, CHECK_OK); | 2392 Expression* cond = ParseExpression(true, CHECK_OK); |
2459 Expect(Token::RPAREN, CHECK_OK); | 2393 Expect(Token::RPAREN, CHECK_OK); |
2460 Statement* body = ParseStatement(NULL, CHECK_OK); | 2394 Statement* body = ParseStatement(NULL, CHECK_OK); |
2461 | 2395 |
2462 if (loop != NULL) loop->Initialize(cond, body); | 2396 if (loop != NULL) loop->Initialize(cond, body); |
2463 return loop; | 2397 return loop; |
(...skipping 14 matching lines...) Expand all Loading... |
2478 Expect(Token::FOR, CHECK_OK); | 2412 Expect(Token::FOR, CHECK_OK); |
2479 Expect(Token::LPAREN, CHECK_OK); | 2413 Expect(Token::LPAREN, CHECK_OK); |
2480 for_scope->set_start_position(scanner().location().beg_pos); | 2414 for_scope->set_start_position(scanner().location().beg_pos); |
2481 if (peek() != Token::SEMICOLON) { | 2415 if (peek() != Token::SEMICOLON) { |
2482 if (peek() == Token::VAR || peek() == Token::CONST) { | 2416 if (peek() == Token::VAR || peek() == Token::CONST) { |
2483 Handle<String> name; | 2417 Handle<String> name; |
2484 Block* variable_statement = | 2418 Block* variable_statement = |
2485 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); | 2419 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); |
2486 | 2420 |
2487 if (peek() == Token::IN && !name.is_null()) { | 2421 if (peek() == Token::IN && !name.is_null()) { |
2488 VariableProxy* each = top_scope_->NewUnresolved(name); | 2422 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); |
2489 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); | 2423 ForInStatement* loop = factory()->NewForInStatement(labels); |
2490 Target target(&this->target_stack_, loop); | 2424 Target target(&this->target_stack_, loop); |
2491 | 2425 |
2492 Expect(Token::IN, CHECK_OK); | 2426 Expect(Token::IN, CHECK_OK); |
2493 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2427 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2494 Expect(Token::RPAREN, CHECK_OK); | 2428 Expect(Token::RPAREN, CHECK_OK); |
2495 | 2429 |
2496 Statement* body = ParseStatement(NULL, CHECK_OK); | 2430 Statement* body = ParseStatement(NULL, CHECK_OK); |
2497 loop->Initialize(each, enumerable, body); | 2431 loop->Initialize(each, enumerable, body); |
2498 Block* result = new(zone()) Block(isolate(), NULL, 2, false); | 2432 Block* result = factory()->NewBlock(NULL, 2, false); |
2499 result->AddStatement(variable_statement); | 2433 result->AddStatement(variable_statement); |
2500 result->AddStatement(loop); | 2434 result->AddStatement(loop); |
2501 top_scope_ = saved_scope; | 2435 top_scope_ = saved_scope; |
2502 for_scope->set_end_position(scanner().location().end_pos); | 2436 for_scope->set_end_position(scanner().location().end_pos); |
2503 for_scope = for_scope->FinalizeBlockScope(); | 2437 for_scope = for_scope->FinalizeBlockScope(); |
2504 ASSERT(for_scope == NULL); | 2438 ASSERT(for_scope == NULL); |
2505 // Parsed for-in loop w/ variable/const declaration. | 2439 // Parsed for-in loop w/ variable/const declaration. |
2506 return result; | 2440 return result; |
2507 } else { | 2441 } else { |
2508 init = variable_statement; | 2442 init = variable_statement; |
(...skipping 17 matching lines...) Expand all Loading... |
2526 // <let x' be a temporary variable> | 2460 // <let x' be a temporary variable> |
2527 // for (x' in e) { | 2461 // for (x' in e) { |
2528 // let x; | 2462 // let x; |
2529 // x = x'; | 2463 // x = x'; |
2530 // b; | 2464 // b; |
2531 // } | 2465 // } |
2532 | 2466 |
2533 // TODO(keuchel): Move the temporary variable to the block scope, after | 2467 // TODO(keuchel): Move the temporary variable to the block scope, after |
2534 // implementing stack allocated block scoped variables. | 2468 // implementing stack allocated block scoped variables. |
2535 Variable* temp = top_scope_->DeclarationScope()->NewTemporary(name); | 2469 Variable* temp = top_scope_->DeclarationScope()->NewTemporary(name); |
2536 VariableProxy* temp_proxy = new(zone()) VariableProxy(isolate(), temp); | 2470 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
2537 VariableProxy* each = top_scope_->NewUnresolved(name); | 2471 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); |
2538 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); | 2472 ForInStatement* loop = factory()->NewForInStatement(labels); |
2539 Target target(&this->target_stack_, loop); | 2473 Target target(&this->target_stack_, loop); |
2540 | 2474 |
2541 Expect(Token::IN, CHECK_OK); | 2475 Expect(Token::IN, CHECK_OK); |
2542 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2476 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2543 Expect(Token::RPAREN, CHECK_OK); | 2477 Expect(Token::RPAREN, CHECK_OK); |
2544 | 2478 |
2545 Statement* body = ParseStatement(NULL, CHECK_OK); | 2479 Statement* body = ParseStatement(NULL, CHECK_OK); |
2546 Block* body_block = new(zone()) Block(isolate(), NULL, 3, false); | 2480 Block* body_block = factory()->NewBlock(NULL, 3, false); |
2547 Assignment* assignment = new(zone()) Assignment(isolate(), | 2481 Assignment* assignment = factory()->NewAssignment( |
2548 Token::ASSIGN, | 2482 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); |
2549 each, | |
2550 temp_proxy, | |
2551 RelocInfo::kNoPosition); | |
2552 Statement* assignment_statement = | 2483 Statement* assignment_statement = |
2553 new(zone()) ExpressionStatement(assignment); | 2484 factory()->NewExpressionStatement(assignment); |
2554 body_block->AddStatement(variable_statement); | 2485 body_block->AddStatement(variable_statement); |
2555 body_block->AddStatement(assignment_statement); | 2486 body_block->AddStatement(assignment_statement); |
2556 body_block->AddStatement(body); | 2487 body_block->AddStatement(body); |
2557 loop->Initialize(temp_proxy, enumerable, body_block); | 2488 loop->Initialize(temp_proxy, enumerable, body_block); |
2558 top_scope_ = saved_scope; | 2489 top_scope_ = saved_scope; |
2559 for_scope->set_end_position(scanner().location().end_pos); | 2490 for_scope->set_end_position(scanner().location().end_pos); |
2560 for_scope = for_scope->FinalizeBlockScope(); | 2491 for_scope = for_scope->FinalizeBlockScope(); |
2561 body_block->set_block_scope(for_scope); | 2492 body_block->set_block_scope(for_scope); |
2562 // Parsed for-in loop w/ let declaration. | 2493 // Parsed for-in loop w/ let declaration. |
2563 return loop; | 2494 return loop; |
2564 | 2495 |
2565 } else { | 2496 } else { |
2566 init = variable_statement; | 2497 init = variable_statement; |
2567 } | 2498 } |
2568 } else { | 2499 } else { |
2569 Expression* expression = ParseExpression(false, CHECK_OK); | 2500 Expression* expression = ParseExpression(false, CHECK_OK); |
2570 if (peek() == Token::IN) { | 2501 if (peek() == Token::IN) { |
2571 // Signal a reference error if the expression is an invalid | 2502 // Signal a reference error if the expression is an invalid |
2572 // left-hand side expression. We could report this as a syntax | 2503 // left-hand side expression. We could report this as a syntax |
2573 // error here but for compatibility with JSC we choose to report | 2504 // error here but for compatibility with JSC we choose to report |
2574 // the error at runtime. | 2505 // the error at runtime. |
2575 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2506 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2576 Handle<String> type = | 2507 Handle<String> type = |
2577 isolate()->factory()->invalid_lhs_in_for_in_symbol(); | 2508 isolate()->factory()->invalid_lhs_in_for_in_symbol(); |
2578 expression = NewThrowReferenceError(type); | 2509 expression = NewThrowReferenceError(type); |
2579 } | 2510 } |
2580 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); | 2511 ForInStatement* loop = factory()->NewForInStatement(labels); |
2581 Target target(&this->target_stack_, loop); | 2512 Target target(&this->target_stack_, loop); |
2582 | 2513 |
2583 Expect(Token::IN, CHECK_OK); | 2514 Expect(Token::IN, CHECK_OK); |
2584 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2515 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2585 Expect(Token::RPAREN, CHECK_OK); | 2516 Expect(Token::RPAREN, CHECK_OK); |
2586 | 2517 |
2587 Statement* body = ParseStatement(NULL, CHECK_OK); | 2518 Statement* body = ParseStatement(NULL, CHECK_OK); |
2588 if (loop) loop->Initialize(expression, enumerable, body); | 2519 if (loop) loop->Initialize(expression, enumerable, body); |
2589 top_scope_ = saved_scope; | 2520 top_scope_ = saved_scope; |
2590 for_scope->set_end_position(scanner().location().end_pos); | 2521 for_scope->set_end_position(scanner().location().end_pos); |
2591 for_scope = for_scope->FinalizeBlockScope(); | 2522 for_scope = for_scope->FinalizeBlockScope(); |
2592 ASSERT(for_scope == NULL); | 2523 ASSERT(for_scope == NULL); |
2593 // Parsed for-in loop. | 2524 // Parsed for-in loop. |
2594 return loop; | 2525 return loop; |
2595 | 2526 |
2596 } else { | 2527 } else { |
2597 init = new(zone()) ExpressionStatement(expression); | 2528 init = factory()->NewExpressionStatement(expression); |
2598 } | 2529 } |
2599 } | 2530 } |
2600 } | 2531 } |
2601 | 2532 |
2602 // Standard 'for' loop | 2533 // Standard 'for' loop |
2603 ForStatement* loop = new(zone()) ForStatement(isolate(), labels); | 2534 ForStatement* loop = factory()->NewForStatement(labels); |
2604 Target target(&this->target_stack_, loop); | 2535 Target target(&this->target_stack_, loop); |
2605 | 2536 |
2606 // Parsed initializer at this point. | 2537 // Parsed initializer at this point. |
2607 Expect(Token::SEMICOLON, CHECK_OK); | 2538 Expect(Token::SEMICOLON, CHECK_OK); |
2608 | 2539 |
2609 Expression* cond = NULL; | 2540 Expression* cond = NULL; |
2610 if (peek() != Token::SEMICOLON) { | 2541 if (peek() != Token::SEMICOLON) { |
2611 cond = ParseExpression(true, CHECK_OK); | 2542 cond = ParseExpression(true, CHECK_OK); |
2612 } | 2543 } |
2613 Expect(Token::SEMICOLON, CHECK_OK); | 2544 Expect(Token::SEMICOLON, CHECK_OK); |
2614 | 2545 |
2615 Statement* next = NULL; | 2546 Statement* next = NULL; |
2616 if (peek() != Token::RPAREN) { | 2547 if (peek() != Token::RPAREN) { |
2617 Expression* exp = ParseExpression(true, CHECK_OK); | 2548 Expression* exp = ParseExpression(true, CHECK_OK); |
2618 next = new(zone()) ExpressionStatement(exp); | 2549 next = factory()->NewExpressionStatement(exp); |
2619 } | 2550 } |
2620 Expect(Token::RPAREN, CHECK_OK); | 2551 Expect(Token::RPAREN, CHECK_OK); |
2621 | 2552 |
2622 Statement* body = ParseStatement(NULL, CHECK_OK); | 2553 Statement* body = ParseStatement(NULL, CHECK_OK); |
2623 top_scope_ = saved_scope; | 2554 top_scope_ = saved_scope; |
2624 for_scope->set_end_position(scanner().location().end_pos); | 2555 for_scope->set_end_position(scanner().location().end_pos); |
2625 for_scope = for_scope->FinalizeBlockScope(); | 2556 for_scope = for_scope->FinalizeBlockScope(); |
2626 if (for_scope != NULL) { | 2557 if (for_scope != NULL) { |
2627 // Rewrite a for statement of the form | 2558 // Rewrite a for statement of the form |
2628 // | 2559 // |
2629 // for (let x = i; c; n) b | 2560 // for (let x = i; c; n) b |
2630 // | 2561 // |
2631 // into | 2562 // into |
2632 // | 2563 // |
2633 // { | 2564 // { |
2634 // let x = i; | 2565 // let x = i; |
2635 // for (; c; n) b | 2566 // for (; c; n) b |
2636 // } | 2567 // } |
2637 ASSERT(init != NULL); | 2568 ASSERT(init != NULL); |
2638 Block* result = new(zone()) Block(isolate(), NULL, 2, false); | 2569 Block* result = factory()->NewBlock(NULL, 2, false); |
2639 result->AddStatement(init); | 2570 result->AddStatement(init); |
2640 result->AddStatement(loop); | 2571 result->AddStatement(loop); |
2641 result->set_block_scope(for_scope); | 2572 result->set_block_scope(for_scope); |
2642 if (loop) loop->Initialize(NULL, cond, next, body); | 2573 if (loop) loop->Initialize(NULL, cond, next, body); |
2643 return result; | 2574 return result; |
2644 } else { | 2575 } else { |
2645 if (loop) loop->Initialize(init, cond, next, body); | 2576 if (loop) loop->Initialize(init, cond, next, body); |
2646 return loop; | 2577 return loop; |
2647 } | 2578 } |
2648 } | 2579 } |
2649 | 2580 |
2650 | 2581 |
2651 // Precedence = 1 | 2582 // Precedence = 1 |
2652 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { | 2583 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { |
2653 // Expression :: | 2584 // Expression :: |
2654 // AssignmentExpression | 2585 // AssignmentExpression |
2655 // Expression ',' AssignmentExpression | 2586 // Expression ',' AssignmentExpression |
2656 | 2587 |
2657 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2588 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); |
2658 while (peek() == Token::COMMA) { | 2589 while (peek() == Token::COMMA) { |
2659 Expect(Token::COMMA, CHECK_OK); | 2590 Expect(Token::COMMA, CHECK_OK); |
2660 int position = scanner().location().beg_pos; | 2591 int position = scanner().location().beg_pos; |
2661 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2592 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); |
2662 result = new(zone()) BinaryOperation( | 2593 result = |
2663 isolate(), Token::COMMA, result, right, position); | 2594 factory()->NewBinaryOperation(Token::COMMA, result, right, position); |
2664 } | 2595 } |
2665 return result; | 2596 return result; |
2666 } | 2597 } |
2667 | 2598 |
2668 | 2599 |
2669 // Precedence = 2 | 2600 // Precedence = 2 |
2670 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { | 2601 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { |
2671 // AssignmentExpression :: | 2602 // AssignmentExpression :: |
2672 // ConditionalExpression | 2603 // ConditionalExpression |
2673 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2604 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2728 || op == Token::INIT_CONST | 2659 || op == Token::INIT_CONST |
2729 || op == Token::ASSIGN) | 2660 || op == Token::ASSIGN) |
2730 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { | 2661 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { |
2731 fni_->Infer(); | 2662 fni_->Infer(); |
2732 } else { | 2663 } else { |
2733 fni_->RemoveLastFunction(); | 2664 fni_->RemoveLastFunction(); |
2734 } | 2665 } |
2735 fni_->Leave(); | 2666 fni_->Leave(); |
2736 } | 2667 } |
2737 | 2668 |
2738 return new(zone()) Assignment(isolate(), op, expression, right, pos); | 2669 return factory()->NewAssignment(op, expression, right, pos); |
2739 } | 2670 } |
2740 | 2671 |
2741 | 2672 |
2742 // Precedence = 3 | 2673 // Precedence = 3 |
2743 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { | 2674 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { |
2744 // ConditionalExpression :: | 2675 // ConditionalExpression :: |
2745 // LogicalOrExpression | 2676 // LogicalOrExpression |
2746 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2677 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2747 | 2678 |
2748 // We start using the binary expression parser for prec >= 4 only! | 2679 // We start using the binary expression parser for prec >= 4 only! |
2749 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); | 2680 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); |
2750 if (peek() != Token::CONDITIONAL) return expression; | 2681 if (peek() != Token::CONDITIONAL) return expression; |
2751 Consume(Token::CONDITIONAL); | 2682 Consume(Token::CONDITIONAL); |
2752 // In parsing the first assignment expression in conditional | 2683 // In parsing the first assignment expression in conditional |
2753 // expressions we always accept the 'in' keyword; see ECMA-262, | 2684 // expressions we always accept the 'in' keyword; see ECMA-262, |
2754 // section 11.12, page 58. | 2685 // section 11.12, page 58. |
2755 int left_position = scanner().peek_location().beg_pos; | 2686 int left_position = scanner().peek_location().beg_pos; |
2756 Expression* left = ParseAssignmentExpression(true, CHECK_OK); | 2687 Expression* left = ParseAssignmentExpression(true, CHECK_OK); |
2757 Expect(Token::COLON, CHECK_OK); | 2688 Expect(Token::COLON, CHECK_OK); |
2758 int right_position = scanner().peek_location().beg_pos; | 2689 int right_position = scanner().peek_location().beg_pos; |
2759 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2690 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); |
2760 return new(zone()) Conditional( | 2691 return factory()->NewConditional( |
2761 isolate(), expression, left, right, left_position, right_position); | 2692 expression, left, right, left_position, right_position); |
2762 } | 2693 } |
2763 | 2694 |
2764 | 2695 |
2765 static int Precedence(Token::Value tok, bool accept_IN) { | 2696 static int Precedence(Token::Value tok, bool accept_IN) { |
2766 if (tok == Token::IN && !accept_IN) | 2697 if (tok == Token::IN && !accept_IN) |
2767 return 0; // 0 precedence will terminate binary expression parsing | 2698 return 0; // 0 precedence will terminate binary expression parsing |
2768 | 2699 |
2769 return Token::Precedence(tok); | 2700 return Token::Precedence(tok); |
2770 } | 2701 } |
2771 | 2702 |
(...skipping 10 matching lines...) Expand all Loading... |
2782 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); | 2713 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); |
2783 | 2714 |
2784 // Compute some expressions involving only number literals. | 2715 // Compute some expressions involving only number literals. |
2785 if (x && x->AsLiteral() && x->AsLiteral()->handle()->IsNumber() && | 2716 if (x && x->AsLiteral() && x->AsLiteral()->handle()->IsNumber() && |
2786 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) { | 2717 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) { |
2787 double x_val = x->AsLiteral()->handle()->Number(); | 2718 double x_val = x->AsLiteral()->handle()->Number(); |
2788 double y_val = y->AsLiteral()->handle()->Number(); | 2719 double y_val = y->AsLiteral()->handle()->Number(); |
2789 | 2720 |
2790 switch (op) { | 2721 switch (op) { |
2791 case Token::ADD: | 2722 case Token::ADD: |
2792 x = NewNumberLiteral(x_val + y_val); | 2723 x = factory()->NewNumberLiteral(x_val + y_val); |
2793 continue; | 2724 continue; |
2794 case Token::SUB: | 2725 case Token::SUB: |
2795 x = NewNumberLiteral(x_val - y_val); | 2726 x = factory()->NewNumberLiteral(x_val - y_val); |
2796 continue; | 2727 continue; |
2797 case Token::MUL: | 2728 case Token::MUL: |
2798 x = NewNumberLiteral(x_val * y_val); | 2729 x = factory()->NewNumberLiteral(x_val * y_val); |
2799 continue; | 2730 continue; |
2800 case Token::DIV: | 2731 case Token::DIV: |
2801 x = NewNumberLiteral(x_val / y_val); | 2732 x = factory()->NewNumberLiteral(x_val / y_val); |
2802 continue; | 2733 continue; |
2803 case Token::BIT_OR: | 2734 case Token::BIT_OR: { |
2804 x = NewNumberLiteral(DoubleToInt32(x_val) | DoubleToInt32(y_val)); | 2735 int value = DoubleToInt32(x_val) | DoubleToInt32(y_val); |
| 2736 x = factory()->NewNumberLiteral(value); |
2805 continue; | 2737 continue; |
2806 case Token::BIT_AND: | 2738 } |
2807 x = NewNumberLiteral(DoubleToInt32(x_val) & DoubleToInt32(y_val)); | 2739 case Token::BIT_AND: { |
| 2740 int value = DoubleToInt32(x_val) & DoubleToInt32(y_val); |
| 2741 x = factory()->NewNumberLiteral(value); |
2808 continue; | 2742 continue; |
2809 case Token::BIT_XOR: | 2743 } |
2810 x = NewNumberLiteral(DoubleToInt32(x_val) ^ DoubleToInt32(y_val)); | 2744 case Token::BIT_XOR: { |
| 2745 int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val); |
| 2746 x = factory()->NewNumberLiteral(value); |
2811 continue; | 2747 continue; |
| 2748 } |
2812 case Token::SHL: { | 2749 case Token::SHL: { |
2813 int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f); | 2750 int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f); |
2814 x = NewNumberLiteral(value); | 2751 x = factory()->NewNumberLiteral(value); |
2815 continue; | 2752 continue; |
2816 } | 2753 } |
2817 case Token::SHR: { | 2754 case Token::SHR: { |
2818 uint32_t shift = DoubleToInt32(y_val) & 0x1f; | 2755 uint32_t shift = DoubleToInt32(y_val) & 0x1f; |
2819 uint32_t value = DoubleToUint32(x_val) >> shift; | 2756 uint32_t value = DoubleToUint32(x_val) >> shift; |
2820 x = NewNumberLiteral(value); | 2757 x = factory()->NewNumberLiteral(value); |
2821 continue; | 2758 continue; |
2822 } | 2759 } |
2823 case Token::SAR: { | 2760 case Token::SAR: { |
2824 uint32_t shift = DoubleToInt32(y_val) & 0x1f; | 2761 uint32_t shift = DoubleToInt32(y_val) & 0x1f; |
2825 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); | 2762 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); |
2826 x = NewNumberLiteral(value); | 2763 x = factory()->NewNumberLiteral(value); |
2827 continue; | 2764 continue; |
2828 } | 2765 } |
2829 default: | 2766 default: |
2830 break; | 2767 break; |
2831 } | 2768 } |
2832 } | 2769 } |
2833 | 2770 |
2834 // For now we distinguish between comparisons and other binary | 2771 // For now we distinguish between comparisons and other binary |
2835 // operations. (We could combine the two and get rid of this | 2772 // operations. (We could combine the two and get rid of this |
2836 // code and AST node eventually.) | 2773 // code and AST node eventually.) |
2837 if (Token::IsCompareOp(op)) { | 2774 if (Token::IsCompareOp(op)) { |
2838 // We have a comparison. | 2775 // We have a comparison. |
2839 Token::Value cmp = op; | 2776 Token::Value cmp = op; |
2840 switch (op) { | 2777 switch (op) { |
2841 case Token::NE: cmp = Token::EQ; break; | 2778 case Token::NE: cmp = Token::EQ; break; |
2842 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; | 2779 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; |
2843 default: break; | 2780 default: break; |
2844 } | 2781 } |
2845 x = new(zone()) CompareOperation(isolate(), cmp, x, y, position); | 2782 x = factory()->NewCompareOperation(cmp, x, y, position); |
2846 if (cmp != op) { | 2783 if (cmp != op) { |
2847 // The comparison was negated - add a NOT. | 2784 // The comparison was negated - add a NOT. |
2848 x = new(zone()) UnaryOperation(isolate(), Token::NOT, x, position); | 2785 x = factory()->NewUnaryOperation(Token::NOT, x, position); |
2849 } | 2786 } |
2850 | 2787 |
2851 } else { | 2788 } else { |
2852 // We have a "normal" binary operation. | 2789 // We have a "normal" binary operation. |
2853 x = new(zone()) BinaryOperation(isolate(), op, x, y, position); | 2790 x = factory()->NewBinaryOperation(op, x, y, position); |
2854 } | 2791 } |
2855 } | 2792 } |
2856 } | 2793 } |
2857 return x; | 2794 return x; |
2858 } | 2795 } |
2859 | 2796 |
2860 | 2797 |
2861 Expression* Parser::ParseUnaryExpression(bool* ok) { | 2798 Expression* Parser::ParseUnaryExpression(bool* ok) { |
2862 // UnaryExpression :: | 2799 // UnaryExpression :: |
2863 // PostfixExpression | 2800 // PostfixExpression |
(...skipping 12 matching lines...) Expand all Loading... |
2876 op = Next(); | 2813 op = Next(); |
2877 int position = scanner().location().beg_pos; | 2814 int position = scanner().location().beg_pos; |
2878 Expression* expression = ParseUnaryExpression(CHECK_OK); | 2815 Expression* expression = ParseUnaryExpression(CHECK_OK); |
2879 | 2816 |
2880 if (expression != NULL && (expression->AsLiteral() != NULL)) { | 2817 if (expression != NULL && (expression->AsLiteral() != NULL)) { |
2881 Handle<Object> literal = expression->AsLiteral()->handle(); | 2818 Handle<Object> literal = expression->AsLiteral()->handle(); |
2882 if (op == Token::NOT) { | 2819 if (op == Token::NOT) { |
2883 // Convert the literal to a boolean condition and negate it. | 2820 // Convert the literal to a boolean condition and negate it. |
2884 bool condition = literal->ToBoolean()->IsTrue(); | 2821 bool condition = literal->ToBoolean()->IsTrue(); |
2885 Handle<Object> result(isolate()->heap()->ToBoolean(!condition)); | 2822 Handle<Object> result(isolate()->heap()->ToBoolean(!condition)); |
2886 return NewLiteral(result); | 2823 return factory()->NewLiteral(result); |
2887 } else if (literal->IsNumber()) { | 2824 } else if (literal->IsNumber()) { |
2888 // Compute some expressions involving only number literals. | 2825 // Compute some expressions involving only number literals. |
2889 double value = literal->Number(); | 2826 double value = literal->Number(); |
2890 switch (op) { | 2827 switch (op) { |
2891 case Token::ADD: | 2828 case Token::ADD: |
2892 return expression; | 2829 return expression; |
2893 case Token::SUB: | 2830 case Token::SUB: |
2894 return NewNumberLiteral(-value); | 2831 return factory()->NewNumberLiteral(-value); |
2895 case Token::BIT_NOT: | 2832 case Token::BIT_NOT: |
2896 return NewNumberLiteral(~DoubleToInt32(value)); | 2833 return factory()->NewNumberLiteral(~DoubleToInt32(value)); |
2897 default: | 2834 default: |
2898 break; | 2835 break; |
2899 } | 2836 } |
2900 } | 2837 } |
2901 } | 2838 } |
2902 | 2839 |
2903 // "delete identifier" is a syntax error in strict mode. | 2840 // "delete identifier" is a syntax error in strict mode. |
2904 if (op == Token::DELETE && !top_scope_->is_classic_mode()) { | 2841 if (op == Token::DELETE && !top_scope_->is_classic_mode()) { |
2905 VariableProxy* operand = expression->AsVariableProxy(); | 2842 VariableProxy* operand = expression->AsVariableProxy(); |
2906 if (operand != NULL && !operand->is_this()) { | 2843 if (operand != NULL && !operand->is_this()) { |
2907 ReportMessage("strict_delete", Vector<const char*>::empty()); | 2844 ReportMessage("strict_delete", Vector<const char*>::empty()); |
2908 *ok = false; | 2845 *ok = false; |
2909 return NULL; | 2846 return NULL; |
2910 } | 2847 } |
2911 } | 2848 } |
2912 | 2849 |
2913 return new(zone()) UnaryOperation(isolate(), op, expression, position); | 2850 return factory()->NewUnaryOperation(op, expression, position); |
2914 | 2851 |
2915 } else if (Token::IsCountOp(op)) { | 2852 } else if (Token::IsCountOp(op)) { |
2916 op = Next(); | 2853 op = Next(); |
2917 Expression* expression = ParseUnaryExpression(CHECK_OK); | 2854 Expression* expression = ParseUnaryExpression(CHECK_OK); |
2918 // Signal a reference error if the expression is an invalid | 2855 // Signal a reference error if the expression is an invalid |
2919 // left-hand side expression. We could report this as a syntax | 2856 // left-hand side expression. We could report this as a syntax |
2920 // error here but for compatibility with JSC we choose to report the | 2857 // error here but for compatibility with JSC we choose to report the |
2921 // error at runtime. | 2858 // error at runtime. |
2922 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2859 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2923 Handle<String> type = | 2860 Handle<String> type = |
2924 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); | 2861 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); |
2925 expression = NewThrowReferenceError(type); | 2862 expression = NewThrowReferenceError(type); |
2926 } | 2863 } |
2927 | 2864 |
2928 if (!top_scope_->is_classic_mode()) { | 2865 if (!top_scope_->is_classic_mode()) { |
2929 // Prefix expression operand in strict mode may not be eval or arguments. | 2866 // Prefix expression operand in strict mode may not be eval or arguments. |
2930 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 2867 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
2931 } | 2868 } |
2932 MarkAsLValue(expression); | 2869 MarkAsLValue(expression); |
2933 | 2870 |
2934 int position = scanner().location().beg_pos; | 2871 int position = scanner().location().beg_pos; |
2935 return new(zone()) CountOperation(isolate(), | 2872 return factory()->NewCountOperation(op, |
2936 op, | 2873 true /* prefix */, |
2937 true /* prefix */, | 2874 expression, |
2938 expression, | 2875 position); |
2939 position); | |
2940 | 2876 |
2941 } else { | 2877 } else { |
2942 return ParsePostfixExpression(ok); | 2878 return ParsePostfixExpression(ok); |
2943 } | 2879 } |
2944 } | 2880 } |
2945 | 2881 |
2946 | 2882 |
2947 Expression* Parser::ParsePostfixExpression(bool* ok) { | 2883 Expression* Parser::ParsePostfixExpression(bool* ok) { |
2948 // PostfixExpression :: | 2884 // PostfixExpression :: |
2949 // LeftHandSideExpression ('++' | '--')? | 2885 // LeftHandSideExpression ('++' | '--')? |
(...skipping 13 matching lines...) Expand all Loading... |
2963 | 2899 |
2964 if (!top_scope_->is_classic_mode()) { | 2900 if (!top_scope_->is_classic_mode()) { |
2965 // Postfix expression operand in strict mode may not be eval or arguments. | 2901 // Postfix expression operand in strict mode may not be eval or arguments. |
2966 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 2902 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
2967 } | 2903 } |
2968 MarkAsLValue(expression); | 2904 MarkAsLValue(expression); |
2969 | 2905 |
2970 Token::Value next = Next(); | 2906 Token::Value next = Next(); |
2971 int position = scanner().location().beg_pos; | 2907 int position = scanner().location().beg_pos; |
2972 expression = | 2908 expression = |
2973 new(zone()) CountOperation(isolate(), | 2909 factory()->NewCountOperation(next, |
2974 next, | 2910 false /* postfix */, |
2975 false /* postfix */, | 2911 expression, |
2976 expression, | 2912 position); |
2977 position); | |
2978 } | 2913 } |
2979 return expression; | 2914 return expression; |
2980 } | 2915 } |
2981 | 2916 |
2982 | 2917 |
2983 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { | 2918 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { |
2984 // LeftHandSideExpression :: | 2919 // LeftHandSideExpression :: |
2985 // (NewExpression | MemberExpression) ... | 2920 // (NewExpression | MemberExpression) ... |
2986 | 2921 |
2987 Expression* result; | 2922 Expression* result; |
2988 if (peek() == Token::NEW) { | 2923 if (peek() == Token::NEW) { |
2989 result = ParseNewExpression(CHECK_OK); | 2924 result = ParseNewExpression(CHECK_OK); |
2990 } else { | 2925 } else { |
2991 result = ParseMemberExpression(CHECK_OK); | 2926 result = ParseMemberExpression(CHECK_OK); |
2992 } | 2927 } |
2993 | 2928 |
2994 while (true) { | 2929 while (true) { |
2995 switch (peek()) { | 2930 switch (peek()) { |
2996 case Token::LBRACK: { | 2931 case Token::LBRACK: { |
2997 Consume(Token::LBRACK); | 2932 Consume(Token::LBRACK); |
2998 int pos = scanner().location().beg_pos; | 2933 int pos = scanner().location().beg_pos; |
2999 Expression* index = ParseExpression(true, CHECK_OK); | 2934 Expression* index = ParseExpression(true, CHECK_OK); |
3000 result = new(zone()) Property(isolate(), result, index, pos); | 2935 result = factory()->NewProperty(result, index, pos); |
3001 Expect(Token::RBRACK, CHECK_OK); | 2936 Expect(Token::RBRACK, CHECK_OK); |
3002 break; | 2937 break; |
3003 } | 2938 } |
3004 | 2939 |
3005 case Token::LPAREN: { | 2940 case Token::LPAREN: { |
3006 int pos; | 2941 int pos; |
3007 if (scanner().current_token() == Token::IDENTIFIER) { | 2942 if (scanner().current_token() == Token::IDENTIFIER) { |
3008 // For call of an identifier we want to report position of | 2943 // For call of an identifier we want to report position of |
3009 // the identifier as position of the call in the stack trace. | 2944 // the identifier as position of the call in the stack trace. |
3010 pos = scanner().location().beg_pos; | 2945 pos = scanner().location().beg_pos; |
(...skipping 12 matching lines...) Expand all Loading... |
3023 // The calls that need special treatment are the | 2958 // The calls that need special treatment are the |
3024 // direct eval calls. These calls are all of the form eval(...), with | 2959 // direct eval calls. These calls are all of the form eval(...), with |
3025 // no explicit receiver. | 2960 // no explicit receiver. |
3026 // These calls are marked as potentially direct eval calls. Whether | 2961 // These calls are marked as potentially direct eval calls. Whether |
3027 // they are actually direct calls to eval is determined at run time. | 2962 // they are actually direct calls to eval is determined at run time. |
3028 VariableProxy* callee = result->AsVariableProxy(); | 2963 VariableProxy* callee = result->AsVariableProxy(); |
3029 if (callee != NULL && | 2964 if (callee != NULL && |
3030 callee->IsVariable(isolate()->factory()->eval_symbol())) { | 2965 callee->IsVariable(isolate()->factory()->eval_symbol())) { |
3031 top_scope_->DeclarationScope()->RecordEvalCall(); | 2966 top_scope_->DeclarationScope()->RecordEvalCall(); |
3032 } | 2967 } |
3033 result = NewCall(result, args, pos); | 2968 result = factory()->NewCall(result, args, pos); |
3034 break; | 2969 break; |
3035 } | 2970 } |
3036 | 2971 |
3037 case Token::PERIOD: { | 2972 case Token::PERIOD: { |
3038 Consume(Token::PERIOD); | 2973 Consume(Token::PERIOD); |
3039 int pos = scanner().location().beg_pos; | 2974 int pos = scanner().location().beg_pos; |
3040 Handle<String> name = ParseIdentifierName(CHECK_OK); | 2975 Handle<String> name = ParseIdentifierName(CHECK_OK); |
3041 result = new(zone()) Property(isolate(), | 2976 result = |
3042 result, | 2977 factory()->NewProperty(result, factory()->NewLiteral(name), pos); |
3043 NewLiteral(name), | |
3044 pos); | |
3045 if (fni_ != NULL) fni_->PushLiteralName(name); | 2978 if (fni_ != NULL) fni_->PushLiteralName(name); |
3046 break; | 2979 break; |
3047 } | 2980 } |
3048 | 2981 |
3049 default: | 2982 default: |
3050 return result; | 2983 return result; |
3051 } | 2984 } |
3052 } | 2985 } |
3053 } | 2986 } |
3054 | 2987 |
(...skipping 15 matching lines...) Expand all Loading... |
3070 | 3003 |
3071 Expression* result; | 3004 Expression* result; |
3072 if (peek() == Token::NEW) { | 3005 if (peek() == Token::NEW) { |
3073 result = ParseNewPrefix(stack, CHECK_OK); | 3006 result = ParseNewPrefix(stack, CHECK_OK); |
3074 } else { | 3007 } else { |
3075 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); | 3008 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); |
3076 } | 3009 } |
3077 | 3010 |
3078 if (!stack->is_empty()) { | 3011 if (!stack->is_empty()) { |
3079 int last = stack->pop(); | 3012 int last = stack->pop(); |
3080 result = new(zone()) CallNew(isolate(), | 3013 result = factory()->NewCallNew( |
3081 result, | 3014 result, new(zone()) ZoneList<Expression*>(0), last); |
3082 new(zone()) ZoneList<Expression*>(0), | |
3083 last); | |
3084 } | 3015 } |
3085 return result; | 3016 return result; |
3086 } | 3017 } |
3087 | 3018 |
3088 | 3019 |
3089 Expression* Parser::ParseNewExpression(bool* ok) { | 3020 Expression* Parser::ParseNewExpression(bool* ok) { |
3090 PositionStack stack(ok); | 3021 PositionStack stack(ok); |
3091 return ParseNewPrefix(&stack, ok); | 3022 return ParseNewPrefix(&stack, ok); |
3092 } | 3023 } |
3093 | 3024 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3125 } else { | 3056 } else { |
3126 result = ParsePrimaryExpression(CHECK_OK); | 3057 result = ParsePrimaryExpression(CHECK_OK); |
3127 } | 3058 } |
3128 | 3059 |
3129 while (true) { | 3060 while (true) { |
3130 switch (peek()) { | 3061 switch (peek()) { |
3131 case Token::LBRACK: { | 3062 case Token::LBRACK: { |
3132 Consume(Token::LBRACK); | 3063 Consume(Token::LBRACK); |
3133 int pos = scanner().location().beg_pos; | 3064 int pos = scanner().location().beg_pos; |
3134 Expression* index = ParseExpression(true, CHECK_OK); | 3065 Expression* index = ParseExpression(true, CHECK_OK); |
3135 result = new(zone()) Property(isolate(), result, index, pos); | 3066 result = factory()->NewProperty(result, index, pos); |
3136 if (fni_ != NULL) { | 3067 if (fni_ != NULL) { |
3137 if (index->IsPropertyName()) { | 3068 if (index->IsPropertyName()) { |
3138 fni_->PushLiteralName(index->AsLiteral()->AsPropertyName()); | 3069 fni_->PushLiteralName(index->AsLiteral()->AsPropertyName()); |
3139 } else { | 3070 } else { |
3140 fni_->PushLiteralName( | 3071 fni_->PushLiteralName( |
3141 isolate()->factory()->anonymous_function_symbol()); | 3072 isolate()->factory()->anonymous_function_symbol()); |
3142 } | 3073 } |
3143 } | 3074 } |
3144 Expect(Token::RBRACK, CHECK_OK); | 3075 Expect(Token::RBRACK, CHECK_OK); |
3145 break; | 3076 break; |
3146 } | 3077 } |
3147 case Token::PERIOD: { | 3078 case Token::PERIOD: { |
3148 Consume(Token::PERIOD); | 3079 Consume(Token::PERIOD); |
3149 int pos = scanner().location().beg_pos; | 3080 int pos = scanner().location().beg_pos; |
3150 Handle<String> name = ParseIdentifierName(CHECK_OK); | 3081 Handle<String> name = ParseIdentifierName(CHECK_OK); |
3151 result = new(zone()) Property(isolate(), | 3082 result = |
3152 result, | 3083 factory()->NewProperty(result, factory()->NewLiteral(name), pos); |
3153 NewLiteral(name), | |
3154 pos); | |
3155 if (fni_ != NULL) fni_->PushLiteralName(name); | 3084 if (fni_ != NULL) fni_->PushLiteralName(name); |
3156 break; | 3085 break; |
3157 } | 3086 } |
3158 case Token::LPAREN: { | 3087 case Token::LPAREN: { |
3159 if ((stack == NULL) || stack->is_empty()) return result; | 3088 if ((stack == NULL) || stack->is_empty()) return result; |
3160 // Consume one of the new prefixes (already parsed). | 3089 // Consume one of the new prefixes (already parsed). |
3161 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 3090 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
3162 int last = stack->pop(); | 3091 int last = stack->pop(); |
3163 result = new(zone()) CallNew(isolate(), result, args, last); | 3092 result = factory()->NewCallNew(result, args, last); |
3164 break; | 3093 break; |
3165 } | 3094 } |
3166 default: | 3095 default: |
3167 return result; | 3096 return result; |
3168 } | 3097 } |
3169 } | 3098 } |
3170 } | 3099 } |
3171 | 3100 |
3172 | 3101 |
3173 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { | 3102 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { |
3174 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser | 3103 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser |
3175 // contexts this is used as a statement which invokes the debugger as i a | 3104 // contexts this is used as a statement which invokes the debugger as i a |
3176 // break point is present. | 3105 // break point is present. |
3177 // DebuggerStatement :: | 3106 // DebuggerStatement :: |
3178 // 'debugger' ';' | 3107 // 'debugger' ';' |
3179 | 3108 |
3180 Expect(Token::DEBUGGER, CHECK_OK); | 3109 Expect(Token::DEBUGGER, CHECK_OK); |
3181 ExpectSemicolon(CHECK_OK); | 3110 ExpectSemicolon(CHECK_OK); |
3182 return new(zone()) DebuggerStatement(); | 3111 return factory()->NewDebuggerStatement(); |
3183 } | 3112 } |
3184 | 3113 |
3185 | 3114 |
3186 void Parser::ReportUnexpectedToken(Token::Value token) { | 3115 void Parser::ReportUnexpectedToken(Token::Value token) { |
3187 // We don't report stack overflows here, to avoid increasing the | 3116 // We don't report stack overflows here, to avoid increasing the |
3188 // stack depth even further. Instead we report it after parsing is | 3117 // stack depth even further. Instead we report it after parsing is |
3189 // over, in ParseProgram/ParseJson. | 3118 // over, in ParseProgram/ParseJson. |
3190 if (token == Token::ILLEGAL && stack_overflow_) return; | 3119 if (token == Token::ILLEGAL && stack_overflow_) return; |
3191 // Four of the tokens are treated specially | 3120 // Four of the tokens are treated specially |
3192 switch (token) { | 3121 switch (token) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3237 // String | 3166 // String |
3238 // ArrayLiteral | 3167 // ArrayLiteral |
3239 // ObjectLiteral | 3168 // ObjectLiteral |
3240 // RegExpLiteral | 3169 // RegExpLiteral |
3241 // '(' Expression ')' | 3170 // '(' Expression ')' |
3242 | 3171 |
3243 Expression* result = NULL; | 3172 Expression* result = NULL; |
3244 switch (peek()) { | 3173 switch (peek()) { |
3245 case Token::THIS: { | 3174 case Token::THIS: { |
3246 Consume(Token::THIS); | 3175 Consume(Token::THIS); |
3247 result = new(zone()) VariableProxy(isolate(), top_scope_->receiver()); | 3176 result = factory()->NewVariableProxy(top_scope_->receiver()); |
3248 break; | 3177 break; |
3249 } | 3178 } |
3250 | 3179 |
3251 case Token::NULL_LITERAL: | 3180 case Token::NULL_LITERAL: |
3252 Consume(Token::NULL_LITERAL); | 3181 Consume(Token::NULL_LITERAL); |
3253 result = new(zone()) Literal( | 3182 result = factory()->NewLiteral(isolate()->factory()->null_value()); |
3254 isolate(), isolate()->factory()->null_value()); | |
3255 break; | 3183 break; |
3256 | 3184 |
3257 case Token::TRUE_LITERAL: | 3185 case Token::TRUE_LITERAL: |
3258 Consume(Token::TRUE_LITERAL); | 3186 Consume(Token::TRUE_LITERAL); |
3259 result = new(zone()) Literal( | 3187 result = factory()->NewLiteral(isolate()->factory()->true_value()); |
3260 isolate(), isolate()->factory()->true_value()); | |
3261 break; | 3188 break; |
3262 | 3189 |
3263 case Token::FALSE_LITERAL: | 3190 case Token::FALSE_LITERAL: |
3264 Consume(Token::FALSE_LITERAL); | 3191 Consume(Token::FALSE_LITERAL); |
3265 result = new(zone()) Literal( | 3192 result = factory()->NewLiteral(isolate()->factory()->false_value()); |
3266 isolate(), isolate()->factory()->false_value()); | |
3267 break; | 3193 break; |
3268 | 3194 |
3269 case Token::IDENTIFIER: | 3195 case Token::IDENTIFIER: |
3270 case Token::FUTURE_STRICT_RESERVED_WORD: { | 3196 case Token::FUTURE_STRICT_RESERVED_WORD: { |
3271 Handle<String> name = ParseIdentifier(CHECK_OK); | 3197 Handle<String> name = ParseIdentifier(CHECK_OK); |
3272 if (fni_ != NULL) fni_->PushVariableName(name); | 3198 if (fni_ != NULL) fni_->PushVariableName(name); |
3273 result = top_scope_->NewUnresolved(name, scanner().location().beg_pos); | 3199 result = top_scope_->NewUnresolved( |
| 3200 factory(), name, scanner().location().beg_pos); |
3274 break; | 3201 break; |
3275 } | 3202 } |
3276 | 3203 |
3277 case Token::NUMBER: { | 3204 case Token::NUMBER: { |
3278 Consume(Token::NUMBER); | 3205 Consume(Token::NUMBER); |
3279 ASSERT(scanner().is_literal_ascii()); | 3206 ASSERT(scanner().is_literal_ascii()); |
3280 double value = StringToDouble(isolate()->unicode_cache(), | 3207 double value = StringToDouble(isolate()->unicode_cache(), |
3281 scanner().literal_ascii_string(), | 3208 scanner().literal_ascii_string(), |
3282 ALLOW_HEX | ALLOW_OCTALS); | 3209 ALLOW_HEX | ALLOW_OCTALS); |
3283 result = NewNumberLiteral(value); | 3210 result = factory()->NewNumberLiteral(value); |
3284 break; | 3211 break; |
3285 } | 3212 } |
3286 | 3213 |
3287 case Token::STRING: { | 3214 case Token::STRING: { |
3288 Consume(Token::STRING); | 3215 Consume(Token::STRING); |
3289 Handle<String> symbol = GetSymbol(CHECK_OK); | 3216 Handle<String> symbol = GetSymbol(CHECK_OK); |
3290 result = NewLiteral(symbol); | 3217 result = factory()->NewLiteral(symbol); |
3291 if (fni_ != NULL) fni_->PushLiteralName(symbol); | 3218 if (fni_ != NULL) fni_->PushLiteralName(symbol); |
3292 break; | 3219 break; |
3293 } | 3220 } |
3294 | 3221 |
3295 case Token::ASSIGN_DIV: | 3222 case Token::ASSIGN_DIV: |
3296 result = ParseRegExpLiteral(true, CHECK_OK); | 3223 result = ParseRegExpLiteral(true, CHECK_OK); |
3297 break; | 3224 break; |
3298 | 3225 |
3299 case Token::DIV: | 3226 case Token::DIV: |
3300 result = ParseRegExpLiteral(false, CHECK_OK); | 3227 result = ParseRegExpLiteral(false, CHECK_OK); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3474 : Handle<FixedArrayBase>(object_literals); | 3401 : Handle<FixedArrayBase>(object_literals); |
3475 | 3402 |
3476 // Remember both the literal's constant values as well as the ElementsKind | 3403 // Remember both the literal's constant values as well as the ElementsKind |
3477 // in a 2-element FixedArray. | 3404 // in a 2-element FixedArray. |
3478 Handle<FixedArray> literals = | 3405 Handle<FixedArray> literals = |
3479 isolate()->factory()->NewFixedArray(2, TENURED); | 3406 isolate()->factory()->NewFixedArray(2, TENURED); |
3480 | 3407 |
3481 literals->set(0, Smi::FromInt(elements_kind)); | 3408 literals->set(0, Smi::FromInt(elements_kind)); |
3482 literals->set(1, *element_values); | 3409 literals->set(1, *element_values); |
3483 | 3410 |
3484 return new(zone()) ArrayLiteral( | 3411 return factory()->NewArrayLiteral( |
3485 isolate(), literals, values, literal_index, is_simple, depth); | 3412 literals, values, literal_index, is_simple, depth); |
3486 } | 3413 } |
3487 | 3414 |
3488 | 3415 |
3489 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3416 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
3490 return property != NULL && | 3417 return property != NULL && |
3491 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 3418 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
3492 } | 3419 } |
3493 | 3420 |
3494 | 3421 |
3495 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { | 3422 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3752 name = GetSymbol(CHECK_OK); | 3679 name = GetSymbol(CHECK_OK); |
3753 } | 3680 } |
3754 FunctionLiteral* value = | 3681 FunctionLiteral* value = |
3755 ParseFunctionLiteral(name, | 3682 ParseFunctionLiteral(name, |
3756 false, // reserved words are allowed here | 3683 false, // reserved words are allowed here |
3757 RelocInfo::kNoPosition, | 3684 RelocInfo::kNoPosition, |
3758 FunctionLiteral::ANONYMOUS_EXPRESSION, | 3685 FunctionLiteral::ANONYMOUS_EXPRESSION, |
3759 CHECK_OK); | 3686 CHECK_OK); |
3760 // Allow any number of parameters for compatibilty with JSC. | 3687 // Allow any number of parameters for compatibilty with JSC. |
3761 // Specification only allows zero parameters for get and one for set. | 3688 // Specification only allows zero parameters for get and one for set. |
3762 ObjectLiteral::Property* property = | 3689 return factory()->NewObjectLiteralProperty(is_getter, value); |
3763 new(zone()) ObjectLiteral::Property(is_getter, value); | |
3764 return property; | |
3765 } else { | 3690 } else { |
3766 ReportUnexpectedToken(next); | 3691 ReportUnexpectedToken(next); |
3767 *ok = false; | 3692 *ok = false; |
3768 return NULL; | 3693 return NULL; |
3769 } | 3694 } |
3770 } | 3695 } |
3771 | 3696 |
3772 | 3697 |
3773 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3698 Expression* Parser::ParseObjectLiteral(bool* ok) { |
3774 // ObjectLiteral :: | 3699 // ObjectLiteral :: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3819 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 3744 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
3820 | 3745 |
3821 if (fni_ != NULL) { | 3746 if (fni_ != NULL) { |
3822 fni_->Infer(); | 3747 fni_->Infer(); |
3823 fni_->Leave(); | 3748 fni_->Leave(); |
3824 } | 3749 } |
3825 continue; // restart the while | 3750 continue; // restart the while |
3826 } | 3751 } |
3827 // Failed to parse as get/set property, so it's just a property | 3752 // Failed to parse as get/set property, so it's just a property |
3828 // called "get" or "set". | 3753 // called "get" or "set". |
3829 key = NewLiteral(id); | 3754 key = factory()->NewLiteral(id); |
3830 break; | 3755 break; |
3831 } | 3756 } |
3832 case Token::STRING: { | 3757 case Token::STRING: { |
3833 Consume(Token::STRING); | 3758 Consume(Token::STRING); |
3834 Handle<String> string = GetSymbol(CHECK_OK); | 3759 Handle<String> string = GetSymbol(CHECK_OK); |
3835 if (fni_ != NULL) fni_->PushLiteralName(string); | 3760 if (fni_ != NULL) fni_->PushLiteralName(string); |
3836 uint32_t index; | 3761 uint32_t index; |
3837 if (!string.is_null() && string->AsArrayIndex(&index)) { | 3762 if (!string.is_null() && string->AsArrayIndex(&index)) { |
3838 key = NewNumberLiteral(index); | 3763 key = factory()->NewNumberLiteral(index); |
3839 break; | 3764 break; |
3840 } | 3765 } |
3841 key = NewLiteral(string); | 3766 key = factory()->NewLiteral(string); |
3842 break; | 3767 break; |
3843 } | 3768 } |
3844 case Token::NUMBER: { | 3769 case Token::NUMBER: { |
3845 Consume(Token::NUMBER); | 3770 Consume(Token::NUMBER); |
3846 ASSERT(scanner().is_literal_ascii()); | 3771 ASSERT(scanner().is_literal_ascii()); |
3847 double value = StringToDouble(isolate()->unicode_cache(), | 3772 double value = StringToDouble(isolate()->unicode_cache(), |
3848 scanner().literal_ascii_string(), | 3773 scanner().literal_ascii_string(), |
3849 ALLOW_HEX | ALLOW_OCTALS); | 3774 ALLOW_HEX | ALLOW_OCTALS); |
3850 key = NewNumberLiteral(value); | 3775 key = factory()->NewNumberLiteral(value); |
3851 break; | 3776 break; |
3852 } | 3777 } |
3853 default: | 3778 default: |
3854 if (Token::IsKeyword(next)) { | 3779 if (Token::IsKeyword(next)) { |
3855 Consume(next); | 3780 Consume(next); |
3856 Handle<String> string = GetSymbol(CHECK_OK); | 3781 Handle<String> string = GetSymbol(CHECK_OK); |
3857 key = NewLiteral(string); | 3782 key = factory()->NewLiteral(string); |
3858 } else { | 3783 } else { |
3859 // Unexpected token. | 3784 // Unexpected token. |
3860 Token::Value next = Next(); | 3785 Token::Value next = Next(); |
3861 ReportUnexpectedToken(next); | 3786 ReportUnexpectedToken(next); |
3862 *ok = false; | 3787 *ok = false; |
3863 return NULL; | 3788 return NULL; |
3864 } | 3789 } |
3865 } | 3790 } |
3866 | 3791 |
3867 Expect(Token::COLON, CHECK_OK); | 3792 Expect(Token::COLON, CHECK_OK); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3902 number_of_boilerplate_properties * 2, TENURED); | 3827 number_of_boilerplate_properties * 2, TENURED); |
3903 | 3828 |
3904 bool is_simple = true; | 3829 bool is_simple = true; |
3905 bool fast_elements = true; | 3830 bool fast_elements = true; |
3906 int depth = 1; | 3831 int depth = 1; |
3907 BuildObjectLiteralConstantProperties(properties, | 3832 BuildObjectLiteralConstantProperties(properties, |
3908 constant_properties, | 3833 constant_properties, |
3909 &is_simple, | 3834 &is_simple, |
3910 &fast_elements, | 3835 &fast_elements, |
3911 &depth); | 3836 &depth); |
3912 return new(zone()) ObjectLiteral(isolate(), | 3837 return factory()->NewObjectLiteral(constant_properties, |
3913 constant_properties, | 3838 properties, |
3914 properties, | 3839 literal_index, |
3915 literal_index, | 3840 is_simple, |
3916 is_simple, | 3841 fast_elements, |
3917 fast_elements, | 3842 depth, |
3918 depth, | 3843 has_function); |
3919 has_function); | |
3920 } | 3844 } |
3921 | 3845 |
3922 | 3846 |
3923 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3847 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
3924 if (!scanner().ScanRegExpPattern(seen_equal)) { | 3848 if (!scanner().ScanRegExpPattern(seen_equal)) { |
3925 Next(); | 3849 Next(); |
3926 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3850 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
3927 *ok = false; | 3851 *ok = false; |
3928 return NULL; | 3852 return NULL; |
3929 } | 3853 } |
3930 | 3854 |
3931 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 3855 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
3932 | 3856 |
3933 Handle<String> js_pattern = NextLiteralString(TENURED); | 3857 Handle<String> js_pattern = NextLiteralString(TENURED); |
3934 scanner().ScanRegExpFlags(); | 3858 scanner().ScanRegExpFlags(); |
3935 Handle<String> js_flags = NextLiteralString(TENURED); | 3859 Handle<String> js_flags = NextLiteralString(TENURED); |
3936 Next(); | 3860 Next(); |
3937 | 3861 |
3938 return new(zone()) RegExpLiteral( | 3862 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index); |
3939 isolate(), js_pattern, js_flags, literal_index); | |
3940 } | 3863 } |
3941 | 3864 |
3942 | 3865 |
3943 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { | 3866 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { |
3944 // Arguments :: | 3867 // Arguments :: |
3945 // '(' (AssignmentExpression)*[','] ')' | 3868 // '(' (AssignmentExpression)*[','] ')' |
3946 | 3869 |
3947 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4); | 3870 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4); |
3948 Expect(Token::LPAREN, CHECK_OK); | 3871 Expect(Token::LPAREN, CHECK_OK); |
3949 bool done = (peek() == Token::RPAREN); | 3872 bool done = (peek() == Token::RPAREN); |
(...skipping 10 matching lines...) Expand all Loading... |
3960 if (!done) Expect(Token::COMMA, CHECK_OK); | 3883 if (!done) Expect(Token::COMMA, CHECK_OK); |
3961 } | 3884 } |
3962 Expect(Token::RPAREN, CHECK_OK); | 3885 Expect(Token::RPAREN, CHECK_OK); |
3963 return result; | 3886 return result; |
3964 } | 3887 } |
3965 | 3888 |
3966 | 3889 |
3967 class SingletonLogger : public ParserRecorder { | 3890 class SingletonLogger : public ParserRecorder { |
3968 public: | 3891 public: |
3969 SingletonLogger() : has_error_(false), start_(-1), end_(-1) { } | 3892 SingletonLogger() : has_error_(false), start_(-1), end_(-1) { } |
3970 ~SingletonLogger() { } | 3893 virtual ~SingletonLogger() { } |
3971 | 3894 |
3972 void Reset() { has_error_ = false; } | 3895 void Reset() { has_error_ = false; } |
3973 | 3896 |
3974 virtual void LogFunction(int start, | 3897 virtual void LogFunction(int start, |
3975 int end, | 3898 int end, |
3976 int literals, | 3899 int literals, |
3977 int properties, | 3900 int properties, |
3978 LanguageMode mode) { | 3901 LanguageMode mode) { |
3979 ASSERT(!has_error_); | 3902 ASSERT(!has_error_); |
3980 start_ = start; | 3903 start_ = start; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4081 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode()) | 4004 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode()) |
4082 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) | 4005 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) |
4083 : NewScope(top_scope_, FUNCTION_SCOPE); | 4006 : NewScope(top_scope_, FUNCTION_SCOPE); |
4084 ZoneList<Statement*>* body = NULL; | 4007 ZoneList<Statement*>* body = NULL; |
4085 int materialized_literal_count = -1; | 4008 int materialized_literal_count = -1; |
4086 int expected_property_count = -1; | 4009 int expected_property_count = -1; |
4087 int handler_count = 0; | 4010 int handler_count = 0; |
4088 bool only_simple_this_property_assignments; | 4011 bool only_simple_this_property_assignments; |
4089 Handle<FixedArray> this_property_assignments; | 4012 Handle<FixedArray> this_property_assignments; |
4090 bool has_duplicate_parameters = false; | 4013 bool has_duplicate_parameters = false; |
| 4014 AstProperties ast_properties; |
4091 // Parse function body. | 4015 // Parse function body. |
4092 { FunctionState function_state(this, scope, isolate()); | 4016 { FunctionState function_state(this, scope, isolate()); |
4093 top_scope_->SetScopeName(function_name); | 4017 top_scope_->SetScopeName(function_name); |
4094 | 4018 |
4095 // FormalParameterList :: | 4019 // FormalParameterList :: |
4096 // '(' (Identifier)*[','] ')' | 4020 // '(' (Identifier)*[','] ')' |
4097 Expect(Token::LPAREN, CHECK_OK); | 4021 Expect(Token::LPAREN, CHECK_OK); |
4098 scope->set_start_position(scanner().location().beg_pos); | 4022 scope->set_start_position(scanner().location().beg_pos); |
4099 Scanner::Location name_loc = Scanner::Location::invalid(); | 4023 Scanner::Location name_loc = Scanner::Location::invalid(); |
4100 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 4024 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4143 Variable* fvar = NULL; | 4067 Variable* fvar = NULL; |
4144 Token::Value fvar_init_op = Token::INIT_CONST; | 4068 Token::Value fvar_init_op = Token::INIT_CONST; |
4145 if (type == FunctionLiteral::NAMED_EXPRESSION) { | 4069 if (type == FunctionLiteral::NAMED_EXPRESSION) { |
4146 VariableMode fvar_mode; | 4070 VariableMode fvar_mode; |
4147 if (is_extended_mode()) { | 4071 if (is_extended_mode()) { |
4148 fvar_mode = CONST_HARMONY; | 4072 fvar_mode = CONST_HARMONY; |
4149 fvar_init_op = Token::INIT_CONST_HARMONY; | 4073 fvar_init_op = Token::INIT_CONST_HARMONY; |
4150 } else { | 4074 } else { |
4151 fvar_mode = CONST; | 4075 fvar_mode = CONST; |
4152 } | 4076 } |
4153 fvar = top_scope_->DeclareFunctionVar(function_name, fvar_mode); | 4077 fvar = |
| 4078 top_scope_->DeclareFunctionVar(function_name, fvar_mode, factory()); |
4154 } | 4079 } |
4155 | 4080 |
4156 // Determine whether the function will be lazily compiled. | 4081 // Determine whether the function will be lazily compiled. |
4157 // The heuristics are: | 4082 // The heuristics are: |
4158 // - It must not have been prohibited by the caller to Parse (some callers | 4083 // - It must not have been prohibited by the caller to Parse (some callers |
4159 // need a full AST). | 4084 // need a full AST). |
4160 // - The outer scope must be trivial (only global variables in scope). | 4085 // - The outer scope must be trivial (only global variables in scope). |
4161 // - The function mustn't be a function expression with an open parenthesis | 4086 // - The function mustn't be a function expression with an open parenthesis |
4162 // before; we consider that a hint that the function will be called | 4087 // before; we consider that a hint that the function will be called |
4163 // immediately, and it would be a waste of time to make it lazily | 4088 // immediately, and it would be a waste of time to make it lazily |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4230 expected_property_count = logger.properties(); | 4155 expected_property_count = logger.properties(); |
4231 top_scope_->SetLanguageMode(logger.language_mode()); | 4156 top_scope_->SetLanguageMode(logger.language_mode()); |
4232 only_simple_this_property_assignments = false; | 4157 only_simple_this_property_assignments = false; |
4233 this_property_assignments = isolate()->factory()->empty_fixed_array(); | 4158 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
4234 } | 4159 } |
4235 } | 4160 } |
4236 | 4161 |
4237 if (!is_lazily_compiled) { | 4162 if (!is_lazily_compiled) { |
4238 body = new(zone()) ZoneList<Statement*>(8); | 4163 body = new(zone()) ZoneList<Statement*>(8); |
4239 if (fvar != NULL) { | 4164 if (fvar != NULL) { |
4240 VariableProxy* fproxy = top_scope_->NewUnresolved(function_name); | 4165 VariableProxy* fproxy = |
| 4166 top_scope_->NewUnresolved(factory(), function_name); |
4241 fproxy->BindTo(fvar); | 4167 fproxy->BindTo(fvar); |
4242 body->Add(new(zone()) ExpressionStatement( | 4168 body->Add(factory()->NewExpressionStatement( |
4243 new(zone()) Assignment(isolate(), | 4169 factory()->NewAssignment(fvar_init_op, |
4244 fvar_init_op, | 4170 fproxy, |
4245 fproxy, | 4171 factory()->NewThisFunction(), |
4246 new(zone()) ThisFunction(isolate()), | 4172 RelocInfo::kNoPosition))); |
4247 RelocInfo::kNoPosition))); | |
4248 } | 4173 } |
4249 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 4174 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
4250 | 4175 |
4251 materialized_literal_count = function_state.materialized_literal_count(); | 4176 materialized_literal_count = function_state.materialized_literal_count(); |
4252 expected_property_count = function_state.expected_property_count(); | 4177 expected_property_count = function_state.expected_property_count(); |
4253 handler_count = function_state.handler_count(); | 4178 handler_count = function_state.handler_count(); |
4254 only_simple_this_property_assignments = | 4179 only_simple_this_property_assignments = |
4255 function_state.only_simple_this_property_assignments(); | 4180 function_state.only_simple_this_property_assignments(); |
4256 this_property_assignments = function_state.this_property_assignments(); | 4181 this_property_assignments = function_state.this_property_assignments(); |
4257 | 4182 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4298 if (reserved_loc.IsValid()) { | 4223 if (reserved_loc.IsValid()) { |
4299 ReportMessageAt(reserved_loc, "strict_reserved_word", | 4224 ReportMessageAt(reserved_loc, "strict_reserved_word", |
4300 Vector<const char*>::empty()); | 4225 Vector<const char*>::empty()); |
4301 *ok = false; | 4226 *ok = false; |
4302 return NULL; | 4227 return NULL; |
4303 } | 4228 } |
4304 CheckOctalLiteral(scope->start_position(), | 4229 CheckOctalLiteral(scope->start_position(), |
4305 scope->end_position(), | 4230 scope->end_position(), |
4306 CHECK_OK); | 4231 CHECK_OK); |
4307 } | 4232 } |
| 4233 ast_properties = *factory()->visitor()->ast_properties(); |
4308 } | 4234 } |
4309 | 4235 |
4310 if (is_extended_mode()) { | 4236 if (is_extended_mode()) { |
4311 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4237 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4312 } | 4238 } |
4313 | 4239 |
4314 FunctionLiteral* function_literal = | 4240 FunctionLiteral* function_literal = |
4315 new(zone()) FunctionLiteral(isolate(), | 4241 factory()->NewFunctionLiteral(function_name, |
4316 function_name, | 4242 scope, |
4317 scope, | 4243 body, |
4318 body, | 4244 materialized_literal_count, |
4319 materialized_literal_count, | 4245 expected_property_count, |
4320 expected_property_count, | 4246 handler_count, |
4321 handler_count, | 4247 only_simple_this_property_assignments, |
4322 only_simple_this_property_assignments, | 4248 this_property_assignments, |
4323 this_property_assignments, | 4249 num_parameters, |
4324 num_parameters, | 4250 has_duplicate_parameters, |
4325 type, | 4251 type, |
4326 has_duplicate_parameters); | 4252 true); |
4327 function_literal->set_function_token_position(function_token_position); | 4253 function_literal->set_function_token_position(function_token_position); |
| 4254 function_literal->set_ast_properties(&ast_properties); |
4328 | 4255 |
4329 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4256 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
4330 return function_literal; | 4257 return function_literal; |
4331 } | 4258 } |
4332 | 4259 |
4333 | 4260 |
4334 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral( | 4261 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral( |
4335 SingletonLogger* logger) { | 4262 SingletonLogger* logger) { |
4336 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); | 4263 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); |
4337 ASSERT_EQ(Token::LBRACE, scanner().current_token()); | 4264 ASSERT_EQ(Token::LBRACE, scanner().current_token()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4387 // Check that the expected number of arguments are being passed. | 4314 // Check that the expected number of arguments are being passed. |
4388 if (function != NULL && | 4315 if (function != NULL && |
4389 function->nargs != -1 && | 4316 function->nargs != -1 && |
4390 function->nargs != args->length()) { | 4317 function->nargs != args->length()) { |
4391 ReportMessage("illegal_access", Vector<const char*>::empty()); | 4318 ReportMessage("illegal_access", Vector<const char*>::empty()); |
4392 *ok = false; | 4319 *ok = false; |
4393 return NULL; | 4320 return NULL; |
4394 } | 4321 } |
4395 | 4322 |
4396 // We have a valid intrinsics call or a call to a builtin. | 4323 // We have a valid intrinsics call or a call to a builtin. |
4397 return new(zone()) CallRuntime(isolate(), name, function, args); | 4324 return factory()->NewCallRuntime(name, function, args); |
4398 } | 4325 } |
4399 | 4326 |
4400 | 4327 |
4401 bool Parser::peek_any_identifier() { | 4328 bool Parser::peek_any_identifier() { |
4402 Token::Value next = peek(); | 4329 Token::Value next = peek(); |
4403 return next == Token::IDENTIFIER || | 4330 return next == Token::IDENTIFIER || |
4404 next == Token::FUTURE_RESERVED_WORD || | 4331 next == Token::FUTURE_RESERVED_WORD || |
4405 next == Token::FUTURE_STRICT_RESERVED_WORD; | 4332 next == Token::FUTURE_STRICT_RESERVED_WORD; |
4406 } | 4333 } |
4407 | 4334 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4443 if (scanner().HasAnyLineTerminatorBeforeNext() || | 4370 if (scanner().HasAnyLineTerminatorBeforeNext() || |
4444 tok == Token::RBRACE || | 4371 tok == Token::RBRACE || |
4445 tok == Token::EOS) { | 4372 tok == Token::EOS) { |
4446 return; | 4373 return; |
4447 } | 4374 } |
4448 Expect(Token::SEMICOLON, ok); | 4375 Expect(Token::SEMICOLON, ok); |
4449 } | 4376 } |
4450 | 4377 |
4451 | 4378 |
4452 Literal* Parser::GetLiteralUndefined() { | 4379 Literal* Parser::GetLiteralUndefined() { |
4453 return NewLiteral(isolate()->factory()->undefined_value()); | 4380 return factory()->NewLiteral(isolate()->factory()->undefined_value()); |
4454 } | 4381 } |
4455 | 4382 |
4456 | 4383 |
4457 Literal* Parser::GetLiteralTheHole() { | 4384 Literal* Parser::GetLiteralTheHole() { |
4458 return NewLiteral(isolate()->factory()->the_hole_value()); | 4385 return factory()->NewLiteral(isolate()->factory()->the_hole_value()); |
4459 } | 4386 } |
4460 | 4387 |
4461 | 4388 |
4462 Literal* Parser::GetLiteralNumber(double value) { | |
4463 return NewNumberLiteral(value); | |
4464 } | |
4465 | |
4466 | |
4467 // Parses an identifier that is valid for the current scope, in particular it | 4389 // Parses an identifier that is valid for the current scope, in particular it |
4468 // fails on strict mode future reserved keywords in a strict scope. | 4390 // fails on strict mode future reserved keywords in a strict scope. |
4469 Handle<String> Parser::ParseIdentifier(bool* ok) { | 4391 Handle<String> Parser::ParseIdentifier(bool* ok) { |
4470 if (!top_scope_->is_classic_mode()) { | 4392 if (!top_scope_->is_classic_mode()) { |
4471 Expect(Token::IDENTIFIER, ok); | 4393 Expect(Token::IDENTIFIER, ok); |
4472 } else if (!Check(Token::IDENTIFIER)) { | 4394 } else if (!Check(Token::IDENTIFIER)) { |
4473 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); | 4395 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); |
4474 } | 4396 } |
4475 if (!*ok) return Handle<String>(); | 4397 if (!*ok) return Handle<String>(); |
4476 return GetSymbol(ok); | 4398 return GetSymbol(ok); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4631 // Register that a break target found at the given stop in the | 4553 // Register that a break target found at the given stop in the |
4632 // target stack has been used from the top of the target stack. Add | 4554 // target stack has been used from the top of the target stack. Add |
4633 // the break target to any TargetCollectors passed on the stack. | 4555 // the break target to any TargetCollectors passed on the stack. |
4634 for (Target* t = target_stack_; t != stop; t = t->previous()) { | 4556 for (Target* t = target_stack_; t != stop; t = t->previous()) { |
4635 TargetCollector* collector = t->node()->AsTargetCollector(); | 4557 TargetCollector* collector = t->node()->AsTargetCollector(); |
4636 if (collector != NULL) collector->AddTarget(target); | 4558 if (collector != NULL) collector->AddTarget(target); |
4637 } | 4559 } |
4638 } | 4560 } |
4639 | 4561 |
4640 | 4562 |
4641 Literal* Parser::NewNumberLiteral(double number) { | |
4642 return NewLiteral(isolate()->factory()->NewNumber(number, TENURED)); | |
4643 } | |
4644 | |
4645 | |
4646 Expression* Parser::NewThrowReferenceError(Handle<String> type) { | 4563 Expression* Parser::NewThrowReferenceError(Handle<String> type) { |
4647 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), | 4564 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), |
4648 type, HandleVector<Object>(NULL, 0)); | 4565 type, HandleVector<Object>(NULL, 0)); |
4649 } | 4566 } |
4650 | 4567 |
4651 | 4568 |
4652 Expression* Parser::NewThrowSyntaxError(Handle<String> type, | 4569 Expression* Parser::NewThrowSyntaxError(Handle<String> type, |
4653 Handle<Object> first) { | 4570 Handle<Object> first) { |
4654 int argc = first.is_null() ? 0 : 1; | 4571 int argc = first.is_null() ? 0 : 1; |
4655 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); | 4572 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); |
(...skipping 23 matching lines...) Expand all Loading... |
4679 for (int i = 0; i < argc; i++) { | 4596 for (int i = 0; i < argc; i++) { |
4680 Handle<Object> element = arguments[i]; | 4597 Handle<Object> element = arguments[i]; |
4681 if (!element.is_null()) { | 4598 if (!element.is_null()) { |
4682 elements->set(i, *element); | 4599 elements->set(i, *element); |
4683 } | 4600 } |
4684 } | 4601 } |
4685 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( | 4602 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( |
4686 elements, FAST_ELEMENTS, TENURED); | 4603 elements, FAST_ELEMENTS, TENURED); |
4687 | 4604 |
4688 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2); | 4605 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2); |
4689 args->Add(NewLiteral(type)); | 4606 args->Add(factory()->NewLiteral(type)); |
4690 args->Add(NewLiteral(array)); | 4607 args->Add(factory()->NewLiteral(array)); |
4691 CallRuntime* call_constructor = new(zone()) CallRuntime(isolate(), | 4608 CallRuntime* call_constructor = |
4692 constructor, | 4609 factory()->NewCallRuntime(constructor, NULL, args); |
4693 NULL, | 4610 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); |
4694 args); | |
4695 return new(zone()) Throw(isolate(), | |
4696 call_constructor, | |
4697 scanner().location().beg_pos); | |
4698 } | 4611 } |
4699 | 4612 |
4700 // ---------------------------------------------------------------------------- | 4613 // ---------------------------------------------------------------------------- |
4701 // Regular expressions | 4614 // Regular expressions |
4702 | 4615 |
4703 | 4616 |
4704 RegExpParser::RegExpParser(FlatStringReader* in, | 4617 RegExpParser::RegExpParser(FlatStringReader* in, |
4705 Handle<String>* error, | 4618 Handle<String>* error, |
4706 bool multiline) | 4619 bool multiline) |
4707 : isolate_(Isolate::Current()), | 4620 : isolate_(Isolate::Current()), |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5659 bool ParserApi::Parse(CompilationInfo* info, int parsing_flags) { | 5572 bool ParserApi::Parse(CompilationInfo* info, int parsing_flags) { |
5660 ASSERT(info->function() == NULL); | 5573 ASSERT(info->function() == NULL); |
5661 FunctionLiteral* result = NULL; | 5574 FunctionLiteral* result = NULL; |
5662 Handle<Script> script = info->script(); | 5575 Handle<Script> script = info->script(); |
5663 ASSERT((parsing_flags & kLanguageModeMask) == CLASSIC_MODE); | 5576 ASSERT((parsing_flags & kLanguageModeMask) == CLASSIC_MODE); |
5664 if (!info->is_native() && FLAG_harmony_scoping) { | 5577 if (!info->is_native() && FLAG_harmony_scoping) { |
5665 // Harmony scoping is requested. | 5578 // Harmony scoping is requested. |
5666 parsing_flags |= EXTENDED_MODE; | 5579 parsing_flags |= EXTENDED_MODE; |
5667 } | 5580 } |
5668 if (FLAG_allow_natives_syntax || info->is_native()) { | 5581 if (FLAG_allow_natives_syntax || info->is_native()) { |
5669 // We requre %identifier(..) syntax. | 5582 // We require %identifier(..) syntax. |
5670 parsing_flags |= kAllowNativesSyntax; | 5583 parsing_flags |= kAllowNativesSyntax; |
5671 } | 5584 } |
5672 if (info->is_lazy()) { | 5585 if (info->is_lazy()) { |
5673 ASSERT(!info->is_eval()); | 5586 ASSERT(!info->is_eval()); |
5674 Parser parser(script, parsing_flags, NULL, NULL); | 5587 Parser parser(script, parsing_flags, NULL, NULL); |
5675 result = parser.ParseLazy(info); | 5588 result = parser.ParseLazy(info); |
5676 } else { | 5589 } else { |
5677 ScriptDataImpl* pre_data = info->pre_parse_data(); | 5590 ScriptDataImpl* pre_data = info->pre_parse_data(); |
5678 Parser parser(script, parsing_flags, info->extension(), pre_data); | 5591 Parser parser(script, parsing_flags, info->extension(), pre_data); |
5679 if (pre_data != NULL && pre_data->has_error()) { | 5592 if (pre_data != NULL && pre_data->has_error()) { |
5680 Scanner::Location loc = pre_data->MessageLocation(); | 5593 Scanner::Location loc = pre_data->MessageLocation(); |
5681 const char* message = pre_data->BuildMessage(); | 5594 const char* message = pre_data->BuildMessage(); |
5682 Vector<const char*> args = pre_data->BuildArgs(); | 5595 Vector<const char*> args = pre_data->BuildArgs(); |
5683 parser.ReportMessageAt(loc, message, args); | 5596 parser.ReportMessageAt(loc, message, args); |
5684 DeleteArray(message); | 5597 DeleteArray(message); |
5685 for (int i = 0; i < args.length(); i++) { | 5598 for (int i = 0; i < args.length(); i++) { |
5686 DeleteArray(args[i]); | 5599 DeleteArray(args[i]); |
5687 } | 5600 } |
5688 DeleteArray(args.start()); | 5601 DeleteArray(args.start()); |
5689 ASSERT(info->isolate()->has_pending_exception()); | 5602 ASSERT(info->isolate()->has_pending_exception()); |
5690 } else { | 5603 } else { |
5691 result = parser.ParseProgram(info); | 5604 result = parser.ParseProgram(info); |
5692 } | 5605 } |
5693 } | 5606 } |
5694 info->SetFunction(result); | 5607 info->SetFunction(result); |
5695 return (result != NULL); | 5608 return (result != NULL); |
5696 } | 5609 } |
5697 | 5610 |
5698 } } // namespace v8::internal | 5611 } } // namespace v8::internal |
OLD | NEW |