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