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

Side by Side Diff: src/parser.cc

Issue 335293004: New try: Parser: Delay internalizing strings and values (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: variable renaming + passing const & 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
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 FunctionLiteral::ArityRestriction arity_restriction, 749 FunctionLiteral::ArityRestriction arity_restriction,
756 bool* ok) { 750 bool* ok) {
757 return parser_->ParseFunctionLiteral(name, function_name_location, 751 return parser_->ParseFunctionLiteral(name, function_name_location,
758 name_is_strict_reserved, is_generator, 752 name_is_strict_reserved, is_generator,
759 function_token_position, type, 753 function_token_position, type,
760 arity_restriction, ok); 754 arity_restriction, ok);
761 } 755 }
762 756
763 757
764 Parser::Parser(CompilationInfo* info) 758 Parser::Parser(CompilationInfo* info)
765 : ParserBase<ParserTraits>(&scanner_, 759 : ParserBase<ParserTraits>(&scanner_,
766 info->isolate()->stack_guard()->real_climit(), 760 info->isolate()->stack_guard()->real_climit(),
767 info->extension(), 761 info->extension(),
768 NULL, 762 NULL,
769 info->zone(), 763 info->zone(),
770 this), 764 this),
771 isolate_(info->isolate()), 765 isolate_(info->isolate()),
772 script_(info->script()), 766 script_(info->script()),
773 scanner_(isolate_->unicode_cache()), 767 scanner_(isolate_->unicode_cache()),
774 reusable_preparser_(NULL), 768 reusable_preparser_(NULL),
775 original_scope_(NULL), 769 original_scope_(NULL),
776 target_stack_(NULL), 770 target_stack_(NULL),
777 cached_data_(NULL), 771 cached_data_(NULL),
778 cached_data_mode_(NO_CACHED_DATA), 772 cached_data_mode_(NO_CACHED_DATA),
773 ast_value_factory_(NULL),
779 info_(info), 774 info_(info),
780 has_pending_error_(false), 775 has_pending_error_(false),
781 pending_error_message_(NULL), 776 pending_error_message_(NULL),
777 pending_error_arg_(NULL),
782 pending_error_char_arg_(NULL) { 778 pending_error_char_arg_(NULL) {
783 ASSERT(!script_.is_null()); 779 ASSERT(!script_.is_null());
784 isolate_->set_ast_node_id(0); 780 isolate_->set_ast_node_id(0);
785 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 781 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
786 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 782 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
787 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 783 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
788 set_allow_lazy(false); // Must be explicitly enabled. 784 set_allow_lazy(false); // Must be explicitly enabled.
789 set_allow_generators(FLAG_harmony_generators); 785 set_allow_generators(FLAG_harmony_generators);
790 set_allow_for_of(FLAG_harmony_iteration); 786 set_allow_for_of(FLAG_harmony_iteration);
791 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 787 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
792 } 788 }
793 789
794 790
795 FunctionLiteral* Parser::ParseProgram() { 791 FunctionLiteral* Parser::ParseProgram() {
796 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 792 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
797 // see comment for HistogramTimerScope class. 793 // see comment for HistogramTimerScope class.
798 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); 794 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
799 Handle<String> source(String::cast(script_->source())); 795 Handle<String> source(String::cast(script_->source()));
800 isolate()->counters()->total_parse_size()->Increment(source->length()); 796 isolate()->counters()->total_parse_size()->Increment(source->length());
801 ElapsedTimer timer; 797 ElapsedTimer timer;
802 if (FLAG_trace_parse) { 798 if (FLAG_trace_parse) {
803 timer.Start(); 799 timer.Start();
804 } 800 }
805 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 801 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
806 802
807 // Initialize parser state. 803 // Initialize parser state.
808 CompleteParserRecorder recorder; 804 CompleteParserRecorder recorder;
809 if (cached_data_mode_ == PRODUCE_CACHED_DATA) { 805 if (cached_data_mode_ == PRODUCE_CACHED_DATA) {
810 log_ = &recorder; 806 log_ = &recorder;
811 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) { 807 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) {
812 (*cached_data_)->Initialize(); 808 (*cached_data_)->Initialize();
813 } 809 }
814 810
815 source = String::Flatten(source); 811 source = String::Flatten(source);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } 846 }
851 return result; 847 return result;
852 } 848 }
853 849
854 850
855 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 851 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
856 Handle<String> source) { 852 Handle<String> source) {
857 ASSERT(scope_ == NULL); 853 ASSERT(scope_ == NULL);
858 ASSERT(target_stack_ == NULL); 854 ASSERT(target_stack_ == NULL);
859 855
860 Handle<String> no_name = isolate()->factory()->empty_string();
861
862 FunctionLiteral* result = NULL; 856 FunctionLiteral* result = NULL;
863 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 857 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
864 info->SetGlobalScope(scope); 858 info->SetGlobalScope(scope);
865 if (!info->context().is_null()) { 859 if (!info->context().is_null()) {
866 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); 860 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone());
861 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
862 // means the Parser cannot operate independent of the V8 heap. Tell the
863 // string table to internalize strings and values right after they're
864 // created.
865 ast_value_factory_->Internalize(isolate());
867 } 866 }
868 original_scope_ = scope; 867 original_scope_ = scope;
869 if (info->is_eval()) { 868 if (info->is_eval()) {
870 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { 869 if (!scope->is_global_scope() || info->strict_mode() == STRICT) {
871 scope = NewScope(scope, EVAL_SCOPE); 870 scope = NewScope(scope, EVAL_SCOPE);
872 } 871 }
873 } else if (info->is_global()) { 872 } else if (info->is_global()) {
874 scope = NewScope(scope, GLOBAL_SCOPE); 873 scope = NewScope(scope, GLOBAL_SCOPE);
875 } 874 }
876 scope->set_start_position(0); 875 scope->set_start_position(0);
877 scope->set_end_position(source->length()); 876 scope->set_end_position(source->length());
878 877
879 // Compute the parsing mode. 878 // Compute the parsing mode.
880 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 879 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
881 if (allow_natives_syntax() || 880 if (allow_natives_syntax() ||
882 extension_ != NULL || 881 extension_ != NULL ||
883 scope->is_eval_scope()) { 882 scope->is_eval_scope()) {
884 mode = PARSE_EAGERLY; 883 mode = PARSE_EAGERLY;
885 } 884 }
886 ParsingModeScope parsing_mode(this, mode); 885 ParsingModeScope parsing_mode(this, mode);
887 886
888 // Enters 'scope'. 887 // Enters 'scope'.
889 FunctionState function_state(&function_state_, &scope_, scope, zone()); 888 FunctionState function_state(&function_state_, &scope_, scope, zone(),
889 ast_value_factory_);
890 890
891 scope_->SetStrictMode(info->strict_mode()); 891 scope_->SetStrictMode(info->strict_mode());
892 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 892 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
893 bool ok = true; 893 bool ok = true;
894 int beg_pos = scanner()->location().beg_pos; 894 int beg_pos = scanner()->location().beg_pos;
895 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 895 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
896 if (ok && strict_mode() == STRICT) { 896 if (ok && strict_mode() == STRICT) {
897 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 897 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
898 } 898 }
899 899
900 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 900 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
901 CheckConflictingVarDeclarations(scope_, &ok); 901 CheckConflictingVarDeclarations(scope_, &ok);
902 } 902 }
903 903
904 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 904 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
905 if (body->length() != 1 || 905 if (body->length() != 1 ||
906 !body->at(0)->IsExpressionStatement() || 906 !body->at(0)->IsExpressionStatement() ||
907 !body->at(0)->AsExpressionStatement()-> 907 !body->at(0)->AsExpressionStatement()->
908 expression()->IsFunctionLiteral()) { 908 expression()->IsFunctionLiteral()) {
909 ReportMessage("single_function_literal"); 909 ReportMessage("single_function_literal");
910 ok = false; 910 ok = false;
911 } 911 }
912 } 912 }
913 913
914 ast_value_factory_->Internalize(isolate());
914 if (ok) { 915 if (ok) {
915 result = factory()->NewFunctionLiteral( 916 result = factory()->NewFunctionLiteral(
916 no_name, 917 ast_value_factory_->empty_string(),
918 ast_value_factory_,
917 scope_, 919 scope_,
918 body, 920 body,
919 function_state.materialized_literal_count(), 921 function_state.materialized_literal_count(),
920 function_state.expected_property_count(), 922 function_state.expected_property_count(),
921 function_state.handler_count(), 923 function_state.handler_count(),
922 0, 924 0,
923 FunctionLiteral::kNoDuplicateParameters, 925 FunctionLiteral::kNoDuplicateParameters,
924 FunctionLiteral::ANONYMOUS_EXPRESSION, 926 FunctionLiteral::ANONYMOUS_EXPRESSION,
925 FunctionLiteral::kGlobalOrEval, 927 FunctionLiteral::kGlobalOrEval,
926 FunctionLiteral::kNotParenthesized, 928 FunctionLiteral::kNotParenthesized,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 980 }
979 981
980 982
981 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { 983 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
982 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 984 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
983 scanner_.Initialize(source); 985 scanner_.Initialize(source);
984 ASSERT(scope_ == NULL); 986 ASSERT(scope_ == NULL);
985 ASSERT(target_stack_ == NULL); 987 ASSERT(target_stack_ == NULL);
986 988
987 Handle<String> name(String::cast(shared_info->name())); 989 Handle<String> name(String::cast(shared_info->name()));
988 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 990 ASSERT(ast_value_factory_);
989 fni_->PushEnclosingName(name); 991 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
992 const AstString* raw_name = ast_value_factory_->GetString(name);
993 fni_->PushEnclosingName(raw_name);
990 994
991 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 995 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
992 996
993 // Place holder for the result. 997 // Place holder for the result.
994 FunctionLiteral* result = NULL; 998 FunctionLiteral* result = NULL;
995 999
996 { 1000 {
997 // Parse the function literal. 1001 // Parse the function literal.
998 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 1002 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
999 info()->SetGlobalScope(scope); 1003 info()->SetGlobalScope(scope);
1000 if (!info()->closure().is_null()) { 1004 if (!info()->closure().is_null()) {
1001 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 1005 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
1002 zone()); 1006 zone());
1003 } 1007 }
1004 original_scope_ = scope; 1008 original_scope_ = scope;
1005 FunctionState function_state(&function_state_, &scope_, scope, zone()); 1009 FunctionState function_state(&function_state_, &scope_, scope, zone(),
1010 ast_value_factory_);
1006 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 1011 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
1007 ASSERT(info()->strict_mode() == shared_info->strict_mode()); 1012 ASSERT(info()->strict_mode() == shared_info->strict_mode());
1008 scope->SetStrictMode(shared_info->strict_mode()); 1013 scope->SetStrictMode(shared_info->strict_mode());
1009 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1014 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1010 ? (shared_info->is_anonymous() 1015 ? (shared_info->is_anonymous()
1011 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1016 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1012 : FunctionLiteral::NAMED_EXPRESSION) 1017 : FunctionLiteral::NAMED_EXPRESSION)
1013 : FunctionLiteral::DECLARATION; 1018 : FunctionLiteral::DECLARATION;
1014 bool ok = true; 1019 bool ok = true;
1015 result = ParseFunctionLiteral(name, 1020 result = ParseFunctionLiteral(raw_name,
1016 Scanner::Location::invalid(), 1021 Scanner::Location::invalid(),
1017 false, // Strict mode name already checked. 1022 false, // Strict mode name already checked.
1018 shared_info->is_generator(), 1023 shared_info->is_generator(),
1019 RelocInfo::kNoPosition, 1024 RelocInfo::kNoPosition,
1020 function_type, 1025 function_type,
1021 FunctionLiteral::NORMAL_ARITY, 1026 FunctionLiteral::NORMAL_ARITY,
1022 &ok); 1027 &ok);
1023 // Make sure the results agree. 1028 // Make sure the results agree.
1024 ASSERT(ok == (result != NULL)); 1029 ASSERT(ok == (result != NULL));
1025 } 1030 }
1026 1031
1027 // Make sure the target stack is empty. 1032 // Make sure the target stack is empty.
1028 ASSERT(target_stack_ == NULL); 1033 ASSERT(target_stack_ == NULL);
1029 1034
1035 ast_value_factory_->Internalize(isolate());
1030 if (result == NULL) { 1036 if (result == NULL) {
1031 if (stack_overflow()) { 1037 if (stack_overflow()) {
1032 isolate()->StackOverflow(); 1038 isolate()->StackOverflow();
1033 } else { 1039 } else {
1034 ThrowPendingError(); 1040 ThrowPendingError();
1035 } 1041 }
1036 } else { 1042 } else {
1037 Handle<String> inferred_name(shared_info->inferred_name()); 1043 Handle<String> inferred_name(shared_info->inferred_name());
1038 result->set_inferred_name(inferred_name); 1044 result->set_inferred_name(inferred_name);
1039 } 1045 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 continue; 1081 continue;
1076 } 1082 }
1077 1083
1078 if (directive_prologue) { 1084 if (directive_prologue) {
1079 // A shot at a directive. 1085 // A shot at a directive.
1080 ExpressionStatement* e_stat; 1086 ExpressionStatement* e_stat;
1081 Literal* literal; 1087 Literal* literal;
1082 // Still processing directive prologue? 1088 // Still processing directive prologue?
1083 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1089 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1084 (literal = e_stat->expression()->AsLiteral()) != NULL && 1090 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1085 literal->value()->IsString()) { 1091 literal->raw_value()->IsString()) {
1086 Handle<String> directive = Handle<String>::cast(literal->value());
1087
1088 // Check "use strict" directive (ES5 14.1). 1092 // Check "use strict" directive (ES5 14.1).
1089 if (strict_mode() == SLOPPY && 1093 if (strict_mode() == SLOPPY &&
1090 String::Equals(isolate()->factory()->use_strict_string(), 1094 literal->raw_value()->AsString() ==
1091 directive) && 1095 ast_value_factory_->use_strict_string() &&
1092 token_loc.end_pos - token_loc.beg_pos == 1096 token_loc.end_pos - token_loc.beg_pos == 12) {
1093 isolate()->heap()->use_strict_string()->length() + 2) {
1094 // TODO(mstarzinger): Global strict eval calls, need their own scope 1097 // TODO(mstarzinger): Global strict eval calls, need their own scope
1095 // as specified in ES5 10.4.2(3). The correct fix would be to always 1098 // as specified in ES5 10.4.2(3). The correct fix would be to always
1096 // add this scope in DoParseProgram(), but that requires adaptations 1099 // add this scope in DoParseProgram(), but that requires adaptations
1097 // all over the code base, so we go with a quick-fix for now. 1100 // all over the code base, so we go with a quick-fix for now.
1098 // In the same manner, we have to patch the parsing mode. 1101 // In the same manner, we have to patch the parsing mode.
1099 if (is_eval && !scope_->is_eval_scope()) { 1102 if (is_eval && !scope_->is_eval_scope()) {
1100 ASSERT(scope_->is_global_scope()); 1103 ASSERT(scope_->is_global_scope());
1101 Scope* scope = NewScope(scope_, EVAL_SCOPE); 1104 Scope* scope = NewScope(scope_, EVAL_SCOPE);
1102 scope->set_start_position(scope_->start_position()); 1105 scope->set_start_position(scope_->start_position());
1103 scope->set_end_position(scope_->end_position()); 1106 scope->set_end_position(scope_->end_position());
(...skipping 10 matching lines...) Expand all
1114 } 1117 }
1115 } 1118 }
1116 1119
1117 processor->Add(stat, zone()); 1120 processor->Add(stat, zone());
1118 } 1121 }
1119 1122
1120 return 0; 1123 return 0;
1121 } 1124 }
1122 1125
1123 1126
1124 Statement* Parser::ParseModuleElement(ZoneStringList* labels, 1127 Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels,
1125 bool* ok) { 1128 bool* ok) {
1126 // (Ecma 262 5th Edition, clause 14): 1129 // (Ecma 262 5th Edition, clause 14):
1127 // SourceElement: 1130 // SourceElement:
1128 // Statement 1131 // Statement
1129 // FunctionDeclaration 1132 // FunctionDeclaration
1130 // 1133 //
1131 // In harmony mode we allow additionally the following productions 1134 // In harmony mode we allow additionally the following productions
1132 // ModuleElement: 1135 // ModuleElement:
1133 // LetDeclaration 1136 // LetDeclaration
1134 // ConstDeclaration 1137 // ConstDeclaration
(...skipping 13 matching lines...) Expand all
1148 case Token::EXPORT: 1151 case Token::EXPORT:
1149 return ParseExportDeclaration(ok); 1152 return ParseExportDeclaration(ok);
1150 default: { 1153 default: {
1151 Statement* stmt = ParseStatement(labels, CHECK_OK); 1154 Statement* stmt = ParseStatement(labels, CHECK_OK);
1152 // Handle 'module' as a context-sensitive keyword. 1155 // Handle 'module' as a context-sensitive keyword.
1153 if (FLAG_harmony_modules && 1156 if (FLAG_harmony_modules &&
1154 peek() == Token::IDENTIFIER && 1157 peek() == Token::IDENTIFIER &&
1155 !scanner()->HasAnyLineTerminatorBeforeNext() && 1158 !scanner()->HasAnyLineTerminatorBeforeNext() &&
1156 stmt != NULL) { 1159 stmt != NULL) {
1157 ExpressionStatement* estmt = stmt->AsExpressionStatement(); 1160 ExpressionStatement* estmt = stmt->AsExpressionStatement();
1158 if (estmt != NULL && 1161 if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL &&
1159 estmt->expression()->AsVariableProxy() != NULL && 1162 estmt->expression()->AsVariableProxy()->raw_name() ==
1160 String::Equals(isolate()->factory()->module_string(), 1163 ast_value_factory_->module_string() &&
1161 estmt->expression()->AsVariableProxy()->name()) &&
1162 !scanner()->literal_contains_escapes()) { 1164 !scanner()->literal_contains_escapes()) {
1163 return ParseModuleDeclaration(NULL, ok); 1165 return ParseModuleDeclaration(NULL, ok);
1164 } 1166 }
1165 } 1167 }
1166 return stmt; 1168 return stmt;
1167 } 1169 }
1168 } 1170 }
1169 } 1171 }
1170 1172
1171 1173
1172 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 1174 Statement* Parser::ParseModuleDeclaration(ZoneList<const AstString*>* names,
1175 bool* ok) {
1173 // ModuleDeclaration: 1176 // ModuleDeclaration:
1174 // 'module' Identifier Module 1177 // 'module' Identifier Module
1175 1178
1176 int pos = peek_position(); 1179 int pos = peek_position();
1177 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1180 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1178 1181
1179 #ifdef DEBUG 1182 #ifdef DEBUG
1180 if (FLAG_print_interface_details) 1183 if (FLAG_print_interface_details)
1181 PrintF("# Module %s...\n", name->ToAsciiArray()); 1184 PrintF("# Module %.*s ", name->length(), name->raw_data());
1182 #endif 1185 #endif
1183 1186
1184 Module* module = ParseModule(CHECK_OK); 1187 Module* module = ParseModule(CHECK_OK);
1185 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); 1188 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface());
1186 Declaration* declaration = 1189 Declaration* declaration =
1187 factory()->NewModuleDeclaration(proxy, module, scope_, pos); 1190 factory()->NewModuleDeclaration(proxy, module, scope_, pos);
1188 Declare(declaration, true, CHECK_OK); 1191 Declare(declaration, true, CHECK_OK);
1189 1192
1190 #ifdef DEBUG 1193 #ifdef DEBUG
1191 if (FLAG_print_interface_details) 1194 if (FLAG_print_interface_details)
1192 PrintF("# Module %s.\n", name->ToAsciiArray()); 1195 PrintF("# Module %.*s ", name->length(), name->raw_data());
1193
1194 if (FLAG_print_interfaces) { 1196 if (FLAG_print_interfaces) {
1195 PrintF("module %s : ", name->ToAsciiArray()); 1197 PrintF("module %.*s: ", name->length(), name->raw_data());
1196 module->interface()->Print(); 1198 module->interface()->Print();
1197 } 1199 }
1198 #endif 1200 #endif
1199 1201
1200 if (names) names->Add(name, zone()); 1202 if (names) names->Add(name, zone());
1201 if (module->body() == NULL) 1203 if (module->body() == NULL)
1202 return factory()->NewEmptyStatement(pos); 1204 return factory()->NewEmptyStatement(pos);
1203 else 1205 else
1204 return factory()->NewModuleStatement(proxy, module->body(), pos); 1206 return factory()->NewModuleStatement(proxy, module->body(), pos);
1205 } 1207 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1288
1287 1289
1288 Module* Parser::ParseModulePath(bool* ok) { 1290 Module* Parser::ParseModulePath(bool* ok) {
1289 // ModulePath: 1291 // ModulePath:
1290 // Identifier 1292 // Identifier
1291 // ModulePath '.' Identifier 1293 // ModulePath '.' Identifier
1292 1294
1293 int pos = peek_position(); 1295 int pos = peek_position();
1294 Module* result = ParseModuleVariable(CHECK_OK); 1296 Module* result = ParseModuleVariable(CHECK_OK);
1295 while (Check(Token::PERIOD)) { 1297 while (Check(Token::PERIOD)) {
1296 Handle<String> name = ParseIdentifierName(CHECK_OK); 1298 const AstString* name = ParseIdentifierName(CHECK_OK);
1297 #ifdef DEBUG 1299 #ifdef DEBUG
1298 if (FLAG_print_interface_details) 1300 if (FLAG_print_interface_details)
1299 PrintF("# Path .%s ", name->ToAsciiArray()); 1301 PrintF("# Path .%.*s ", name->length(), name->raw_data());
1300 #endif 1302 #endif
1301 Module* member = factory()->NewModulePath(result, name, pos); 1303 Module* member = factory()->NewModulePath(result, name, pos);
1302 result->interface()->Add(name, member->interface(), zone(), ok); 1304 result->interface()->Add(name, member->interface(), zone(), ok);
1303 if (!*ok) { 1305 if (!*ok) {
1304 #ifdef DEBUG 1306 #ifdef DEBUG
1305 if (FLAG_print_interfaces) { 1307 if (FLAG_print_interfaces) {
1306 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); 1308 PrintF("PATH TYPE ERROR at '%.*s'\n", name->length(), name->raw_data());
1307 PrintF("result: "); 1309 PrintF("result: ");
1308 result->interface()->Print(); 1310 result->interface()->Print();
1309 PrintF("member: "); 1311 PrintF("member: ");
1310 member->interface()->Print(); 1312 member->interface()->Print();
1311 } 1313 }
1312 #endif 1314 #endif
1313 ParserTraits::ReportMessage("invalid_module_path", name); 1315 ParserTraits::ReportMessage("invalid_module_path", name);
1314 return NULL; 1316 return NULL;
1315 } 1317 }
1316 result = member; 1318 result = member;
1317 } 1319 }
1318 1320
1319 return result; 1321 return result;
1320 } 1322 }
1321 1323
1322 1324
1323 Module* Parser::ParseModuleVariable(bool* ok) { 1325 Module* Parser::ParseModuleVariable(bool* ok) {
1324 // ModulePath: 1326 // ModulePath:
1325 // Identifier 1327 // Identifier
1326 1328
1327 int pos = peek_position(); 1329 int pos = peek_position();
1328 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1330 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1329 #ifdef DEBUG 1331 #ifdef DEBUG
1330 if (FLAG_print_interface_details) 1332 if (FLAG_print_interface_details)
1331 PrintF("# Module variable %s ", name->ToAsciiArray()); 1333 PrintF("# Module variable %.*s ", name->length(), name->raw_data());
1332 #endif 1334 #endif
1333 VariableProxy* proxy = scope_->NewUnresolved( 1335 VariableProxy* proxy = scope_->NewUnresolved(
1334 factory(), name, Interface::NewModule(zone()), 1336 factory(), name, Interface::NewModule(zone()),
1335 scanner()->location().beg_pos); 1337 scanner()->location().beg_pos);
1336 1338
1337 return factory()->NewModuleVariable(proxy, pos); 1339 return factory()->NewModuleVariable(proxy, pos);
1338 } 1340 }
1339 1341
1340 1342
1341 Module* Parser::ParseModuleUrl(bool* ok) { 1343 Module* Parser::ParseModuleUrl(bool* ok) {
1342 // Module: 1344 // Module:
1343 // String 1345 // String
1344 1346
1345 int pos = peek_position(); 1347 int pos = peek_position();
1346 Expect(Token::STRING, CHECK_OK); 1348 Expect(Token::STRING, CHECK_OK);
1347 Handle<String> symbol = GetSymbol(); 1349 const AstString* symbol = GetSymbol(scanner());
1348 1350
1349 // TODO(ES6): Request JS resource from environment... 1351 // TODO(ES6): Request JS resource from environment...
1350 1352
1351 #ifdef DEBUG 1353 #ifdef DEBUG
1352 if (FLAG_print_interface_details) PrintF("# Url "); 1354 if (FLAG_print_interface_details) PrintF("# Url ");
1353 #endif 1355 #endif
1354 1356
1355 // Create an empty literal as long as the feature isn't finished. 1357 // Create an empty literal as long as the feature isn't finished.
1356 USE(symbol); 1358 USE(symbol);
1357 Scope* scope = NewScope(scope_, MODULE_SCOPE); 1359 Scope* scope = NewScope(scope_, MODULE_SCOPE);
(...skipping 23 matching lines...) Expand all
1381 1383
1382 1384
1383 Block* Parser::ParseImportDeclaration(bool* ok) { 1385 Block* Parser::ParseImportDeclaration(bool* ok) {
1384 // ImportDeclaration: 1386 // ImportDeclaration:
1385 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' 1387 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';'
1386 // 1388 //
1387 // TODO(ES6): implement destructuring ImportSpecifiers 1389 // TODO(ES6): implement destructuring ImportSpecifiers
1388 1390
1389 int pos = peek_position(); 1391 int pos = peek_position();
1390 Expect(Token::IMPORT, CHECK_OK); 1392 Expect(Token::IMPORT, CHECK_OK);
1391 ZoneStringList names(1, zone()); 1393 ZoneList<const AstString*> names(1, zone());
1392 1394
1393 Handle<String> name = ParseIdentifierName(CHECK_OK); 1395 const AstString* name = ParseIdentifierName(CHECK_OK);
1394 names.Add(name, zone()); 1396 names.Add(name, zone());
1395 while (peek() == Token::COMMA) { 1397 while (peek() == Token::COMMA) {
1396 Consume(Token::COMMA); 1398 Consume(Token::COMMA);
1397 name = ParseIdentifierName(CHECK_OK); 1399 name = ParseIdentifierName(CHECK_OK);
1398 names.Add(name, zone()); 1400 names.Add(name, zone());
1399 } 1401 }
1400 1402
1401 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1403 ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
1402 Module* module = ParseModuleSpecifier(CHECK_OK); 1404 Module* module = ParseModuleSpecifier(CHECK_OK);
1403 ExpectSemicolon(CHECK_OK); 1405 ExpectSemicolon(CHECK_OK);
1404 1406
1405 // Generate a separate declaration for each identifier. 1407 // Generate a separate declaration for each identifier.
1406 // TODO(ES6): once we implement destructuring, make that one declaration. 1408 // TODO(ES6): once we implement destructuring, make that one declaration.
1407 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); 1409 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
1408 for (int i = 0; i < names.length(); ++i) { 1410 for (int i = 0; i < names.length(); ++i) {
1409 #ifdef DEBUG 1411 #ifdef DEBUG
1410 if (FLAG_print_interface_details) 1412 if (FLAG_print_interface_details)
1411 PrintF("# Import %s ", names[i]->ToAsciiArray()); 1413 PrintF("# Import %.*s ", name->length(), name->raw_data());
1412 #endif 1414 #endif
1413 Interface* interface = Interface::NewUnknown(zone()); 1415 Interface* interface = Interface::NewUnknown(zone());
1414 module->interface()->Add(names[i], interface, zone(), ok); 1416 module->interface()->Add(names[i], interface, zone(), ok);
1415 if (!*ok) { 1417 if (!*ok) {
1416 #ifdef DEBUG 1418 #ifdef DEBUG
1417 if (FLAG_print_interfaces) { 1419 if (FLAG_print_interfaces) {
1418 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); 1420 PrintF("IMPORT TYPE ERROR at '%.*s'\n", name->length(),
1421 name->raw_data());
1419 PrintF("module: "); 1422 PrintF("module: ");
1420 module->interface()->Print(); 1423 module->interface()->Print();
1421 } 1424 }
1422 #endif 1425 #endif
1423 ParserTraits::ReportMessage("invalid_module_path", name); 1426 ParserTraits::ReportMessage("invalid_module_path", name);
1424 return NULL; 1427 return NULL;
1425 } 1428 }
1426 VariableProxy* proxy = NewUnresolved(names[i], LET, interface); 1429 VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
1427 Declaration* declaration = 1430 Declaration* declaration =
1428 factory()->NewImportDeclaration(proxy, module, scope_, pos); 1431 factory()->NewImportDeclaration(proxy, module, scope_, pos);
(...skipping 10 matching lines...) Expand all
1439 // 'export' VariableDeclaration 1442 // 'export' VariableDeclaration
1440 // 'export' FunctionDeclaration 1443 // 'export' FunctionDeclaration
1441 // 'export' GeneratorDeclaration 1444 // 'export' GeneratorDeclaration
1442 // 'export' ModuleDeclaration 1445 // 'export' ModuleDeclaration
1443 // 1446 //
1444 // TODO(ES6): implement structuring ExportSpecifiers 1447 // TODO(ES6): implement structuring ExportSpecifiers
1445 1448
1446 Expect(Token::EXPORT, CHECK_OK); 1449 Expect(Token::EXPORT, CHECK_OK);
1447 1450
1448 Statement* result = NULL; 1451 Statement* result = NULL;
1449 ZoneStringList names(1, zone()); 1452 ZoneList<const AstString*> names(1, zone());
1450 switch (peek()) { 1453 switch (peek()) {
1451 case Token::IDENTIFIER: { 1454 case Token::IDENTIFIER: {
1452 int pos = position(); 1455 int pos = position();
1453 Handle<String> name = 1456 const AstString* name =
1454 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1457 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1455 // Handle 'module' as a context-sensitive keyword. 1458 // Handle 'module' as a context-sensitive keyword.
1456 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { 1459 if (name != ast_value_factory_->module_string()) {
1457 names.Add(name, zone()); 1460 names.Add(name, zone());
1458 while (peek() == Token::COMMA) { 1461 while (peek() == Token::COMMA) {
1459 Consume(Token::COMMA); 1462 Consume(Token::COMMA);
1460 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1463 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1461 names.Add(name, zone()); 1464 names.Add(name, zone());
1462 } 1465 }
1463 ExpectSemicolon(CHECK_OK); 1466 ExpectSemicolon(CHECK_OK);
1464 result = factory()->NewEmptyStatement(pos); 1467 result = factory()->NewEmptyStatement(pos);
1465 } else { 1468 } else {
1466 result = ParseModuleDeclaration(&names, CHECK_OK); 1469 result = ParseModuleDeclaration(&names, CHECK_OK);
(...skipping 15 matching lines...) Expand all
1482 *ok = false; 1485 *ok = false;
1483 ReportUnexpectedToken(scanner()->current_token()); 1486 ReportUnexpectedToken(scanner()->current_token());
1484 return NULL; 1487 return NULL;
1485 } 1488 }
1486 1489
1487 // Extract declared names into export declarations and interface. 1490 // Extract declared names into export declarations and interface.
1488 Interface* interface = scope_->interface(); 1491 Interface* interface = scope_->interface();
1489 for (int i = 0; i < names.length(); ++i) { 1492 for (int i = 0; i < names.length(); ++i) {
1490 #ifdef DEBUG 1493 #ifdef DEBUG
1491 if (FLAG_print_interface_details) 1494 if (FLAG_print_interface_details)
1492 PrintF("# Export %s ", names[i]->ToAsciiArray()); 1495 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data());
1493 #endif 1496 #endif
1494 Interface* inner = Interface::NewUnknown(zone()); 1497 Interface* inner = Interface::NewUnknown(zone());
1495 interface->Add(names[i], inner, zone(), CHECK_OK); 1498 interface->Add(names[i], inner, zone(), CHECK_OK);
1496 if (!*ok) 1499 if (!*ok)
1497 return NULL; 1500 return NULL;
1498 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); 1501 VariableProxy* proxy = NewUnresolved(names[i], LET, inner);
1499 USE(proxy); 1502 USE(proxy);
1500 // TODO(rossberg): Rethink whether we actually need to store export 1503 // TODO(rossberg): Rethink whether we actually need to store export
1501 // declarations (for compilation?). 1504 // declarations (for compilation?).
1502 // ExportDeclaration* declaration = 1505 // ExportDeclaration* declaration =
1503 // factory()->NewExportDeclaration(proxy, scope_, position); 1506 // factory()->NewExportDeclaration(proxy, scope_, position);
1504 // scope_->AddDeclaration(declaration); 1507 // scope_->AddDeclaration(declaration);
1505 } 1508 }
1506 1509
1507 ASSERT(result != NULL); 1510 ASSERT(result != NULL);
1508 return result; 1511 return result;
1509 } 1512 }
1510 1513
1511 1514
1512 Statement* Parser::ParseBlockElement(ZoneStringList* labels, 1515 Statement* Parser::ParseBlockElement(ZoneList<const AstString*>* labels,
1513 bool* ok) { 1516 bool* ok) {
1514 // (Ecma 262 5th Edition, clause 14): 1517 // (Ecma 262 5th Edition, clause 14):
1515 // SourceElement: 1518 // SourceElement:
1516 // Statement 1519 // Statement
1517 // FunctionDeclaration 1520 // FunctionDeclaration
1518 // 1521 //
1519 // In harmony mode we allow additionally the following productions 1522 // In harmony mode we allow additionally the following productions
1520 // BlockElement (aka SourceElement): 1523 // BlockElement (aka SourceElement):
1521 // LetDeclaration 1524 // LetDeclaration
1522 // ConstDeclaration 1525 // ConstDeclaration
1523 // GeneratorDeclaration 1526 // GeneratorDeclaration
1524 1527
1525 switch (peek()) { 1528 switch (peek()) {
1526 case Token::FUNCTION: 1529 case Token::FUNCTION:
1527 return ParseFunctionDeclaration(NULL, ok); 1530 return ParseFunctionDeclaration(NULL, ok);
1528 case Token::LET: 1531 case Token::LET:
1529 case Token::CONST: 1532 case Token::CONST:
1530 return ParseVariableStatement(kModuleElement, NULL, ok); 1533 return ParseVariableStatement(kModuleElement, NULL, ok);
1531 default: 1534 default:
1532 return ParseStatement(labels, ok); 1535 return ParseStatement(labels, ok);
1533 } 1536 }
1534 } 1537 }
1535 1538
1536 1539
1537 Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { 1540 Statement* Parser::ParseStatement(ZoneList<const AstString*>* labels,
1541 bool* ok) {
1538 // Statement :: 1542 // Statement ::
1539 // Block 1543 // Block
1540 // VariableStatement 1544 // VariableStatement
1541 // EmptyStatement 1545 // EmptyStatement
1542 // ExpressionStatement 1546 // ExpressionStatement
1543 // IfStatement 1547 // IfStatement
1544 // IterationStatement 1548 // IterationStatement
1545 // ContinueStatement 1549 // ContinueStatement
1546 // BreakStatement 1550 // BreakStatement
1547 // ReturnStatement 1551 // ReturnStatement
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 1641
1638 case Token::DEBUGGER: 1642 case Token::DEBUGGER:
1639 return ParseDebuggerStatement(ok); 1643 return ParseDebuggerStatement(ok);
1640 1644
1641 default: 1645 default:
1642 return ParseExpressionOrLabelledStatement(labels, ok); 1646 return ParseExpressionOrLabelledStatement(labels, ok);
1643 } 1647 }
1644 } 1648 }
1645 1649
1646 1650
1647 VariableProxy* Parser::NewUnresolved( 1651 VariableProxy* Parser::NewUnresolved(const AstString* name, VariableMode mode,
1648 Handle<String> name, VariableMode mode, Interface* interface) { 1652 Interface* interface) {
1649 // If we are inside a function, a declaration of a var/const variable is a 1653 // If we are inside a function, a declaration of a var/const variable is a
1650 // truly local variable, and the scope of the variable is always the function 1654 // truly local variable, and the scope of the variable is always the function
1651 // scope. 1655 // scope.
1652 // Let/const variables in harmony mode are always added to the immediately 1656 // Let/const variables in harmony mode are always added to the immediately
1653 // enclosing scope. 1657 // enclosing scope.
1654 return DeclarationScope(mode)->NewUnresolved( 1658 return DeclarationScope(mode)->NewUnresolved(
1655 factory(), name, interface, position()); 1659 factory(), name, interface, position());
1656 } 1660 }
1657 1661
1658 1662
1659 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { 1663 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
1660 VariableProxy* proxy = declaration->proxy(); 1664 VariableProxy* proxy = declaration->proxy();
1661 Handle<String> name = proxy->name(); 1665 ASSERT(proxy->raw_name() != NULL);
1666 const AstString* name = proxy->raw_name();
1662 VariableMode mode = declaration->mode(); 1667 VariableMode mode = declaration->mode();
1663 Scope* declaration_scope = DeclarationScope(mode); 1668 Scope* declaration_scope = DeclarationScope(mode);
1664 Variable* var = NULL; 1669 Variable* var = NULL;
1665 1670
1666 // If a suitable scope exists, then we can statically declare this 1671 // If a suitable scope exists, then we can statically declare this
1667 // variable and also set its mode. In any case, a Declaration node 1672 // variable and also set its mode. In any case, a Declaration node
1668 // will be added to the scope so that the declaration can be added 1673 // will be added to the scope so that the declaration can be added
1669 // to the corresponding activation frame at runtime if necessary. 1674 // to the corresponding activation frame at runtime if necessary.
1670 // For instance declarations inside an eval scope need to be added 1675 // For instance declarations inside an eval scope need to be added
1671 // to the calling function context. 1676 // to the calling function context.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 // with a context slot index and a context chain length for this 1784 // with a context slot index and a context chain length for this
1780 // initialization code. Thus, inside the 'with' statement, we need 1785 // initialization code. Thus, inside the 'with' statement, we need
1781 // both access to the static and the dynamic context chain; the 1786 // both access to the static and the dynamic context chain; the
1782 // runtime needs to provide both. 1787 // runtime needs to provide both.
1783 if (resolve && var != NULL) { 1788 if (resolve && var != NULL) {
1784 proxy->BindTo(var); 1789 proxy->BindTo(var);
1785 1790
1786 if (FLAG_harmony_modules) { 1791 if (FLAG_harmony_modules) {
1787 bool ok; 1792 bool ok;
1788 #ifdef DEBUG 1793 #ifdef DEBUG
1789 if (FLAG_print_interface_details) 1794 if (FLAG_print_interface_details) {
1790 PrintF("# Declare %s\n", var->name()->ToAsciiArray()); 1795 PrintF("# Declare %.*s ", var->raw_name()->length(),
1796 var->raw_name()->raw_data());
1797 }
1791 #endif 1798 #endif
1792 proxy->interface()->Unify(var->interface(), zone(), &ok); 1799 proxy->interface()->Unify(var->interface(), zone(), &ok);
1793 if (!ok) { 1800 if (!ok) {
1794 #ifdef DEBUG 1801 #ifdef DEBUG
1795 if (FLAG_print_interfaces) { 1802 if (FLAG_print_interfaces) {
1796 PrintF("DECLARE TYPE ERROR\n"); 1803 PrintF("DECLARE TYPE ERROR\n");
1797 PrintF("proxy: "); 1804 PrintF("proxy: ");
1798 proxy->interface()->Print(); 1805 proxy->interface()->Print();
1799 PrintF("var: "); 1806 PrintF("var: ");
1800 var->interface()->Print(); 1807 var->interface()->Print();
1801 } 1808 }
1802 #endif 1809 #endif
1803 ParserTraits::ReportMessage("module_type_error", name); 1810 ParserTraits::ReportMessage("module_type_error", name);
1804 } 1811 }
1805 } 1812 }
1806 } 1813 }
1807 } 1814 }
1808 1815
1809 1816
1810 // Language extension which is only enabled for source files loaded 1817 // Language extension which is only enabled for source files loaded
1811 // through the API's extension mechanism. A native function 1818 // through the API's extension mechanism. A native function
1812 // declaration is resolved by looking up the function through a 1819 // declaration is resolved by looking up the function through a
1813 // callback provided by the extension. 1820 // callback provided by the extension.
1814 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1821 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1815 int pos = peek_position(); 1822 int pos = peek_position();
1816 Expect(Token::FUNCTION, CHECK_OK); 1823 Expect(Token::FUNCTION, CHECK_OK);
1817 // Allow "eval" or "arguments" for backward compatibility. 1824 // Allow "eval" or "arguments" for backward compatibility.
1818 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1825 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1819 Expect(Token::LPAREN, CHECK_OK); 1826 Expect(Token::LPAREN, CHECK_OK);
1820 bool done = (peek() == Token::RPAREN); 1827 bool done = (peek() == Token::RPAREN);
1821 while (!done) { 1828 while (!done) {
1822 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1829 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1823 done = (peek() == Token::RPAREN); 1830 done = (peek() == Token::RPAREN);
1824 if (!done) { 1831 if (!done) {
1825 Expect(Token::COMMA, CHECK_OK); 1832 Expect(Token::COMMA, CHECK_OK);
1826 } 1833 }
1827 } 1834 }
1828 Expect(Token::RPAREN, CHECK_OK); 1835 Expect(Token::RPAREN, CHECK_OK);
(...skipping 14 matching lines...) Expand all
1843 Declare(declaration, true, CHECK_OK); 1850 Declare(declaration, true, CHECK_OK);
1844 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( 1851 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(
1845 name, extension_, RelocInfo::kNoPosition); 1852 name, extension_, RelocInfo::kNoPosition);
1846 return factory()->NewExpressionStatement( 1853 return factory()->NewExpressionStatement(
1847 factory()->NewAssignment( 1854 factory()->NewAssignment(
1848 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), 1855 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition),
1849 pos); 1856 pos);
1850 } 1857 }
1851 1858
1852 1859
1853 Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { 1860 Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names,
1861 bool* ok) {
1854 // FunctionDeclaration :: 1862 // FunctionDeclaration ::
1855 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1863 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1856 // GeneratorDeclaration :: 1864 // GeneratorDeclaration ::
1857 // 'function' '*' Identifier '(' FormalParameterListopt ')' 1865 // 'function' '*' Identifier '(' FormalParameterListopt ')'
1858 // '{' FunctionBody '}' 1866 // '{' FunctionBody '}'
1859 Expect(Token::FUNCTION, CHECK_OK); 1867 Expect(Token::FUNCTION, CHECK_OK);
1860 int pos = position(); 1868 int pos = position();
1861 bool is_generator = allow_generators() && Check(Token::MUL); 1869 bool is_generator = allow_generators() && Check(Token::MUL);
1862 bool is_strict_reserved = false; 1870 bool is_strict_reserved = false;
1863 Handle<String> name = ParseIdentifierOrStrictReservedWord( 1871 const AstString* name = ParseIdentifierOrStrictReservedWord(
1864 &is_strict_reserved, CHECK_OK); 1872 &is_strict_reserved, CHECK_OK);
1865 FunctionLiteral* fun = ParseFunctionLiteral(name, 1873 FunctionLiteral* fun = ParseFunctionLiteral(name,
1866 scanner()->location(), 1874 scanner()->location(),
1867 is_strict_reserved, 1875 is_strict_reserved,
1868 is_generator, 1876 is_generator,
1869 pos, 1877 pos,
1870 FunctionLiteral::DECLARATION, 1878 FunctionLiteral::DECLARATION,
1871 FunctionLiteral::NORMAL_ARITY, 1879 FunctionLiteral::NORMAL_ARITY,
1872 CHECK_OK); 1880 CHECK_OK);
1873 // Even if we're not at the top-level of the global or a function 1881 // Even if we're not at the top-level of the global or a function
1874 // scope, we treat it as such and introduce the function with its 1882 // scope, we treat it as such and introduce the function with its
1875 // initial value upon entering the corresponding scope. 1883 // initial value upon entering the corresponding scope.
1876 // In extended mode, a function behaves as a lexical binding, except in the 1884 // In extended mode, a function behaves as a lexical binding, except in the
1877 // global scope. 1885 // global scope.
1878 VariableMode mode = 1886 VariableMode mode =
1879 allow_harmony_scoping() && 1887 allow_harmony_scoping() &&
1880 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR; 1888 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR;
1881 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); 1889 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
1882 Declaration* declaration = 1890 Declaration* declaration =
1883 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 1891 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
1884 Declare(declaration, true, CHECK_OK); 1892 Declare(declaration, true, CHECK_OK);
1885 if (names) names->Add(name, zone()); 1893 if (names) names->Add(name, zone());
1886 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1894 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1887 } 1895 }
1888 1896
1889 1897
1890 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1898 Block* Parser::ParseBlock(ZoneList<const AstString*>* labels, bool* ok) {
1891 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1899 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1892 return ParseScopedBlock(labels, ok); 1900 return ParseScopedBlock(labels, ok);
1893 } 1901 }
1894 1902
1895 // Block :: 1903 // Block ::
1896 // '{' Statement* '}' 1904 // '{' Statement* '}'
1897 1905
1898 // Note that a Block does not introduce a new execution scope! 1906 // Note that a Block does not introduce a new execution scope!
1899 // (ECMA-262, 3rd, 12.2) 1907 // (ECMA-262, 3rd, 12.2)
1900 // 1908 //
1901 // Construct block expecting 16 statements. 1909 // Construct block expecting 16 statements.
1902 Block* result = 1910 Block* result =
1903 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1911 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1904 Target target(&this->target_stack_, result); 1912 Target target(&this->target_stack_, result);
1905 Expect(Token::LBRACE, CHECK_OK); 1913 Expect(Token::LBRACE, CHECK_OK);
1906 while (peek() != Token::RBRACE) { 1914 while (peek() != Token::RBRACE) {
1907 Statement* stat = ParseStatement(NULL, CHECK_OK); 1915 Statement* stat = ParseStatement(NULL, CHECK_OK);
1908 if (stat && !stat->IsEmpty()) { 1916 if (stat && !stat->IsEmpty()) {
1909 result->AddStatement(stat, zone()); 1917 result->AddStatement(stat, zone());
1910 } 1918 }
1911 } 1919 }
1912 Expect(Token::RBRACE, CHECK_OK); 1920 Expect(Token::RBRACE, CHECK_OK);
1913 return result; 1921 return result;
1914 } 1922 }
1915 1923
1916 1924
1917 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 1925 Block* Parser::ParseScopedBlock(ZoneList<const AstString*>* labels, bool* ok) {
1918 // The harmony mode uses block elements instead of statements. 1926 // The harmony mode uses block elements instead of statements.
1919 // 1927 //
1920 // Block :: 1928 // Block ::
1921 // '{' BlockElement* '}' 1929 // '{' BlockElement* '}'
1922 1930
1923 // Construct block expecting 16 statements. 1931 // Construct block expecting 16 statements.
1924 Block* body = 1932 Block* body =
1925 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1933 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1926 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 1934 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
1927 1935
(...skipping 14 matching lines...) Expand all
1942 } 1950 }
1943 Expect(Token::RBRACE, CHECK_OK); 1951 Expect(Token::RBRACE, CHECK_OK);
1944 block_scope->set_end_position(scanner()->location().end_pos); 1952 block_scope->set_end_position(scanner()->location().end_pos);
1945 block_scope = block_scope->FinalizeBlockScope(); 1953 block_scope = block_scope->FinalizeBlockScope();
1946 body->set_scope(block_scope); 1954 body->set_scope(block_scope);
1947 return body; 1955 return body;
1948 } 1956 }
1949 1957
1950 1958
1951 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, 1959 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context,
1952 ZoneStringList* names, 1960 ZoneList<const AstString*>* names,
1953 bool* ok) { 1961 bool* ok) {
1954 // VariableStatement :: 1962 // VariableStatement ::
1955 // VariableDeclarations ';' 1963 // VariableDeclarations ';'
1956 1964
1957 Handle<String> ignore; 1965 const AstString* ignore;
1958 Block* result = 1966 Block* result =
1959 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK); 1967 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK);
1960 ExpectSemicolon(CHECK_OK); 1968 ExpectSemicolon(CHECK_OK);
1961 return result; 1969 return result;
1962 } 1970 }
1963 1971
1964 1972
1965 // If the variable declaration declares exactly one non-const 1973 // If the variable declaration declares exactly one non-const
1966 // variable, then *out is set to that variable. In all other cases, 1974 // variable, then *out is set to that variable. In all other cases,
1967 // *out is untouched; in particular, it is the caller's responsibility 1975 // *out is untouched; in particular, it is the caller's responsibility
1968 // to initialize it properly. This mechanism is used for the parsing 1976 // to initialize it properly. This mechanism is used for the parsing
1969 // of 'for-in' loops. 1977 // of 'for-in' loops.
1970 Block* Parser::ParseVariableDeclarations( 1978 Block* Parser::ParseVariableDeclarations(
1971 VariableDeclarationContext var_context, 1979 VariableDeclarationContext var_context,
1972 VariableDeclarationProperties* decl_props, 1980 VariableDeclarationProperties* decl_props,
1973 ZoneStringList* names, 1981 ZoneList<const AstString*>* names,
1974 Handle<String>* out, 1982 const AstString** out,
1975 bool* ok) { 1983 bool* ok) {
1976 // VariableDeclarations :: 1984 // VariableDeclarations ::
1977 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] 1985 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
1978 // 1986 //
1979 // The ES6 Draft Rev3 specifies the following grammar for const declarations 1987 // The ES6 Draft Rev3 specifies the following grammar for const declarations
1980 // 1988 //
1981 // ConstDeclaration :: 1989 // ConstDeclaration ::
1982 // const ConstBinding (',' ConstBinding)* ';' 1990 // const ConstBinding (',' ConstBinding)* ';'
1983 // ConstBinding :: 1991 // ConstBinding ::
1984 // Identifier '=' AssignmentExpression 1992 // Identifier '=' AssignmentExpression
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 // 2080 //
2073 // We mark the block as initializer block because we don't want the 2081 // We mark the block as initializer block because we don't want the
2074 // rewriter to add a '.result' assignment to such a block (to get compliant 2082 // rewriter to add a '.result' assignment to such a block (to get compliant
2075 // behavior for code such as print(eval('var x = 7')), and for cosmetic 2083 // behavior for code such as print(eval('var x = 7')), and for cosmetic
2076 // reasons when pretty-printing. Also, unless an assignment (initialization) 2084 // reasons when pretty-printing. Also, unless an assignment (initialization)
2077 // is inside an initializer block, it is ignored. 2085 // is inside an initializer block, it is ignored.
2078 // 2086 //
2079 // Create new block with one expected declaration. 2087 // Create new block with one expected declaration.
2080 Block* block = factory()->NewBlock(NULL, 1, true, pos); 2088 Block* block = factory()->NewBlock(NULL, 1, true, pos);
2081 int nvars = 0; // the number of variables declared 2089 int nvars = 0; // the number of variables declared
2082 Handle<String> name; 2090 const AstString* name = NULL;
2083 do { 2091 do {
2084 if (fni_ != NULL) fni_->Enter(); 2092 if (fni_ != NULL) fni_->Enter();
2085 2093
2086 // Parse variable name. 2094 // Parse variable name.
2087 if (nvars > 0) Consume(Token::COMMA); 2095 if (nvars > 0) Consume(Token::COMMA);
2088 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2096 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2089 if (fni_ != NULL) fni_->PushVariableName(name); 2097 if (fni_ != NULL) fni_->PushVariableName(name);
2090 2098
2091 // Declare variable. 2099 // Declare variable.
2092 // Note that we *always* must treat the initial value via a separate init 2100 // 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
2191 // properties in the prototype chain, but only after the variable 2199 // properties in the prototype chain, but only after the variable
2192 // declaration statement has been executed. This is important in 2200 // declaration statement has been executed. This is important in
2193 // browsers where the global object (window) has lots of 2201 // browsers where the global object (window) has lots of
2194 // properties defined in prototype objects. 2202 // properties defined in prototype objects.
2195 if (initialization_scope->is_global_scope() && 2203 if (initialization_scope->is_global_scope() &&
2196 !IsLexicalVariableMode(mode)) { 2204 !IsLexicalVariableMode(mode)) {
2197 // Compute the arguments for the runtime call. 2205 // Compute the arguments for the runtime call.
2198 ZoneList<Expression*>* arguments = 2206 ZoneList<Expression*>* arguments =
2199 new(zone()) ZoneList<Expression*>(3, zone()); 2207 new(zone()) ZoneList<Expression*>(3, zone());
2200 // We have at least 1 parameter. 2208 // We have at least 1 parameter.
2201 arguments->Add(factory()->NewLiteral(name, pos), zone()); 2209 arguments->Add(factory()->NewStringLiteral(name, pos), zone());
2202 CallRuntime* initialize; 2210 CallRuntime* initialize;
2203 2211
2204 if (is_const) { 2212 if (is_const) {
2205 arguments->Add(value, zone()); 2213 arguments->Add(value, zone());
2206 value = NULL; // zap the value to avoid the unnecessary assignment 2214 value = NULL; // zap the value to avoid the unnecessary assignment
2207 2215
2208 // Construct the call to Runtime_InitializeConstGlobal 2216 // Construct the call to Runtime_InitializeConstGlobal
2209 // and add it to the initialization statement block. 2217 // and add it to the initialization statement block.
2210 // Note that the function does different things depending on 2218 // Note that the function does different things depending on
2211 // the number of arguments (1 or 2). 2219 // the number of arguments (1 or 2).
2212 initialize = factory()->NewCallRuntime( 2220 initialize = factory()->NewCallRuntime(
2213 isolate()->factory()->InitializeConstGlobal_string(), 2221 ast_value_factory_->initialize_const_global_string(),
2214 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal), 2222 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal),
2215 arguments, pos); 2223 arguments, pos);
2216 } else { 2224 } else {
2217 // Add strict mode. 2225 // Add strict mode.
2218 // We may want to pass singleton to avoid Literal allocations. 2226 // We may want to pass singleton to avoid Literal allocations.
2219 StrictMode strict_mode = initialization_scope->strict_mode(); 2227 StrictMode strict_mode = initialization_scope->strict_mode();
2220 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); 2228 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone());
2221 2229
2222 // Be careful not to assign a value to the global variable if 2230 // Be careful not to assign a value to the global variable if
2223 // we're in a with. The initialization value should not 2231 // we're in a with. The initialization value should not
2224 // necessarily be stored in the global object in that case, 2232 // necessarily be stored in the global object in that case,
2225 // which is why we need to generate a separate assignment node. 2233 // which is why we need to generate a separate assignment node.
2226 if (value != NULL && !inside_with()) { 2234 if (value != NULL && !inside_with()) {
2227 arguments->Add(value, zone()); 2235 arguments->Add(value, zone());
2228 value = NULL; // zap the value to avoid the unnecessary assignment 2236 value = NULL; // zap the value to avoid the unnecessary assignment
2229 } 2237 }
2230 2238
2231 // Construct the call to Runtime_InitializeVarGlobal 2239 // Construct the call to Runtime_InitializeVarGlobal
2232 // and add it to the initialization statement block. 2240 // and add it to the initialization statement block.
2233 // Note that the function does different things depending on 2241 // Note that the function does different things depending on
2234 // the number of arguments (2 or 3). 2242 // the number of arguments (2 or 3).
2235 initialize = factory()->NewCallRuntime( 2243 initialize = factory()->NewCallRuntime(
2236 isolate()->factory()->InitializeVarGlobal_string(), 2244 ast_value_factory_->initialize_var_global_string(),
2237 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 2245 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
2238 arguments, pos); 2246 arguments, pos);
2239 } 2247 }
2240 2248
2241 block->AddStatement( 2249 block->AddStatement(
2242 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), 2250 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition),
2243 zone()); 2251 zone());
2244 } else if (needs_init) { 2252 } else if (needs_init) {
2245 // Constant initializations always assign to the declared constant which 2253 // Constant initializations always assign to the declared constant which
2246 // is always at the function scope level. This is only relevant for 2254 // is always at the function scope level. This is only relevant for
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 // If there was a single non-const declaration, return it in the output 2290 // If there was a single non-const declaration, return it in the output
2283 // parameter for possible use by for/in. 2291 // parameter for possible use by for/in.
2284 if (nvars == 1 && !is_const) { 2292 if (nvars == 1 && !is_const) {
2285 *out = name; 2293 *out = name;
2286 } 2294 }
2287 2295
2288 return block; 2296 return block;
2289 } 2297 }
2290 2298
2291 2299
2292 static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) { 2300 static bool ContainsLabel(ZoneList<const AstString*>* labels,
2293 ASSERT(!label.is_null()); 2301 const AstString* label) {
2302 ASSERT(label != NULL);
2294 if (labels != NULL) { 2303 if (labels != NULL) {
2295 for (int i = labels->length(); i-- > 0; ) { 2304 for (int i = labels->length(); i-- > 0; ) {
2296 if (labels->at(i).is_identical_to(label)) { 2305 if (labels->at(i) == label) {
2297 return true; 2306 return true;
2298 } 2307 }
2299 } 2308 }
2300 } 2309 }
2301 return false; 2310 return false;
2302 } 2311 }
2303 2312
2304 2313
2305 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 2314 Statement* Parser::ParseExpressionOrLabelledStatement(
2306 bool* ok) { 2315 ZoneList<const AstString*>* labels, bool* ok) {
2307 // ExpressionStatement | LabelledStatement :: 2316 // ExpressionStatement | LabelledStatement ::
2308 // Expression ';' 2317 // Expression ';'
2309 // Identifier ':' Statement 2318 // Identifier ':' Statement
2310 int pos = peek_position(); 2319 int pos = peek_position();
2311 bool starts_with_idenfifier = peek_any_identifier(); 2320 bool starts_with_idenfifier = peek_any_identifier();
2312 Expression* expr = ParseExpression(true, CHECK_OK); 2321 Expression* expr = ParseExpression(true, CHECK_OK);
2313 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && 2322 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
2314 expr->AsVariableProxy() != NULL && 2323 expr->AsVariableProxy() != NULL &&
2315 !expr->AsVariableProxy()->is_this()) { 2324 !expr->AsVariableProxy()->is_this()) {
2316 // Expression is a single identifier, and not, e.g., a parenthesized 2325 // Expression is a single identifier, and not, e.g., a parenthesized
2317 // identifier. 2326 // identifier.
2318 VariableProxy* var = expr->AsVariableProxy(); 2327 VariableProxy* var = expr->AsVariableProxy();
2319 Handle<String> label = var->name(); 2328 const AstString* label = var->raw_name();
2320 // TODO(1240780): We don't check for redeclaration of labels 2329 // TODO(1240780): We don't check for redeclaration of labels
2321 // during preparsing since keeping track of the set of active 2330 // during preparsing since keeping track of the set of active
2322 // labels requires nontrivial changes to the way scopes are 2331 // labels requires nontrivial changes to the way scopes are
2323 // structured. However, these are probably changes we want to 2332 // structured. However, these are probably changes we want to
2324 // make later anyway so we should go back and fix this then. 2333 // make later anyway so we should go back and fix this then.
2325 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2334 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
2326 ParserTraits::ReportMessage("label_redeclaration", label); 2335 ParserTraits::ReportMessage("label_redeclaration", label);
2327 *ok = false; 2336 *ok = false;
2328 return NULL; 2337 return NULL;
2329 } 2338 }
2330 if (labels == NULL) { 2339 if (labels == NULL) {
2331 labels = new(zone()) ZoneStringList(4, zone()); 2340 labels = new(zone()) ZoneList<const AstString*>(4, zone());
2332 } 2341 }
2333 labels->Add(label, zone()); 2342 labels->Add(label, zone());
2334 // Remove the "ghost" variable that turned out to be a label 2343 // Remove the "ghost" variable that turned out to be a label
2335 // from the top scope. This way, we don't try to resolve it 2344 // from the top scope. This way, we don't try to resolve it
2336 // during the scope processing. 2345 // during the scope processing.
2337 scope_->RemoveUnresolved(var); 2346 scope_->RemoveUnresolved(var);
2338 Expect(Token::COLON, CHECK_OK); 2347 Expect(Token::COLON, CHECK_OK);
2339 return ParseStatement(labels, ok); 2348 return ParseStatement(labels, ok);
2340 } 2349 }
2341 2350
2342 // If we have an extension, we allow a native function declaration. 2351 // If we have an extension, we allow a native function declaration.
2343 // A native function declaration starts with "native function" with 2352 // A native function declaration starts with "native function" with
2344 // no line-terminator between the two words. 2353 // no line-terminator between the two words.
2345 if (extension_ != NULL && 2354 if (extension_ != NULL &&
2346 peek() == Token::FUNCTION && 2355 peek() == Token::FUNCTION &&
2347 !scanner()->HasAnyLineTerminatorBeforeNext() && 2356 !scanner()->HasAnyLineTerminatorBeforeNext() &&
2348 expr != NULL && 2357 expr != NULL &&
2349 expr->AsVariableProxy() != NULL && 2358 expr->AsVariableProxy() != NULL &&
2350 String::Equals(isolate()->factory()->native_string(), 2359 expr->AsVariableProxy()->raw_name() ==
2351 expr->AsVariableProxy()->name()) && 2360 ast_value_factory_->native_string() &&
2352 !scanner()->literal_contains_escapes()) { 2361 !scanner()->literal_contains_escapes()) {
2353 return ParseNativeDeclaration(ok); 2362 return ParseNativeDeclaration(ok);
2354 } 2363 }
2355 2364
2356 // Parsed expression statement, or the context-sensitive 'module' keyword. 2365 // Parsed expression statement, or the context-sensitive 'module' keyword.
2357 // Only expect semicolon in the former case. 2366 // Only expect semicolon in the former case.
2358 if (!FLAG_harmony_modules || 2367 if (!FLAG_harmony_modules ||
2359 peek() != Token::IDENTIFIER || 2368 peek() != Token::IDENTIFIER ||
2360 scanner()->HasAnyLineTerminatorBeforeNext() || 2369 scanner()->HasAnyLineTerminatorBeforeNext() ||
2361 expr->AsVariableProxy() == NULL || 2370 expr->AsVariableProxy() == NULL ||
2362 !String::Equals(isolate()->factory()->module_string(), 2371 expr->AsVariableProxy()->raw_name() !=
2363 expr->AsVariableProxy()->name()) || 2372 ast_value_factory_->module_string() ||
2364 scanner()->literal_contains_escapes()) { 2373 scanner()->literal_contains_escapes()) {
2365 ExpectSemicolon(CHECK_OK); 2374 ExpectSemicolon(CHECK_OK);
2366 } 2375 }
2367 return factory()->NewExpressionStatement(expr, pos); 2376 return factory()->NewExpressionStatement(expr, pos);
2368 } 2377 }
2369 2378
2370 2379
2371 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 2380 IfStatement* Parser::ParseIfStatement(ZoneList<const AstString*>* labels,
2381 bool* ok) {
2372 // IfStatement :: 2382 // IfStatement ::
2373 // 'if' '(' Expression ')' Statement ('else' Statement)? 2383 // 'if' '(' Expression ')' Statement ('else' Statement)?
2374 2384
2375 int pos = peek_position(); 2385 int pos = peek_position();
2376 Expect(Token::IF, CHECK_OK); 2386 Expect(Token::IF, CHECK_OK);
2377 Expect(Token::LPAREN, CHECK_OK); 2387 Expect(Token::LPAREN, CHECK_OK);
2378 Expression* condition = ParseExpression(true, CHECK_OK); 2388 Expression* condition = ParseExpression(true, CHECK_OK);
2379 Expect(Token::RPAREN, CHECK_OK); 2389 Expect(Token::RPAREN, CHECK_OK);
2380 Statement* then_statement = ParseStatement(labels, CHECK_OK); 2390 Statement* then_statement = ParseStatement(labels, CHECK_OK);
2381 Statement* else_statement = NULL; 2391 Statement* else_statement = NULL;
2382 if (peek() == Token::ELSE) { 2392 if (peek() == Token::ELSE) {
2383 Next(); 2393 Next();
2384 else_statement = ParseStatement(labels, CHECK_OK); 2394 else_statement = ParseStatement(labels, CHECK_OK);
2385 } else { 2395 } else {
2386 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2396 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2387 } 2397 }
2388 return factory()->NewIfStatement( 2398 return factory()->NewIfStatement(
2389 condition, then_statement, else_statement, pos); 2399 condition, then_statement, else_statement, pos);
2390 } 2400 }
2391 2401
2392 2402
2393 Statement* Parser::ParseContinueStatement(bool* ok) { 2403 Statement* Parser::ParseContinueStatement(bool* ok) {
2394 // ContinueStatement :: 2404 // ContinueStatement ::
2395 // 'continue' Identifier? ';' 2405 // 'continue' Identifier? ';'
2396 2406
2397 int pos = peek_position(); 2407 int pos = peek_position();
2398 Expect(Token::CONTINUE, CHECK_OK); 2408 Expect(Token::CONTINUE, CHECK_OK);
2399 Handle<String> label = Handle<String>::null(); 2409 const AstString* label = NULL;
2400 Token::Value tok = peek(); 2410 Token::Value tok = peek();
2401 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2411 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2402 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2412 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2403 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2413 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2404 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2414 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2405 } 2415 }
2406 IterationStatement* target = NULL; 2416 IterationStatement* target = LookupContinueTarget(label, CHECK_OK);
2407 target = LookupContinueTarget(label, CHECK_OK);
2408 if (target == NULL) { 2417 if (target == NULL) {
2409 // Illegal continue statement. 2418 // Illegal continue statement.
2410 const char* message = "illegal_continue"; 2419 const char* message = "illegal_continue";
2411 if (!label.is_null()) { 2420 if (label != NULL) {
2412 message = "unknown_label"; 2421 message = "unknown_label";
2413 } 2422 }
2414 ParserTraits::ReportMessage(message, label); 2423 ParserTraits::ReportMessage(message, label);
2415 *ok = false; 2424 *ok = false;
2416 return NULL; 2425 return NULL;
2417 } 2426 }
2418 ExpectSemicolon(CHECK_OK); 2427 ExpectSemicolon(CHECK_OK);
2419 return factory()->NewContinueStatement(target, pos); 2428 return factory()->NewContinueStatement(target, pos);
2420 } 2429 }
2421 2430
2422 2431
2423 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 2432 Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels,
2433 bool* ok) {
2424 // BreakStatement :: 2434 // BreakStatement ::
2425 // 'break' Identifier? ';' 2435 // 'break' Identifier? ';'
2426 2436
2427 int pos = peek_position(); 2437 int pos = peek_position();
2428 Expect(Token::BREAK, CHECK_OK); 2438 Expect(Token::BREAK, CHECK_OK);
2429 Handle<String> label; 2439 const AstString* label = NULL;
2430 Token::Value tok = peek(); 2440 Token::Value tok = peek();
2431 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2441 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2432 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2442 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2433 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2443 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2434 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2444 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2435 } 2445 }
2436 // Parse labeled break statements that target themselves into 2446 // Parse labeled break statements that target themselves into
2437 // empty statements, e.g. 'l1: l2: l3: break l2;' 2447 // empty statements, e.g. 'l1: l2: l3: break l2;'
2438 if (!label.is_null() && ContainsLabel(labels, label)) { 2448 if (label != NULL && ContainsLabel(labels, label)) {
2439 ExpectSemicolon(CHECK_OK); 2449 ExpectSemicolon(CHECK_OK);
2440 return factory()->NewEmptyStatement(pos); 2450 return factory()->NewEmptyStatement(pos);
2441 } 2451 }
2442 BreakableStatement* target = NULL; 2452 BreakableStatement* target = NULL;
2443 target = LookupBreakTarget(label, CHECK_OK); 2453 target = LookupBreakTarget(label, CHECK_OK);
2444 if (target == NULL) { 2454 if (target == NULL) {
2445 // Illegal break statement. 2455 // Illegal break statement.
2446 const char* message = "illegal_break"; 2456 const char* message = "illegal_break";
2447 if (!label.is_null()) { 2457 if (label != NULL) {
2448 message = "unknown_label"; 2458 message = "unknown_label";
2449 } 2459 }
2450 ParserTraits::ReportMessage(message, label); 2460 ParserTraits::ReportMessage(message, label);
2451 *ok = false; 2461 *ok = false;
2452 return NULL; 2462 return NULL;
2453 } 2463 }
2454 ExpectSemicolon(CHECK_OK); 2464 ExpectSemicolon(CHECK_OK);
2455 return factory()->NewBreakStatement(target, pos); 2465 return factory()->NewBreakStatement(target, pos);
2456 } 2466 }
2457 2467
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 Scope* decl_scope = scope_->DeclarationScope(); 2501 Scope* decl_scope = scope_->DeclarationScope();
2492 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) { 2502 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) {
2493 ReportMessageAt(loc, "illegal_return"); 2503 ReportMessageAt(loc, "illegal_return");
2494 *ok = false; 2504 *ok = false;
2495 return NULL; 2505 return NULL;
2496 } 2506 }
2497 return result; 2507 return result;
2498 } 2508 }
2499 2509
2500 2510
2501 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2511 Statement* Parser::ParseWithStatement(ZoneList<const AstString*>* labels,
2512 bool* ok) {
2502 // WithStatement :: 2513 // WithStatement ::
2503 // 'with' '(' Expression ')' Statement 2514 // 'with' '(' Expression ')' Statement
2504 2515
2505 Expect(Token::WITH, CHECK_OK); 2516 Expect(Token::WITH, CHECK_OK);
2506 int pos = position(); 2517 int pos = position();
2507 2518
2508 if (strict_mode() == STRICT) { 2519 if (strict_mode() == STRICT) {
2509 ReportMessage("strict_mode_with"); 2520 ReportMessage("strict_mode_with");
2510 *ok = false; 2521 *ok = false;
2511 return NULL; 2522 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 peek() != Token::DEFAULT && 2564 peek() != Token::DEFAULT &&
2554 peek() != Token::RBRACE) { 2565 peek() != Token::RBRACE) {
2555 Statement* stat = ParseStatement(NULL, CHECK_OK); 2566 Statement* stat = ParseStatement(NULL, CHECK_OK);
2556 statements->Add(stat, zone()); 2567 statements->Add(stat, zone());
2557 } 2568 }
2558 2569
2559 return factory()->NewCaseClause(label, statements, pos); 2570 return factory()->NewCaseClause(label, statements, pos);
2560 } 2571 }
2561 2572
2562 2573
2563 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 2574 SwitchStatement* Parser::ParseSwitchStatement(
2564 bool* ok) { 2575 ZoneList<const AstString*>* labels, bool* ok) {
2565 // SwitchStatement :: 2576 // SwitchStatement ::
2566 // 'switch' '(' Expression ')' '{' CaseClause* '}' 2577 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2567 2578
2568 SwitchStatement* statement = 2579 SwitchStatement* statement =
2569 factory()->NewSwitchStatement(labels, peek_position()); 2580 factory()->NewSwitchStatement(labels, peek_position());
2570 Target target(&this->target_stack_, statement); 2581 Target target(&this->target_stack_, statement);
2571 2582
2572 Expect(Token::SWITCH, CHECK_OK); 2583 Expect(Token::SWITCH, CHECK_OK);
2573 Expect(Token::LPAREN, CHECK_OK); 2584 Expect(Token::LPAREN, CHECK_OK);
2574 Expression* tag = ParseExpression(true, CHECK_OK); 2585 Expression* tag = ParseExpression(true, CHECK_OK);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 } 2648 }
2638 2649
2639 // If we can break out from the catch block and there is a finally block, 2650 // If we can break out from the catch block and there is a finally block,
2640 // then we will need to collect escaping targets from the catch 2651 // then we will need to collect escaping targets from the catch
2641 // block. Since we don't know yet if there will be a finally block, we 2652 // block. Since we don't know yet if there will be a finally block, we
2642 // always collect the targets. 2653 // always collect the targets.
2643 TargetCollector catch_collector(zone()); 2654 TargetCollector catch_collector(zone());
2644 Scope* catch_scope = NULL; 2655 Scope* catch_scope = NULL;
2645 Variable* catch_variable = NULL; 2656 Variable* catch_variable = NULL;
2646 Block* catch_block = NULL; 2657 Block* catch_block = NULL;
2647 Handle<String> name; 2658 const AstString* name = NULL;
2648 if (tok == Token::CATCH) { 2659 if (tok == Token::CATCH) {
2649 Consume(Token::CATCH); 2660 Consume(Token::CATCH);
2650 2661
2651 Expect(Token::LPAREN, CHECK_OK); 2662 Expect(Token::LPAREN, CHECK_OK);
2652 catch_scope = NewScope(scope_, CATCH_SCOPE); 2663 catch_scope = NewScope(scope_, CATCH_SCOPE);
2653 catch_scope->set_start_position(scanner()->location().beg_pos); 2664 catch_scope->set_start_position(scanner()->location().beg_pos);
2654 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2665 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2655 2666
2656 Expect(Token::RPAREN, CHECK_OK); 2667 Expect(Token::RPAREN, CHECK_OK);
2657 2668
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2707 index, try_block, finally_block, pos); 2718 index, try_block, finally_block, pos);
2708 // Combine the jump targets of the try block and the possible catch block. 2719 // Combine the jump targets of the try block and the possible catch block.
2709 try_collector.targets()->AddAll(*catch_collector.targets(), zone()); 2720 try_collector.targets()->AddAll(*catch_collector.targets(), zone());
2710 } 2721 }
2711 2722
2712 result->set_escaping_targets(try_collector.targets()); 2723 result->set_escaping_targets(try_collector.targets());
2713 return result; 2724 return result;
2714 } 2725 }
2715 2726
2716 2727
2717 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2728 DoWhileStatement* Parser::ParseDoWhileStatement(
2718 bool* ok) { 2729 ZoneList<const AstString*>* labels, bool* ok) {
2719 // DoStatement :: 2730 // DoStatement ::
2720 // 'do' Statement 'while' '(' Expression ')' ';' 2731 // 'do' Statement 'while' '(' Expression ')' ';'
2721 2732
2722 DoWhileStatement* loop = 2733 DoWhileStatement* loop =
2723 factory()->NewDoWhileStatement(labels, peek_position()); 2734 factory()->NewDoWhileStatement(labels, peek_position());
2724 Target target(&this->target_stack_, loop); 2735 Target target(&this->target_stack_, loop);
2725 2736
2726 Expect(Token::DO, CHECK_OK); 2737 Expect(Token::DO, CHECK_OK);
2727 Statement* body = ParseStatement(NULL, CHECK_OK); 2738 Statement* body = ParseStatement(NULL, CHECK_OK);
2728 Expect(Token::WHILE, CHECK_OK); 2739 Expect(Token::WHILE, CHECK_OK);
2729 Expect(Token::LPAREN, CHECK_OK); 2740 Expect(Token::LPAREN, CHECK_OK);
2730 2741
2731 Expression* cond = ParseExpression(true, CHECK_OK); 2742 Expression* cond = ParseExpression(true, CHECK_OK);
2732 Expect(Token::RPAREN, CHECK_OK); 2743 Expect(Token::RPAREN, CHECK_OK);
2733 2744
2734 // Allow do-statements to be terminated with and without 2745 // Allow do-statements to be terminated with and without
2735 // semi-colons. This allows code such as 'do;while(0)return' to 2746 // semi-colons. This allows code such as 'do;while(0)return' to
2736 // parse, which would not be the case if we had used the 2747 // parse, which would not be the case if we had used the
2737 // ExpectSemicolon() functionality here. 2748 // ExpectSemicolon() functionality here.
2738 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); 2749 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
2739 2750
2740 if (loop != NULL) loop->Initialize(cond, body); 2751 if (loop != NULL) loop->Initialize(cond, body);
2741 return loop; 2752 return loop;
2742 } 2753 }
2743 2754
2744 2755
2745 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2756 WhileStatement* Parser::ParseWhileStatement(ZoneList<const AstString*>* labels,
2757 bool* ok) {
2746 // WhileStatement :: 2758 // WhileStatement ::
2747 // 'while' '(' Expression ')' Statement 2759 // 'while' '(' Expression ')' Statement
2748 2760
2749 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position()); 2761 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position());
2750 Target target(&this->target_stack_, loop); 2762 Target target(&this->target_stack_, loop);
2751 2763
2752 Expect(Token::WHILE, CHECK_OK); 2764 Expect(Token::WHILE, CHECK_OK);
2753 Expect(Token::LPAREN, CHECK_OK); 2765 Expect(Token::LPAREN, CHECK_OK);
2754 Expression* cond = ParseExpression(true, CHECK_OK); 2766 Expression* cond = ParseExpression(true, CHECK_OK);
2755 Expect(Token::RPAREN, CHECK_OK); 2767 Expect(Token::RPAREN, CHECK_OK);
(...skipping 18 matching lines...) Expand all
2774 } 2786 }
2775 2787
2776 2788
2777 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2789 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2778 Expression* each, 2790 Expression* each,
2779 Expression* subject, 2791 Expression* subject,
2780 Statement* body) { 2792 Statement* body) {
2781 ForOfStatement* for_of = stmt->AsForOfStatement(); 2793 ForOfStatement* for_of = stmt->AsForOfStatement();
2782 2794
2783 if (for_of != NULL) { 2795 if (for_of != NULL) {
2784 Factory* heap_factory = isolate()->factory();
2785 Variable* iterable = scope_->DeclarationScope()->NewTemporary( 2796 Variable* iterable = scope_->DeclarationScope()->NewTemporary(
2786 heap_factory->dot_iterable_string()); 2797 ast_value_factory_->dot_iterable_string());
2787 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2798 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2788 heap_factory->dot_iterator_string()); 2799 ast_value_factory_->dot_iterator_string());
2789 Variable* result = scope_->DeclarationScope()->NewTemporary( 2800 Variable* result = scope_->DeclarationScope()->NewTemporary(
2790 heap_factory->dot_result_string()); 2801 ast_value_factory_->dot_result_string());
2791 2802
2792 Expression* assign_iterable; 2803 Expression* assign_iterable;
2793 Expression* assign_iterator; 2804 Expression* assign_iterator;
2794 Expression* next_result; 2805 Expression* next_result;
2795 Expression* result_done; 2806 Expression* result_done;
2796 Expression* assign_each; 2807 Expression* assign_each;
2797 2808
2798 // var iterable = subject; 2809 // var iterable = subject;
2799 { 2810 {
2800 Expression* iterable_proxy = factory()->NewVariableProxy(iterable); 2811 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2801 assign_iterable = factory()->NewAssignment( 2812 assign_iterable = factory()->NewAssignment(
2802 Token::ASSIGN, iterable_proxy, subject, subject->position()); 2813 Token::ASSIGN, iterable_proxy, subject, subject->position());
2803 } 2814 }
2804 2815
2805 // var iterator = iterable[Symbol.iterator](); 2816 // var iterator = iterable[Symbol.iterator]();
2806 { 2817 {
2807 Expression* iterable_proxy = factory()->NewVariableProxy(iterable); 2818 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2808 Handle<Symbol> iterator_symbol( 2819 Expression* iterator_symbol_literal =
2809 isolate()->native_context()->iterator_symbol(), isolate()); 2820 factory()->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition);
2810 Expression* iterator_symbol_literal = factory()->NewLiteral(
2811 iterator_symbol, RelocInfo::kNoPosition);
2812 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a 2821 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a
2813 // for-of doesn't have a Symbol.iterator property. We should do better 2822 // for-of doesn't have a Symbol.iterator property. We should do better
2814 // than informing the user that "undefined is not a function". 2823 // than informing the user that "undefined is not a function".
2815 int pos = subject->position(); 2824 int pos = subject->position();
2816 Expression* iterator_property = factory()->NewProperty( 2825 Expression* iterator_property = factory()->NewProperty(
2817 iterable_proxy, iterator_symbol_literal, pos); 2826 iterable_proxy, iterator_symbol_literal, pos);
2818 ZoneList<Expression*>* iterator_arguments = 2827 ZoneList<Expression*>* iterator_arguments =
2819 new(zone()) ZoneList<Expression*>(0, zone()); 2828 new(zone()) ZoneList<Expression*>(0, zone());
2820 Expression* iterator_call = factory()->NewCall( 2829 Expression* iterator_call = factory()->NewCall(
2821 iterator_property, iterator_arguments, pos); 2830 iterator_property, iterator_arguments, pos);
2822 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2831 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2823 assign_iterator = factory()->NewAssignment( 2832 assign_iterator = factory()->NewAssignment(
2824 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition); 2833 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition);
2825 } 2834 }
2826 2835
2827 // var result = iterator.next(); 2836 // var result = iterator.next();
2828 { 2837 {
2829 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2838 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2830 Expression* next_literal = factory()->NewLiteral( 2839 Expression* next_literal = factory()->NewStringLiteral(
2831 heap_factory->next_string(), RelocInfo::kNoPosition); 2840 ast_value_factory_->next_string(), RelocInfo::kNoPosition);
2832 Expression* next_property = factory()->NewProperty( 2841 Expression* next_property = factory()->NewProperty(
2833 iterator_proxy, next_literal, RelocInfo::kNoPosition); 2842 iterator_proxy, next_literal, RelocInfo::kNoPosition);
2834 ZoneList<Expression*>* next_arguments = 2843 ZoneList<Expression*>* next_arguments =
2835 new(zone()) ZoneList<Expression*>(0, zone()); 2844 new(zone()) ZoneList<Expression*>(0, zone());
2836 Expression* next_call = factory()->NewCall( 2845 Expression* next_call = factory()->NewCall(
2837 next_property, next_arguments, RelocInfo::kNoPosition); 2846 next_property, next_arguments, RelocInfo::kNoPosition);
2838 Expression* result_proxy = factory()->NewVariableProxy(result); 2847 Expression* result_proxy = factory()->NewVariableProxy(result);
2839 next_result = factory()->NewAssignment( 2848 next_result = factory()->NewAssignment(
2840 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition); 2849 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition);
2841 } 2850 }
2842 2851
2843 // result.done 2852 // result.done
2844 { 2853 {
2845 Expression* done_literal = factory()->NewLiteral( 2854 Expression* done_literal = factory()->NewStringLiteral(
2846 heap_factory->done_string(), RelocInfo::kNoPosition); 2855 ast_value_factory_->done_string(), RelocInfo::kNoPosition);
2847 Expression* result_proxy = factory()->NewVariableProxy(result); 2856 Expression* result_proxy = factory()->NewVariableProxy(result);
2848 result_done = factory()->NewProperty( 2857 result_done = factory()->NewProperty(
2849 result_proxy, done_literal, RelocInfo::kNoPosition); 2858 result_proxy, done_literal, RelocInfo::kNoPosition);
2850 } 2859 }
2851 2860
2852 // each = result.value 2861 // each = result.value
2853 { 2862 {
2854 Expression* value_literal = factory()->NewLiteral( 2863 Expression* value_literal = factory()->NewStringLiteral(
2855 heap_factory->value_string(), RelocInfo::kNoPosition); 2864 ast_value_factory_->value_string(), RelocInfo::kNoPosition);
2856 Expression* result_proxy = factory()->NewVariableProxy(result); 2865 Expression* result_proxy = factory()->NewVariableProxy(result);
2857 Expression* result_value = factory()->NewProperty( 2866 Expression* result_value = factory()->NewProperty(
2858 result_proxy, value_literal, RelocInfo::kNoPosition); 2867 result_proxy, value_literal, RelocInfo::kNoPosition);
2859 assign_each = factory()->NewAssignment( 2868 assign_each = factory()->NewAssignment(
2860 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2869 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2861 } 2870 }
2862 2871
2863 for_of->Initialize(each, subject, body, 2872 for_of->Initialize(each, subject, body,
2864 assign_iterable, 2873 assign_iterable,
2865 assign_iterator, 2874 assign_iterator,
2866 next_result, 2875 next_result,
2867 result_done, 2876 result_done,
2868 assign_each); 2877 assign_each);
2869 } else { 2878 } else {
2870 stmt->Initialize(each, subject, body); 2879 stmt->Initialize(each, subject, body);
2871 } 2880 }
2872 } 2881 }
2873 2882
2874 2883
2875 Statement* Parser::DesugarLetBindingsInForStatement( 2884 Statement* Parser::DesugarLetBindingsInForStatement(
2876 Scope* inner_scope, ZoneStringList* names, ForStatement* loop, 2885 Scope* inner_scope, ZoneList<const AstString*>* names,
2877 Statement* init, Expression* cond, Statement* next, Statement* body, 2886 ForStatement* loop, Statement* init, Expression* cond, Statement* next,
2878 bool* ok) { 2887 Statement* body, bool* ok) {
2879 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are 2888 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are
2880 // copied into a new environment. After copying, the "next" statement of the 2889 // copied into a new environment. After copying, the "next" statement of the
2881 // loop is executed to update the loop variables. The loop condition is 2890 // loop is executed to update the loop variables. The loop condition is
2882 // checked and the loop body is executed. 2891 // checked and the loop body is executed.
2883 // 2892 //
2884 // We rewrite a for statement of the form 2893 // We rewrite a for statement of the form
2885 // 2894 //
2886 // for (let x = i; cond; next) body 2895 // for (let x = i; cond; next) body
2887 // 2896 //
2888 // into 2897 // into
(...skipping 20 matching lines...) Expand all
2909 // } 2918 // }
2910 2919
2911 ASSERT(names->length() > 0); 2920 ASSERT(names->length() > 0);
2912 Scope* for_scope = scope_; 2921 Scope* for_scope = scope_;
2913 ZoneList<Variable*> temps(names->length(), zone()); 2922 ZoneList<Variable*> temps(names->length(), zone());
2914 2923
2915 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, 2924 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false,
2916 RelocInfo::kNoPosition); 2925 RelocInfo::kNoPosition);
2917 outer_block->AddStatement(init, zone()); 2926 outer_block->AddStatement(init, zone());
2918 2927
2919 Handle<String> temp_name = isolate()->factory()->dot_for_string(); 2928 const AstString* temp_name = ast_value_factory_->dot_for_string();
2920 Handle<Smi> smi0 = handle(Smi::FromInt(0), isolate());
2921 Handle<Smi> smi1 = handle(Smi::FromInt(1), isolate());
2922
2923 2929
2924 // For each let variable x: 2930 // For each let variable x:
2925 // make statement: temp_x = x. 2931 // make statement: temp_x = x.
2926 for (int i = 0; i < names->length(); i++) { 2932 for (int i = 0; i < names->length(); i++) {
2927 VariableProxy* proxy = 2933 VariableProxy* proxy =
2928 NewUnresolved(names->at(i), LET, Interface::NewValue()); 2934 NewUnresolved(names->at(i), LET, Interface::NewValue());
2929 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); 2935 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name);
2930 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2936 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2931 Assignment* assignment = factory()->NewAssignment( 2937 Assignment* assignment = factory()->NewAssignment(
2932 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 2938 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
2933 Statement* assignment_statement = factory()->NewExpressionStatement( 2939 Statement* assignment_statement = factory()->NewExpressionStatement(
2934 assignment, RelocInfo::kNoPosition); 2940 assignment, RelocInfo::kNoPosition);
2935 outer_block->AddStatement(assignment_statement, zone()); 2941 outer_block->AddStatement(assignment_statement, zone());
2936 temps.Add(temp, zone()); 2942 temps.Add(temp, zone());
2937 } 2943 }
2938 2944
2939 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name); 2945 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name);
2940 // Make statement: flag = 1. 2946 // Make statement: flag = 1.
2941 { 2947 {
2942 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2948 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2943 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2949 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2944 Assignment* assignment = factory()->NewAssignment( 2950 Assignment* assignment = factory()->NewAssignment(
2945 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); 2951 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
2946 Statement* assignment_statement = factory()->NewExpressionStatement( 2952 Statement* assignment_statement = factory()->NewExpressionStatement(
2947 assignment, RelocInfo::kNoPosition); 2953 assignment, RelocInfo::kNoPosition);
2948 outer_block->AddStatement(assignment_statement, zone()); 2954 outer_block->AddStatement(assignment_statement, zone());
2949 } 2955 }
2950 2956
2951 outer_block->AddStatement(loop, zone()); 2957 outer_block->AddStatement(loop, zone());
2952 outer_block->set_scope(for_scope); 2958 outer_block->set_scope(for_scope);
2953 scope_ = inner_scope; 2959 scope_ = inner_scope;
(...skipping 19 matching lines...) Expand all
2973 assignment, pos); 2979 assignment, pos);
2974 proxy->var()->set_initializer_position(pos); 2980 proxy->var()->set_initializer_position(pos);
2975 inner_block->AddStatement(assignment_statement, zone()); 2981 inner_block->AddStatement(assignment_statement, zone());
2976 } 2982 }
2977 2983
2978 // Make statement: if (flag == 1) { flag = 0; } else { next; }. 2984 // Make statement: if (flag == 1) { flag = 0; } else { next; }.
2979 { 2985 {
2980 Expression* compare = NULL; 2986 Expression* compare = NULL;
2981 // Make compare expresion: flag == 1. 2987 // Make compare expresion: flag == 1.
2982 { 2988 {
2983 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2989 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2984 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2990 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2985 compare = factory()->NewCompareOperation( 2991 compare = factory()->NewCompareOperation(
2986 Token::EQ, flag_proxy, const1, pos); 2992 Token::EQ, flag_proxy, const1, pos);
2987 } 2993 }
2988 Statement* clear_flag = NULL; 2994 Statement* clear_flag = NULL;
2989 // Make statement: flag = 0. 2995 // Make statement: flag = 0.
2990 { 2996 {
2991 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2997 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2992 Expression* const0 = factory()->NewLiteral(smi0, RelocInfo::kNoPosition); 2998 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition);
2993 Assignment* assignment = factory()->NewAssignment( 2999 Assignment* assignment = factory()->NewAssignment(
2994 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); 3000 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition);
2995 clear_flag = factory()->NewExpressionStatement(assignment, pos); 3001 clear_flag = factory()->NewExpressionStatement(assignment, pos);
2996 } 3002 }
2997 Statement* clear_flag_or_next = factory()->NewIfStatement( 3003 Statement* clear_flag_or_next = factory()->NewIfStatement(
2998 compare, clear_flag, next, RelocInfo::kNoPosition); 3004 compare, clear_flag, next, RelocInfo::kNoPosition);
2999 inner_block->AddStatement(clear_flag_or_next, zone()); 3005 inner_block->AddStatement(clear_flag_or_next, zone());
3000 } 3006 }
3001 3007
3002 3008
3003 // Make statement: if (cond) { } else { break; }. 3009 // Make statement: if (cond) { } else { break; }.
3004 { 3010 {
3005 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 3011 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
3006 BreakableStatement* t = LookupBreakTarget(Handle<String>(), CHECK_OK); 3012 BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK);
3007 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); 3013 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition);
3008 Statement* if_not_cond_break = factory()->NewIfStatement( 3014 Statement* if_not_cond_break = factory()->NewIfStatement(
3009 cond, empty, stop, cond->position()); 3015 cond, empty, stop, cond->position());
3010 inner_block->AddStatement(if_not_cond_break, zone()); 3016 inner_block->AddStatement(if_not_cond_break, zone());
3011 } 3017 }
3012 3018
3013 inner_block->AddStatement(body, zone()); 3019 inner_block->AddStatement(body, zone());
3014 3020
3015 // For each let variable x: 3021 // For each let variable x:
3016 // make statement: temp_x = x; 3022 // make statement: temp_x = x;
(...skipping 10 matching lines...) Expand all
3027 3033
3028 inner_scope->set_end_position(scanner()->location().end_pos); 3034 inner_scope->set_end_position(scanner()->location().end_pos);
3029 inner_block->set_scope(inner_scope); 3035 inner_block->set_scope(inner_scope);
3030 scope_ = for_scope; 3036 scope_ = for_scope;
3031 3037
3032 loop->Initialize(NULL, NULL, NULL, inner_block); 3038 loop->Initialize(NULL, NULL, NULL, inner_block);
3033 return outer_block; 3039 return outer_block;
3034 } 3040 }
3035 3041
3036 3042
3037 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 3043 Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels,
3044 bool* ok) {
3038 // ForStatement :: 3045 // ForStatement ::
3039 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 3046 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
3040 3047
3041 int pos = peek_position(); 3048 int pos = peek_position();
3042 Statement* init = NULL; 3049 Statement* init = NULL;
3043 ZoneStringList let_bindings(1, zone()); 3050 ZoneList<const AstString*> let_bindings(1, zone());
3044 3051
3045 // Create an in-between scope for let-bound iteration variables. 3052 // Create an in-between scope for let-bound iteration variables.
3046 Scope* saved_scope = scope_; 3053 Scope* saved_scope = scope_;
3047 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); 3054 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE);
3048 scope_ = for_scope; 3055 scope_ = for_scope;
3049 3056
3050 Expect(Token::FOR, CHECK_OK); 3057 Expect(Token::FOR, CHECK_OK);
3051 Expect(Token::LPAREN, CHECK_OK); 3058 Expect(Token::LPAREN, CHECK_OK);
3052 for_scope->set_start_position(scanner()->location().beg_pos); 3059 for_scope->set_start_position(scanner()->location().beg_pos);
3053 if (peek() != Token::SEMICOLON) { 3060 if (peek() != Token::SEMICOLON) {
3054 if (peek() == Token::VAR || peek() == Token::CONST) { 3061 if (peek() == Token::VAR || peek() == Token::CONST) {
3055 bool is_const = peek() == Token::CONST; 3062 bool is_const = peek() == Token::CONST;
3056 Handle<String> name; 3063 const AstString* name = NULL;
3057 VariableDeclarationProperties decl_props = kHasNoInitializers; 3064 VariableDeclarationProperties decl_props = kHasNoInitializers;
3058 Block* variable_statement = 3065 Block* variable_statement =
3059 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, 3066 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
3060 CHECK_OK); 3067 CHECK_OK);
3061 bool accept_OF = decl_props == kHasNoInitializers; 3068 bool accept_OF = decl_props == kHasNoInitializers;
3062 ForEachStatement::VisitMode mode; 3069 ForEachStatement::VisitMode mode;
3063 3070
3064 if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) { 3071 if (name != NULL && CheckInOrOf(accept_OF, &mode)) {
3065 Interface* interface = 3072 Interface* interface =
3066 is_const ? Interface::NewConst() : Interface::NewValue(); 3073 is_const ? Interface::NewConst() : Interface::NewValue();
3067 ForEachStatement* loop = 3074 ForEachStatement* loop =
3068 factory()->NewForEachStatement(mode, labels, pos); 3075 factory()->NewForEachStatement(mode, labels, pos);
3069 Target target(&this->target_stack_, loop); 3076 Target target(&this->target_stack_, loop);
3070 3077
3071 Expression* enumerable = ParseExpression(true, CHECK_OK); 3078 Expression* enumerable = ParseExpression(true, CHECK_OK);
3072 Expect(Token::RPAREN, CHECK_OK); 3079 Expect(Token::RPAREN, CHECK_OK);
3073 3080
3074 VariableProxy* each = 3081 VariableProxy* each =
3075 scope_->NewUnresolved(factory(), name, interface); 3082 scope_->NewUnresolved(factory(), name, interface);
3076 Statement* body = ParseStatement(NULL, CHECK_OK); 3083 Statement* body = ParseStatement(NULL, CHECK_OK);
3077 InitializeForEachStatement(loop, each, enumerable, body); 3084 InitializeForEachStatement(loop, each, enumerable, body);
3078 Block* result = 3085 Block* result =
3079 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 3086 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
3080 result->AddStatement(variable_statement, zone()); 3087 result->AddStatement(variable_statement, zone());
3081 result->AddStatement(loop, zone()); 3088 result->AddStatement(loop, zone());
3082 scope_ = saved_scope; 3089 scope_ = saved_scope;
3083 for_scope->set_end_position(scanner()->location().end_pos); 3090 for_scope->set_end_position(scanner()->location().end_pos);
3084 for_scope = for_scope->FinalizeBlockScope(); 3091 for_scope = for_scope->FinalizeBlockScope();
3085 ASSERT(for_scope == NULL); 3092 ASSERT(for_scope == NULL);
3086 // Parsed for-in loop w/ variable/const declaration. 3093 // Parsed for-in loop w/ variable/const declaration.
3087 return result; 3094 return result;
3088 } else { 3095 } else {
3089 init = variable_statement; 3096 init = variable_statement;
3090 } 3097 }
3091 } else if (peek() == Token::LET) { 3098 } else if (peek() == Token::LET) {
3092 Handle<String> name; 3099 const AstString* name = NULL;
3093 VariableDeclarationProperties decl_props = kHasNoInitializers; 3100 VariableDeclarationProperties decl_props = kHasNoInitializers;
3094 Block* variable_statement = 3101 Block* variable_statement =
3095 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, 3102 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings,
3096 &name, CHECK_OK); 3103 &name, CHECK_OK);
3097 bool accept_IN = !name.is_null() && decl_props != kHasInitializers; 3104 bool accept_IN = name != NULL && decl_props != kHasInitializers;
3098 bool accept_OF = decl_props == kHasNoInitializers; 3105 bool accept_OF = decl_props == kHasNoInitializers;
3099 ForEachStatement::VisitMode mode; 3106 ForEachStatement::VisitMode mode;
3100 3107
3101 if (accept_IN && CheckInOrOf(accept_OF, &mode)) { 3108 if (accept_IN && CheckInOrOf(accept_OF, &mode)) {
3102 // Rewrite a for-in statement of the form 3109 // Rewrite a for-in statement of the form
3103 // 3110 //
3104 // for (let x in e) b 3111 // for (let x in e) b
3105 // 3112 //
3106 // into 3113 // into
3107 // 3114 //
3108 // <let x' be a temporary variable> 3115 // <let x' be a temporary variable>
3109 // for (x' in e) { 3116 // for (x' in e) {
3110 // let x; 3117 // let x;
3111 // x = x'; 3118 // x = x';
3112 // b; 3119 // b;
3113 // } 3120 // }
3114 3121
3115 // TODO(keuchel): Move the temporary variable to the block scope, after 3122 // TODO(keuchel): Move the temporary variable to the block scope, after
3116 // implementing stack allocated block scoped variables. 3123 // implementing stack allocated block scoped variables.
3117 Factory* heap_factory = isolate()->factory(); 3124 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3118 Handle<String> tempstr; 3125 ast_value_factory_->dot_for_string());
3119 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3120 isolate(), tempstr,
3121 heap_factory->NewConsString(heap_factory->dot_for_string(), name),
3122 0);
3123 Handle<String> tempname = heap_factory->InternalizeString(tempstr);
3124 Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname);
3125 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3126 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3126 ForEachStatement* loop = 3127 ForEachStatement* loop =
3127 factory()->NewForEachStatement(mode, labels, pos); 3128 factory()->NewForEachStatement(mode, labels, pos);
3128 Target target(&this->target_stack_, loop); 3129 Target target(&this->target_stack_, loop);
3129 3130
3130 // The expression does not see the loop variable. 3131 // The expression does not see the loop variable.
3131 scope_ = saved_scope; 3132 scope_ = saved_scope;
3132 Expression* enumerable = ParseExpression(true, CHECK_OK); 3133 Expression* enumerable = ParseExpression(true, CHECK_OK);
3133 scope_ = for_scope; 3134 scope_ = for_scope;
3134 Expect(Token::RPAREN, CHECK_OK); 3135 Expect(Token::RPAREN, CHECK_OK);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3245 // DebuggerStatement :: 3246 // DebuggerStatement ::
3246 // 'debugger' ';' 3247 // 'debugger' ';'
3247 3248
3248 int pos = peek_position(); 3249 int pos = peek_position();
3249 Expect(Token::DEBUGGER, CHECK_OK); 3250 Expect(Token::DEBUGGER, CHECK_OK);
3250 ExpectSemicolon(CHECK_OK); 3251 ExpectSemicolon(CHECK_OK);
3251 return factory()->NewDebuggerStatement(pos); 3252 return factory()->NewDebuggerStatement(pos);
3252 } 3253 }
3253 3254
3254 3255
3255 void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) { 3256 void Parser::ReportInvalidCachedData(const AstString* name, bool* ok) {
3256 ParserTraits::ReportMessage("invalid_cached_data_function", name); 3257 ParserTraits::ReportMessage("invalid_cached_data_function", name);
3257 *ok = false; 3258 *ok = false;
3258 } 3259 }
3259 3260
3260 3261
3261 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3262 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
3262 if (expression->IsLiteral()) return true; 3263 if (expression->IsLiteral()) return true;
3263 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3264 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
3264 return lit != NULL && lit->is_simple(); 3265 return lit != NULL && lit->is_simple();
3265 } 3266 }
(...skipping 29 matching lines...) Expand all
3295 return static_cast<LiteralType>(literal_type->value()); 3296 return static_cast<LiteralType>(literal_type->value());
3296 } 3297 }
3297 3298
3298 3299
3299 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3300 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3300 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3301 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3301 } 3302 }
3302 3303
3303 3304
3304 FunctionLiteral* Parser::ParseFunctionLiteral( 3305 FunctionLiteral* Parser::ParseFunctionLiteral(
3305 Handle<String> function_name, 3306 const AstString* function_name,
3306 Scanner::Location function_name_location, 3307 Scanner::Location function_name_location,
3307 bool name_is_strict_reserved, 3308 bool name_is_strict_reserved,
3308 bool is_generator, 3309 bool is_generator,
3309 int function_token_pos, 3310 int function_token_pos,
3310 FunctionLiteral::FunctionType function_type, 3311 FunctionLiteral::FunctionType function_type,
3311 FunctionLiteral::ArityRestriction arity_restriction, 3312 FunctionLiteral::ArityRestriction arity_restriction,
3312 bool* ok) { 3313 bool* ok) {
3313 // Function :: 3314 // Function ::
3314 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3315 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3315 // 3316 //
3316 // Getter :: 3317 // Getter ::
3317 // '(' ')' '{' FunctionBody '}' 3318 // '(' ')' '{' FunctionBody '}'
3318 // 3319 //
3319 // Setter :: 3320 // Setter ::
3320 // '(' PropertySetParameterList ')' '{' FunctionBody '}' 3321 // '(' PropertySetParameterList ')' '{' FunctionBody '}'
3321 3322
3322 int pos = function_token_pos == RelocInfo::kNoPosition 3323 int pos = function_token_pos == RelocInfo::kNoPosition
3323 ? peek_position() : function_token_pos; 3324 ? peek_position() : function_token_pos;
3324 3325
3325 // Anonymous functions were passed either the empty symbol or a null 3326 // Anonymous functions were passed either the empty symbol or a null
3326 // handle as the function name. Remember if we were passed a non-empty 3327 // handle as the function name. Remember if we were passed a non-empty
3327 // handle to decide whether to invoke function name inference. 3328 // handle to decide whether to invoke function name inference.
3328 bool should_infer_name = function_name.is_null(); 3329 bool should_infer_name = function_name == NULL;
3329 3330
3330 // We want a non-null handle as the function name. 3331 // We want a non-null handle as the function name.
3331 if (should_infer_name) { 3332 if (should_infer_name) {
3332 function_name = isolate()->factory()->empty_string(); 3333 function_name = ast_value_factory_->empty_string();
3333 } 3334 }
3334 3335
3335 int num_parameters = 0; 3336 int num_parameters = 0;
3336 // Function declarations are function scoped in normal mode, so they are 3337 // Function declarations are function scoped in normal mode, so they are
3337 // hoisted. In harmony block scoping mode they are block scoped, so they 3338 // hoisted. In harmony block scoping mode they are block scoped, so they
3338 // are not hoisted. 3339 // are not hoisted.
3339 // 3340 //
3340 // One tricky case are function declarations in a local sloppy-mode eval: 3341 // One tricky case are function declarations in a local sloppy-mode eval:
3341 // their declaration is hoisted, but they still see the local scope. E.g., 3342 // their declaration is hoisted, but they still see the local scope. E.g.,
3342 // 3343 //
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3374 int expected_property_count = -1; 3375 int expected_property_count = -1;
3375 int handler_count = 0; 3376 int handler_count = 0;
3376 FunctionLiteral::ParameterFlag duplicate_parameters = 3377 FunctionLiteral::ParameterFlag duplicate_parameters =
3377 FunctionLiteral::kNoDuplicateParameters; 3378 FunctionLiteral::kNoDuplicateParameters;
3378 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3379 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3379 ? FunctionLiteral::kIsParenthesized 3380 ? FunctionLiteral::kIsParenthesized
3380 : FunctionLiteral::kNotParenthesized; 3381 : FunctionLiteral::kNotParenthesized;
3381 AstProperties ast_properties; 3382 AstProperties ast_properties;
3382 BailoutReason dont_optimize_reason = kNoReason; 3383 BailoutReason dont_optimize_reason = kNoReason;
3383 // Parse function body. 3384 // Parse function body.
3384 { FunctionState function_state(&function_state_, &scope_, scope, zone()); 3385 {
3386 FunctionState function_state(&function_state_, &scope_, scope, zone(),
3387 ast_value_factory_);
3385 scope_->SetScopeName(function_name); 3388 scope_->SetScopeName(function_name);
3386 3389
3387 if (is_generator) { 3390 if (is_generator) {
3388 // For generators, allocating variables in contexts is currently a win 3391 // For generators, allocating variables in contexts is currently a win
3389 // because it minimizes the work needed to suspend and resume an 3392 // because it minimizes the work needed to suspend and resume an
3390 // activation. 3393 // activation.
3391 scope_->ForceContextAllocation(); 3394 scope_->ForceContextAllocation();
3392 3395
3393 // Calling a generator returns a generator object. That object is stored 3396 // Calling a generator returns a generator object. That object is stored
3394 // in a temporary variable, a definition that is used by "yield" 3397 // in a temporary variable, a definition that is used by "yield"
3395 // expressions. This also marks the FunctionState as a generator. 3398 // expressions. This also marks the FunctionState as a generator.
3396 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3399 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3397 isolate()->factory()->dot_generator_object_string()); 3400 ast_value_factory_->dot_generator_object_string());
3398 function_state.set_generator_object_variable(temp); 3401 function_state.set_generator_object_variable(temp);
3399 } 3402 }
3400 3403
3401 // FormalParameterList :: 3404 // FormalParameterList ::
3402 // '(' (Identifier)*[','] ')' 3405 // '(' (Identifier)*[','] ')'
3403 Expect(Token::LPAREN, CHECK_OK); 3406 Expect(Token::LPAREN, CHECK_OK);
3404 scope->set_start_position(scanner()->location().beg_pos); 3407 scope->set_start_position(scanner()->location().beg_pos);
3405 3408
3406 // We don't yet know if the function will be strict, so we cannot yet 3409 // We don't yet know if the function will be strict, so we cannot yet
3407 // produce errors for parameter names or duplicates. However, we remember 3410 // produce errors for parameter names or duplicates. However, we remember
3408 // the locations of these errors if they occur and produce the errors later. 3411 // the locations of these errors if they occur and produce the errors later.
3409 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); 3412 Scanner::Location eval_args_error_log = Scanner::Location::invalid();
3410 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 3413 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
3411 Scanner::Location reserved_loc = Scanner::Location::invalid(); 3414 Scanner::Location reserved_loc = Scanner::Location::invalid();
3412 3415
3413 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 3416 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
3414 (peek() == Token::RPAREN && 3417 (peek() == Token::RPAREN &&
3415 arity_restriction != FunctionLiteral::SETTER_ARITY); 3418 arity_restriction != FunctionLiteral::SETTER_ARITY);
3416 while (!done) { 3419 while (!done) {
3417 bool is_strict_reserved = false; 3420 bool is_strict_reserved = false;
3418 Handle<String> param_name = 3421 const AstString* param_name =
3419 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 3422 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
3420 3423
3421 // Store locations for possible future error reports. 3424 // Store locations for possible future error reports.
3422 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { 3425 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) {
3423 eval_args_error_log = scanner()->location(); 3426 eval_args_error_log = scanner()->location();
3424 } 3427 }
3425 if (!reserved_loc.IsValid() && is_strict_reserved) { 3428 if (!reserved_loc.IsValid() && is_strict_reserved) {
3426 reserved_loc = scanner()->location(); 3429 reserved_loc = scanner()->location();
3427 } 3430 }
3428 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { 3431 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) {
(...skipping 24 matching lines...) Expand all
3453 // instead of Variables and Proxis as is the case now. 3456 // instead of Variables and Proxis as is the case now.
3454 Variable* fvar = NULL; 3457 Variable* fvar = NULL;
3455 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; 3458 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
3456 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { 3459 if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
3457 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3460 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3458 fvar_init_op = Token::INIT_CONST; 3461 fvar_init_op = Token::INIT_CONST;
3459 } 3462 }
3460 VariableMode fvar_mode = 3463 VariableMode fvar_mode =
3461 allow_harmony_scoping() && strict_mode() == STRICT ? CONST 3464 allow_harmony_scoping() && strict_mode() == STRICT ? CONST
3462 : CONST_LEGACY; 3465 : CONST_LEGACY;
3466 ASSERT(function_name != NULL);
3463 fvar = new(zone()) Variable(scope_, 3467 fvar = new(zone()) Variable(scope_,
3464 function_name, fvar_mode, true /* is valid LHS */, 3468 function_name, fvar_mode, true /* is valid LHS */,
3465 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); 3469 Variable::NORMAL, kCreatedInitialized, Interface::NewConst());
3466 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 3470 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
3467 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 3471 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
3468 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); 3472 proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
3469 scope_->DeclareFunctionVar(fvar_declaration); 3473 scope_->DeclareFunctionVar(fvar_declaration);
3470 } 3474 }
3471 3475
3472 // Determine if the function can be parsed lazily. Lazy parsing is different 3476 // Determine if the function can be parsed lazily. Lazy parsing is different
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 3560
3557 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3561 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3558 CheckConflictingVarDeclarations(scope, CHECK_OK); 3562 CheckConflictingVarDeclarations(scope, CHECK_OK);
3559 } 3563 }
3560 3564
3561 FunctionLiteral::IsGeneratorFlag generator = is_generator 3565 FunctionLiteral::IsGeneratorFlag generator = is_generator
3562 ? FunctionLiteral::kIsGenerator 3566 ? FunctionLiteral::kIsGenerator
3563 : FunctionLiteral::kNotGenerator; 3567 : FunctionLiteral::kNotGenerator;
3564 FunctionLiteral* function_literal = 3568 FunctionLiteral* function_literal =
3565 factory()->NewFunctionLiteral(function_name, 3569 factory()->NewFunctionLiteral(function_name,
3570 ast_value_factory_,
3566 scope, 3571 scope,
3567 body, 3572 body,
3568 materialized_literal_count, 3573 materialized_literal_count,
3569 expected_property_count, 3574 expected_property_count,
3570 handler_count, 3575 handler_count,
3571 num_parameters, 3576 num_parameters,
3572 duplicate_parameters, 3577 duplicate_parameters,
3573 function_type, 3578 function_type,
3574 FunctionLiteral::kIsFunction, 3579 FunctionLiteral::kIsFunction,
3575 parenthesized, 3580 parenthesized,
3576 generator, 3581 generator,
3577 pos); 3582 pos);
3578 function_literal->set_function_token_position(function_token_pos); 3583 function_literal->set_function_token_position(function_token_pos);
3579 function_literal->set_ast_properties(&ast_properties); 3584 function_literal->set_ast_properties(&ast_properties);
3580 function_literal->set_dont_optimize_reason(dont_optimize_reason); 3585 function_literal->set_dont_optimize_reason(dont_optimize_reason);
3581 3586
3582 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3587 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3583 return function_literal; 3588 return function_literal;
3584 } 3589 }
3585 3590
3586 3591
3587 void Parser::SkipLazyFunctionBody(Handle<String> function_name, 3592 void Parser::SkipLazyFunctionBody(const AstString* function_name,
3588 int* materialized_literal_count, 3593 int* materialized_literal_count,
3589 int* expected_property_count, 3594 int* expected_property_count,
3590 bool* ok) { 3595 bool* ok) {
3591 int function_block_pos = position(); 3596 int function_block_pos = position();
3592 if (cached_data_mode_ == CONSUME_CACHED_DATA) { 3597 if (cached_data_mode_ == CONSUME_CACHED_DATA) {
3593 // If we have cached data, we use it to skip parsing the function body. The 3598 // If we have cached data, we use it to skip parsing the function body. The
3594 // data contains the information we need to construct the lazy function. 3599 // data contains the information we need to construct the lazy function.
3595 FunctionEntry entry = 3600 FunctionEntry entry =
3596 (*cached_data())->GetFunctionEntry(function_block_pos); 3601 (*cached_data())->GetFunctionEntry(function_block_pos);
3597 if (entry.is_valid()) { 3602 if (entry.is_valid()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3656 log_->LogFunction(function_block_pos, body_end, 3661 log_->LogFunction(function_block_pos, body_end,
3657 *materialized_literal_count, 3662 *materialized_literal_count,
3658 *expected_property_count, 3663 *expected_property_count,
3659 scope_->strict_mode()); 3664 scope_->strict_mode());
3660 } 3665 }
3661 } 3666 }
3662 } 3667 }
3663 3668
3664 3669
3665 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 3670 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
3666 Handle<String> function_name, int pos, Variable* fvar, 3671 const AstString* function_name, int pos, Variable* fvar,
3667 Token::Value fvar_init_op, bool is_generator, bool* ok) { 3672 Token::Value fvar_init_op, bool is_generator, bool* ok) {
3668 // Everything inside an eagerly parsed function will be parsed eagerly 3673 // Everything inside an eagerly parsed function will be parsed eagerly
3669 // (see comment above). 3674 // (see comment above).
3670 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 3675 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
3671 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); 3676 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone());
3672 if (fvar != NULL) { 3677 if (fvar != NULL) {
3673 VariableProxy* fproxy = scope_->NewUnresolved( 3678 VariableProxy* fproxy = scope_->NewUnresolved(
3674 factory(), function_name, Interface::NewConst()); 3679 factory(), function_name, Interface::NewConst());
3675 fproxy->BindTo(fvar); 3680 fproxy->BindTo(fvar);
3676 body->Add(factory()->NewExpressionStatement( 3681 body->Add(factory()->NewExpressionStatement(
3677 factory()->NewAssignment(fvar_init_op, 3682 factory()->NewAssignment(fvar_init_op,
3678 fproxy, 3683 fproxy,
3679 factory()->NewThisFunction(pos), 3684 factory()->NewThisFunction(pos),
3680 RelocInfo::kNoPosition), 3685 RelocInfo::kNoPosition),
3681 RelocInfo::kNoPosition), zone()); 3686 RelocInfo::kNoPosition), zone());
3682 } 3687 }
3683 3688
3684 // For generators, allocate and yield an iterator on function entry. 3689 // For generators, allocate and yield an iterator on function entry.
3685 if (is_generator) { 3690 if (is_generator) {
3686 ZoneList<Expression*>* arguments = 3691 ZoneList<Expression*>* arguments =
3687 new(zone()) ZoneList<Expression*>(0, zone()); 3692 new(zone()) ZoneList<Expression*>(0, zone());
3688 CallRuntime* allocation = factory()->NewCallRuntime( 3693 CallRuntime* allocation = factory()->NewCallRuntime(
3689 isolate()->factory()->empty_string(), 3694 ast_value_factory_->empty_string(),
3690 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject), 3695 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject),
3691 arguments, pos); 3696 arguments, pos);
3692 VariableProxy* init_proxy = factory()->NewVariableProxy( 3697 VariableProxy* init_proxy = factory()->NewVariableProxy(
3693 function_state_->generator_object_variable()); 3698 function_state_->generator_object_variable());
3694 Assignment* assignment = factory()->NewAssignment( 3699 Assignment* assignment = factory()->NewAssignment(
3695 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 3700 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
3696 VariableProxy* get_proxy = factory()->NewVariableProxy( 3701 VariableProxy* get_proxy = factory()->NewVariableProxy(
3697 function_state_->generator_object_variable()); 3702 function_state_->generator_object_variable());
3698 Yield* yield = factory()->NewYield( 3703 Yield* yield = factory()->NewYield(
3699 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); 3704 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
3700 body->Add(factory()->NewExpressionStatement( 3705 body->Add(factory()->NewExpressionStatement(
3701 yield, RelocInfo::kNoPosition), zone()); 3706 yield, RelocInfo::kNoPosition), zone());
3702 } 3707 }
3703 3708
3704 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); 3709 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
3705 3710
3706 if (is_generator) { 3711 if (is_generator) {
3707 VariableProxy* get_proxy = factory()->NewVariableProxy( 3712 VariableProxy* get_proxy = factory()->NewVariableProxy(
3708 function_state_->generator_object_variable()); 3713 function_state_->generator_object_variable());
3709 Expression *undefined = factory()->NewLiteral( 3714 Expression* undefined =
3710 isolate()->factory()->undefined_value(), RelocInfo::kNoPosition); 3715 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
3711 Yield* yield = factory()->NewYield( 3716 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL,
3712 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); 3717 RelocInfo::kNoPosition);
3713 body->Add(factory()->NewExpressionStatement( 3718 body->Add(factory()->NewExpressionStatement(
3714 yield, RelocInfo::kNoPosition), zone()); 3719 yield, RelocInfo::kNoPosition), zone());
3715 } 3720 }
3716 3721
3717 Expect(Token::RBRACE, CHECK_OK); 3722 Expect(Token::RBRACE, CHECK_OK);
3718 scope_->set_end_position(scanner()->location().end_pos); 3723 scope_->set_end_position(scanner()->location().end_pos);
3719 3724
3720 return body; 3725 return body;
3721 } 3726 }
3722 3727
(...skipping 23 matching lines...) Expand all
3746 } 3751 }
3747 3752
3748 3753
3749 Expression* Parser::ParseV8Intrinsic(bool* ok) { 3754 Expression* Parser::ParseV8Intrinsic(bool* ok) {
3750 // CallRuntime :: 3755 // CallRuntime ::
3751 // '%' Identifier Arguments 3756 // '%' Identifier Arguments
3752 3757
3753 int pos = peek_position(); 3758 int pos = peek_position();
3754 Expect(Token::MOD, CHECK_OK); 3759 Expect(Token::MOD, CHECK_OK);
3755 // Allow "eval" or "arguments" for backward compatibility. 3760 // Allow "eval" or "arguments" for backward compatibility.
3756 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 3761 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
3757 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 3762 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
3758 3763
3759 if (extension_ != NULL) { 3764 if (extension_ != NULL) {
3760 // The extension structures are only accessible while parsing the 3765 // The extension structures are only accessible while parsing the
3761 // very first time not when reparsing because of lazy compilation. 3766 // very first time not when reparsing because of lazy compilation.
3762 scope_->DeclarationScope()->ForceEagerCompilation(); 3767 scope_->DeclarationScope()->ForceEagerCompilation();
3763 } 3768 }
3764 3769
3765 const Runtime::Function* function = Runtime::FunctionForName(name); 3770 const Runtime::Function* function = Runtime::FunctionForName(name->string());
3766 3771
3767 // Check for built-in IS_VAR macro. 3772 // Check for built-in IS_VAR macro.
3768 if (function != NULL && 3773 if (function != NULL &&
3769 function->intrinsic_type == Runtime::RUNTIME && 3774 function->intrinsic_type == Runtime::RUNTIME &&
3770 function->function_id == Runtime::kIS_VAR) { 3775 function->function_id == Runtime::kIS_VAR) {
3771 // %IS_VAR(x) evaluates to x if x is a variable, 3776 // %IS_VAR(x) evaluates to x if x is a variable,
3772 // leads to a parse error otherwise. Could be implemented as an 3777 // leads to a parse error otherwise. Could be implemented as an
3773 // inline function %_IS_VAR(x) to eliminate this special case. 3778 // inline function %_IS_VAR(x) to eliminate this special case.
3774 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { 3779 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
3775 return args->at(0); 3780 return args->at(0);
3776 } else { 3781 } else {
3777 ReportMessage("not_isvar"); 3782 ReportMessage("not_isvar");
3778 *ok = false; 3783 *ok = false;
3779 return NULL; 3784 return NULL;
3780 } 3785 }
3781 } 3786 }
3782 3787
3783 // Check that the expected number of arguments are being passed. 3788 // Check that the expected number of arguments are being passed.
3784 if (function != NULL && 3789 if (function != NULL &&
3785 function->nargs != -1 && 3790 function->nargs != -1 &&
3786 function->nargs != args->length()) { 3791 function->nargs != args->length()) {
3787 ReportMessage("illegal_access"); 3792 ReportMessage("illegal_access");
3788 *ok = false; 3793 *ok = false;
3789 return NULL; 3794 return NULL;
3790 } 3795 }
3791 3796
3792 // Check that the function is defined if it's an inline runtime call. 3797 // Check that the function is defined if it's an inline runtime call.
3793 if (function == NULL && name->Get(0) == '_') { 3798 if (function == NULL && name->FirstCharacter() == '_') {
3794 ParserTraits::ReportMessage("not_defined", name); 3799 ParserTraits::ReportMessage("not_defined", name);
3795 *ok = false; 3800 *ok = false;
3796 return NULL; 3801 return NULL;
3797 } 3802 }
3798 3803
3799 // We have a valid intrinsics call or a call to a builtin. 3804 // We have a valid intrinsics call or a call to a builtin.
3800 return factory()->NewCallRuntime(name, function, args, pos); 3805 return factory()->NewCallRuntime(name, function, args, pos);
3801 } 3806 }
3802 3807
3803 3808
3804 Literal* Parser::GetLiteralUndefined(int position) { 3809 Literal* Parser::GetLiteralUndefined(int position) {
3805 return factory()->NewLiteral( 3810 return factory()->NewUndefinedLiteral(position);
3806 isolate()->factory()->undefined_value(), position);
3807 } 3811 }
3808 3812
3809 3813
3810 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 3814 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
3811 Declaration* decl = scope->CheckConflictingVarDeclarations(); 3815 Declaration* decl = scope->CheckConflictingVarDeclarations();
3812 if (decl != NULL) { 3816 if (decl != NULL) {
3813 // In harmony mode we treat conflicting variable bindinds as early 3817 // In harmony mode we treat conflicting variable bindinds as early
3814 // errors. See ES5 16 for a definition of early errors. 3818 // errors. See ES5 16 for a definition of early errors.
3815 Handle<String> name = decl->proxy()->name(); 3819 const AstString* name = decl->proxy()->raw_name();
3816 int position = decl->proxy()->position(); 3820 int position = decl->proxy()->position();
3817 Scanner::Location location = position == RelocInfo::kNoPosition 3821 Scanner::Location location = position == RelocInfo::kNoPosition
3818 ? Scanner::Location::invalid() 3822 ? Scanner::Location::invalid()
3819 : Scanner::Location(position, position + 1); 3823 : Scanner::Location(position, position + 1);
3820 ParserTraits::ReportMessageAt(location, "var_redeclaration", name); 3824 ParserTraits::ReportMessageAt(location, "var_redeclaration", name);
3821 *ok = false; 3825 *ok = false;
3822 } 3826 }
3823 } 3827 }
3824 3828
3825 3829
3826 // ---------------------------------------------------------------------------- 3830 // ----------------------------------------------------------------------------
3827 // Parser support 3831 // Parser support
3828 3832
3829 3833
3830 bool Parser::TargetStackContainsLabel(Handle<String> label) { 3834 bool Parser::TargetStackContainsLabel(const AstString* label) {
3831 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3835 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3832 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3836 BreakableStatement* stat = t->node()->AsBreakableStatement();
3833 if (stat != NULL && ContainsLabel(stat->labels(), label)) 3837 if (stat != NULL && ContainsLabel(stat->labels(), label))
3834 return true; 3838 return true;
3835 } 3839 }
3836 return false; 3840 return false;
3837 } 3841 }
3838 3842
3839 3843
3840 BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) { 3844 BreakableStatement* Parser::LookupBreakTarget(const AstString* label,
3841 bool anonymous = label.is_null(); 3845 bool* ok) {
3846 bool anonymous = label == NULL;
3842 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3847 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3843 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3848 BreakableStatement* stat = t->node()->AsBreakableStatement();
3844 if (stat == NULL) continue; 3849 if (stat == NULL) continue;
3845 if ((anonymous && stat->is_target_for_anonymous()) || 3850 if ((anonymous && stat->is_target_for_anonymous()) ||
3846 (!anonymous && ContainsLabel(stat->labels(), label))) { 3851 (!anonymous && ContainsLabel(stat->labels(), label))) {
3847 RegisterTargetUse(stat->break_target(), t->previous()); 3852 RegisterTargetUse(stat->break_target(), t->previous());
3848 return stat; 3853 return stat;
3849 } 3854 }
3850 } 3855 }
3851 return NULL; 3856 return NULL;
3852 } 3857 }
3853 3858
3854 3859
3855 IterationStatement* Parser::LookupContinueTarget(Handle<String> label, 3860 IterationStatement* Parser::LookupContinueTarget(const AstString* label,
3856 bool* ok) { 3861 bool* ok) {
3857 bool anonymous = label.is_null(); 3862 bool anonymous = label == NULL;
3858 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3863 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3859 IterationStatement* stat = t->node()->AsIterationStatement(); 3864 IterationStatement* stat = t->node()->AsIterationStatement();
3860 if (stat == NULL) continue; 3865 if (stat == NULL) continue;
3861 3866
3862 ASSERT(stat->is_target_for_anonymous()); 3867 ASSERT(stat->is_target_for_anonymous());
3863 if (anonymous || ContainsLabel(stat->labels(), label)) { 3868 if (anonymous || ContainsLabel(stat->labels(), label)) {
3864 RegisterTargetUse(stat->continue_target(), t->previous()); 3869 RegisterTargetUse(stat->continue_target(), t->previous());
3865 return stat; 3870 return stat;
3866 } 3871 }
3867 } 3872 }
3868 return NULL; 3873 return NULL;
3869 } 3874 }
3870 3875
3871 3876
3872 void Parser::RegisterTargetUse(Label* target, Target* stop) { 3877 void Parser::RegisterTargetUse(Label* target, Target* stop) {
3873 // Register that a break target found at the given stop in the 3878 // Register that a break target found at the given stop in the
3874 // target stack has been used from the top of the target stack. Add 3879 // target stack has been used from the top of the target stack. Add
3875 // the break target to any TargetCollectors passed on the stack. 3880 // the break target to any TargetCollectors passed on the stack.
3876 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3881 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3877 TargetCollector* collector = t->node()->AsTargetCollector(); 3882 TargetCollector* collector = t->node()->AsTargetCollector();
3878 if (collector != NULL) collector->AddTarget(target, zone()); 3883 if (collector != NULL) collector->AddTarget(target, zone());
3879 } 3884 }
3880 } 3885 }
3881 3886
3882 3887
3883 void Parser::ThrowPendingError() { 3888 void Parser::ThrowPendingError() {
3889 ASSERT(ast_value_factory_->IsInternalized());
3884 if (has_pending_error_) { 3890 if (has_pending_error_) {
3885 MessageLocation location(script_, 3891 MessageLocation location(script_,
3886 pending_error_location_.beg_pos, 3892 pending_error_location_.beg_pos,
3887 pending_error_location_.end_pos); 3893 pending_error_location_.end_pos);
3888 Factory* factory = isolate()->factory(); 3894 Factory* factory = isolate()->factory();
3889 bool has_arg = 3895 bool has_arg =
3890 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL; 3896 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL;
3891 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); 3897 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3892 if (!pending_error_arg_.is_null()) { 3898 if (pending_error_arg_ != NULL) {
3893 elements->set(0, *(pending_error_arg_.ToHandleChecked())); 3899 Handle<String> arg_string = pending_error_arg_->string();
3900 elements->set(0, *arg_string);
3894 } else if (pending_error_char_arg_ != NULL) { 3901 } else if (pending_error_char_arg_ != NULL) {
3895 Handle<String> arg_string = 3902 Handle<String> arg_string =
3896 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) 3903 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_))
3897 .ToHandleChecked(); 3904 .ToHandleChecked();
3898 elements->set(0, *arg_string); 3905 elements->set(0, *arg_string);
3899 } 3906 }
3900 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 3907 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
3901 Handle<Object> result = pending_error_is_reference_error_ 3908 Handle<Object> result = pending_error_is_reference_error_
3902 ? factory->NewReferenceError(pending_error_message_, array) 3909 ? factory->NewReferenceError(pending_error_message_, array)
3903 : factory->NewSyntaxError(pending_error_message_, array); 3910 : factory->NewSyntaxError(pending_error_message_, array);
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
4797 result->contains_anchor = parser.contains_anchor(); 4804 result->contains_anchor = parser.contains_anchor();
4798 result->capture_count = capture_count; 4805 result->capture_count = capture_count;
4799 } 4806 }
4800 return !parser.failed(); 4807 return !parser.failed();
4801 } 4808 }
4802 4809
4803 4810
4804 bool Parser::Parse() { 4811 bool Parser::Parse() {
4805 ASSERT(info()->function() == NULL); 4812 ASSERT(info()->function() == NULL);
4806 FunctionLiteral* result = NULL; 4813 FunctionLiteral* result = NULL;
4814 ast_value_factory_ = info()->ast_value_factory();
4815 if (ast_value_factory_ == NULL) {
4816 ast_value_factory_ = new AstValueFactory(zone());
4817 }
4818 if (allow_natives_syntax() || extension_ != NULL) {
4819 // If intrinsics are allowed, the Parser cannot operate independent of the
4820 // V8 heap because of Rumtime. Tell the string table to internalize strings
4821 // and values right after they're created.
4822 ast_value_factory_->Internalize(isolate());
4823 }
4824
4807 if (info()->is_lazy()) { 4825 if (info()->is_lazy()) {
4808 ASSERT(!info()->is_eval()); 4826 ASSERT(!info()->is_eval());
4809 if (info()->shared_info()->is_function()) { 4827 if (info()->shared_info()->is_function()) {
4810 result = ParseLazy(); 4828 result = ParseLazy();
4811 } else { 4829 } else {
4812 result = ParseProgram(); 4830 result = ParseProgram();
4813 } 4831 }
4814 } else { 4832 } else {
4815 SetCachedData(info()->cached_data(), info()->cached_data_mode()); 4833 SetCachedData(info()->cached_data(), info()->cached_data_mode());
4816 if (info()->cached_data_mode() == CONSUME_CACHED_DATA && 4834 if (info()->cached_data_mode() == CONSUME_CACHED_DATA &&
4817 (*info()->cached_data())->has_error()) { 4835 (*info()->cached_data())->has_error()) {
4818 ScriptData* cached_data = *(info()->cached_data()); 4836 ScriptData* cached_data = *(info()->cached_data());
4819 Scanner::Location loc = cached_data->MessageLocation(); 4837 Scanner::Location loc = cached_data->MessageLocation();
4820 const char* message = cached_data->BuildMessage(); 4838 const char* message = cached_data->BuildMessage();
4821 const char* arg = cached_data->BuildArg(); 4839 const char* arg = cached_data->BuildArg();
4822 ParserTraits::ReportMessageAt(loc, message, arg, 4840 ParserTraits::ReportMessageAt(loc, message, arg,
4823 cached_data->IsReferenceError()); 4841 cached_data->IsReferenceError());
4824 DeleteArray(message); 4842 DeleteArray(message);
4825 DeleteArray(arg); 4843 DeleteArray(arg);
4826 ASSERT(info()->isolate()->has_pending_exception()); 4844 ASSERT(info()->isolate()->has_pending_exception());
4827 } else { 4845 } else {
4828 result = ParseProgram(); 4846 result = ParseProgram();
4829 } 4847 }
4830 } 4848 }
4831 info()->SetFunction(result); 4849 info()->SetFunction(result);
4850 ASSERT(ast_value_factory_->IsInternalized());
4851 // info takes ownership of ast_value_factory_.
4852 if (info()->ast_value_factory() == NULL) {
4853 info()->SetAstValueFactory(ast_value_factory_);
4854 }
4855 ast_value_factory_ = NULL;
4832 return (result != NULL); 4856 return (result != NULL);
4833 } 4857 }
4834 4858
4835 } } // namespace v8::internal 4859 } } // namespace v8::internal
OLDNEW
« src/ast-value-factory.h ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698