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