Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: src/parser.cc

Issue 314603004: Parser: Delay internalizing strings and values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/char-predicates-inl.h" 10 #include "src/char-predicates-inl.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return store_[PreparseDataConstants::kHeaderSize + position]; 319 return store_[PreparseDataConstants::kHeaderSize + position];
320 } 320 }
321 321
322 322
323 unsigned* ScriptData::ReadAddress(int position) const { 323 unsigned* ScriptData::ReadAddress(int position) const {
324 return &store_[PreparseDataConstants::kHeaderSize + position]; 324 return &store_[PreparseDataConstants::kHeaderSize + position];
325 } 325 }
326 326
327 327
328 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 328 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
329 Scope* result = new(zone()) Scope(parent, scope_type, zone()); 329 ASSERT(ast_value_factory_);
330 Scope* result =
331 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone());
330 result->Initialize(); 332 result->Initialize();
331 return result; 333 return result;
332 } 334 }
333 335
334 336
335 // ---------------------------------------------------------------------------- 337 // ----------------------------------------------------------------------------
336 // Target is a support class to facilitate manipulation of the 338 // Target is a support class to facilitate manipulation of the
337 // Parser's target_stack_ (the stack of potential 'break' and 339 // Parser's target_stack_ (the stack of potential 'break' and
338 // 'continue' statement targets). Upon construction, a new target is 340 // 'continue' statement targets). Upon construction, a new target is
339 // added; it is removed upon destruction. 341 // added; it is removed upon destruction.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 394
393 #define CHECK_FAILED /**/); \ 395 #define CHECK_FAILED /**/); \
394 if (failed_) return NULL; \ 396 if (failed_) return NULL; \
395 ((void)0 397 ((void)0
396 #define DUMMY ) // to make indentation work 398 #define DUMMY ) // to make indentation work
397 #undef DUMMY 399 #undef DUMMY
398 400
399 // ---------------------------------------------------------------------------- 401 // ----------------------------------------------------------------------------
400 // Implementation of Parser 402 // Implementation of Parser
401 403
402 bool ParserTraits::IsEvalOrArguments(Handle<String> identifier) const { 404 bool ParserTraits::IsEvalOrArguments(const AstString* identifier) const {
403 Factory* factory = parser_->isolate()->factory(); 405 return identifier == parser_->ast_value_factory_->eval_string() ||
404 return identifier.is_identical_to(factory->eval_string()) 406 identifier == parser_->ast_value_factory_->arguments_string();
405 || identifier.is_identical_to(factory->arguments_string());
406 } 407 }
407 408
408 409
409 bool ParserTraits::IsThisProperty(Expression* expression) { 410 bool ParserTraits::IsThisProperty(Expression* expression) {
410 ASSERT(expression != NULL); 411 ASSERT(expression != NULL);
411 Property* property = expression->AsProperty(); 412 Property* property = expression->AsProperty();
412 return property != NULL && 413 return property != NULL &&
413 property->obj()->AsVariableProxy() != NULL && 414 property->obj()->AsVariableProxy() != NULL &&
414 property->obj()->AsVariableProxy()->is_this(); 415 property->obj()->AsVariableProxy()->is_this();
415 } 416 }
416 417
417 418
418 bool ParserTraits::IsIdentifier(Expression* expression) { 419 bool ParserTraits::IsIdentifier(Expression* expression) {
419 VariableProxy* operand = expression->AsVariableProxy(); 420 VariableProxy* operand = expression->AsVariableProxy();
420 return operand != NULL && !operand->is_this(); 421 return operand != NULL && !operand->is_this();
421 } 422 }
422 423
423 424
424 void ParserTraits::PushPropertyName(FuncNameInferrer* fni, 425 void ParserTraits::PushPropertyName(FuncNameInferrer* fni,
425 Expression* expression) { 426 Expression* expression) {
426 if (expression->IsPropertyName()) { 427 if (expression->IsPropertyName()) {
427 fni->PushLiteralName(expression->AsLiteral()->AsPropertyName()); 428 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
428 } else { 429 } else {
429 fni->PushLiteralName( 430 fni->PushLiteralName(
430 parser_->isolate()->factory()->anonymous_function_string()); 431 parser_->ast_value_factory_->anonymous_function_string());
431 } 432 }
432 } 433 }
433 434
434 435
435 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, 436 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left,
436 Expression* right) { 437 Expression* right) {
437 ASSERT(left != NULL); 438 ASSERT(left != NULL);
438 if (left->AsProperty() != NULL && 439 if (left->AsProperty() != NULL &&
439 right->AsFunctionLiteral() != NULL) { 440 right->AsFunctionLiteral() != NULL) {
440 right->AsFunctionLiteral()->set_pretenure(); 441 right->AsFunctionLiteral()->set_pretenure();
441 } 442 }
442 } 443 }
443 444
444 445
445 void ParserTraits::CheckPossibleEvalCall(Expression* expression, 446 void ParserTraits::CheckPossibleEvalCall(Expression* expression,
446 Scope* scope) { 447 Scope* scope) {
447 VariableProxy* callee = expression->AsVariableProxy(); 448 VariableProxy* callee = expression->AsVariableProxy();
448 if (callee != NULL && 449 if (callee != NULL &&
449 callee->IsVariable(parser_->isolate()->factory()->eval_string())) { 450 callee->raw_name() == parser_->ast_value_factory_->eval_string()) {
450 scope->DeclarationScope()->RecordEvalCall(); 451 scope->DeclarationScope()->RecordEvalCall();
451 } 452 }
452 } 453 }
453 454
454 455
455 Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) { 456 Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) {
456 VariableProxy* proxy = expression != NULL 457 VariableProxy* proxy = expression != NULL
457 ? expression->AsVariableProxy() 458 ? expression->AsVariableProxy()
458 : NULL; 459 : NULL;
459 if (proxy != NULL) proxy->MarkAsLValue(); 460 if (proxy != NULL) proxy->MarkAsLValue();
460 return expression; 461 return expression;
461 } 462 }
462 463
463 464
464 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( 465 bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
465 Expression** x, Expression* y, Token::Value op, int pos, 466 Expression** x, Expression* y, Token::Value op, int pos,
466 AstNodeFactory<AstConstructionVisitor>* factory) { 467 AstNodeFactory<AstConstructionVisitor>* factory) {
467 if ((*x)->AsLiteral() && (*x)->AsLiteral()->value()->IsNumber() && 468 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() &&
468 y->AsLiteral() && y->AsLiteral()->value()->IsNumber()) { 469 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) {
469 double x_val = (*x)->AsLiteral()->value()->Number(); 470 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber();
470 double y_val = y->AsLiteral()->value()->Number(); 471 double y_val = y->AsLiteral()->raw_value()->AsNumber();
471 switch (op) { 472 switch (op) {
472 case Token::ADD: 473 case Token::ADD:
473 *x = factory->NewNumberLiteral(x_val + y_val, pos); 474 *x = factory->NewNumberLiteral(x_val + y_val, pos);
474 return true; 475 return true;
475 case Token::SUB: 476 case Token::SUB:
476 *x = factory->NewNumberLiteral(x_val - y_val, pos); 477 *x = factory->NewNumberLiteral(x_val - y_val, pos);
477 return true; 478 return true;
478 case Token::MUL: 479 case Token::MUL:
479 *x = factory->NewNumberLiteral(x_val * y_val, pos); 480 *x = factory->NewNumberLiteral(x_val * y_val, pos);
480 return true; 481 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 520 }
520 return false; 521 return false;
521 } 522 }
522 523
523 524
524 Expression* ParserTraits::BuildUnaryExpression( 525 Expression* ParserTraits::BuildUnaryExpression(
525 Expression* expression, Token::Value op, int pos, 526 Expression* expression, Token::Value op, int pos,
526 AstNodeFactory<AstConstructionVisitor>* factory) { 527 AstNodeFactory<AstConstructionVisitor>* factory) {
527 ASSERT(expression != NULL); 528 ASSERT(expression != NULL);
528 if (expression->IsLiteral()) { 529 if (expression->IsLiteral()) {
529 Handle<Object> literal = expression->AsLiteral()->value(); 530 const AstValue* literal = expression->AsLiteral()->raw_value();
530 if (op == Token::NOT) { 531 if (op == Token::NOT) {
531 // Convert the literal to a boolean condition and negate it. 532 // Convert the literal to a boolean condition and negate it.
532 bool condition = literal->BooleanValue(); 533 bool condition = literal->BooleanValue();
533 Handle<Object> result = 534 return factory->NewBooleanLiteral(!condition, pos);
534 parser_->isolate()->factory()->ToBoolean(!condition);
535 return factory->NewLiteral(result, pos);
536 } else if (literal->IsNumber()) { 535 } else if (literal->IsNumber()) {
537 // Compute some expressions involving only number literals. 536 // Compute some expressions involving only number literals.
538 double value = literal->Number(); 537 double value = literal->AsNumber();
539 switch (op) { 538 switch (op) {
540 case Token::ADD: 539 case Token::ADD:
541 return expression; 540 return expression;
542 case Token::SUB: 541 case Token::SUB:
543 return factory->NewNumberLiteral(-value, pos); 542 return factory->NewNumberLiteral(-value, pos);
544 case Token::BIT_NOT: 543 case Token::BIT_NOT:
545 return factory->NewNumberLiteral(~DoubleToInt32(value), pos); 544 return factory->NewNumberLiteral(~DoubleToInt32(value), pos);
546 default: 545 default:
547 break; 546 break;
548 } 547 }
(...skipping 13 matching lines...) Expand all
562 if (op == Token::BIT_NOT) { 561 if (op == Token::BIT_NOT) {
563 return factory->NewBinaryOperation( 562 return factory->NewBinaryOperation(
564 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); 563 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos);
565 } 564 }
566 return factory->NewUnaryOperation(op, expression, pos); 565 return factory->NewUnaryOperation(op, expression, pos);
567 } 566 }
568 567
569 568
570 Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) { 569 Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) {
571 return NewThrowError( 570 return NewThrowError(
572 parser_->isolate()->factory()->MakeReferenceError_string(), 571 parser_->ast_value_factory_->make_reference_error_string(), message, NULL,
573 message, HandleVector<Object>(NULL, 0), pos); 572 pos);
574 } 573 }
575 574
576 575
577 Expression* ParserTraits::NewThrowSyntaxError( 576 Expression* ParserTraits::NewThrowSyntaxError(
578 const char* message, Handle<Object> arg, int pos) { 577 const char* message, const AstString* arg, int pos) {
579 int argc = arg.is_null() ? 0 : 1; 578 return NewThrowError(parser_->ast_value_factory_->make_syntax_error_string(),
580 Vector< Handle<Object> > arguments = HandleVector<Object>(&arg, argc); 579 message, arg, pos);
581 return NewThrowError(
582 parser_->isolate()->factory()->MakeSyntaxError_string(),
583 message, arguments, pos);
584 } 580 }
585 581
586 582
587 Expression* ParserTraits::NewThrowTypeError( 583 Expression* ParserTraits::NewThrowTypeError(
588 const char* message, Handle<Object> arg, int pos) { 584 const char* message, const AstString* arg, int pos) {
589 int argc = arg.is_null() ? 0 : 1; 585 return NewThrowError(parser_->ast_value_factory_->make_type_error_string(),
590 Vector< Handle<Object> > arguments = HandleVector<Object>(&arg, argc); 586 message, arg, pos);
591 return NewThrowError(
592 parser_->isolate()->factory()->MakeTypeError_string(),
593 message, arguments, pos);
594 } 587 }
595 588
596 589
597 Expression* ParserTraits::NewThrowError( 590 Expression* ParserTraits::NewThrowError(
598 Handle<String> constructor, const char* message, 591 const AstString* constructor, const char* message,
599 Vector<Handle<Object> > arguments, int pos) { 592 const AstString* arg, int pos) {
600 Zone* zone = parser_->zone(); 593 Zone* zone = parser_->zone();
601 Factory* factory = parser_->isolate()->factory(); 594 int argc = arg != NULL ? 1 : 0;
602 int argc = arguments.length(); 595 const AstString* type =
603 Handle<FixedArray> elements = factory->NewFixedArray(argc, TENURED); 596 parser_->ast_value_factory_->GetOneByteString(Vector<const uint8_t>(
604 for (int i = 0; i < argc; i++) { 597 reinterpret_cast<const uint8_t*>(message), StrLength(message)));
605 Handle<Object> element = arguments[i]; 598 ZoneList<const AstString*>* array =
606 if (!element.is_null()) { 599 new (zone) ZoneList<const AstString*>(argc, zone);
607 elements->set(i, *element); 600 if (arg != NULL) {
608 } 601 array->Add(arg, zone);
609 } 602 }
610 Handle<JSArray> array = 603 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone);
611 factory->NewJSArrayWithElements(elements, FAST_ELEMENTS, TENURED); 604 args->Add(parser_->factory()->NewStringLiteral(type, pos), zone);
612 605 args->Add(parser_->factory()->NewStringListLiteral(array, pos), zone);
613 ZoneList<Expression*>* args = new(zone) ZoneList<Expression*>(2, zone);
614 Handle<String> type = factory->InternalizeUtf8String(message);
615 args->Add(parser_->factory()->NewLiteral(type, pos), zone);
616 args->Add(parser_->factory()->NewLiteral(array, pos), zone);
617 CallRuntime* call_constructor = 606 CallRuntime* call_constructor =
618 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); 607 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos);
619 return parser_->factory()->NewThrow(call_constructor, pos); 608 return parser_->factory()->NewThrow(call_constructor, pos);
620 } 609 }
621 610
622 611
623 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 612 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
624 const char* message, 613 const char* message,
625 const char* arg, 614 const char* arg,
626 bool is_reference_error) { 615 bool is_reference_error) {
627 if (parser_->stack_overflow()) { 616 if (parser_->stack_overflow()) {
628 // Suppress the error message (syntax error or such) in the presence of a 617 // Suppress the error message (syntax error or such) in the presence of a
629 // stack overflow. The isolate allows only one pending exception at at time 618 // stack overflow. The isolate allows only one pending exception at at time
630 // and we want to report the stack overflow later. 619 // and we want to report the stack overflow later.
631 return; 620 return;
632 } 621 }
633 parser_->has_pending_error_ = true; 622 parser_->has_pending_error_ = true;
634 parser_->pending_error_location_ = source_location; 623 parser_->pending_error_location_ = source_location;
635 parser_->pending_error_message_ = message; 624 parser_->pending_error_message_ = message;
636 parser_->pending_error_char_arg_ = arg; 625 parser_->pending_error_char_arg_ = arg;
637 parser_->pending_error_arg_ = Handle<String>(); 626 parser_->pending_error_arg_ = NULL;
638 parser_->pending_error_is_reference_error_ = is_reference_error; 627 parser_->pending_error_is_reference_error_ = is_reference_error;
639 } 628 }
640 629
641 630
642 void ParserTraits::ReportMessage(const char* message, 631 void ParserTraits::ReportMessage(const char* message,
643 MaybeHandle<String> arg, 632 const char* arg,
644 bool is_reference_error) { 633 bool is_reference_error) {
645 Scanner::Location source_location = parser_->scanner()->location(); 634 Scanner::Location source_location = parser_->scanner()->location();
646 ReportMessageAt(source_location, message, arg, is_reference_error); 635 ReportMessageAt(source_location, message, arg, is_reference_error);
636 }
637
638
639 void ParserTraits::ReportMessage(const char* message,
640 const AstString* arg,
641 bool is_reference_error) {
642 Scanner::Location source_location = parser_->scanner()->location();
643 ReportMessageAt(source_location, message, arg, is_reference_error);
647 } 644 }
648 645
649 646
650 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 647 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
651 const char* message, 648 const char* message,
652 MaybeHandle<String> arg, 649 const AstString* arg,
653 bool is_reference_error) { 650 bool is_reference_error) {
654 if (parser_->stack_overflow()) { 651 if (parser_->stack_overflow()) {
655 // Suppress the error message (syntax error or such) in the presence of a 652 // Suppress the error message (syntax error or such) in the presence of a
656 // stack overflow. The isolate allows only one pending exception at at time 653 // stack overflow. The isolate allows only one pending exception at at time
657 // and we want to report the stack overflow later. 654 // and we want to report the stack overflow later.
658 return; 655 return;
659 } 656 }
660 parser_->has_pending_error_ = true; 657 parser_->has_pending_error_ = true;
661 parser_->pending_error_location_ = source_location; 658 parser_->pending_error_location_ = source_location;
662 parser_->pending_error_message_ = message; 659 parser_->pending_error_message_ = message;
663 parser_->pending_error_char_arg_ = NULL; 660 parser_->pending_error_char_arg_ = NULL;
664 parser_->pending_error_arg_ = arg; 661 parser_->pending_error_arg_ = arg;
665 parser_->pending_error_is_reference_error_ = is_reference_error; 662 parser_->pending_error_is_reference_error_ = is_reference_error;
666 } 663 }
667 664
668 665
669 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { 666 const AstString* ParserTraits::GetSymbol(Scanner* scanner) {
670 Handle<String> result = 667 const AstString* result =
671 parser_->scanner()->AllocateInternalizedString(parser_->isolate()); 668 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory_);
672 ASSERT(!result.is_null()); 669 ASSERT(result != NULL);
673 return result; 670 return result;
674 } 671 }
675 672
676 673
677 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, 674 const AstString* ParserTraits::GetNextSymbol(Scanner* scanner) {
678 PretenureFlag tenured) { 675 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_);
679 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured);
680 } 676 }
681 677
682 678
683 Expression* ParserTraits::ThisExpression( 679 Expression* ParserTraits::ThisExpression(
684 Scope* scope, 680 Scope* scope,
685 AstNodeFactory<AstConstructionVisitor>* factory) { 681 AstNodeFactory<AstConstructionVisitor>* factory) {
686 return factory->NewVariableProxy(scope->receiver()); 682 return factory->NewVariableProxy(scope->receiver());
687 } 683 }
688 684
689 685
690 Literal* ParserTraits::ExpressionFromLiteral( 686 Literal* ParserTraits::ExpressionFromLiteral(
691 Token::Value token, int pos, 687 Token::Value token, int pos,
692 Scanner* scanner, 688 Scanner* scanner,
693 AstNodeFactory<AstConstructionVisitor>* factory) { 689 AstNodeFactory<AstConstructionVisitor>* factory) {
694 Factory* isolate_factory = parser_->isolate()->factory();
695 switch (token) { 690 switch (token) {
696 case Token::NULL_LITERAL: 691 case Token::NULL_LITERAL:
697 return factory->NewLiteral(isolate_factory->null_value(), pos); 692 return factory->NewNullLiteral(pos);
698 case Token::TRUE_LITERAL: 693 case Token::TRUE_LITERAL:
699 return factory->NewLiteral(isolate_factory->true_value(), pos); 694 return factory->NewBooleanLiteral(true, pos);
700 case Token::FALSE_LITERAL: 695 case Token::FALSE_LITERAL:
701 return factory->NewLiteral(isolate_factory->false_value(), pos); 696 return factory->NewBooleanLiteral(false, pos);
702 case Token::NUMBER: { 697 case Token::NUMBER: {
703 double value = scanner->DoubleValue(); 698 double value = scanner->DoubleValue();
704 return factory->NewNumberLiteral(value, pos); 699 return factory->NewNumberLiteral(value, pos);
705 } 700 }
706 default: 701 default:
707 ASSERT(false); 702 ASSERT(false);
708 } 703 }
709 return NULL; 704 return NULL;
710 } 705 }
711 706
712 707
713 Expression* ParserTraits::ExpressionFromIdentifier( 708 Expression* ParserTraits::ExpressionFromIdentifier(
714 Handle<String> name, int pos, Scope* scope, 709 const AstString* name, int pos, Scope* scope,
715 AstNodeFactory<AstConstructionVisitor>* factory) { 710 AstNodeFactory<AstConstructionVisitor>* factory) {
716 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); 711 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
717 // The name may refer to a module instance object, so its type is unknown. 712 // The name may refer to a module instance object, so its type is unknown.
718 #ifdef DEBUG 713 #ifdef DEBUG
719 if (FLAG_print_interface_details) 714 if (FLAG_print_interface_details)
720 PrintF("# Variable %s ", name->ToAsciiArray()); 715 PrintF("# Variable %.*s ", name->length(), name->raw_data());
721 #endif 716 #endif
722 Interface* interface = Interface::NewUnknown(parser_->zone()); 717 Interface* interface = Interface::NewUnknown(parser_->zone());
723 return scope->NewUnresolved(factory, name, interface, pos); 718 return scope->NewUnresolved(factory, name, interface, pos);
724 } 719 }
725 720
726 721
727 Expression* ParserTraits::ExpressionFromString( 722 Expression* ParserTraits::ExpressionFromString(
728 int pos, Scanner* scanner, 723 int pos, Scanner* scanner,
729 AstNodeFactory<AstConstructionVisitor>* factory) { 724 AstNodeFactory<AstConstructionVisitor>* factory) {
730 Handle<String> symbol = GetSymbol(scanner); 725 const AstString* symbol = GetSymbol(scanner);
731 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 726 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
732 return factory->NewLiteral(symbol, pos); 727 return factory->NewStringLiteral(symbol, pos);
733 } 728 }
734 729
735 730
736 Literal* ParserTraits::GetLiteralTheHole( 731 Literal* ParserTraits::GetLiteralTheHole(
737 int position, AstNodeFactory<AstConstructionVisitor>* factory) { 732 int position, AstNodeFactory<AstConstructionVisitor>* factory) {
738 return factory->NewLiteral(parser_->isolate()->factory()->the_hole_value(), 733 return factory->NewTheHoleLiteral(RelocInfo::kNoPosition);
739 RelocInfo::kNoPosition);
740 } 734 }
741 735
742 736
743 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { 737 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) {
744 return parser_->ParseV8Intrinsic(ok); 738 return parser_->ParseV8Intrinsic(ok);
745 } 739 }
746 740
747 741
748 FunctionLiteral* ParserTraits::ParseFunctionLiteral( 742 FunctionLiteral* ParserTraits::ParseFunctionLiteral(
749 Handle<String> name, 743 const AstString* name,
750 Scanner::Location function_name_location, 744 Scanner::Location function_name_location,
751 bool name_is_strict_reserved, 745 bool name_is_strict_reserved,
752 bool is_generator, 746 bool is_generator,
753 int function_token_position, 747 int function_token_position,
754 FunctionLiteral::FunctionType type, 748 FunctionLiteral::FunctionType type,
755 bool* ok) { 749 bool* ok) {
756 return parser_->ParseFunctionLiteral(name, function_name_location, 750 return parser_->ParseFunctionLiteral(name, function_name_location,
757 name_is_strict_reserved, is_generator, 751 name_is_strict_reserved, is_generator,
758 function_token_position, type, ok); 752 function_token_position, type, ok);
759 } 753 }
760 754
761 755
762 Parser::Parser(CompilationInfo* info) 756 Parser::Parser(CompilationInfo* info)
763 : ParserBase<ParserTraits>(&scanner_, 757 : ParserBase<ParserTraits>(&scanner_,
764 info->isolate()->stack_guard()->real_climit(), 758 info->isolate()->stack_guard()->real_climit(),
765 info->extension(), 759 info->extension(),
766 NULL, 760 NULL,
767 info->zone(), 761 info->zone(),
768 this), 762 this),
769 isolate_(info->isolate()), 763 isolate_(info->isolate()),
770 script_(info->script()), 764 script_(info->script()),
771 scanner_(isolate_->unicode_cache()), 765 scanner_(isolate_->unicode_cache()),
772 reusable_preparser_(NULL), 766 reusable_preparser_(NULL),
773 original_scope_(NULL), 767 original_scope_(NULL),
774 target_stack_(NULL), 768 target_stack_(NULL),
775 cached_data_(NULL), 769 cached_data_(NULL),
776 cached_data_mode_(NO_CACHED_DATA), 770 cached_data_mode_(NO_CACHED_DATA),
771 ast_value_factory_(NULL),
777 info_(info), 772 info_(info),
778 has_pending_error_(false), 773 has_pending_error_(false),
779 pending_error_message_(NULL), 774 pending_error_message_(NULL),
775 pending_error_arg_(NULL),
780 pending_error_char_arg_(NULL) { 776 pending_error_char_arg_(NULL) {
781 ASSERT(!script_.is_null()); 777 ASSERT(!script_.is_null());
782 isolate_->set_ast_node_id(0); 778 isolate_->set_ast_node_id(0);
783 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
784 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 780 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
785 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
786 set_allow_lazy(false); // Must be explicitly enabled. 782 set_allow_lazy(false); // Must be explicitly enabled.
787 set_allow_generators(FLAG_harmony_generators); 783 set_allow_generators(FLAG_harmony_generators);
788 set_allow_for_of(FLAG_harmony_iteration); 784 set_allow_for_of(FLAG_harmony_iteration);
789 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
790 } 786 }
791 787
792 788
793 FunctionLiteral* Parser::ParseProgram() { 789 FunctionLiteral* Parser::ParseProgram() {
794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 790 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
795 // see comment for HistogramTimerScope class. 791 // see comment for HistogramTimerScope class.
796 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); 792 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
797 Handle<String> source(String::cast(script_->source())); 793 Handle<String> source(String::cast(script_->source()));
798 isolate()->counters()->total_parse_size()->Increment(source->length()); 794 isolate()->counters()->total_parse_size()->Increment(source->length());
799 ElapsedTimer timer; 795 ElapsedTimer timer;
800 if (FLAG_trace_parse) { 796 if (FLAG_trace_parse) {
801 timer.Start(); 797 timer.Start();
802 } 798 }
803 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 799 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
804 800
805 // Initialize parser state. 801 // Initialize parser state.
806 CompleteParserRecorder recorder; 802 CompleteParserRecorder recorder;
807 if (cached_data_mode_ == PRODUCE_CACHED_DATA) { 803 if (cached_data_mode_ == PRODUCE_CACHED_DATA) {
808 log_ = &recorder; 804 log_ = &recorder;
809 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) { 805 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) {
810 (*cached_data_)->Initialize(); 806 (*cached_data_)->Initialize();
811 } 807 }
812 808
813 source = String::Flatten(source); 809 source = String::Flatten(source);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 844 }
849 return result; 845 return result;
850 } 846 }
851 847
852 848
853 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 849 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
854 Handle<String> source) { 850 Handle<String> source) {
855 ASSERT(scope_ == NULL); 851 ASSERT(scope_ == NULL);
856 ASSERT(target_stack_ == NULL); 852 ASSERT(target_stack_ == NULL);
857 853
858 Handle<String> no_name = isolate()->factory()->empty_string();
859
860 FunctionLiteral* result = NULL; 854 FunctionLiteral* result = NULL;
861 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 855 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
862 info->SetGlobalScope(scope); 856 info->SetGlobalScope(scope);
863 if (!info->context().is_null()) { 857 if (!info->context().is_null()) {
864 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); 858 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone());
859 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
860 // means the Parser cannot operate independent of the V8 heap. Tell the
861 // string table to internalize strings and values right after they're
862 // created.
863 ast_value_factory_->Internalize(isolate());
865 } 864 }
866 original_scope_ = scope; 865 original_scope_ = scope;
867 if (info->is_eval()) { 866 if (info->is_eval()) {
868 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { 867 if (!scope->is_global_scope() || info->strict_mode() == STRICT) {
869 scope = NewScope(scope, EVAL_SCOPE); 868 scope = NewScope(scope, EVAL_SCOPE);
870 } 869 }
871 } else if (info->is_global()) { 870 } else if (info->is_global()) {
872 scope = NewScope(scope, GLOBAL_SCOPE); 871 scope = NewScope(scope, GLOBAL_SCOPE);
873 } 872 }
874 scope->set_start_position(0); 873 scope->set_start_position(0);
875 scope->set_end_position(source->length()); 874 scope->set_end_position(source->length());
876 875
877 // Compute the parsing mode. 876 // Compute the parsing mode.
878 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 877 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
879 if (allow_natives_syntax() || 878 if (allow_natives_syntax() ||
880 extension_ != NULL || 879 extension_ != NULL ||
881 scope->is_eval_scope()) { 880 scope->is_eval_scope()) {
882 mode = PARSE_EAGERLY; 881 mode = PARSE_EAGERLY;
883 } 882 }
884 ParsingModeScope parsing_mode(this, mode); 883 ParsingModeScope parsing_mode(this, mode);
885 884
886 // Enters 'scope'. 885 // Enters 'scope'.
887 FunctionState function_state(&function_state_, &scope_, scope, zone()); 886 FunctionState function_state(&function_state_, &scope_, scope, zone(),
887 ast_value_factory_);
888 888
889 scope_->SetStrictMode(info->strict_mode()); 889 scope_->SetStrictMode(info->strict_mode());
890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
891 bool ok = true; 891 bool ok = true;
892 int beg_pos = scanner()->location().beg_pos; 892 int beg_pos = scanner()->location().beg_pos;
893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
894 if (ok && strict_mode() == STRICT) { 894 if (ok && strict_mode() == STRICT) {
895 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 895 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
896 } 896 }
897 897
898 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 898 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
899 CheckConflictingVarDeclarations(scope_, &ok); 899 CheckConflictingVarDeclarations(scope_, &ok);
900 } 900 }
901 901
902 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 902 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
903 if (body->length() != 1 || 903 if (body->length() != 1 ||
904 !body->at(0)->IsExpressionStatement() || 904 !body->at(0)->IsExpressionStatement() ||
905 !body->at(0)->AsExpressionStatement()-> 905 !body->at(0)->AsExpressionStatement()->
906 expression()->IsFunctionLiteral()) { 906 expression()->IsFunctionLiteral()) {
907 ReportMessage("single_function_literal"); 907 ReportMessage("single_function_literal");
908 ok = false; 908 ok = false;
909 } 909 }
910 } 910 }
911 911
912 if (ok) { 912 if (ok) {
913 result = factory()->NewFunctionLiteral( 913 result = factory()->NewFunctionLiteral(
914 no_name, 914 ast_value_factory_->empty_string(),
915 ast_value_factory_,
915 scope_, 916 scope_,
916 body, 917 body,
917 function_state.materialized_literal_count(), 918 function_state.materialized_literal_count(),
918 function_state.expected_property_count(), 919 function_state.expected_property_count(),
919 function_state.handler_count(), 920 function_state.handler_count(),
920 0, 921 0,
921 FunctionLiteral::kNoDuplicateParameters, 922 FunctionLiteral::kNoDuplicateParameters,
922 FunctionLiteral::ANONYMOUS_EXPRESSION, 923 FunctionLiteral::ANONYMOUS_EXPRESSION,
923 FunctionLiteral::kGlobalOrEval, 924 FunctionLiteral::kGlobalOrEval,
924 FunctionLiteral::kNotParenthesized, 925 FunctionLiteral::kNotParenthesized,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 977 }
977 978
978 979
979 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { 980 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
980 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 981 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
981 scanner_.Initialize(source); 982 scanner_.Initialize(source);
982 ASSERT(scope_ == NULL); 983 ASSERT(scope_ == NULL);
983 ASSERT(target_stack_ == NULL); 984 ASSERT(target_stack_ == NULL);
984 985
985 Handle<String> name(String::cast(shared_info->name())); 986 Handle<String> name(String::cast(shared_info->name()));
986 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 987 ASSERT(ast_value_factory_);
987 fni_->PushEnclosingName(name); 988 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
989 const AstString* raw_name = ast_value_factory_->GetString(name);
990 fni_->PushEnclosingName(raw_name);
988 991
989 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 992 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
990 993
991 // Place holder for the result. 994 // Place holder for the result.
992 FunctionLiteral* result = NULL; 995 FunctionLiteral* result = NULL;
993 996
994 { 997 {
995 // Parse the function literal. 998 // Parse the function literal.
996 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 999 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
997 info()->SetGlobalScope(scope); 1000 info()->SetGlobalScope(scope);
998 if (!info()->closure().is_null()) { 1001 if (!info()->closure().is_null()) {
999 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 1002 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
1000 zone()); 1003 zone());
1001 } 1004 }
1002 original_scope_ = scope; 1005 original_scope_ = scope;
1003 FunctionState function_state(&function_state_, &scope_, scope, zone()); 1006 FunctionState function_state(&function_state_, &scope_, scope, zone(),
1007 ast_value_factory_);
1004 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 1008 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
1005 ASSERT(info()->strict_mode() == shared_info->strict_mode()); 1009 ASSERT(info()->strict_mode() == shared_info->strict_mode());
1006 scope->SetStrictMode(shared_info->strict_mode()); 1010 scope->SetStrictMode(shared_info->strict_mode());
1007 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1011 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1008 ? (shared_info->is_anonymous() 1012 ? (shared_info->is_anonymous()
1009 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1013 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1010 : FunctionLiteral::NAMED_EXPRESSION) 1014 : FunctionLiteral::NAMED_EXPRESSION)
1011 : FunctionLiteral::DECLARATION; 1015 : FunctionLiteral::DECLARATION;
1012 bool ok = true; 1016 bool ok = true;
1013 result = ParseFunctionLiteral(name, 1017 result = ParseFunctionLiteral(raw_name,
1014 Scanner::Location::invalid(), 1018 Scanner::Location::invalid(),
1015 false, // Strict mode name already checked. 1019 false, // Strict mode name already checked.
1016 shared_info->is_generator(), 1020 shared_info->is_generator(),
1017 RelocInfo::kNoPosition, 1021 RelocInfo::kNoPosition,
1018 function_type, 1022 function_type,
1019 &ok); 1023 &ok);
1020 // Make sure the results agree. 1024 // Make sure the results agree.
1021 ASSERT(ok == (result != NULL)); 1025 ASSERT(ok == (result != NULL));
1022 } 1026 }
1023 1027
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 continue; 1076 continue;
1073 } 1077 }
1074 1078
1075 if (directive_prologue) { 1079 if (directive_prologue) {
1076 // A shot at a directive. 1080 // A shot at a directive.
1077 ExpressionStatement* e_stat; 1081 ExpressionStatement* e_stat;
1078 Literal* literal; 1082 Literal* literal;
1079 // Still processing directive prologue? 1083 // Still processing directive prologue?
1080 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1084 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1081 (literal = e_stat->expression()->AsLiteral()) != NULL && 1085 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1082 literal->value()->IsString()) { 1086 literal->raw_value()->IsString()) {
1083 Handle<String> directive = Handle<String>::cast(literal->value());
1084
1085 // Check "use strict" directive (ES5 14.1). 1087 // Check "use strict" directive (ES5 14.1).
1086 if (strict_mode() == SLOPPY && 1088 if (strict_mode() == SLOPPY &&
1087 String::Equals(isolate()->factory()->use_strict_string(), 1089 literal->raw_value()->AsString() ==
1088 directive) && 1090 ast_value_factory_->use_strict_string() &&
1089 token_loc.end_pos - token_loc.beg_pos == 1091 token_loc.end_pos - token_loc.beg_pos == 12) {
1090 isolate()->heap()->use_strict_string()->length() + 2) {
1091 // TODO(mstarzinger): Global strict eval calls, need their own scope 1092 // TODO(mstarzinger): Global strict eval calls, need their own scope
1092 // as specified in ES5 10.4.2(3). The correct fix would be to always 1093 // as specified in ES5 10.4.2(3). The correct fix would be to always
1093 // add this scope in DoParseProgram(), but that requires adaptations 1094 // add this scope in DoParseProgram(), but that requires adaptations
1094 // all over the code base, so we go with a quick-fix for now. 1095 // all over the code base, so we go with a quick-fix for now.
1095 // In the same manner, we have to patch the parsing mode. 1096 // In the same manner, we have to patch the parsing mode.
1096 if (is_eval && !scope_->is_eval_scope()) { 1097 if (is_eval && !scope_->is_eval_scope()) {
1097 ASSERT(scope_->is_global_scope()); 1098 ASSERT(scope_->is_global_scope());
1098 Scope* scope = NewScope(scope_, EVAL_SCOPE); 1099 Scope* scope = NewScope(scope_, EVAL_SCOPE);
1099 scope->set_start_position(scope_->start_position()); 1100 scope->set_start_position(scope_->start_position());
1100 scope->set_end_position(scope_->end_position()); 1101 scope->set_end_position(scope_->end_position());
(...skipping 10 matching lines...) Expand all
1111 } 1112 }
1112 } 1113 }
1113 1114
1114 processor->Add(stat, zone()); 1115 processor->Add(stat, zone());
1115 } 1116 }
1116 1117
1117 return 0; 1118 return 0;
1118 } 1119 }
1119 1120
1120 1121
1121 Statement* Parser::ParseModuleElement(ZoneStringList* labels, 1122 Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels,
1122 bool* ok) { 1123 bool* ok) {
1123 // (Ecma 262 5th Edition, clause 14): 1124 // (Ecma 262 5th Edition, clause 14):
1124 // SourceElement: 1125 // SourceElement:
1125 // Statement 1126 // Statement
1126 // FunctionDeclaration 1127 // FunctionDeclaration
1127 // 1128 //
1128 // In harmony mode we allow additionally the following productions 1129 // In harmony mode we allow additionally the following productions
1129 // ModuleElement: 1130 // ModuleElement:
1130 // LetDeclaration 1131 // LetDeclaration
1131 // ConstDeclaration 1132 // ConstDeclaration
(...skipping 13 matching lines...) Expand all
1145 case Token::EXPORT: 1146 case Token::EXPORT:
1146 return ParseExportDeclaration(ok); 1147 return ParseExportDeclaration(ok);
1147 default: { 1148 default: {
1148 Statement* stmt = ParseStatement(labels, CHECK_OK); 1149 Statement* stmt = ParseStatement(labels, CHECK_OK);
1149 // Handle 'module' as a context-sensitive keyword. 1150 // Handle 'module' as a context-sensitive keyword.
1150 if (FLAG_harmony_modules && 1151 if (FLAG_harmony_modules &&
1151 peek() == Token::IDENTIFIER && 1152 peek() == Token::IDENTIFIER &&
1152 !scanner()->HasAnyLineTerminatorBeforeNext() && 1153 !scanner()->HasAnyLineTerminatorBeforeNext() &&
1153 stmt != NULL) { 1154 stmt != NULL) {
1154 ExpressionStatement* estmt = stmt->AsExpressionStatement(); 1155 ExpressionStatement* estmt = stmt->AsExpressionStatement();
1155 if (estmt != NULL && 1156 if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL &&
1156 estmt->expression()->AsVariableProxy() != NULL && 1157 estmt->expression()->AsVariableProxy()->raw_name() ==
1157 String::Equals(isolate()->factory()->module_string(), 1158 ast_value_factory_->module_string() &&
1158 estmt->expression()->AsVariableProxy()->name()) &&
1159 !scanner()->literal_contains_escapes()) { 1159 !scanner()->literal_contains_escapes()) {
1160 return ParseModuleDeclaration(NULL, ok); 1160 return ParseModuleDeclaration(NULL, ok);
1161 } 1161 }
1162 } 1162 }
1163 return stmt; 1163 return stmt;
1164 } 1164 }
1165 } 1165 }
1166 } 1166 }
1167 1167
1168 1168
1169 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 1169 Statement* Parser::ParseModuleDeclaration(ZoneList<const AstString*>* names,
1170 bool* ok) {
1170 // ModuleDeclaration: 1171 // ModuleDeclaration:
1171 // 'module' Identifier Module 1172 // 'module' Identifier Module
1172 1173
1173 int pos = peek_position(); 1174 int pos = peek_position();
1174 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1175 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1175 1176
1176 #ifdef DEBUG 1177 #ifdef DEBUG
1177 if (FLAG_print_interface_details) 1178 if (FLAG_print_interface_details)
1178 PrintF("# Module %s...\n", name->ToAsciiArray()); 1179 PrintF("# Module %.*s ", name->length(), name->raw_data());
1179 #endif 1180 #endif
1180 1181
1181 Module* module = ParseModule(CHECK_OK); 1182 Module* module = ParseModule(CHECK_OK);
1182 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); 1183 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface());
1183 Declaration* declaration = 1184 Declaration* declaration =
1184 factory()->NewModuleDeclaration(proxy, module, scope_, pos); 1185 factory()->NewModuleDeclaration(proxy, module, scope_, pos);
1185 Declare(declaration, true, CHECK_OK); 1186 Declare(declaration, true, CHECK_OK);
1186 1187
1187 #ifdef DEBUG 1188 #ifdef DEBUG
1188 if (FLAG_print_interface_details) 1189 if (FLAG_print_interface_details)
1189 PrintF("# Module %s.\n", name->ToAsciiArray()); 1190 PrintF("# Module %.*s ", name->length(), name->raw_data());
1190
1191 if (FLAG_print_interfaces) { 1191 if (FLAG_print_interfaces) {
1192 PrintF("module %s : ", name->ToAsciiArray()); 1192 PrintF("module %.*s: ", name->length(), name->raw_data());
1193 module->interface()->Print(); 1193 module->interface()->Print();
1194 } 1194 }
1195 #endif 1195 #endif
1196 1196
1197 if (names) names->Add(name, zone()); 1197 if (names) names->Add(name, zone());
1198 if (module->body() == NULL) 1198 if (module->body() == NULL)
1199 return factory()->NewEmptyStatement(pos); 1199 return factory()->NewEmptyStatement(pos);
1200 else 1200 else
1201 return factory()->NewModuleStatement(proxy, module->body(), pos); 1201 return factory()->NewModuleStatement(proxy, module->body(), pos);
1202 } 1202 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 1283
1284 1284
1285 Module* Parser::ParseModulePath(bool* ok) { 1285 Module* Parser::ParseModulePath(bool* ok) {
1286 // ModulePath: 1286 // ModulePath:
1287 // Identifier 1287 // Identifier
1288 // ModulePath '.' Identifier 1288 // ModulePath '.' Identifier
1289 1289
1290 int pos = peek_position(); 1290 int pos = peek_position();
1291 Module* result = ParseModuleVariable(CHECK_OK); 1291 Module* result = ParseModuleVariable(CHECK_OK);
1292 while (Check(Token::PERIOD)) { 1292 while (Check(Token::PERIOD)) {
1293 Handle<String> name = ParseIdentifierName(CHECK_OK); 1293 const AstString* name = ParseIdentifierName(CHECK_OK);
1294 #ifdef DEBUG 1294 #ifdef DEBUG
1295 if (FLAG_print_interface_details) 1295 if (FLAG_print_interface_details)
1296 PrintF("# Path .%s ", name->ToAsciiArray()); 1296 PrintF("# Path .%.*s ", name->length(), name->raw_data());
1297 #endif 1297 #endif
1298 Module* member = factory()->NewModulePath(result, name, pos); 1298 Module* member = factory()->NewModulePath(result, name, pos);
1299 result->interface()->Add(name, member->interface(), zone(), ok); 1299 result->interface()->Add(name, member->interface(), zone(), ok);
1300 if (!*ok) { 1300 if (!*ok) {
1301 #ifdef DEBUG 1301 #ifdef DEBUG
1302 if (FLAG_print_interfaces) { 1302 if (FLAG_print_interfaces) {
1303 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); 1303 PrintF("PATH TYPE ERROR at '%.*s'\n", name->length(), name->raw_data());
1304 PrintF("result: "); 1304 PrintF("result: ");
1305 result->interface()->Print(); 1305 result->interface()->Print();
1306 PrintF("member: "); 1306 PrintF("member: ");
1307 member->interface()->Print(); 1307 member->interface()->Print();
1308 } 1308 }
1309 #endif 1309 #endif
1310 ParserTraits::ReportMessage("invalid_module_path", name); 1310 ParserTraits::ReportMessage("invalid_module_path", name);
1311 return NULL; 1311 return NULL;
1312 } 1312 }
1313 result = member; 1313 result = member;
1314 } 1314 }
1315 1315
1316 return result; 1316 return result;
1317 } 1317 }
1318 1318
1319 1319
1320 Module* Parser::ParseModuleVariable(bool* ok) { 1320 Module* Parser::ParseModuleVariable(bool* ok) {
1321 // ModulePath: 1321 // ModulePath:
1322 // Identifier 1322 // Identifier
1323 1323
1324 int pos = peek_position(); 1324 int pos = peek_position();
1325 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1325 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1326 #ifdef DEBUG 1326 #ifdef DEBUG
1327 if (FLAG_print_interface_details) 1327 if (FLAG_print_interface_details)
1328 PrintF("# Module variable %s ", name->ToAsciiArray()); 1328 PrintF("# Module variable %.*s ", name->length(), name->raw_data());
1329 #endif 1329 #endif
1330 VariableProxy* proxy = scope_->NewUnresolved( 1330 VariableProxy* proxy = scope_->NewUnresolved(
1331 factory(), name, Interface::NewModule(zone()), 1331 factory(), name, Interface::NewModule(zone()),
1332 scanner()->location().beg_pos); 1332 scanner()->location().beg_pos);
1333 1333
1334 return factory()->NewModuleVariable(proxy, pos); 1334 return factory()->NewModuleVariable(proxy, pos);
1335 } 1335 }
1336 1336
1337 1337
1338 Module* Parser::ParseModuleUrl(bool* ok) { 1338 Module* Parser::ParseModuleUrl(bool* ok) {
1339 // Module: 1339 // Module:
1340 // String 1340 // String
1341 1341
1342 int pos = peek_position(); 1342 int pos = peek_position();
1343 Expect(Token::STRING, CHECK_OK); 1343 Expect(Token::STRING, CHECK_OK);
1344 Handle<String> symbol = GetSymbol(); 1344 const AstString* symbol = GetSymbol(scanner());
1345 1345
1346 // TODO(ES6): Request JS resource from environment... 1346 // TODO(ES6): Request JS resource from environment...
1347 1347
1348 #ifdef DEBUG 1348 #ifdef DEBUG
1349 if (FLAG_print_interface_details) PrintF("# Url "); 1349 if (FLAG_print_interface_details) PrintF("# Url ");
1350 #endif 1350 #endif
1351 1351
1352 // Create an empty literal as long as the feature isn't finished. 1352 // Create an empty literal as long as the feature isn't finished.
1353 USE(symbol); 1353 USE(symbol);
1354 Scope* scope = NewScope(scope_, MODULE_SCOPE); 1354 Scope* scope = NewScope(scope_, MODULE_SCOPE);
(...skipping 23 matching lines...) Expand all
1378 1378
1379 1379
1380 Block* Parser::ParseImportDeclaration(bool* ok) { 1380 Block* Parser::ParseImportDeclaration(bool* ok) {
1381 // ImportDeclaration: 1381 // ImportDeclaration:
1382 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' 1382 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';'
1383 // 1383 //
1384 // TODO(ES6): implement destructuring ImportSpecifiers 1384 // TODO(ES6): implement destructuring ImportSpecifiers
1385 1385
1386 int pos = peek_position(); 1386 int pos = peek_position();
1387 Expect(Token::IMPORT, CHECK_OK); 1387 Expect(Token::IMPORT, CHECK_OK);
1388 ZoneStringList names(1, zone()); 1388 ZoneList<const AstString*> names(1, zone());
1389 1389
1390 Handle<String> name = ParseIdentifierName(CHECK_OK); 1390 const AstString* name = ParseIdentifierName(CHECK_OK);
1391 names.Add(name, zone()); 1391 names.Add(name, zone());
1392 while (peek() == Token::COMMA) { 1392 while (peek() == Token::COMMA) {
1393 Consume(Token::COMMA); 1393 Consume(Token::COMMA);
1394 name = ParseIdentifierName(CHECK_OK); 1394 name = ParseIdentifierName(CHECK_OK);
1395 names.Add(name, zone()); 1395 names.Add(name, zone());
1396 } 1396 }
1397 1397
1398 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1398 ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
1399 Module* module = ParseModuleSpecifier(CHECK_OK); 1399 Module* module = ParseModuleSpecifier(CHECK_OK);
1400 ExpectSemicolon(CHECK_OK); 1400 ExpectSemicolon(CHECK_OK);
1401 1401
1402 // Generate a separate declaration for each identifier. 1402 // Generate a separate declaration for each identifier.
1403 // TODO(ES6): once we implement destructuring, make that one declaration. 1403 // TODO(ES6): once we implement destructuring, make that one declaration.
1404 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); 1404 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
1405 for (int i = 0; i < names.length(); ++i) { 1405 for (int i = 0; i < names.length(); ++i) {
1406 #ifdef DEBUG 1406 #ifdef DEBUG
1407 if (FLAG_print_interface_details) 1407 if (FLAG_print_interface_details)
1408 PrintF("# Import %s ", names[i]->ToAsciiArray()); 1408 PrintF("# Import %.*s ", name->length(), name->raw_data());
1409 #endif 1409 #endif
1410 Interface* interface = Interface::NewUnknown(zone()); 1410 Interface* interface = Interface::NewUnknown(zone());
1411 module->interface()->Add(names[i], interface, zone(), ok); 1411 module->interface()->Add(names[i], interface, zone(), ok);
1412 if (!*ok) { 1412 if (!*ok) {
1413 #ifdef DEBUG 1413 #ifdef DEBUG
1414 if (FLAG_print_interfaces) { 1414 if (FLAG_print_interfaces) {
1415 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); 1415 PrintF("IMPORT TYPE ERROR at '%.*s'\n", name->length(),
1416 name->raw_data());
1416 PrintF("module: "); 1417 PrintF("module: ");
1417 module->interface()->Print(); 1418 module->interface()->Print();
1418 } 1419 }
1419 #endif 1420 #endif
1420 ParserTraits::ReportMessage("invalid_module_path", name); 1421 ParserTraits::ReportMessage("invalid_module_path", name);
1421 return NULL; 1422 return NULL;
1422 } 1423 }
1423 VariableProxy* proxy = NewUnresolved(names[i], LET, interface); 1424 VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
1424 Declaration* declaration = 1425 Declaration* declaration =
1425 factory()->NewImportDeclaration(proxy, module, scope_, pos); 1426 factory()->NewImportDeclaration(proxy, module, scope_, pos);
(...skipping 10 matching lines...) Expand all
1436 // 'export' VariableDeclaration 1437 // 'export' VariableDeclaration
1437 // 'export' FunctionDeclaration 1438 // 'export' FunctionDeclaration
1438 // 'export' GeneratorDeclaration 1439 // 'export' GeneratorDeclaration
1439 // 'export' ModuleDeclaration 1440 // 'export' ModuleDeclaration
1440 // 1441 //
1441 // TODO(ES6): implement structuring ExportSpecifiers 1442 // TODO(ES6): implement structuring ExportSpecifiers
1442 1443
1443 Expect(Token::EXPORT, CHECK_OK); 1444 Expect(Token::EXPORT, CHECK_OK);
1444 1445
1445 Statement* result = NULL; 1446 Statement* result = NULL;
1446 ZoneStringList names(1, zone()); 1447 ZoneList<const AstString*> names(1, zone());
1447 switch (peek()) { 1448 switch (peek()) {
1448 case Token::IDENTIFIER: { 1449 case Token::IDENTIFIER: {
1449 int pos = position(); 1450 int pos = position();
1450 Handle<String> name = 1451 const AstString* name =
1451 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1452 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1452 // Handle 'module' as a context-sensitive keyword. 1453 // Handle 'module' as a context-sensitive keyword.
1453 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { 1454 if (name != ast_value_factory_->module_string()) {
1454 names.Add(name, zone()); 1455 names.Add(name, zone());
1455 while (peek() == Token::COMMA) { 1456 while (peek() == Token::COMMA) {
1456 Consume(Token::COMMA); 1457 Consume(Token::COMMA);
1457 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1458 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1458 names.Add(name, zone()); 1459 names.Add(name, zone());
1459 } 1460 }
1460 ExpectSemicolon(CHECK_OK); 1461 ExpectSemicolon(CHECK_OK);
1461 result = factory()->NewEmptyStatement(pos); 1462 result = factory()->NewEmptyStatement(pos);
1462 } else { 1463 } else {
1463 result = ParseModuleDeclaration(&names, CHECK_OK); 1464 result = ParseModuleDeclaration(&names, CHECK_OK);
(...skipping 15 matching lines...) Expand all
1479 *ok = false; 1480 *ok = false;
1480 ReportUnexpectedToken(scanner()->current_token()); 1481 ReportUnexpectedToken(scanner()->current_token());
1481 return NULL; 1482 return NULL;
1482 } 1483 }
1483 1484
1484 // Extract declared names into export declarations and interface. 1485 // Extract declared names into export declarations and interface.
1485 Interface* interface = scope_->interface(); 1486 Interface* interface = scope_->interface();
1486 for (int i = 0; i < names.length(); ++i) { 1487 for (int i = 0; i < names.length(); ++i) {
1487 #ifdef DEBUG 1488 #ifdef DEBUG
1488 if (FLAG_print_interface_details) 1489 if (FLAG_print_interface_details)
1489 PrintF("# Export %s ", names[i]->ToAsciiArray()); 1490 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data());
1490 #endif 1491 #endif
1491 Interface* inner = Interface::NewUnknown(zone()); 1492 Interface* inner = Interface::NewUnknown(zone());
1492 interface->Add(names[i], inner, zone(), CHECK_OK); 1493 interface->Add(names[i], inner, zone(), CHECK_OK);
1493 if (!*ok) 1494 if (!*ok)
1494 return NULL; 1495 return NULL;
1495 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); 1496 VariableProxy* proxy = NewUnresolved(names[i], LET, inner);
1496 USE(proxy); 1497 USE(proxy);
1497 // TODO(rossberg): Rethink whether we actually need to store export 1498 // TODO(rossberg): Rethink whether we actually need to store export
1498 // declarations (for compilation?). 1499 // declarations (for compilation?).
1499 // ExportDeclaration* declaration = 1500 // ExportDeclaration* declaration =
1500 // factory()->NewExportDeclaration(proxy, scope_, position); 1501 // factory()->NewExportDeclaration(proxy, scope_, position);
1501 // scope_->AddDeclaration(declaration); 1502 // scope_->AddDeclaration(declaration);
1502 } 1503 }
1503 1504
1504 ASSERT(result != NULL); 1505 ASSERT(result != NULL);
1505 return result; 1506 return result;
1506 } 1507 }
1507 1508
1508 1509
1509 Statement* Parser::ParseBlockElement(ZoneStringList* labels, 1510 Statement* Parser::ParseBlockElement(ZoneList<const AstString*>* labels,
1510 bool* ok) { 1511 bool* ok) {
1511 // (Ecma 262 5th Edition, clause 14): 1512 // (Ecma 262 5th Edition, clause 14):
1512 // SourceElement: 1513 // SourceElement:
1513 // Statement 1514 // Statement
1514 // FunctionDeclaration 1515 // FunctionDeclaration
1515 // 1516 //
1516 // In harmony mode we allow additionally the following productions 1517 // In harmony mode we allow additionally the following productions
1517 // BlockElement (aka SourceElement): 1518 // BlockElement (aka SourceElement):
1518 // LetDeclaration 1519 // LetDeclaration
1519 // ConstDeclaration 1520 // ConstDeclaration
1520 // GeneratorDeclaration 1521 // GeneratorDeclaration
1521 1522
1522 switch (peek()) { 1523 switch (peek()) {
1523 case Token::FUNCTION: 1524 case Token::FUNCTION:
1524 return ParseFunctionDeclaration(NULL, ok); 1525 return ParseFunctionDeclaration(NULL, ok);
1525 case Token::LET: 1526 case Token::LET:
1526 case Token::CONST: 1527 case Token::CONST:
1527 return ParseVariableStatement(kModuleElement, NULL, ok); 1528 return ParseVariableStatement(kModuleElement, NULL, ok);
1528 default: 1529 default:
1529 return ParseStatement(labels, ok); 1530 return ParseStatement(labels, ok);
1530 } 1531 }
1531 } 1532 }
1532 1533
1533 1534
1534 Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { 1535 Statement* Parser::ParseStatement(ZoneList<const AstString*>* labels,
1536 bool* ok) {
1535 // Statement :: 1537 // Statement ::
1536 // Block 1538 // Block
1537 // VariableStatement 1539 // VariableStatement
1538 // EmptyStatement 1540 // EmptyStatement
1539 // ExpressionStatement 1541 // ExpressionStatement
1540 // IfStatement 1542 // IfStatement
1541 // IterationStatement 1543 // IterationStatement
1542 // ContinueStatement 1544 // ContinueStatement
1543 // BreakStatement 1545 // BreakStatement
1544 // ReturnStatement 1546 // ReturnStatement
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 1636
1635 case Token::DEBUGGER: 1637 case Token::DEBUGGER:
1636 return ParseDebuggerStatement(ok); 1638 return ParseDebuggerStatement(ok);
1637 1639
1638 default: 1640 default:
1639 return ParseExpressionOrLabelledStatement(labels, ok); 1641 return ParseExpressionOrLabelledStatement(labels, ok);
1640 } 1642 }
1641 } 1643 }
1642 1644
1643 1645
1644 VariableProxy* Parser::NewUnresolved( 1646 VariableProxy* Parser::NewUnresolved(const AstString* name, VariableMode mode,
1645 Handle<String> name, VariableMode mode, Interface* interface) { 1647 Interface* interface) {
1646 // If we are inside a function, a declaration of a var/const variable is a 1648 // If we are inside a function, a declaration of a var/const variable is a
1647 // truly local variable, and the scope of the variable is always the function 1649 // truly local variable, and the scope of the variable is always the function
1648 // scope. 1650 // scope.
1649 // Let/const variables in harmony mode are always added to the immediately 1651 // Let/const variables in harmony mode are always added to the immediately
1650 // enclosing scope. 1652 // enclosing scope.
1651 return DeclarationScope(mode)->NewUnresolved( 1653 return DeclarationScope(mode)->NewUnresolved(
1652 factory(), name, interface, position()); 1654 factory(), name, interface, position());
1653 } 1655 }
1654 1656
1655 1657
1656 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { 1658 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
1657 VariableProxy* proxy = declaration->proxy(); 1659 VariableProxy* proxy = declaration->proxy();
1658 Handle<String> name = proxy->name(); 1660 ASSERT(proxy->raw_name() != NULL);
1661 const AstString* name = proxy->raw_name();
1659 VariableMode mode = declaration->mode(); 1662 VariableMode mode = declaration->mode();
1660 Scope* declaration_scope = DeclarationScope(mode); 1663 Scope* declaration_scope = DeclarationScope(mode);
1661 Variable* var = NULL; 1664 Variable* var = NULL;
1662 1665
1663 // If a suitable scope exists, then we can statically declare this 1666 // If a suitable scope exists, then we can statically declare this
1664 // variable and also set its mode. In any case, a Declaration node 1667 // variable and also set its mode. In any case, a Declaration node
1665 // will be added to the scope so that the declaration can be added 1668 // will be added to the scope so that the declaration can be added
1666 // to the corresponding activation frame at runtime if necessary. 1669 // to the corresponding activation frame at runtime if necessary.
1667 // For instance declarations inside an eval scope need to be added 1670 // For instance declarations inside an eval scope need to be added
1668 // to the calling function context. 1671 // to the calling function context.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 // with a context slot index and a context chain length for this 1779 // with a context slot index and a context chain length for this
1777 // initialization code. Thus, inside the 'with' statement, we need 1780 // initialization code. Thus, inside the 'with' statement, we need
1778 // both access to the static and the dynamic context chain; the 1781 // both access to the static and the dynamic context chain; the
1779 // runtime needs to provide both. 1782 // runtime needs to provide both.
1780 if (resolve && var != NULL) { 1783 if (resolve && var != NULL) {
1781 proxy->BindTo(var); 1784 proxy->BindTo(var);
1782 1785
1783 if (FLAG_harmony_modules) { 1786 if (FLAG_harmony_modules) {
1784 bool ok; 1787 bool ok;
1785 #ifdef DEBUG 1788 #ifdef DEBUG
1786 if (FLAG_print_interface_details) 1789 if (FLAG_print_interface_details) {
1787 PrintF("# Declare %s\n", var->name()->ToAsciiArray()); 1790 PrintF("# Declare %.*s ", var->raw_name()->length(),
1791 var->raw_name()->raw_data());
1792 }
1788 #endif 1793 #endif
1789 proxy->interface()->Unify(var->interface(), zone(), &ok); 1794 proxy->interface()->Unify(var->interface(), zone(), &ok);
1790 if (!ok) { 1795 if (!ok) {
1791 #ifdef DEBUG 1796 #ifdef DEBUG
1792 if (FLAG_print_interfaces) { 1797 if (FLAG_print_interfaces) {
1793 PrintF("DECLARE TYPE ERROR\n"); 1798 PrintF("DECLARE TYPE ERROR\n");
1794 PrintF("proxy: "); 1799 PrintF("proxy: ");
1795 proxy->interface()->Print(); 1800 proxy->interface()->Print();
1796 PrintF("var: "); 1801 PrintF("var: ");
1797 var->interface()->Print(); 1802 var->interface()->Print();
1798 } 1803 }
1799 #endif 1804 #endif
1800 ParserTraits::ReportMessage("module_type_error", name); 1805 ParserTraits::ReportMessage("module_type_error", name);
1801 } 1806 }
1802 } 1807 }
1803 } 1808 }
1804 } 1809 }
1805 1810
1806 1811
1807 // Language extension which is only enabled for source files loaded 1812 // Language extension which is only enabled for source files loaded
1808 // through the API's extension mechanism. A native function 1813 // through the API's extension mechanism. A native function
1809 // declaration is resolved by looking up the function through a 1814 // declaration is resolved by looking up the function through a
1810 // callback provided by the extension. 1815 // callback provided by the extension.
1811 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1816 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1812 int pos = peek_position(); 1817 int pos = peek_position();
1813 Expect(Token::FUNCTION, CHECK_OK); 1818 Expect(Token::FUNCTION, CHECK_OK);
1814 // Allow "eval" or "arguments" for backward compatibility. 1819 // Allow "eval" or "arguments" for backward compatibility.
1815 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1820 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1816 Expect(Token::LPAREN, CHECK_OK); 1821 Expect(Token::LPAREN, CHECK_OK);
1817 bool done = (peek() == Token::RPAREN); 1822 bool done = (peek() == Token::RPAREN);
1818 while (!done) { 1823 while (!done) {
1819 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1824 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1820 done = (peek() == Token::RPAREN); 1825 done = (peek() == Token::RPAREN);
1821 if (!done) { 1826 if (!done) {
1822 Expect(Token::COMMA, CHECK_OK); 1827 Expect(Token::COMMA, CHECK_OK);
1823 } 1828 }
1824 } 1829 }
1825 Expect(Token::RPAREN, CHECK_OK); 1830 Expect(Token::RPAREN, CHECK_OK);
(...skipping 14 matching lines...) Expand all
1840 Declare(declaration, true, CHECK_OK); 1845 Declare(declaration, true, CHECK_OK);
1841 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( 1846 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(
1842 name, extension_, RelocInfo::kNoPosition); 1847 name, extension_, RelocInfo::kNoPosition);
1843 return factory()->NewExpressionStatement( 1848 return factory()->NewExpressionStatement(
1844 factory()->NewAssignment( 1849 factory()->NewAssignment(
1845 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), 1850 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition),
1846 pos); 1851 pos);
1847 } 1852 }
1848 1853
1849 1854
1850 Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { 1855 Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names,
1856 bool* ok) {
1851 // FunctionDeclaration :: 1857 // FunctionDeclaration ::
1852 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1858 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1853 // GeneratorDeclaration :: 1859 // GeneratorDeclaration ::
1854 // 'function' '*' Identifier '(' FormalParameterListopt ')' 1860 // 'function' '*' Identifier '(' FormalParameterListopt ')'
1855 // '{' FunctionBody '}' 1861 // '{' FunctionBody '}'
1856 Expect(Token::FUNCTION, CHECK_OK); 1862 Expect(Token::FUNCTION, CHECK_OK);
1857 int pos = position(); 1863 int pos = position();
1858 bool is_generator = allow_generators() && Check(Token::MUL); 1864 bool is_generator = allow_generators() && Check(Token::MUL);
1859 bool is_strict_reserved = false; 1865 bool is_strict_reserved = false;
1860 Handle<String> name = ParseIdentifierOrStrictReservedWord( 1866 const AstString* name = ParseIdentifierOrStrictReservedWord(
1861 &is_strict_reserved, CHECK_OK); 1867 &is_strict_reserved, CHECK_OK);
1862 FunctionLiteral* fun = ParseFunctionLiteral(name, 1868 FunctionLiteral* fun = ParseFunctionLiteral(name,
1863 scanner()->location(), 1869 scanner()->location(),
1864 is_strict_reserved, 1870 is_strict_reserved,
1865 is_generator, 1871 is_generator,
1866 pos, 1872 pos,
1867 FunctionLiteral::DECLARATION, 1873 FunctionLiteral::DECLARATION,
1868 CHECK_OK); 1874 CHECK_OK);
1869 // Even if we're not at the top-level of the global or a function 1875 // Even if we're not at the top-level of the global or a function
1870 // scope, we treat it as such and introduce the function with its 1876 // scope, we treat it as such and introduce the function with its
1871 // initial value upon entering the corresponding scope. 1877 // initial value upon entering the corresponding scope.
1872 // In extended mode, a function behaves as a lexical binding, except in the 1878 // In extended mode, a function behaves as a lexical binding, except in the
1873 // global scope. 1879 // global scope.
1874 VariableMode mode = 1880 VariableMode mode =
1875 allow_harmony_scoping() && 1881 allow_harmony_scoping() &&
1876 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR; 1882 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR;
1877 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); 1883 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
1878 Declaration* declaration = 1884 Declaration* declaration =
1879 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 1885 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
1880 Declare(declaration, true, CHECK_OK); 1886 Declare(declaration, true, CHECK_OK);
1881 if (names) names->Add(name, zone()); 1887 if (names) names->Add(name, zone());
1882 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1888 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1883 } 1889 }
1884 1890
1885 1891
1886 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1892 Block* Parser::ParseBlock(ZoneList<const AstString*>* labels, bool* ok) {
1887 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1893 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1888 return ParseScopedBlock(labels, ok); 1894 return ParseScopedBlock(labels, ok);
1889 } 1895 }
1890 1896
1891 // Block :: 1897 // Block ::
1892 // '{' Statement* '}' 1898 // '{' Statement* '}'
1893 1899
1894 // Note that a Block does not introduce a new execution scope! 1900 // Note that a Block does not introduce a new execution scope!
1895 // (ECMA-262, 3rd, 12.2) 1901 // (ECMA-262, 3rd, 12.2)
1896 // 1902 //
1897 // Construct block expecting 16 statements. 1903 // Construct block expecting 16 statements.
1898 Block* result = 1904 Block* result =
1899 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1905 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1900 Target target(&this->target_stack_, result); 1906 Target target(&this->target_stack_, result);
1901 Expect(Token::LBRACE, CHECK_OK); 1907 Expect(Token::LBRACE, CHECK_OK);
1902 while (peek() != Token::RBRACE) { 1908 while (peek() != Token::RBRACE) {
1903 Statement* stat = ParseStatement(NULL, CHECK_OK); 1909 Statement* stat = ParseStatement(NULL, CHECK_OK);
1904 if (stat && !stat->IsEmpty()) { 1910 if (stat && !stat->IsEmpty()) {
1905 result->AddStatement(stat, zone()); 1911 result->AddStatement(stat, zone());
1906 } 1912 }
1907 } 1913 }
1908 Expect(Token::RBRACE, CHECK_OK); 1914 Expect(Token::RBRACE, CHECK_OK);
1909 return result; 1915 return result;
1910 } 1916 }
1911 1917
1912 1918
1913 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 1919 Block* Parser::ParseScopedBlock(ZoneList<const AstString*>* labels, bool* ok) {
1914 // The harmony mode uses block elements instead of statements. 1920 // The harmony mode uses block elements instead of statements.
1915 // 1921 //
1916 // Block :: 1922 // Block ::
1917 // '{' BlockElement* '}' 1923 // '{' BlockElement* '}'
1918 1924
1919 // Construct block expecting 16 statements. 1925 // Construct block expecting 16 statements.
1920 Block* body = 1926 Block* body =
1921 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1927 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1922 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 1928 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
1923 1929
(...skipping 14 matching lines...) Expand all
1938 } 1944 }
1939 Expect(Token::RBRACE, CHECK_OK); 1945 Expect(Token::RBRACE, CHECK_OK);
1940 block_scope->set_end_position(scanner()->location().end_pos); 1946 block_scope->set_end_position(scanner()->location().end_pos);
1941 block_scope = block_scope->FinalizeBlockScope(); 1947 block_scope = block_scope->FinalizeBlockScope();
1942 body->set_scope(block_scope); 1948 body->set_scope(block_scope);
1943 return body; 1949 return body;
1944 } 1950 }
1945 1951
1946 1952
1947 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, 1953 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context,
1948 ZoneStringList* names, 1954 ZoneList<const AstString*>* names,
1949 bool* ok) { 1955 bool* ok) {
1950 // VariableStatement :: 1956 // VariableStatement ::
1951 // VariableDeclarations ';' 1957 // VariableDeclarations ';'
1952 1958
1953 Handle<String> ignore; 1959 const AstString* ignore;
1954 Block* result = 1960 Block* result =
1955 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK); 1961 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK);
1956 ExpectSemicolon(CHECK_OK); 1962 ExpectSemicolon(CHECK_OK);
1957 return result; 1963 return result;
1958 } 1964 }
1959 1965
1960 1966
1961 // If the variable declaration declares exactly one non-const 1967 // If the variable declaration declares exactly one non-const
1962 // variable, then *out is set to that variable. In all other cases, 1968 // variable, then *out is set to that variable. In all other cases,
1963 // *out is untouched; in particular, it is the caller's responsibility 1969 // *out is untouched; in particular, it is the caller's responsibility
1964 // to initialize it properly. This mechanism is used for the parsing 1970 // to initialize it properly. This mechanism is used for the parsing
1965 // of 'for-in' loops. 1971 // of 'for-in' loops.
1966 Block* Parser::ParseVariableDeclarations( 1972 Block* Parser::ParseVariableDeclarations(
1967 VariableDeclarationContext var_context, 1973 VariableDeclarationContext var_context,
1968 VariableDeclarationProperties* decl_props, 1974 VariableDeclarationProperties* decl_props,
1969 ZoneStringList* names, 1975 ZoneList<const AstString*>* names,
1970 Handle<String>* out, 1976 const AstString** out,
1971 bool* ok) { 1977 bool* ok) {
1972 // VariableDeclarations :: 1978 // VariableDeclarations ::
1973 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] 1979 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
1974 // 1980 //
1975 // The ES6 Draft Rev3 specifies the following grammar for const declarations 1981 // The ES6 Draft Rev3 specifies the following grammar for const declarations
1976 // 1982 //
1977 // ConstDeclaration :: 1983 // ConstDeclaration ::
1978 // const ConstBinding (',' ConstBinding)* ';' 1984 // const ConstBinding (',' ConstBinding)* ';'
1979 // ConstBinding :: 1985 // ConstBinding ::
1980 // Identifier '=' AssignmentExpression 1986 // Identifier '=' AssignmentExpression
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 // 2074 //
2069 // We mark the block as initializer block because we don't want the 2075 // We mark the block as initializer block because we don't want the
2070 // rewriter to add a '.result' assignment to such a block (to get compliant 2076 // rewriter to add a '.result' assignment to such a block (to get compliant
2071 // behavior for code such as print(eval('var x = 7')), and for cosmetic 2077 // behavior for code such as print(eval('var x = 7')), and for cosmetic
2072 // reasons when pretty-printing. Also, unless an assignment (initialization) 2078 // reasons when pretty-printing. Also, unless an assignment (initialization)
2073 // is inside an initializer block, it is ignored. 2079 // is inside an initializer block, it is ignored.
2074 // 2080 //
2075 // Create new block with one expected declaration. 2081 // Create new block with one expected declaration.
2076 Block* block = factory()->NewBlock(NULL, 1, true, pos); 2082 Block* block = factory()->NewBlock(NULL, 1, true, pos);
2077 int nvars = 0; // the number of variables declared 2083 int nvars = 0; // the number of variables declared
2078 Handle<String> name; 2084 const AstString* name = NULL;
2079 do { 2085 do {
2080 if (fni_ != NULL) fni_->Enter(); 2086 if (fni_ != NULL) fni_->Enter();
2081 2087
2082 // Parse variable name. 2088 // Parse variable name.
2083 if (nvars > 0) Consume(Token::COMMA); 2089 if (nvars > 0) Consume(Token::COMMA);
2084 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2090 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2085 if (fni_ != NULL) fni_->PushVariableName(name); 2091 if (fni_ != NULL) fni_->PushVariableName(name);
2086 2092
2087 // Declare variable. 2093 // Declare variable.
2088 // Note that we *always* must treat the initial value via a separate init 2094 // Note that we *always* must treat the initial value via a separate init
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 // properties in the prototype chain, but only after the variable 2193 // properties in the prototype chain, but only after the variable
2188 // declaration statement has been executed. This is important in 2194 // declaration statement has been executed. This is important in
2189 // browsers where the global object (window) has lots of 2195 // browsers where the global object (window) has lots of
2190 // properties defined in prototype objects. 2196 // properties defined in prototype objects.
2191 if (initialization_scope->is_global_scope() && 2197 if (initialization_scope->is_global_scope() &&
2192 !IsLexicalVariableMode(mode)) { 2198 !IsLexicalVariableMode(mode)) {
2193 // Compute the arguments for the runtime call. 2199 // Compute the arguments for the runtime call.
2194 ZoneList<Expression*>* arguments = 2200 ZoneList<Expression*>* arguments =
2195 new(zone()) ZoneList<Expression*>(3, zone()); 2201 new(zone()) ZoneList<Expression*>(3, zone());
2196 // We have at least 1 parameter. 2202 // We have at least 1 parameter.
2197 arguments->Add(factory()->NewLiteral(name, pos), zone()); 2203 arguments->Add(factory()->NewStringLiteral(name, pos), zone());
2198 CallRuntime* initialize; 2204 CallRuntime* initialize;
2199 2205
2200 if (is_const) { 2206 if (is_const) {
2201 arguments->Add(value, zone()); 2207 arguments->Add(value, zone());
2202 value = NULL; // zap the value to avoid the unnecessary assignment 2208 value = NULL; // zap the value to avoid the unnecessary assignment
2203 2209
2204 // Construct the call to Runtime_InitializeConstGlobal 2210 // Construct the call to Runtime_InitializeConstGlobal
2205 // and add it to the initialization statement block. 2211 // and add it to the initialization statement block.
2206 // Note that the function does different things depending on 2212 // Note that the function does different things depending on
2207 // the number of arguments (1 or 2). 2213 // the number of arguments (1 or 2).
2208 initialize = factory()->NewCallRuntime( 2214 initialize = factory()->NewCallRuntime(
2209 isolate()->factory()->InitializeConstGlobal_string(), 2215 ast_value_factory_->initialize_const_global_string(),
2210 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal), 2216 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal),
2211 arguments, pos); 2217 arguments, pos);
2212 } else { 2218 } else {
2213 // Add strict mode. 2219 // Add strict mode.
2214 // We may want to pass singleton to avoid Literal allocations. 2220 // We may want to pass singleton to avoid Literal allocations.
2215 StrictMode strict_mode = initialization_scope->strict_mode(); 2221 StrictMode strict_mode = initialization_scope->strict_mode();
2216 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); 2222 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone());
2217 2223
2218 // Be careful not to assign a value to the global variable if 2224 // Be careful not to assign a value to the global variable if
2219 // we're in a with. The initialization value should not 2225 // we're in a with. The initialization value should not
2220 // necessarily be stored in the global object in that case, 2226 // necessarily be stored in the global object in that case,
2221 // which is why we need to generate a separate assignment node. 2227 // which is why we need to generate a separate assignment node.
2222 if (value != NULL && !inside_with()) { 2228 if (value != NULL && !inside_with()) {
2223 arguments->Add(value, zone()); 2229 arguments->Add(value, zone());
2224 value = NULL; // zap the value to avoid the unnecessary assignment 2230 value = NULL; // zap the value to avoid the unnecessary assignment
2225 } 2231 }
2226 2232
2227 // Construct the call to Runtime_InitializeVarGlobal 2233 // Construct the call to Runtime_InitializeVarGlobal
2228 // and add it to the initialization statement block. 2234 // and add it to the initialization statement block.
2229 // Note that the function does different things depending on 2235 // Note that the function does different things depending on
2230 // the number of arguments (2 or 3). 2236 // the number of arguments (2 or 3).
2231 initialize = factory()->NewCallRuntime( 2237 initialize = factory()->NewCallRuntime(
2232 isolate()->factory()->InitializeVarGlobal_string(), 2238 ast_value_factory_->initialize_var_global_string(),
2233 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 2239 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
2234 arguments, pos); 2240 arguments, pos);
2235 } 2241 }
2236 2242
2237 block->AddStatement( 2243 block->AddStatement(
2238 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), 2244 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition),
2239 zone()); 2245 zone());
2240 } else if (needs_init) { 2246 } else if (needs_init) {
2241 // Constant initializations always assign to the declared constant which 2247 // Constant initializations always assign to the declared constant which
2242 // is always at the function scope level. This is only relevant for 2248 // is always at the function scope level. This is only relevant for
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 // If there was a single non-const declaration, return it in the output 2284 // If there was a single non-const declaration, return it in the output
2279 // parameter for possible use by for/in. 2285 // parameter for possible use by for/in.
2280 if (nvars == 1 && !is_const) { 2286 if (nvars == 1 && !is_const) {
2281 *out = name; 2287 *out = name;
2282 } 2288 }
2283 2289
2284 return block; 2290 return block;
2285 } 2291 }
2286 2292
2287 2293
2288 static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) { 2294 static bool ContainsLabel(ZoneList<const AstString*>* labels,
2289 ASSERT(!label.is_null()); 2295 const AstString* label) {
2296 ASSERT(label != NULL);
2290 if (labels != NULL) { 2297 if (labels != NULL) {
2291 for (int i = labels->length(); i-- > 0; ) { 2298 for (int i = labels->length(); i-- > 0; ) {
2292 if (labels->at(i).is_identical_to(label)) { 2299 if (labels->at(i) == label) {
2293 return true; 2300 return true;
2294 } 2301 }
2295 } 2302 }
2296 } 2303 }
2297 return false; 2304 return false;
2298 } 2305 }
2299 2306
2300 2307
2301 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 2308 Statement* Parser::ParseExpressionOrLabelledStatement(
2302 bool* ok) { 2309 ZoneList<const AstString*>* labels, bool* ok) {
2303 // ExpressionStatement | LabelledStatement :: 2310 // ExpressionStatement | LabelledStatement ::
2304 // Expression ';' 2311 // Expression ';'
2305 // Identifier ':' Statement 2312 // Identifier ':' Statement
2306 int pos = peek_position(); 2313 int pos = peek_position();
2307 bool starts_with_idenfifier = peek_any_identifier(); 2314 bool starts_with_idenfifier = peek_any_identifier();
2308 Expression* expr = ParseExpression(true, CHECK_OK); 2315 Expression* expr = ParseExpression(true, CHECK_OK);
2309 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && 2316 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
2310 expr->AsVariableProxy() != NULL && 2317 expr->AsVariableProxy() != NULL &&
2311 !expr->AsVariableProxy()->is_this()) { 2318 !expr->AsVariableProxy()->is_this()) {
2312 // Expression is a single identifier, and not, e.g., a parenthesized 2319 // Expression is a single identifier, and not, e.g., a parenthesized
2313 // identifier. 2320 // identifier.
2314 VariableProxy* var = expr->AsVariableProxy(); 2321 VariableProxy* var = expr->AsVariableProxy();
2315 Handle<String> label = var->name(); 2322 const AstString* label = var->raw_name();
2316 // TODO(1240780): We don't check for redeclaration of labels 2323 // TODO(1240780): We don't check for redeclaration of labels
2317 // during preparsing since keeping track of the set of active 2324 // during preparsing since keeping track of the set of active
2318 // labels requires nontrivial changes to the way scopes are 2325 // labels requires nontrivial changes to the way scopes are
2319 // structured. However, these are probably changes we want to 2326 // structured. However, these are probably changes we want to
2320 // make later anyway so we should go back and fix this then. 2327 // make later anyway so we should go back and fix this then.
2321 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2328 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
2322 ParserTraits::ReportMessage("label_redeclaration", label); 2329 ParserTraits::ReportMessage("label_redeclaration", label);
2323 *ok = false; 2330 *ok = false;
2324 return NULL; 2331 return NULL;
2325 } 2332 }
2326 if (labels == NULL) { 2333 if (labels == NULL) {
2327 labels = new(zone()) ZoneStringList(4, zone()); 2334 labels = new(zone()) ZoneList<const AstString*>(4, zone());
2328 } 2335 }
2329 labels->Add(label, zone()); 2336 labels->Add(label, zone());
2330 // Remove the "ghost" variable that turned out to be a label 2337 // Remove the "ghost" variable that turned out to be a label
2331 // from the top scope. This way, we don't try to resolve it 2338 // from the top scope. This way, we don't try to resolve it
2332 // during the scope processing. 2339 // during the scope processing.
2333 scope_->RemoveUnresolved(var); 2340 scope_->RemoveUnresolved(var);
2334 Expect(Token::COLON, CHECK_OK); 2341 Expect(Token::COLON, CHECK_OK);
2335 return ParseStatement(labels, ok); 2342 return ParseStatement(labels, ok);
2336 } 2343 }
2337 2344
2338 // If we have an extension, we allow a native function declaration. 2345 // If we have an extension, we allow a native function declaration.
2339 // A native function declaration starts with "native function" with 2346 // A native function declaration starts with "native function" with
2340 // no line-terminator between the two words. 2347 // no line-terminator between the two words.
2341 if (extension_ != NULL && 2348 if (extension_ != NULL &&
2342 peek() == Token::FUNCTION && 2349 peek() == Token::FUNCTION &&
2343 !scanner()->HasAnyLineTerminatorBeforeNext() && 2350 !scanner()->HasAnyLineTerminatorBeforeNext() &&
2344 expr != NULL && 2351 expr != NULL &&
2345 expr->AsVariableProxy() != NULL && 2352 expr->AsVariableProxy() != NULL &&
2346 String::Equals(isolate()->factory()->native_string(), 2353 expr->AsVariableProxy()->raw_name() ==
2347 expr->AsVariableProxy()->name()) && 2354 ast_value_factory_->native_string() &&
2348 !scanner()->literal_contains_escapes()) { 2355 !scanner()->literal_contains_escapes()) {
2349 return ParseNativeDeclaration(ok); 2356 return ParseNativeDeclaration(ok);
2350 } 2357 }
2351 2358
2352 // Parsed expression statement, or the context-sensitive 'module' keyword. 2359 // Parsed expression statement, or the context-sensitive 'module' keyword.
2353 // Only expect semicolon in the former case. 2360 // Only expect semicolon in the former case.
2354 if (!FLAG_harmony_modules || 2361 if (!FLAG_harmony_modules ||
2355 peek() != Token::IDENTIFIER || 2362 peek() != Token::IDENTIFIER ||
2356 scanner()->HasAnyLineTerminatorBeforeNext() || 2363 scanner()->HasAnyLineTerminatorBeforeNext() ||
2357 expr->AsVariableProxy() == NULL || 2364 expr->AsVariableProxy() == NULL ||
2358 !String::Equals(isolate()->factory()->module_string(), 2365 expr->AsVariableProxy()->raw_name() !=
2359 expr->AsVariableProxy()->name()) || 2366 ast_value_factory_->module_string() ||
2360 scanner()->literal_contains_escapes()) { 2367 scanner()->literal_contains_escapes()) {
2361 ExpectSemicolon(CHECK_OK); 2368 ExpectSemicolon(CHECK_OK);
2362 } 2369 }
2363 return factory()->NewExpressionStatement(expr, pos); 2370 return factory()->NewExpressionStatement(expr, pos);
2364 } 2371 }
2365 2372
2366 2373
2367 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 2374 IfStatement* Parser::ParseIfStatement(ZoneList<const AstString*>* labels,
2375 bool* ok) {
2368 // IfStatement :: 2376 // IfStatement ::
2369 // 'if' '(' Expression ')' Statement ('else' Statement)? 2377 // 'if' '(' Expression ')' Statement ('else' Statement)?
2370 2378
2371 int pos = peek_position(); 2379 int pos = peek_position();
2372 Expect(Token::IF, CHECK_OK); 2380 Expect(Token::IF, CHECK_OK);
2373 Expect(Token::LPAREN, CHECK_OK); 2381 Expect(Token::LPAREN, CHECK_OK);
2374 Expression* condition = ParseExpression(true, CHECK_OK); 2382 Expression* condition = ParseExpression(true, CHECK_OK);
2375 Expect(Token::RPAREN, CHECK_OK); 2383 Expect(Token::RPAREN, CHECK_OK);
2376 Statement* then_statement = ParseStatement(labels, CHECK_OK); 2384 Statement* then_statement = ParseStatement(labels, CHECK_OK);
2377 Statement* else_statement = NULL; 2385 Statement* else_statement = NULL;
2378 if (peek() == Token::ELSE) { 2386 if (peek() == Token::ELSE) {
2379 Next(); 2387 Next();
2380 else_statement = ParseStatement(labels, CHECK_OK); 2388 else_statement = ParseStatement(labels, CHECK_OK);
2381 } else { 2389 } else {
2382 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2390 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2383 } 2391 }
2384 return factory()->NewIfStatement( 2392 return factory()->NewIfStatement(
2385 condition, then_statement, else_statement, pos); 2393 condition, then_statement, else_statement, pos);
2386 } 2394 }
2387 2395
2388 2396
2389 Statement* Parser::ParseContinueStatement(bool* ok) { 2397 Statement* Parser::ParseContinueStatement(bool* ok) {
2390 // ContinueStatement :: 2398 // ContinueStatement ::
2391 // 'continue' Identifier? ';' 2399 // 'continue' Identifier? ';'
2392 2400
2393 int pos = peek_position(); 2401 int pos = peek_position();
2394 Expect(Token::CONTINUE, CHECK_OK); 2402 Expect(Token::CONTINUE, CHECK_OK);
2395 Handle<String> label = Handle<String>::null(); 2403 const AstString* label = NULL;
2396 Token::Value tok = peek(); 2404 Token::Value tok = peek();
2397 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2405 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2398 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2406 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2399 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2407 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2400 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2408 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2401 } 2409 }
2402 IterationStatement* target = NULL; 2410 IterationStatement* target = LookupContinueTarget(label, CHECK_OK);
2403 target = LookupContinueTarget(label, CHECK_OK);
2404 if (target == NULL) { 2411 if (target == NULL) {
2405 // Illegal continue statement. 2412 // Illegal continue statement.
2406 const char* message = "illegal_continue"; 2413 const char* message = "illegal_continue";
2407 if (!label.is_null()) { 2414 if (label != NULL) {
2408 message = "unknown_label"; 2415 message = "unknown_label";
2409 } 2416 }
2410 ParserTraits::ReportMessage(message, label); 2417 ParserTraits::ReportMessage(message, label);
2411 *ok = false; 2418 *ok = false;
2412 return NULL; 2419 return NULL;
2413 } 2420 }
2414 ExpectSemicolon(CHECK_OK); 2421 ExpectSemicolon(CHECK_OK);
2415 return factory()->NewContinueStatement(target, pos); 2422 return factory()->NewContinueStatement(target, pos);
2416 } 2423 }
2417 2424
2418 2425
2419 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 2426 Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels,
2427 bool* ok) {
2420 // BreakStatement :: 2428 // BreakStatement ::
2421 // 'break' Identifier? ';' 2429 // 'break' Identifier? ';'
2422 2430
2423 int pos = peek_position(); 2431 int pos = peek_position();
2424 Expect(Token::BREAK, CHECK_OK); 2432 Expect(Token::BREAK, CHECK_OK);
2425 Handle<String> label; 2433 const AstString* label = NULL;
2426 Token::Value tok = peek(); 2434 Token::Value tok = peek();
2427 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2435 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2428 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2436 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2429 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2437 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2430 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2438 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2431 } 2439 }
2432 // Parse labeled break statements that target themselves into 2440 // Parse labeled break statements that target themselves into
2433 // empty statements, e.g. 'l1: l2: l3: break l2;' 2441 // empty statements, e.g. 'l1: l2: l3: break l2;'
2434 if (!label.is_null() && ContainsLabel(labels, label)) { 2442 if (label != NULL && ContainsLabel(labels, label)) {
2435 ExpectSemicolon(CHECK_OK); 2443 ExpectSemicolon(CHECK_OK);
2436 return factory()->NewEmptyStatement(pos); 2444 return factory()->NewEmptyStatement(pos);
2437 } 2445 }
2438 BreakableStatement* target = NULL; 2446 BreakableStatement* target = NULL;
2439 target = LookupBreakTarget(label, CHECK_OK); 2447 target = LookupBreakTarget(label, CHECK_OK);
2440 if (target == NULL) { 2448 if (target == NULL) {
2441 // Illegal break statement. 2449 // Illegal break statement.
2442 const char* message = "illegal_break"; 2450 const char* message = "illegal_break";
2443 if (!label.is_null()) { 2451 if (label != NULL) {
2444 message = "unknown_label"; 2452 message = "unknown_label";
2445 } 2453 }
2446 ParserTraits::ReportMessage(message, label); 2454 ParserTraits::ReportMessage(message, label);
2447 *ok = false; 2455 *ok = false;
2448 return NULL; 2456 return NULL;
2449 } 2457 }
2450 ExpectSemicolon(CHECK_OK); 2458 ExpectSemicolon(CHECK_OK);
2451 return factory()->NewBreakStatement(target, pos); 2459 return factory()->NewBreakStatement(target, pos);
2452 } 2460 }
2453 2461
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 Scope* decl_scope = scope_->DeclarationScope(); 2495 Scope* decl_scope = scope_->DeclarationScope();
2488 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) { 2496 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) {
2489 ReportMessageAt(loc, "illegal_return"); 2497 ReportMessageAt(loc, "illegal_return");
2490 *ok = false; 2498 *ok = false;
2491 return NULL; 2499 return NULL;
2492 } 2500 }
2493 return result; 2501 return result;
2494 } 2502 }
2495 2503
2496 2504
2497 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2505 Statement* Parser::ParseWithStatement(ZoneList<const AstString*>* labels,
2506 bool* ok) {
2498 // WithStatement :: 2507 // WithStatement ::
2499 // 'with' '(' Expression ')' Statement 2508 // 'with' '(' Expression ')' Statement
2500 2509
2501 Expect(Token::WITH, CHECK_OK); 2510 Expect(Token::WITH, CHECK_OK);
2502 int pos = position(); 2511 int pos = position();
2503 2512
2504 if (strict_mode() == STRICT) { 2513 if (strict_mode() == STRICT) {
2505 ReportMessage("strict_mode_with"); 2514 ReportMessage("strict_mode_with");
2506 *ok = false; 2515 *ok = false;
2507 return NULL; 2516 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 peek() != Token::DEFAULT && 2558 peek() != Token::DEFAULT &&
2550 peek() != Token::RBRACE) { 2559 peek() != Token::RBRACE) {
2551 Statement* stat = ParseStatement(NULL, CHECK_OK); 2560 Statement* stat = ParseStatement(NULL, CHECK_OK);
2552 statements->Add(stat, zone()); 2561 statements->Add(stat, zone());
2553 } 2562 }
2554 2563
2555 return factory()->NewCaseClause(label, statements, pos); 2564 return factory()->NewCaseClause(label, statements, pos);
2556 } 2565 }
2557 2566
2558 2567
2559 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 2568 SwitchStatement* Parser::ParseSwitchStatement(
2560 bool* ok) { 2569 ZoneList<const AstString*>* labels, bool* ok) {
2561 // SwitchStatement :: 2570 // SwitchStatement ::
2562 // 'switch' '(' Expression ')' '{' CaseClause* '}' 2571 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2563 2572
2564 SwitchStatement* statement = 2573 SwitchStatement* statement =
2565 factory()->NewSwitchStatement(labels, peek_position()); 2574 factory()->NewSwitchStatement(labels, peek_position());
2566 Target target(&this->target_stack_, statement); 2575 Target target(&this->target_stack_, statement);
2567 2576
2568 Expect(Token::SWITCH, CHECK_OK); 2577 Expect(Token::SWITCH, CHECK_OK);
2569 Expect(Token::LPAREN, CHECK_OK); 2578 Expect(Token::LPAREN, CHECK_OK);
2570 Expression* tag = ParseExpression(true, CHECK_OK); 2579 Expression* tag = ParseExpression(true, CHECK_OK);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 } 2642 }
2634 2643
2635 // If we can break out from the catch block and there is a finally block, 2644 // If we can break out from the catch block and there is a finally block,
2636 // then we will need to collect escaping targets from the catch 2645 // then we will need to collect escaping targets from the catch
2637 // block. Since we don't know yet if there will be a finally block, we 2646 // block. Since we don't know yet if there will be a finally block, we
2638 // always collect the targets. 2647 // always collect the targets.
2639 TargetCollector catch_collector(zone()); 2648 TargetCollector catch_collector(zone());
2640 Scope* catch_scope = NULL; 2649 Scope* catch_scope = NULL;
2641 Variable* catch_variable = NULL; 2650 Variable* catch_variable = NULL;
2642 Block* catch_block = NULL; 2651 Block* catch_block = NULL;
2643 Handle<String> name; 2652 const AstString* name = NULL;
2644 if (tok == Token::CATCH) { 2653 if (tok == Token::CATCH) {
2645 Consume(Token::CATCH); 2654 Consume(Token::CATCH);
2646 2655
2647 Expect(Token::LPAREN, CHECK_OK); 2656 Expect(Token::LPAREN, CHECK_OK);
2648 catch_scope = NewScope(scope_, CATCH_SCOPE); 2657 catch_scope = NewScope(scope_, CATCH_SCOPE);
2649 catch_scope->set_start_position(scanner()->location().beg_pos); 2658 catch_scope->set_start_position(scanner()->location().beg_pos);
2650 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2659 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2651 2660
2652 Expect(Token::RPAREN, CHECK_OK); 2661 Expect(Token::RPAREN, CHECK_OK);
2653 2662
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2703 index, try_block, finally_block, pos); 2712 index, try_block, finally_block, pos);
2704 // Combine the jump targets of the try block and the possible catch block. 2713 // Combine the jump targets of the try block and the possible catch block.
2705 try_collector.targets()->AddAll(*catch_collector.targets(), zone()); 2714 try_collector.targets()->AddAll(*catch_collector.targets(), zone());
2706 } 2715 }
2707 2716
2708 result->set_escaping_targets(try_collector.targets()); 2717 result->set_escaping_targets(try_collector.targets());
2709 return result; 2718 return result;
2710 } 2719 }
2711 2720
2712 2721
2713 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2722 DoWhileStatement* Parser::ParseDoWhileStatement(
2714 bool* ok) { 2723 ZoneList<const AstString*>* labels, bool* ok) {
2715 // DoStatement :: 2724 // DoStatement ::
2716 // 'do' Statement 'while' '(' Expression ')' ';' 2725 // 'do' Statement 'while' '(' Expression ')' ';'
2717 2726
2718 DoWhileStatement* loop = 2727 DoWhileStatement* loop =
2719 factory()->NewDoWhileStatement(labels, peek_position()); 2728 factory()->NewDoWhileStatement(labels, peek_position());
2720 Target target(&this->target_stack_, loop); 2729 Target target(&this->target_stack_, loop);
2721 2730
2722 Expect(Token::DO, CHECK_OK); 2731 Expect(Token::DO, CHECK_OK);
2723 Statement* body = ParseStatement(NULL, CHECK_OK); 2732 Statement* body = ParseStatement(NULL, CHECK_OK);
2724 Expect(Token::WHILE, CHECK_OK); 2733 Expect(Token::WHILE, CHECK_OK);
2725 Expect(Token::LPAREN, CHECK_OK); 2734 Expect(Token::LPAREN, CHECK_OK);
2726 2735
2727 Expression* cond = ParseExpression(true, CHECK_OK); 2736 Expression* cond = ParseExpression(true, CHECK_OK);
2728 Expect(Token::RPAREN, CHECK_OK); 2737 Expect(Token::RPAREN, CHECK_OK);
2729 2738
2730 // Allow do-statements to be terminated with and without 2739 // Allow do-statements to be terminated with and without
2731 // semi-colons. This allows code such as 'do;while(0)return' to 2740 // semi-colons. This allows code such as 'do;while(0)return' to
2732 // parse, which would not be the case if we had used the 2741 // parse, which would not be the case if we had used the
2733 // ExpectSemicolon() functionality here. 2742 // ExpectSemicolon() functionality here.
2734 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); 2743 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
2735 2744
2736 if (loop != NULL) loop->Initialize(cond, body); 2745 if (loop != NULL) loop->Initialize(cond, body);
2737 return loop; 2746 return loop;
2738 } 2747 }
2739 2748
2740 2749
2741 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2750 WhileStatement* Parser::ParseWhileStatement(ZoneList<const AstString*>* labels,
2751 bool* ok) {
2742 // WhileStatement :: 2752 // WhileStatement ::
2743 // 'while' '(' Expression ')' Statement 2753 // 'while' '(' Expression ')' Statement
2744 2754
2745 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position()); 2755 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position());
2746 Target target(&this->target_stack_, loop); 2756 Target target(&this->target_stack_, loop);
2747 2757
2748 Expect(Token::WHILE, CHECK_OK); 2758 Expect(Token::WHILE, CHECK_OK);
2749 Expect(Token::LPAREN, CHECK_OK); 2759 Expect(Token::LPAREN, CHECK_OK);
2750 Expression* cond = ParseExpression(true, CHECK_OK); 2760 Expression* cond = ParseExpression(true, CHECK_OK);
2751 Expect(Token::RPAREN, CHECK_OK); 2761 Expect(Token::RPAREN, CHECK_OK);
(...skipping 18 matching lines...) Expand all
2770 } 2780 }
2771 2781
2772 2782
2773 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2783 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2774 Expression* each, 2784 Expression* each,
2775 Expression* subject, 2785 Expression* subject,
2776 Statement* body) { 2786 Statement* body) {
2777 ForOfStatement* for_of = stmt->AsForOfStatement(); 2787 ForOfStatement* for_of = stmt->AsForOfStatement();
2778 2788
2779 if (for_of != NULL) { 2789 if (for_of != NULL) {
2780 Factory* heap_factory = isolate()->factory();
2781 Variable* iterable = scope_->DeclarationScope()->NewTemporary( 2790 Variable* iterable = scope_->DeclarationScope()->NewTemporary(
2782 heap_factory->dot_iterable_string()); 2791 ast_value_factory_->dot_iterable_string());
2783 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2792 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2784 heap_factory->dot_iterator_string()); 2793 ast_value_factory_->dot_iterator_string());
2785 Variable* result = scope_->DeclarationScope()->NewTemporary( 2794 Variable* result = scope_->DeclarationScope()->NewTemporary(
2786 heap_factory->dot_result_string()); 2795 ast_value_factory_->dot_result_string());
2787 2796
2788 Expression* assign_iterable; 2797 Expression* assign_iterable;
2789 Expression* assign_iterator; 2798 Expression* assign_iterator;
2790 Expression* next_result; 2799 Expression* next_result;
2791 Expression* result_done; 2800 Expression* result_done;
2792 Expression* assign_each; 2801 Expression* assign_each;
2793 2802
2794 // var iterable = subject; 2803 // var iterable = subject;
2795 { 2804 {
2796 Expression* iterable_proxy = factory()->NewVariableProxy(iterable); 2805 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2797 assign_iterable = factory()->NewAssignment( 2806 assign_iterable = factory()->NewAssignment(
2798 Token::ASSIGN, iterable_proxy, subject, subject->position()); 2807 Token::ASSIGN, iterable_proxy, subject, subject->position());
2799 } 2808 }
2800 2809
2801 // var iterator = iterable[Symbol.iterator](); 2810 // var iterator = iterable[Symbol.iterator]();
2802 { 2811 {
2803 Expression* iterable_proxy = factory()->NewVariableProxy(iterable); 2812 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2804 Handle<Symbol> iterator_symbol( 2813 Expression* iterator_symbol_literal =
2805 isolate()->native_context()->iterator_symbol(), isolate()); 2814 factory()->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition);
2806 Expression* iterator_symbol_literal = factory()->NewLiteral(
2807 iterator_symbol, RelocInfo::kNoPosition);
2808 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a 2815 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a
2809 // for-of doesn't have a Symbol.iterator property. We should do better 2816 // for-of doesn't have a Symbol.iterator property. We should do better
2810 // than informing the user that "undefined is not a function". 2817 // than informing the user that "undefined is not a function".
2811 int pos = subject->position(); 2818 int pos = subject->position();
2812 Expression* iterator_property = factory()->NewProperty( 2819 Expression* iterator_property = factory()->NewProperty(
2813 iterable_proxy, iterator_symbol_literal, pos); 2820 iterable_proxy, iterator_symbol_literal, pos);
2814 ZoneList<Expression*>* iterator_arguments = 2821 ZoneList<Expression*>* iterator_arguments =
2815 new(zone()) ZoneList<Expression*>(0, zone()); 2822 new(zone()) ZoneList<Expression*>(0, zone());
2816 Expression* iterator_call = factory()->NewCall( 2823 Expression* iterator_call = factory()->NewCall(
2817 iterator_property, iterator_arguments, pos); 2824 iterator_property, iterator_arguments, pos);
2818 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2825 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2819 assign_iterator = factory()->NewAssignment( 2826 assign_iterator = factory()->NewAssignment(
2820 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition); 2827 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition);
2821 } 2828 }
2822 2829
2823 // var result = iterator.next(); 2830 // var result = iterator.next();
2824 { 2831 {
2825 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2832 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2826 Expression* next_literal = factory()->NewLiteral( 2833 Expression* next_literal = factory()->NewStringLiteral(
2827 heap_factory->next_string(), RelocInfo::kNoPosition); 2834 ast_value_factory_->next_string(), RelocInfo::kNoPosition);
2828 Expression* next_property = factory()->NewProperty( 2835 Expression* next_property = factory()->NewProperty(
2829 iterator_proxy, next_literal, RelocInfo::kNoPosition); 2836 iterator_proxy, next_literal, RelocInfo::kNoPosition);
2830 ZoneList<Expression*>* next_arguments = 2837 ZoneList<Expression*>* next_arguments =
2831 new(zone()) ZoneList<Expression*>(0, zone()); 2838 new(zone()) ZoneList<Expression*>(0, zone());
2832 Expression* next_call = factory()->NewCall( 2839 Expression* next_call = factory()->NewCall(
2833 next_property, next_arguments, RelocInfo::kNoPosition); 2840 next_property, next_arguments, RelocInfo::kNoPosition);
2834 Expression* result_proxy = factory()->NewVariableProxy(result); 2841 Expression* result_proxy = factory()->NewVariableProxy(result);
2835 next_result = factory()->NewAssignment( 2842 next_result = factory()->NewAssignment(
2836 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition); 2843 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition);
2837 } 2844 }
2838 2845
2839 // result.done 2846 // result.done
2840 { 2847 {
2841 Expression* done_literal = factory()->NewLiteral( 2848 Expression* done_literal = factory()->NewStringLiteral(
2842 heap_factory->done_string(), RelocInfo::kNoPosition); 2849 ast_value_factory_->done_string(), RelocInfo::kNoPosition);
2843 Expression* result_proxy = factory()->NewVariableProxy(result); 2850 Expression* result_proxy = factory()->NewVariableProxy(result);
2844 result_done = factory()->NewProperty( 2851 result_done = factory()->NewProperty(
2845 result_proxy, done_literal, RelocInfo::kNoPosition); 2852 result_proxy, done_literal, RelocInfo::kNoPosition);
2846 } 2853 }
2847 2854
2848 // each = result.value 2855 // each = result.value
2849 { 2856 {
2850 Expression* value_literal = factory()->NewLiteral( 2857 Expression* value_literal = factory()->NewStringLiteral(
2851 heap_factory->value_string(), RelocInfo::kNoPosition); 2858 ast_value_factory_->value_string(), RelocInfo::kNoPosition);
2852 Expression* result_proxy = factory()->NewVariableProxy(result); 2859 Expression* result_proxy = factory()->NewVariableProxy(result);
2853 Expression* result_value = factory()->NewProperty( 2860 Expression* result_value = factory()->NewProperty(
2854 result_proxy, value_literal, RelocInfo::kNoPosition); 2861 result_proxy, value_literal, RelocInfo::kNoPosition);
2855 assign_each = factory()->NewAssignment( 2862 assign_each = factory()->NewAssignment(
2856 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2863 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2857 } 2864 }
2858 2865
2859 for_of->Initialize(each, subject, body, 2866 for_of->Initialize(each, subject, body,
2860 assign_iterable, 2867 assign_iterable,
2861 assign_iterator, 2868 assign_iterator,
2862 next_result, 2869 next_result,
2863 result_done, 2870 result_done,
2864 assign_each); 2871 assign_each);
2865 } else { 2872 } else {
2866 stmt->Initialize(each, subject, body); 2873 stmt->Initialize(each, subject, body);
2867 } 2874 }
2868 } 2875 }
2869 2876
2870 2877
2871 Statement* Parser::DesugarLetBindingsInForStatement( 2878 Statement* Parser::DesugarLetBindingsInForStatement(
2872 Scope* inner_scope, ZoneStringList* names, ForStatement* loop, 2879 Scope* inner_scope, ZoneList<const AstString*>* names,
2873 Statement* init, Expression* cond, Statement* next, Statement* body, 2880 ForStatement* loop, Statement* init, Expression* cond, Statement* next,
2874 bool* ok) { 2881 Statement* body, bool* ok) {
2875 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are 2882 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are
2876 // copied into a new environment. After copying, the "next" statement of the 2883 // copied into a new environment. After copying, the "next" statement of the
2877 // loop is executed to update the loop variables. The loop condition is 2884 // loop is executed to update the loop variables. The loop condition is
2878 // checked and the loop body is executed. 2885 // checked and the loop body is executed.
2879 // 2886 //
2880 // We rewrite a for statement of the form 2887 // We rewrite a for statement of the form
2881 // 2888 //
2882 // for (let x = i; cond; next) body 2889 // for (let x = i; cond; next) body
2883 // 2890 //
2884 // into 2891 // into
(...skipping 20 matching lines...) Expand all
2905 // } 2912 // }
2906 2913
2907 ASSERT(names->length() > 0); 2914 ASSERT(names->length() > 0);
2908 Scope* for_scope = scope_; 2915 Scope* for_scope = scope_;
2909 ZoneList<Variable*> temps(names->length(), zone()); 2916 ZoneList<Variable*> temps(names->length(), zone());
2910 2917
2911 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, 2918 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false,
2912 RelocInfo::kNoPosition); 2919 RelocInfo::kNoPosition);
2913 outer_block->AddStatement(init, zone()); 2920 outer_block->AddStatement(init, zone());
2914 2921
2915 Handle<String> temp_name = isolate()->factory()->dot_for_string(); 2922 const AstString* temp_name = ast_value_factory_->dot_for_string();
2916 Handle<Smi> smi0 = handle(Smi::FromInt(0), isolate());
2917 Handle<Smi> smi1 = handle(Smi::FromInt(1), isolate());
2918
2919 2923
2920 // For each let variable x: 2924 // For each let variable x:
2921 // make statement: temp_x = x. 2925 // make statement: temp_x = x.
2922 for (int i = 0; i < names->length(); i++) { 2926 for (int i = 0; i < names->length(); i++) {
2923 VariableProxy* proxy = 2927 VariableProxy* proxy =
2924 NewUnresolved(names->at(i), LET, Interface::NewValue()); 2928 NewUnresolved(names->at(i), LET, Interface::NewValue());
2925 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); 2929 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name);
2926 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2930 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2927 Assignment* assignment = factory()->NewAssignment( 2931 Assignment* assignment = factory()->NewAssignment(
2928 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 2932 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
2929 Statement* assignment_statement = factory()->NewExpressionStatement( 2933 Statement* assignment_statement = factory()->NewExpressionStatement(
2930 assignment, RelocInfo::kNoPosition); 2934 assignment, RelocInfo::kNoPosition);
2931 outer_block->AddStatement(assignment_statement, zone()); 2935 outer_block->AddStatement(assignment_statement, zone());
2932 temps.Add(temp, zone()); 2936 temps.Add(temp, zone());
2933 } 2937 }
2934 2938
2935 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name); 2939 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name);
2936 // Make statement: flag = 1. 2940 // Make statement: flag = 1.
2937 { 2941 {
2938 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2942 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2939 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2943 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2940 Assignment* assignment = factory()->NewAssignment( 2944 Assignment* assignment = factory()->NewAssignment(
2941 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); 2945 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
2942 Statement* assignment_statement = factory()->NewExpressionStatement( 2946 Statement* assignment_statement = factory()->NewExpressionStatement(
2943 assignment, RelocInfo::kNoPosition); 2947 assignment, RelocInfo::kNoPosition);
2944 outer_block->AddStatement(assignment_statement, zone()); 2948 outer_block->AddStatement(assignment_statement, zone());
2945 } 2949 }
2946 2950
2947 outer_block->AddStatement(loop, zone()); 2951 outer_block->AddStatement(loop, zone());
2948 outer_block->set_scope(for_scope); 2952 outer_block->set_scope(for_scope);
2949 scope_ = inner_scope; 2953 scope_ = inner_scope;
(...skipping 19 matching lines...) Expand all
2969 assignment, pos); 2973 assignment, pos);
2970 proxy->var()->set_initializer_position(pos); 2974 proxy->var()->set_initializer_position(pos);
2971 inner_block->AddStatement(assignment_statement, zone()); 2975 inner_block->AddStatement(assignment_statement, zone());
2972 } 2976 }
2973 2977
2974 // Make statement: if (flag == 1) { flag = 0; } else { next; }. 2978 // Make statement: if (flag == 1) { flag = 0; } else { next; }.
2975 { 2979 {
2976 Expression* compare = NULL; 2980 Expression* compare = NULL;
2977 // Make compare expresion: flag == 1. 2981 // Make compare expresion: flag == 1.
2978 { 2982 {
2979 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2983 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2980 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2984 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2981 compare = factory()->NewCompareOperation( 2985 compare = factory()->NewCompareOperation(
2982 Token::EQ, flag_proxy, const1, pos); 2986 Token::EQ, flag_proxy, const1, pos);
2983 } 2987 }
2984 Statement* clear_flag = NULL; 2988 Statement* clear_flag = NULL;
2985 // Make statement: flag = 0. 2989 // Make statement: flag = 0.
2986 { 2990 {
2987 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2991 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2988 Expression* const0 = factory()->NewLiteral(smi0, RelocInfo::kNoPosition); 2992 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition);
2989 Assignment* assignment = factory()->NewAssignment( 2993 Assignment* assignment = factory()->NewAssignment(
2990 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); 2994 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition);
2991 clear_flag = factory()->NewExpressionStatement(assignment, pos); 2995 clear_flag = factory()->NewExpressionStatement(assignment, pos);
2992 } 2996 }
2993 Statement* clear_flag_or_next = factory()->NewIfStatement( 2997 Statement* clear_flag_or_next = factory()->NewIfStatement(
2994 compare, clear_flag, next, RelocInfo::kNoPosition); 2998 compare, clear_flag, next, RelocInfo::kNoPosition);
2995 inner_block->AddStatement(clear_flag_or_next, zone()); 2999 inner_block->AddStatement(clear_flag_or_next, zone());
2996 } 3000 }
2997 3001
2998 3002
2999 // Make statement: if (cond) { } else { break; }. 3003 // Make statement: if (cond) { } else { break; }.
3000 { 3004 {
3001 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 3005 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
3002 BreakableStatement* t = LookupBreakTarget(Handle<String>(), CHECK_OK); 3006 BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK);
3003 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); 3007 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition);
3004 Statement* if_not_cond_break = factory()->NewIfStatement( 3008 Statement* if_not_cond_break = factory()->NewIfStatement(
3005 cond, empty, stop, cond->position()); 3009 cond, empty, stop, cond->position());
3006 inner_block->AddStatement(if_not_cond_break, zone()); 3010 inner_block->AddStatement(if_not_cond_break, zone());
3007 } 3011 }
3008 3012
3009 inner_block->AddStatement(body, zone()); 3013 inner_block->AddStatement(body, zone());
3010 3014
3011 // For each let variable x: 3015 // For each let variable x:
3012 // make statement: temp_x = x; 3016 // make statement: temp_x = x;
(...skipping 10 matching lines...) Expand all
3023 3027
3024 inner_scope->set_end_position(scanner()->location().end_pos); 3028 inner_scope->set_end_position(scanner()->location().end_pos);
3025 inner_block->set_scope(inner_scope); 3029 inner_block->set_scope(inner_scope);
3026 scope_ = for_scope; 3030 scope_ = for_scope;
3027 3031
3028 loop->Initialize(NULL, NULL, NULL, inner_block); 3032 loop->Initialize(NULL, NULL, NULL, inner_block);
3029 return outer_block; 3033 return outer_block;
3030 } 3034 }
3031 3035
3032 3036
3033 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 3037 Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels,
3038 bool* ok) {
3034 // ForStatement :: 3039 // ForStatement ::
3035 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 3040 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
3036 3041
3037 int pos = peek_position(); 3042 int pos = peek_position();
3038 Statement* init = NULL; 3043 Statement* init = NULL;
3039 ZoneStringList let_bindings(1, zone()); 3044 ZoneList<const AstString*> let_bindings(1, zone());
3040 3045
3041 // Create an in-between scope for let-bound iteration variables. 3046 // Create an in-between scope for let-bound iteration variables.
3042 Scope* saved_scope = scope_; 3047 Scope* saved_scope = scope_;
3043 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); 3048 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE);
3044 scope_ = for_scope; 3049 scope_ = for_scope;
3045 3050
3046 Expect(Token::FOR, CHECK_OK); 3051 Expect(Token::FOR, CHECK_OK);
3047 Expect(Token::LPAREN, CHECK_OK); 3052 Expect(Token::LPAREN, CHECK_OK);
3048 for_scope->set_start_position(scanner()->location().beg_pos); 3053 for_scope->set_start_position(scanner()->location().beg_pos);
3049 if (peek() != Token::SEMICOLON) { 3054 if (peek() != Token::SEMICOLON) {
3050 if (peek() == Token::VAR || peek() == Token::CONST) { 3055 if (peek() == Token::VAR || peek() == Token::CONST) {
3051 bool is_const = peek() == Token::CONST; 3056 bool is_const = peek() == Token::CONST;
3052 Handle<String> name; 3057 const AstString* name = NULL;
3053 VariableDeclarationProperties decl_props = kHasNoInitializers; 3058 VariableDeclarationProperties decl_props = kHasNoInitializers;
3054 Block* variable_statement = 3059 Block* variable_statement =
3055 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, 3060 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
3056 CHECK_OK); 3061 CHECK_OK);
3057 bool accept_OF = decl_props == kHasNoInitializers; 3062 bool accept_OF = decl_props == kHasNoInitializers;
3058 ForEachStatement::VisitMode mode; 3063 ForEachStatement::VisitMode mode;
3059 3064
3060 if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) { 3065 if (name != NULL && CheckInOrOf(accept_OF, &mode)) {
3061 Interface* interface = 3066 Interface* interface =
3062 is_const ? Interface::NewConst() : Interface::NewValue(); 3067 is_const ? Interface::NewConst() : Interface::NewValue();
3063 ForEachStatement* loop = 3068 ForEachStatement* loop =
3064 factory()->NewForEachStatement(mode, labels, pos); 3069 factory()->NewForEachStatement(mode, labels, pos);
3065 Target target(&this->target_stack_, loop); 3070 Target target(&this->target_stack_, loop);
3066 3071
3067 Expression* enumerable = ParseExpression(true, CHECK_OK); 3072 Expression* enumerable = ParseExpression(true, CHECK_OK);
3068 Expect(Token::RPAREN, CHECK_OK); 3073 Expect(Token::RPAREN, CHECK_OK);
3069 3074
3070 VariableProxy* each = 3075 VariableProxy* each =
3071 scope_->NewUnresolved(factory(), name, interface); 3076 scope_->NewUnresolved(factory(), name, interface);
3072 Statement* body = ParseStatement(NULL, CHECK_OK); 3077 Statement* body = ParseStatement(NULL, CHECK_OK);
3073 InitializeForEachStatement(loop, each, enumerable, body); 3078 InitializeForEachStatement(loop, each, enumerable, body);
3074 Block* result = 3079 Block* result =
3075 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 3080 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
3076 result->AddStatement(variable_statement, zone()); 3081 result->AddStatement(variable_statement, zone());
3077 result->AddStatement(loop, zone()); 3082 result->AddStatement(loop, zone());
3078 scope_ = saved_scope; 3083 scope_ = saved_scope;
3079 for_scope->set_end_position(scanner()->location().end_pos); 3084 for_scope->set_end_position(scanner()->location().end_pos);
3080 for_scope = for_scope->FinalizeBlockScope(); 3085 for_scope = for_scope->FinalizeBlockScope();
3081 ASSERT(for_scope == NULL); 3086 ASSERT(for_scope == NULL);
3082 // Parsed for-in loop w/ variable/const declaration. 3087 // Parsed for-in loop w/ variable/const declaration.
3083 return result; 3088 return result;
3084 } else { 3089 } else {
3085 init = variable_statement; 3090 init = variable_statement;
3086 } 3091 }
3087 } else if (peek() == Token::LET) { 3092 } else if (peek() == Token::LET) {
3088 Handle<String> name; 3093 const AstString* name = NULL;
3089 VariableDeclarationProperties decl_props = kHasNoInitializers; 3094 VariableDeclarationProperties decl_props = kHasNoInitializers;
3090 Block* variable_statement = 3095 Block* variable_statement =
3091 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, 3096 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings,
3092 &name, CHECK_OK); 3097 &name, CHECK_OK);
3093 bool accept_IN = !name.is_null() && decl_props != kHasInitializers; 3098 bool accept_IN = name != NULL && decl_props != kHasInitializers;
3094 bool accept_OF = decl_props == kHasNoInitializers; 3099 bool accept_OF = decl_props == kHasNoInitializers;
3095 ForEachStatement::VisitMode mode; 3100 ForEachStatement::VisitMode mode;
3096 3101
3097 if (accept_IN && CheckInOrOf(accept_OF, &mode)) { 3102 if (accept_IN && CheckInOrOf(accept_OF, &mode)) {
3098 // Rewrite a for-in statement of the form 3103 // Rewrite a for-in statement of the form
3099 // 3104 //
3100 // for (let x in e) b 3105 // for (let x in e) b
3101 // 3106 //
3102 // into 3107 // into
3103 // 3108 //
3104 // <let x' be a temporary variable> 3109 // <let x' be a temporary variable>
3105 // for (x' in e) { 3110 // for (x' in e) {
3106 // let x; 3111 // let x;
3107 // x = x'; 3112 // x = x';
3108 // b; 3113 // b;
3109 // } 3114 // }
3110 3115
3111 // TODO(keuchel): Move the temporary variable to the block scope, after 3116 // TODO(keuchel): Move the temporary variable to the block scope, after
3112 // implementing stack allocated block scoped variables. 3117 // implementing stack allocated block scoped variables.
3113 Factory* heap_factory = isolate()->factory(); 3118 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3114 Handle<String> tempstr; 3119 ast_value_factory_->dot_for_string());
3115 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3116 isolate(), tempstr,
3117 heap_factory->NewConsString(heap_factory->dot_for_string(), name),
3118 0);
3119 Handle<String> tempname = heap_factory->InternalizeString(tempstr);
3120 Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname);
3121 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3120 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3122 ForEachStatement* loop = 3121 ForEachStatement* loop =
3123 factory()->NewForEachStatement(mode, labels, pos); 3122 factory()->NewForEachStatement(mode, labels, pos);
3124 Target target(&this->target_stack_, loop); 3123 Target target(&this->target_stack_, loop);
3125 3124
3126 // The expression does not see the loop variable. 3125 // The expression does not see the loop variable.
3127 scope_ = saved_scope; 3126 scope_ = saved_scope;
3128 Expression* enumerable = ParseExpression(true, CHECK_OK); 3127 Expression* enumerable = ParseExpression(true, CHECK_OK);
3129 scope_ = for_scope; 3128 scope_ = for_scope;
3130 Expect(Token::RPAREN, CHECK_OK); 3129 Expect(Token::RPAREN, CHECK_OK);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 // DebuggerStatement :: 3240 // DebuggerStatement ::
3242 // 'debugger' ';' 3241 // 'debugger' ';'
3243 3242
3244 int pos = peek_position(); 3243 int pos = peek_position();
3245 Expect(Token::DEBUGGER, CHECK_OK); 3244 Expect(Token::DEBUGGER, CHECK_OK);
3246 ExpectSemicolon(CHECK_OK); 3245 ExpectSemicolon(CHECK_OK);
3247 return factory()->NewDebuggerStatement(pos); 3246 return factory()->NewDebuggerStatement(pos);
3248 } 3247 }
3249 3248
3250 3249
3251 void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) { 3250 void Parser::ReportInvalidCachedData(const AstString* name, bool* ok) {
3252 ParserTraits::ReportMessage("invalid_cached_data_function", name); 3251 ParserTraits::ReportMessage("invalid_cached_data_function", name);
3253 *ok = false; 3252 *ok = false;
3254 } 3253 }
3255 3254
3256 3255
3257 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3256 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
3258 if (expression->IsLiteral()) return true; 3257 if (expression->IsLiteral()) return true;
3259 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3258 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
3260 return lit != NULL && lit->is_simple(); 3259 return lit != NULL && lit->is_simple();
3261 } 3260 }
(...skipping 29 matching lines...) Expand all
3291 return static_cast<LiteralType>(literal_type->value()); 3290 return static_cast<LiteralType>(literal_type->value());
3292 } 3291 }
3293 3292
3294 3293
3295 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3294 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3296 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3295 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3297 } 3296 }
3298 3297
3299 3298
3300 FunctionLiteral* Parser::ParseFunctionLiteral( 3299 FunctionLiteral* Parser::ParseFunctionLiteral(
3301 Handle<String> function_name, 3300 const AstString* function_name,
3302 Scanner::Location function_name_location, 3301 Scanner::Location function_name_location,
3303 bool name_is_strict_reserved, 3302 bool name_is_strict_reserved,
3304 bool is_generator, 3303 bool is_generator,
3305 int function_token_pos, 3304 int function_token_pos,
3306 FunctionLiteral::FunctionType function_type, 3305 FunctionLiteral::FunctionType function_type,
3307 bool* ok) { 3306 bool* ok) {
3308 // Function :: 3307 // Function ::
3309 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3308 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3310 3309
3311 int pos = function_token_pos == RelocInfo::kNoPosition 3310 int pos = function_token_pos == RelocInfo::kNoPosition
3312 ? peek_position() : function_token_pos; 3311 ? peek_position() : function_token_pos;
3313 3312
3314 // Anonymous functions were passed either the empty symbol or a null 3313 // Anonymous functions were passed either the empty symbol or a null
3315 // handle as the function name. Remember if we were passed a non-empty 3314 // handle as the function name. Remember if we were passed a non-empty
3316 // handle to decide whether to invoke function name inference. 3315 // handle to decide whether to invoke function name inference.
3317 bool should_infer_name = function_name.is_null(); 3316 bool should_infer_name = function_name == NULL;
3318 3317
3319 // We want a non-null handle as the function name. 3318 // We want a non-null handle as the function name.
3320 if (should_infer_name) { 3319 if (should_infer_name) {
3321 function_name = isolate()->factory()->empty_string(); 3320 function_name = ast_value_factory_->empty_string();
3322 } 3321 }
3323 3322
3324 int num_parameters = 0; 3323 int num_parameters = 0;
3325 // Function declarations are function scoped in normal mode, so they are 3324 // Function declarations are function scoped in normal mode, so they are
3326 // hoisted. In harmony block scoping mode they are block scoped, so they 3325 // hoisted. In harmony block scoping mode they are block scoped, so they
3327 // are not hoisted. 3326 // are not hoisted.
3328 // 3327 //
3329 // One tricky case are function declarations in a local sloppy-mode eval: 3328 // One tricky case are function declarations in a local sloppy-mode eval:
3330 // their declaration is hoisted, but they still see the local scope. E.g., 3329 // their declaration is hoisted, but they still see the local scope. E.g.,
3331 // 3330 //
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 int expected_property_count = -1; 3362 int expected_property_count = -1;
3364 int handler_count = 0; 3363 int handler_count = 0;
3365 FunctionLiteral::ParameterFlag duplicate_parameters = 3364 FunctionLiteral::ParameterFlag duplicate_parameters =
3366 FunctionLiteral::kNoDuplicateParameters; 3365 FunctionLiteral::kNoDuplicateParameters;
3367 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3366 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3368 ? FunctionLiteral::kIsParenthesized 3367 ? FunctionLiteral::kIsParenthesized
3369 : FunctionLiteral::kNotParenthesized; 3368 : FunctionLiteral::kNotParenthesized;
3370 AstProperties ast_properties; 3369 AstProperties ast_properties;
3371 BailoutReason dont_optimize_reason = kNoReason; 3370 BailoutReason dont_optimize_reason = kNoReason;
3372 // Parse function body. 3371 // Parse function body.
3373 { FunctionState function_state(&function_state_, &scope_, scope, zone()); 3372 {
3373 FunctionState function_state(&function_state_, &scope_, scope, zone(),
3374 ast_value_factory_);
3374 scope_->SetScopeName(function_name); 3375 scope_->SetScopeName(function_name);
3375 3376
3376 if (is_generator) { 3377 if (is_generator) {
3377 // For generators, allocating variables in contexts is currently a win 3378 // For generators, allocating variables in contexts is currently a win
3378 // because it minimizes the work needed to suspend and resume an 3379 // because it minimizes the work needed to suspend and resume an
3379 // activation. 3380 // activation.
3380 scope_->ForceContextAllocation(); 3381 scope_->ForceContextAllocation();
3381 3382
3382 // Calling a generator returns a generator object. That object is stored 3383 // Calling a generator returns a generator object. That object is stored
3383 // in a temporary variable, a definition that is used by "yield" 3384 // in a temporary variable, a definition that is used by "yield"
3384 // expressions. This also marks the FunctionState as a generator. 3385 // expressions. This also marks the FunctionState as a generator.
3385 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3386 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3386 isolate()->factory()->dot_generator_object_string()); 3387 ast_value_factory_->dot_generator_object_string());
3387 function_state.set_generator_object_variable(temp); 3388 function_state.set_generator_object_variable(temp);
3388 } 3389 }
3389 3390
3390 // FormalParameterList :: 3391 // FormalParameterList ::
3391 // '(' (Identifier)*[','] ')' 3392 // '(' (Identifier)*[','] ')'
3392 Expect(Token::LPAREN, CHECK_OK); 3393 Expect(Token::LPAREN, CHECK_OK);
3393 scope->set_start_position(scanner()->location().beg_pos); 3394 scope->set_start_position(scanner()->location().beg_pos);
3394 3395
3395 // We don't yet know if the function will be strict, so we cannot yet 3396 // We don't yet know if the function will be strict, so we cannot yet
3396 // produce errors for parameter names or duplicates. However, we remember 3397 // produce errors for parameter names or duplicates. However, we remember
3397 // the locations of these errors if they occur and produce the errors later. 3398 // the locations of these errors if they occur and produce the errors later.
3398 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); 3399 Scanner::Location eval_args_error_log = Scanner::Location::invalid();
3399 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 3400 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
3400 Scanner::Location reserved_loc = Scanner::Location::invalid(); 3401 Scanner::Location reserved_loc = Scanner::Location::invalid();
3401 3402
3402 bool done = (peek() == Token::RPAREN); 3403 bool done = (peek() == Token::RPAREN);
3403 while (!done) { 3404 while (!done) {
3404 bool is_strict_reserved = false; 3405 bool is_strict_reserved = false;
3405 Handle<String> param_name = 3406 const AstString* param_name =
3406 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 3407 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
3407 3408
3408 // Store locations for possible future error reports. 3409 // Store locations for possible future error reports.
3409 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { 3410 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) {
3410 eval_args_error_log = scanner()->location(); 3411 eval_args_error_log = scanner()->location();
3411 } 3412 }
3412 if (!reserved_loc.IsValid() && is_strict_reserved) { 3413 if (!reserved_loc.IsValid() && is_strict_reserved) {
3413 reserved_loc = scanner()->location(); 3414 reserved_loc = scanner()->location();
3414 } 3415 }
3415 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { 3416 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) {
(...skipping 23 matching lines...) Expand all
3439 // instead of Variables and Proxis as is the case now. 3440 // instead of Variables and Proxis as is the case now.
3440 Variable* fvar = NULL; 3441 Variable* fvar = NULL;
3441 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; 3442 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
3442 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { 3443 if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
3443 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3444 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3444 fvar_init_op = Token::INIT_CONST; 3445 fvar_init_op = Token::INIT_CONST;
3445 } 3446 }
3446 VariableMode fvar_mode = 3447 VariableMode fvar_mode =
3447 allow_harmony_scoping() && strict_mode() == STRICT ? CONST 3448 allow_harmony_scoping() && strict_mode() == STRICT ? CONST
3448 : CONST_LEGACY; 3449 : CONST_LEGACY;
3450 ASSERT(function_name != NULL);
3449 fvar = new(zone()) Variable(scope_, 3451 fvar = new(zone()) Variable(scope_,
3450 function_name, fvar_mode, true /* is valid LHS */, 3452 function_name, fvar_mode, true /* is valid LHS */,
3451 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); 3453 Variable::NORMAL, kCreatedInitialized, Interface::NewConst());
3452 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 3454 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
3453 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 3455 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
3454 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); 3456 proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
3455 scope_->DeclareFunctionVar(fvar_declaration); 3457 scope_->DeclareFunctionVar(fvar_declaration);
3456 } 3458 }
3457 3459
3458 // Determine if the function can be parsed lazily. Lazy parsing is different 3460 // Determine if the function can be parsed lazily. Lazy parsing is different
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3542 3544
3543 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3545 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3544 CheckConflictingVarDeclarations(scope, CHECK_OK); 3546 CheckConflictingVarDeclarations(scope, CHECK_OK);
3545 } 3547 }
3546 3548
3547 FunctionLiteral::IsGeneratorFlag generator = is_generator 3549 FunctionLiteral::IsGeneratorFlag generator = is_generator
3548 ? FunctionLiteral::kIsGenerator 3550 ? FunctionLiteral::kIsGenerator
3549 : FunctionLiteral::kNotGenerator; 3551 : FunctionLiteral::kNotGenerator;
3550 FunctionLiteral* function_literal = 3552 FunctionLiteral* function_literal =
3551 factory()->NewFunctionLiteral(function_name, 3553 factory()->NewFunctionLiteral(function_name,
3554 ast_value_factory_,
3552 scope, 3555 scope,
3553 body, 3556 body,
3554 materialized_literal_count, 3557 materialized_literal_count,
3555 expected_property_count, 3558 expected_property_count,
3556 handler_count, 3559 handler_count,
3557 num_parameters, 3560 num_parameters,
3558 duplicate_parameters, 3561 duplicate_parameters,
3559 function_type, 3562 function_type,
3560 FunctionLiteral::kIsFunction, 3563 FunctionLiteral::kIsFunction,
3561 parenthesized, 3564 parenthesized,
3562 generator, 3565 generator,
3563 pos); 3566 pos);
3564 function_literal->set_function_token_position(function_token_pos); 3567 function_literal->set_function_token_position(function_token_pos);
3565 function_literal->set_ast_properties(&ast_properties); 3568 function_literal->set_ast_properties(&ast_properties);
3566 function_literal->set_dont_optimize_reason(dont_optimize_reason); 3569 function_literal->set_dont_optimize_reason(dont_optimize_reason);
3567 3570
3568 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3571 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3569 return function_literal; 3572 return function_literal;
3570 } 3573 }
3571 3574
3572 3575
3573 void Parser::SkipLazyFunctionBody(Handle<String> function_name, 3576 void Parser::SkipLazyFunctionBody(const AstString* function_name,
3574 int* materialized_literal_count, 3577 int* materialized_literal_count,
3575 int* expected_property_count, 3578 int* expected_property_count,
3576 bool* ok) { 3579 bool* ok) {
3577 int function_block_pos = position(); 3580 int function_block_pos = position();
3578 if (cached_data_mode_ == CONSUME_CACHED_DATA) { 3581 if (cached_data_mode_ == CONSUME_CACHED_DATA) {
3579 // If we have cached data, we use it to skip parsing the function body. The 3582 // If we have cached data, we use it to skip parsing the function body. The
3580 // data contains the information we need to construct the lazy function. 3583 // data contains the information we need to construct the lazy function.
3581 FunctionEntry entry = 3584 FunctionEntry entry =
3582 (*cached_data())->GetFunctionEntry(function_block_pos); 3585 (*cached_data())->GetFunctionEntry(function_block_pos);
3583 if (entry.is_valid()) { 3586 if (entry.is_valid()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 log_->LogFunction(function_block_pos, body_end, 3645 log_->LogFunction(function_block_pos, body_end,
3643 *materialized_literal_count, 3646 *materialized_literal_count,
3644 *expected_property_count, 3647 *expected_property_count,
3645 scope_->strict_mode()); 3648 scope_->strict_mode());
3646 } 3649 }
3647 } 3650 }
3648 } 3651 }
3649 3652
3650 3653
3651 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 3654 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
3652 Handle<String> function_name, int pos, Variable* fvar, 3655 const AstString* function_name, int pos, Variable* fvar,
3653 Token::Value fvar_init_op, bool is_generator, bool* ok) { 3656 Token::Value fvar_init_op, bool is_generator, bool* ok) {
3654 // Everything inside an eagerly parsed function will be parsed eagerly 3657 // Everything inside an eagerly parsed function will be parsed eagerly
3655 // (see comment above). 3658 // (see comment above).
3656 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 3659 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
3657 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); 3660 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone());
3658 if (fvar != NULL) { 3661 if (fvar != NULL) {
3659 VariableProxy* fproxy = scope_->NewUnresolved( 3662 VariableProxy* fproxy = scope_->NewUnresolved(
3660 factory(), function_name, Interface::NewConst()); 3663 factory(), function_name, Interface::NewConst());
3661 fproxy->BindTo(fvar); 3664 fproxy->BindTo(fvar);
3662 body->Add(factory()->NewExpressionStatement( 3665 body->Add(factory()->NewExpressionStatement(
3663 factory()->NewAssignment(fvar_init_op, 3666 factory()->NewAssignment(fvar_init_op,
3664 fproxy, 3667 fproxy,
3665 factory()->NewThisFunction(pos), 3668 factory()->NewThisFunction(pos),
3666 RelocInfo::kNoPosition), 3669 RelocInfo::kNoPosition),
3667 RelocInfo::kNoPosition), zone()); 3670 RelocInfo::kNoPosition), zone());
3668 } 3671 }
3669 3672
3670 // For generators, allocate and yield an iterator on function entry. 3673 // For generators, allocate and yield an iterator on function entry.
3671 if (is_generator) { 3674 if (is_generator) {
3672 ZoneList<Expression*>* arguments = 3675 ZoneList<Expression*>* arguments =
3673 new(zone()) ZoneList<Expression*>(0, zone()); 3676 new(zone()) ZoneList<Expression*>(0, zone());
3674 CallRuntime* allocation = factory()->NewCallRuntime( 3677 CallRuntime* allocation = factory()->NewCallRuntime(
3675 isolate()->factory()->empty_string(), 3678 ast_value_factory_->empty_string(),
3676 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject), 3679 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject),
3677 arguments, pos); 3680 arguments, pos);
3678 VariableProxy* init_proxy = factory()->NewVariableProxy( 3681 VariableProxy* init_proxy = factory()->NewVariableProxy(
3679 function_state_->generator_object_variable()); 3682 function_state_->generator_object_variable());
3680 Assignment* assignment = factory()->NewAssignment( 3683 Assignment* assignment = factory()->NewAssignment(
3681 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 3684 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
3682 VariableProxy* get_proxy = factory()->NewVariableProxy( 3685 VariableProxy* get_proxy = factory()->NewVariableProxy(
3683 function_state_->generator_object_variable()); 3686 function_state_->generator_object_variable());
3684 Yield* yield = factory()->NewYield( 3687 Yield* yield = factory()->NewYield(
3685 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); 3688 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
3686 body->Add(factory()->NewExpressionStatement( 3689 body->Add(factory()->NewExpressionStatement(
3687 yield, RelocInfo::kNoPosition), zone()); 3690 yield, RelocInfo::kNoPosition), zone());
3688 } 3691 }
3689 3692
3690 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); 3693 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
3691 3694
3692 if (is_generator) { 3695 if (is_generator) {
3693 VariableProxy* get_proxy = factory()->NewVariableProxy( 3696 VariableProxy* get_proxy = factory()->NewVariableProxy(
3694 function_state_->generator_object_variable()); 3697 function_state_->generator_object_variable());
3695 Expression *undefined = factory()->NewLiteral( 3698 Expression* undefined =
3696 isolate()->factory()->undefined_value(), RelocInfo::kNoPosition); 3699 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
3697 Yield* yield = factory()->NewYield( 3700 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL,
3698 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); 3701 RelocInfo::kNoPosition);
3699 body->Add(factory()->NewExpressionStatement( 3702 body->Add(factory()->NewExpressionStatement(
3700 yield, RelocInfo::kNoPosition), zone()); 3703 yield, RelocInfo::kNoPosition), zone());
3701 } 3704 }
3702 3705
3703 Expect(Token::RBRACE, CHECK_OK); 3706 Expect(Token::RBRACE, CHECK_OK);
3704 scope_->set_end_position(scanner()->location().end_pos); 3707 scope_->set_end_position(scanner()->location().end_pos);
3705 3708
3706 return body; 3709 return body;
3707 } 3710 }
3708 3711
(...skipping 23 matching lines...) Expand all
3732 } 3735 }
3733 3736
3734 3737
3735 Expression* Parser::ParseV8Intrinsic(bool* ok) { 3738 Expression* Parser::ParseV8Intrinsic(bool* ok) {
3736 // CallRuntime :: 3739 // CallRuntime ::
3737 // '%' Identifier Arguments 3740 // '%' Identifier Arguments
3738 3741
3739 int pos = peek_position(); 3742 int pos = peek_position();
3740 Expect(Token::MOD, CHECK_OK); 3743 Expect(Token::MOD, CHECK_OK);
3741 // Allow "eval" or "arguments" for backward compatibility. 3744 // Allow "eval" or "arguments" for backward compatibility.
3742 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 3745 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
3743 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 3746 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
3744 3747
3745 if (extension_ != NULL) { 3748 if (extension_ != NULL) {
3746 // The extension structures are only accessible while parsing the 3749 // The extension structures are only accessible while parsing the
3747 // very first time not when reparsing because of lazy compilation. 3750 // very first time not when reparsing because of lazy compilation.
3748 scope_->DeclarationScope()->ForceEagerCompilation(); 3751 scope_->DeclarationScope()->ForceEagerCompilation();
3749 } 3752 }
3750 3753
3751 const Runtime::Function* function = Runtime::FunctionForName(name); 3754 const Runtime::Function* function = Runtime::FunctionForName(name->string());
3752 3755
3753 // Check for built-in IS_VAR macro. 3756 // Check for built-in IS_VAR macro.
3754 if (function != NULL && 3757 if (function != NULL &&
3755 function->intrinsic_type == Runtime::RUNTIME && 3758 function->intrinsic_type == Runtime::RUNTIME &&
3756 function->function_id == Runtime::kIS_VAR) { 3759 function->function_id == Runtime::kIS_VAR) {
3757 // %IS_VAR(x) evaluates to x if x is a variable, 3760 // %IS_VAR(x) evaluates to x if x is a variable,
3758 // leads to a parse error otherwise. Could be implemented as an 3761 // leads to a parse error otherwise. Could be implemented as an
3759 // inline function %_IS_VAR(x) to eliminate this special case. 3762 // inline function %_IS_VAR(x) to eliminate this special case.
3760 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { 3763 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
3761 return args->at(0); 3764 return args->at(0);
3762 } else { 3765 } else {
3763 ReportMessage("not_isvar"); 3766 ReportMessage("not_isvar");
3764 *ok = false; 3767 *ok = false;
3765 return NULL; 3768 return NULL;
3766 } 3769 }
3767 } 3770 }
3768 3771
3769 // Check that the expected number of arguments are being passed. 3772 // Check that the expected number of arguments are being passed.
3770 if (function != NULL && 3773 if (function != NULL &&
3771 function->nargs != -1 && 3774 function->nargs != -1 &&
3772 function->nargs != args->length()) { 3775 function->nargs != args->length()) {
3773 ReportMessage("illegal_access"); 3776 ReportMessage("illegal_access");
3774 *ok = false; 3777 *ok = false;
3775 return NULL; 3778 return NULL;
3776 } 3779 }
3777 3780
3778 // Check that the function is defined if it's an inline runtime call. 3781 // Check that the function is defined if it's an inline runtime call.
3779 if (function == NULL && name->Get(0) == '_') { 3782 if (function == NULL && name->FirstCharacter() == '_') {
3780 ParserTraits::ReportMessage("not_defined", name); 3783 ParserTraits::ReportMessage("not_defined", name);
3781 *ok = false; 3784 *ok = false;
3782 return NULL; 3785 return NULL;
3783 } 3786 }
3784 3787
3785 // We have a valid intrinsics call or a call to a builtin. 3788 // We have a valid intrinsics call or a call to a builtin.
3786 return factory()->NewCallRuntime(name, function, args, pos); 3789 return factory()->NewCallRuntime(name, function, args, pos);
3787 } 3790 }
3788 3791
3789 3792
3790 Literal* Parser::GetLiteralUndefined(int position) { 3793 Literal* Parser::GetLiteralUndefined(int position) {
3791 return factory()->NewLiteral( 3794 return factory()->NewUndefinedLiteral(position);
3792 isolate()->factory()->undefined_value(), position);
3793 } 3795 }
3794 3796
3795 3797
3796 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 3798 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
3797 Declaration* decl = scope->CheckConflictingVarDeclarations(); 3799 Declaration* decl = scope->CheckConflictingVarDeclarations();
3798 if (decl != NULL) { 3800 if (decl != NULL) {
3799 // In harmony mode we treat conflicting variable bindinds as early 3801 // In harmony mode we treat conflicting variable bindinds as early
3800 // errors. See ES5 16 for a definition of early errors. 3802 // errors. See ES5 16 for a definition of early errors.
3801 Handle<String> name = decl->proxy()->name(); 3803 const AstString* name = decl->proxy()->raw_name();
3802 int position = decl->proxy()->position(); 3804 int position = decl->proxy()->position();
3803 Scanner::Location location = position == RelocInfo::kNoPosition 3805 Scanner::Location location = position == RelocInfo::kNoPosition
3804 ? Scanner::Location::invalid() 3806 ? Scanner::Location::invalid()
3805 : Scanner::Location(position, position + 1); 3807 : Scanner::Location(position, position + 1);
3806 ParserTraits::ReportMessageAt(location, "var_redeclaration", name); 3808 ParserTraits::ReportMessageAt(location, "var_redeclaration", name);
3807 *ok = false; 3809 *ok = false;
3808 } 3810 }
3809 } 3811 }
3810 3812
3811 3813
3812 // ---------------------------------------------------------------------------- 3814 // ----------------------------------------------------------------------------
3813 // Parser support 3815 // Parser support
3814 3816
3815 3817
3816 bool Parser::TargetStackContainsLabel(Handle<String> label) { 3818 bool Parser::TargetStackContainsLabel(const AstString* label) {
3817 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3819 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3818 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3820 BreakableStatement* stat = t->node()->AsBreakableStatement();
3819 if (stat != NULL && ContainsLabel(stat->labels(), label)) 3821 if (stat != NULL && ContainsLabel(stat->labels(), label))
3820 return true; 3822 return true;
3821 } 3823 }
3822 return false; 3824 return false;
3823 } 3825 }
3824 3826
3825 3827
3826 BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) { 3828 BreakableStatement* Parser::LookupBreakTarget(const AstString* label,
3827 bool anonymous = label.is_null(); 3829 bool* ok) {
3830 bool anonymous = label == NULL;
3828 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3831 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3829 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3832 BreakableStatement* stat = t->node()->AsBreakableStatement();
3830 if (stat == NULL) continue; 3833 if (stat == NULL) continue;
3831 if ((anonymous && stat->is_target_for_anonymous()) || 3834 if ((anonymous && stat->is_target_for_anonymous()) ||
3832 (!anonymous && ContainsLabel(stat->labels(), label))) { 3835 (!anonymous && ContainsLabel(stat->labels(), label))) {
3833 RegisterTargetUse(stat->break_target(), t->previous()); 3836 RegisterTargetUse(stat->break_target(), t->previous());
3834 return stat; 3837 return stat;
3835 } 3838 }
3836 } 3839 }
3837 return NULL; 3840 return NULL;
3838 } 3841 }
3839 3842
3840 3843
3841 IterationStatement* Parser::LookupContinueTarget(Handle<String> label, 3844 IterationStatement* Parser::LookupContinueTarget(const AstString* label,
3842 bool* ok) { 3845 bool* ok) {
3843 bool anonymous = label.is_null(); 3846 bool anonymous = label == NULL;
3844 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3847 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3845 IterationStatement* stat = t->node()->AsIterationStatement(); 3848 IterationStatement* stat = t->node()->AsIterationStatement();
3846 if (stat == NULL) continue; 3849 if (stat == NULL) continue;
3847 3850
3848 ASSERT(stat->is_target_for_anonymous()); 3851 ASSERT(stat->is_target_for_anonymous());
3849 if (anonymous || ContainsLabel(stat->labels(), label)) { 3852 if (anonymous || ContainsLabel(stat->labels(), label)) {
3850 RegisterTargetUse(stat->continue_target(), t->previous()); 3853 RegisterTargetUse(stat->continue_target(), t->previous());
3851 return stat; 3854 return stat;
3852 } 3855 }
3853 } 3856 }
(...skipping 12 matching lines...) Expand all
3866 } 3869 }
3867 3870
3868 3871
3869 void Parser::ThrowPendingError() { 3872 void Parser::ThrowPendingError() {
3870 if (has_pending_error_) { 3873 if (has_pending_error_) {
3871 MessageLocation location(script_, 3874 MessageLocation location(script_,
3872 pending_error_location_.beg_pos, 3875 pending_error_location_.beg_pos,
3873 pending_error_location_.end_pos); 3876 pending_error_location_.end_pos);
3874 Factory* factory = isolate()->factory(); 3877 Factory* factory = isolate()->factory();
3875 bool has_arg = 3878 bool has_arg =
3876 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL; 3879 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL;
3877 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); 3880 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3878 if (!pending_error_arg_.is_null()) { 3881 if (pending_error_arg_ != NULL) {
3879 elements->set(0, *(pending_error_arg_.ToHandleChecked())); 3882 Handle<String> arg_string = pending_error_arg_->string();
3883 elements->set(0, *arg_string);
3880 } else if (pending_error_char_arg_ != NULL) { 3884 } else if (pending_error_char_arg_ != NULL) {
3881 Handle<String> arg_string = 3885 Handle<String> arg_string =
3882 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) 3886 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_))
3883 .ToHandleChecked(); 3887 .ToHandleChecked();
3884 elements->set(0, *arg_string); 3888 elements->set(0, *arg_string);
3885 } 3889 }
3886 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 3890 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
3887 Handle<Object> result = pending_error_is_reference_error_ 3891 Handle<Object> result = pending_error_is_reference_error_
3888 ? factory->NewReferenceError(pending_error_message_, array) 3892 ? factory->NewReferenceError(pending_error_message_, array)
3889 : factory->NewSyntaxError(pending_error_message_, array); 3893 : factory->NewSyntaxError(pending_error_message_, array);
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
4782 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 4786 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
4783 result->contains_anchor = parser.contains_anchor(); 4787 result->contains_anchor = parser.contains_anchor();
4784 result->capture_count = capture_count; 4788 result->capture_count = capture_count;
4785 } 4789 }
4786 return !parser.failed(); 4790 return !parser.failed();
4787 } 4791 }
4788 4792
4789 4793
4790 bool Parser::Parse() { 4794 bool Parser::Parse() {
4791 ASSERT(info()->function() == NULL); 4795 ASSERT(info()->function() == NULL);
4796 ASSERT(info()->ast_value_factory() == NULL);
4792 FunctionLiteral* result = NULL; 4797 FunctionLiteral* result = NULL;
4798 ast_value_factory_ = new AstValueFactory(zone());
4799 if (allow_natives_syntax() || extension_ != NULL) {
4800 // If intrinsics are allowed, the Parser cannot operate independent of the
4801 // V8 heap because of Rumtime. Tell the string table to internalize strings
4802 // and values right after they're created.
4803 ast_value_factory_->Internalize(isolate());
4804 }
4805
4793 if (info()->is_lazy()) { 4806 if (info()->is_lazy()) {
4794 ASSERT(!info()->is_eval()); 4807 ASSERT(!info()->is_eval());
4795 if (info()->shared_info()->is_function()) { 4808 if (info()->shared_info()->is_function()) {
4796 result = ParseLazy(); 4809 result = ParseLazy();
4797 } else { 4810 } else {
4798 result = ParseProgram(); 4811 result = ParseProgram();
4799 } 4812 }
4800 } else { 4813 } else {
4801 SetCachedData(info()->cached_data(), info()->cached_data_mode()); 4814 SetCachedData(info()->cached_data(), info()->cached_data_mode());
4802 if (info()->cached_data_mode() == CONSUME_CACHED_DATA && 4815 if (info()->cached_data_mode() == CONSUME_CACHED_DATA &&
4803 (*info()->cached_data())->has_error()) { 4816 (*info()->cached_data())->has_error()) {
4804 ScriptData* cached_data = *(info()->cached_data()); 4817 ScriptData* cached_data = *(info()->cached_data());
4805 Scanner::Location loc = cached_data->MessageLocation(); 4818 Scanner::Location loc = cached_data->MessageLocation();
4806 const char* message = cached_data->BuildMessage(); 4819 const char* message = cached_data->BuildMessage();
4807 const char* arg = cached_data->BuildArg(); 4820 const char* arg = cached_data->BuildArg();
4808 ParserTraits::ReportMessageAt(loc, message, arg, 4821 ParserTraits::ReportMessageAt(loc, message, arg,
4809 cached_data->IsReferenceError()); 4822 cached_data->IsReferenceError());
4810 DeleteArray(message); 4823 DeleteArray(message);
4811 DeleteArray(arg); 4824 DeleteArray(arg);
4812 ASSERT(info()->isolate()->has_pending_exception()); 4825 ASSERT(info()->isolate()->has_pending_exception());
4813 } else { 4826 } else {
4814 result = ParseProgram(); 4827 result = ParseProgram();
4815 } 4828 }
4816 } 4829 }
4817 info()->SetFunction(result); 4830 info()->SetFunction(result);
4831 ast_value_factory_->Internalize(isolate());
4832 // info takes ownership of ast_value_factory_.
4833 info()->SetAstValueFactory(ast_value_factory_);
4834 ast_value_factory_ = NULL;
4818 return (result != NULL); 4835 return (result != NULL);
4819 } 4836 }
4820 4837
4821 } } // namespace v8::internal 4838 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698