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

Side by Side Diff: src/parser.cc

Issue 314603004: Parser: Delay internalizing strings and values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: oops, #include fix 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->NewSpecialLiteral(
rossberg 2014/06/12 12:20:28 Nit: just for symmetry, I would wrap this up into
marja 2014/06/12 12:35:03 Done.
693 parser_->ast_value_factory_->NewNull(), pos);
698 case Token::TRUE_LITERAL: 694 case Token::TRUE_LITERAL:
699 return factory->NewLiteral(isolate_factory->true_value(), pos); 695 return factory->NewBooleanLiteral(true, pos);
700 case Token::FALSE_LITERAL: 696 case Token::FALSE_LITERAL:
701 return factory->NewLiteral(isolate_factory->false_value(), pos); 697 return factory->NewBooleanLiteral(false, pos);
702 case Token::NUMBER: { 698 case Token::NUMBER: {
703 double value = scanner->DoubleValue(); 699 double value = scanner->DoubleValue();
704 return factory->NewNumberLiteral(value, pos); 700 return factory->NewNumberLiteral(value, pos);
705 } 701 }
706 default: 702 default:
707 ASSERT(false); 703 ASSERT(false);
708 } 704 }
709 return NULL; 705 return NULL;
710 } 706 }
711 707
712 708
713 Expression* ParserTraits::ExpressionFromIdentifier( 709 Expression* ParserTraits::ExpressionFromIdentifier(
714 Handle<String> name, int pos, Scope* scope, 710 const AstString* name, int pos, Scope* scope,
715 AstNodeFactory<AstConstructionVisitor>* factory) { 711 AstNodeFactory<AstConstructionVisitor>* factory) {
716 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); 712 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
717 // The name may refer to a module instance object, so its type is unknown. 713 // The name may refer to a module instance object, so its type is unknown.
718 #ifdef DEBUG 714 #ifdef DEBUG
719 if (FLAG_print_interface_details) 715 if (FLAG_print_interface_details)
720 PrintF("# Variable %s ", name->ToAsciiArray()); 716 PrintF("# Variable %.*s ", name->length(), name->raw_data());
721 #endif 717 #endif
722 Interface* interface = Interface::NewUnknown(parser_->zone()); 718 Interface* interface = Interface::NewUnknown(parser_->zone());
723 return scope->NewUnresolved(factory, name, interface, pos); 719 return scope->NewUnresolved(factory, name, interface, pos);
724 } 720 }
725 721
726 722
727 Expression* ParserTraits::ExpressionFromString( 723 Expression* ParserTraits::ExpressionFromString(
728 int pos, Scanner* scanner, 724 int pos, Scanner* scanner,
729 AstNodeFactory<AstConstructionVisitor>* factory) { 725 AstNodeFactory<AstConstructionVisitor>* factory) {
730 Handle<String> symbol = GetSymbol(scanner); 726 const AstString* symbol = GetSymbol(scanner);
731 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 727 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
732 return factory->NewLiteral(symbol, pos); 728 return factory->NewStringLiteral(symbol, pos);
733 } 729 }
734 730
735 731
736 Literal* ParserTraits::GetLiteralTheHole( 732 Literal* ParserTraits::GetLiteralTheHole(
737 int position, AstNodeFactory<AstConstructionVisitor>* factory) { 733 int position, AstNodeFactory<AstConstructionVisitor>* factory) {
738 return factory->NewLiteral(parser_->isolate()->factory()->the_hole_value(), 734 return factory->NewSpecialLiteral(
rossberg 2014/06/12 12:20:28 ...and similarly here.
marja 2014/06/12 12:35:03 Done.
739 RelocInfo::kNoPosition); 735 parser_->ast_value_factory_->NewTheHole(), RelocInfo::kNoPosition);
740 } 736 }
741 737
742 738
743 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { 739 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) {
744 return parser_->ParseV8Intrinsic(ok); 740 return parser_->ParseV8Intrinsic(ok);
745 } 741 }
746 742
747 743
748 FunctionLiteral* ParserTraits::ParseFunctionLiteral( 744 FunctionLiteral* ParserTraits::ParseFunctionLiteral(
749 Handle<String> name, 745 const AstString* name,
750 Scanner::Location function_name_location, 746 Scanner::Location function_name_location,
751 bool name_is_strict_reserved, 747 bool name_is_strict_reserved,
752 bool is_generator, 748 bool is_generator,
753 int function_token_position, 749 int function_token_position,
754 FunctionLiteral::FunctionType type, 750 FunctionLiteral::FunctionType type,
755 bool* ok) { 751 bool* ok) {
756 return parser_->ParseFunctionLiteral(name, function_name_location, 752 return parser_->ParseFunctionLiteral(name, function_name_location,
757 name_is_strict_reserved, is_generator, 753 name_is_strict_reserved, is_generator,
758 function_token_position, type, ok); 754 function_token_position, type, ok);
759 } 755 }
760 756
761 757
762 Parser::Parser(CompilationInfo* info) 758 Parser::Parser(CompilationInfo* info)
763 : ParserBase<ParserTraits>(&scanner_, 759 : ParserBase<ParserTraits>(&scanner_,
764 info->isolate()->stack_guard()->real_climit(), 760 info->isolate()->stack_guard()->real_climit(),
765 info->extension(), 761 info->extension(),
766 NULL, 762 NULL,
767 info->zone(), 763 info->zone(),
768 this), 764 this),
769 isolate_(info->isolate()), 765 isolate_(info->isolate()),
770 script_(info->script()), 766 script_(info->script()),
771 scanner_(isolate_->unicode_cache()), 767 scanner_(isolate_->unicode_cache()),
772 reusable_preparser_(NULL), 768 reusable_preparser_(NULL),
773 original_scope_(NULL), 769 original_scope_(NULL),
774 target_stack_(NULL), 770 target_stack_(NULL),
775 cached_data_(NULL), 771 cached_data_(NULL),
776 cached_data_mode_(NO_CACHED_DATA), 772 cached_data_mode_(NO_CACHED_DATA),
773 ast_value_factory_(NULL),
777 info_(info), 774 info_(info),
778 has_pending_error_(false), 775 has_pending_error_(false),
779 pending_error_message_(NULL), 776 pending_error_message_(NULL),
777 pending_error_arg_(NULL),
780 pending_error_char_arg_(NULL) { 778 pending_error_char_arg_(NULL) {
781 ASSERT(!script_.is_null()); 779 ASSERT(!script_.is_null());
782 isolate_->set_ast_node_id(0); 780 isolate_->set_ast_node_id(0);
783 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 781 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
784 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 782 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
785 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 783 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
786 set_allow_lazy(false); // Must be explicitly enabled. 784 set_allow_lazy(false); // Must be explicitly enabled.
787 set_allow_generators(FLAG_harmony_generators); 785 set_allow_generators(FLAG_harmony_generators);
788 set_allow_for_of(FLAG_harmony_iteration); 786 set_allow_for_of(FLAG_harmony_iteration);
789 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 787 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
790 } 788 }
791 789
792 790
793 FunctionLiteral* Parser::ParseProgram() { 791 FunctionLiteral* Parser::ParseProgram() {
794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 792 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
795 // see comment for HistogramTimerScope class. 793 // see comment for HistogramTimerScope class.
796 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); 794 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
797 Handle<String> source(String::cast(script_->source())); 795 Handle<String> source(String::cast(script_->source()));
798 isolate()->counters()->total_parse_size()->Increment(source->length()); 796 isolate()->counters()->total_parse_size()->Increment(source->length());
799 ElapsedTimer timer; 797 ElapsedTimer timer;
800 if (FLAG_trace_parse) { 798 if (FLAG_trace_parse) {
801 timer.Start(); 799 timer.Start();
802 } 800 }
803 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 801 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
804 802
805 // Initialize parser state. 803 // Initialize parser state.
806 CompleteParserRecorder recorder; 804 CompleteParserRecorder recorder;
807 if (cached_data_mode_ == PRODUCE_CACHED_DATA) { 805 if (cached_data_mode_ == PRODUCE_CACHED_DATA) {
808 log_ = &recorder; 806 log_ = &recorder;
809 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) { 807 } else if (cached_data_mode_ == CONSUME_CACHED_DATA) {
810 (*cached_data_)->Initialize(); 808 (*cached_data_)->Initialize();
811 } 809 }
812 810
813 source = String::Flatten(source); 811 source = String::Flatten(source);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 846 }
849 return result; 847 return result;
850 } 848 }
851 849
852 850
853 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 851 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
854 Handle<String> source) { 852 Handle<String> source) {
855 ASSERT(scope_ == NULL); 853 ASSERT(scope_ == NULL);
856 ASSERT(target_stack_ == NULL); 854 ASSERT(target_stack_ == NULL);
857 855
858 Handle<String> no_name = isolate()->factory()->empty_string();
859
860 FunctionLiteral* result = NULL; 856 FunctionLiteral* result = NULL;
861 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 857 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
862 info->SetGlobalScope(scope); 858 info->SetGlobalScope(scope);
863 if (!info->context().is_null()) { 859 if (!info->context().is_null()) {
864 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());
865 } 866 }
866 original_scope_ = scope; 867 original_scope_ = scope;
867 if (info->is_eval()) { 868 if (info->is_eval()) {
868 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { 869 if (!scope->is_global_scope() || info->strict_mode() == STRICT) {
869 scope = NewScope(scope, EVAL_SCOPE); 870 scope = NewScope(scope, EVAL_SCOPE);
870 } 871 }
871 } else if (info->is_global()) { 872 } else if (info->is_global()) {
872 scope = NewScope(scope, GLOBAL_SCOPE); 873 scope = NewScope(scope, GLOBAL_SCOPE);
873 } 874 }
874 scope->set_start_position(0); 875 scope->set_start_position(0);
875 scope->set_end_position(source->length()); 876 scope->set_end_position(source->length());
876 877
877 // Compute the parsing mode. 878 // Compute the parsing mode.
878 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 879 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
879 if (allow_natives_syntax() || 880 if (allow_natives_syntax() ||
880 extension_ != NULL || 881 extension_ != NULL ||
881 scope->is_eval_scope()) { 882 scope->is_eval_scope()) {
882 mode = PARSE_EAGERLY; 883 mode = PARSE_EAGERLY;
883 } 884 }
884 ParsingModeScope parsing_mode(this, mode); 885 ParsingModeScope parsing_mode(this, mode);
885 886
886 // Enters 'scope'. 887 // Enters 'scope'.
887 FunctionState function_state(&function_state_, &scope_, scope, zone()); 888 FunctionState function_state(&function_state_, &scope_, scope, zone(),
889 ast_value_factory_);
888 890
889 scope_->SetStrictMode(info->strict_mode()); 891 scope_->SetStrictMode(info->strict_mode());
890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 892 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
891 bool ok = true; 893 bool ok = true;
892 int beg_pos = scanner()->location().beg_pos; 894 int beg_pos = scanner()->location().beg_pos;
893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 895 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
894 if (ok && strict_mode() == STRICT) { 896 if (ok && strict_mode() == STRICT) {
895 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 897 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
896 } 898 }
897 899
898 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 900 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
899 CheckConflictingVarDeclarations(scope_, &ok); 901 CheckConflictingVarDeclarations(scope_, &ok);
900 } 902 }
901 903
902 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 904 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
903 if (body->length() != 1 || 905 if (body->length() != 1 ||
904 !body->at(0)->IsExpressionStatement() || 906 !body->at(0)->IsExpressionStatement() ||
905 !body->at(0)->AsExpressionStatement()-> 907 !body->at(0)->AsExpressionStatement()->
906 expression()->IsFunctionLiteral()) { 908 expression()->IsFunctionLiteral()) {
907 ReportMessage("single_function_literal"); 909 ReportMessage("single_function_literal");
908 ok = false; 910 ok = false;
909 } 911 }
910 } 912 }
911 913
912 if (ok) { 914 if (ok) {
913 result = factory()->NewFunctionLiteral( 915 result = factory()->NewFunctionLiteral(
914 no_name, 916 ast_value_factory_->empty_string(),
917 ast_value_factory_,
915 scope_, 918 scope_,
916 body, 919 body,
917 function_state.materialized_literal_count(), 920 function_state.materialized_literal_count(),
918 function_state.expected_property_count(), 921 function_state.expected_property_count(),
919 function_state.handler_count(), 922 function_state.handler_count(),
920 0, 923 0,
921 FunctionLiteral::kNoDuplicateParameters, 924 FunctionLiteral::kNoDuplicateParameters,
922 FunctionLiteral::ANONYMOUS_EXPRESSION, 925 FunctionLiteral::ANONYMOUS_EXPRESSION,
923 FunctionLiteral::kGlobalOrEval, 926 FunctionLiteral::kGlobalOrEval,
924 FunctionLiteral::kNotParenthesized, 927 FunctionLiteral::kNotParenthesized,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 979 }
977 980
978 981
979 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { 982 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
980 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 983 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
981 scanner_.Initialize(source); 984 scanner_.Initialize(source);
982 ASSERT(scope_ == NULL); 985 ASSERT(scope_ == NULL);
983 ASSERT(target_stack_ == NULL); 986 ASSERT(target_stack_ == NULL);
984 987
985 Handle<String> name(String::cast(shared_info->name())); 988 Handle<String> name(String::cast(shared_info->name()));
986 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 989 ASSERT(ast_value_factory_);
987 fni_->PushEnclosingName(name); 990 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
991 const AstString* raw_name = ast_value_factory_->GetString(name);
992 fni_->PushEnclosingName(raw_name);
988 993
989 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 994 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
990 995
991 // Place holder for the result. 996 // Place holder for the result.
992 FunctionLiteral* result = NULL; 997 FunctionLiteral* result = NULL;
993 998
994 { 999 {
995 // Parse the function literal. 1000 // Parse the function literal.
996 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 1001 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
997 info()->SetGlobalScope(scope); 1002 info()->SetGlobalScope(scope);
998 if (!info()->closure().is_null()) { 1003 if (!info()->closure().is_null()) {
999 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 1004 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
1000 zone()); 1005 zone());
1001 } 1006 }
1002 original_scope_ = scope; 1007 original_scope_ = scope;
1003 FunctionState function_state(&function_state_, &scope_, scope, zone()); 1008 FunctionState function_state(&function_state_, &scope_, scope, zone(),
1009 ast_value_factory_);
1004 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 1010 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
1005 ASSERT(info()->strict_mode() == shared_info->strict_mode()); 1011 ASSERT(info()->strict_mode() == shared_info->strict_mode());
1006 scope->SetStrictMode(shared_info->strict_mode()); 1012 scope->SetStrictMode(shared_info->strict_mode());
1007 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1013 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1008 ? (shared_info->is_anonymous() 1014 ? (shared_info->is_anonymous()
1009 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1015 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1010 : FunctionLiteral::NAMED_EXPRESSION) 1016 : FunctionLiteral::NAMED_EXPRESSION)
1011 : FunctionLiteral::DECLARATION; 1017 : FunctionLiteral::DECLARATION;
1012 bool ok = true; 1018 bool ok = true;
1013 result = ParseFunctionLiteral(name, 1019 result = ParseFunctionLiteral(raw_name,
1014 Scanner::Location::invalid(), 1020 Scanner::Location::invalid(),
1015 false, // Strict mode name already checked. 1021 false, // Strict mode name already checked.
1016 shared_info->is_generator(), 1022 shared_info->is_generator(),
1017 RelocInfo::kNoPosition, 1023 RelocInfo::kNoPosition,
1018 function_type, 1024 function_type,
1019 &ok); 1025 &ok);
1020 // Make sure the results agree. 1026 // Make sure the results agree.
1021 ASSERT(ok == (result != NULL)); 1027 ASSERT(ok == (result != NULL));
1022 } 1028 }
1023 1029
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 continue; 1078 continue;
1073 } 1079 }
1074 1080
1075 if (directive_prologue) { 1081 if (directive_prologue) {
1076 // A shot at a directive. 1082 // A shot at a directive.
1077 ExpressionStatement* e_stat; 1083 ExpressionStatement* e_stat;
1078 Literal* literal; 1084 Literal* literal;
1079 // Still processing directive prologue? 1085 // Still processing directive prologue?
1080 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1086 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1081 (literal = e_stat->expression()->AsLiteral()) != NULL && 1087 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1082 literal->value()->IsString()) { 1088 literal->raw_value()->IsString()) {
1083 Handle<String> directive = Handle<String>::cast(literal->value());
1084
1085 // Check "use strict" directive (ES5 14.1). 1089 // Check "use strict" directive (ES5 14.1).
1086 if (strict_mode() == SLOPPY && 1090 if (strict_mode() == SLOPPY &&
1087 String::Equals(isolate()->factory()->use_strict_string(), 1091 literal->raw_value()->AsString() ==
1088 directive) && 1092 ast_value_factory_->use_strict_string() &&
1089 token_loc.end_pos - token_loc.beg_pos == 1093 token_loc.end_pos - token_loc.beg_pos == 12) {
1090 isolate()->heap()->use_strict_string()->length() + 2) {
1091 // TODO(mstarzinger): Global strict eval calls, need their own scope 1094 // TODO(mstarzinger): Global strict eval calls, need their own scope
1092 // as specified in ES5 10.4.2(3). The correct fix would be to always 1095 // as specified in ES5 10.4.2(3). The correct fix would be to always
1093 // add this scope in DoParseProgram(), but that requires adaptations 1096 // add this scope in DoParseProgram(), but that requires adaptations
1094 // all over the code base, so we go with a quick-fix for now. 1097 // all over the code base, so we go with a quick-fix for now.
1095 // In the same manner, we have to patch the parsing mode. 1098 // In the same manner, we have to patch the parsing mode.
1096 if (is_eval && !scope_->is_eval_scope()) { 1099 if (is_eval && !scope_->is_eval_scope()) {
1097 ASSERT(scope_->is_global_scope()); 1100 ASSERT(scope_->is_global_scope());
1098 Scope* scope = NewScope(scope_, EVAL_SCOPE); 1101 Scope* scope = NewScope(scope_, EVAL_SCOPE);
1099 scope->set_start_position(scope_->start_position()); 1102 scope->set_start_position(scope_->start_position());
1100 scope->set_end_position(scope_->end_position()); 1103 scope->set_end_position(scope_->end_position());
(...skipping 10 matching lines...) Expand all
1111 } 1114 }
1112 } 1115 }
1113 1116
1114 processor->Add(stat, zone()); 1117 processor->Add(stat, zone());
1115 } 1118 }
1116 1119
1117 return 0; 1120 return 0;
1118 } 1121 }
1119 1122
1120 1123
1121 Statement* Parser::ParseModuleElement(ZoneStringList* labels, 1124 Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels,
1122 bool* ok) { 1125 bool* ok) {
1123 // (Ecma 262 5th Edition, clause 14): 1126 // (Ecma 262 5th Edition, clause 14):
1124 // SourceElement: 1127 // SourceElement:
1125 // Statement 1128 // Statement
1126 // FunctionDeclaration 1129 // FunctionDeclaration
1127 // 1130 //
1128 // In harmony mode we allow additionally the following productions 1131 // In harmony mode we allow additionally the following productions
1129 // ModuleElement: 1132 // ModuleElement:
1130 // LetDeclaration 1133 // LetDeclaration
1131 // ConstDeclaration 1134 // ConstDeclaration
(...skipping 13 matching lines...) Expand all
1145 case Token::EXPORT: 1148 case Token::EXPORT:
1146 return ParseExportDeclaration(ok); 1149 return ParseExportDeclaration(ok);
1147 default: { 1150 default: {
1148 Statement* stmt = ParseStatement(labels, CHECK_OK); 1151 Statement* stmt = ParseStatement(labels, CHECK_OK);
1149 // Handle 'module' as a context-sensitive keyword. 1152 // Handle 'module' as a context-sensitive keyword.
1150 if (FLAG_harmony_modules && 1153 if (FLAG_harmony_modules &&
1151 peek() == Token::IDENTIFIER && 1154 peek() == Token::IDENTIFIER &&
1152 !scanner()->HasAnyLineTerminatorBeforeNext() && 1155 !scanner()->HasAnyLineTerminatorBeforeNext() &&
1153 stmt != NULL) { 1156 stmt != NULL) {
1154 ExpressionStatement* estmt = stmt->AsExpressionStatement(); 1157 ExpressionStatement* estmt = stmt->AsExpressionStatement();
1155 if (estmt != NULL && 1158 if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL &&
1156 estmt->expression()->AsVariableProxy() != NULL && 1159 estmt->expression()->AsVariableProxy()->raw_name() ==
1157 String::Equals(isolate()->factory()->module_string(), 1160 ast_value_factory_->module_string() &&
1158 estmt->expression()->AsVariableProxy()->name()) &&
1159 !scanner()->literal_contains_escapes()) { 1161 !scanner()->literal_contains_escapes()) {
1160 return ParseModuleDeclaration(NULL, ok); 1162 return ParseModuleDeclaration(NULL, ok);
1161 } 1163 }
1162 } 1164 }
1163 return stmt; 1165 return stmt;
1164 } 1166 }
1165 } 1167 }
1166 } 1168 }
1167 1169
1168 1170
1169 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 1171 Statement* Parser::ParseModuleDeclaration(ZoneList<const AstString*>* names,
1172 bool* ok) {
1170 // ModuleDeclaration: 1173 // ModuleDeclaration:
1171 // 'module' Identifier Module 1174 // 'module' Identifier Module
1172 1175
1173 int pos = peek_position(); 1176 int pos = peek_position();
1174 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1177 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1175 1178
1176 #ifdef DEBUG 1179 #ifdef DEBUG
1177 if (FLAG_print_interface_details) 1180 if (FLAG_print_interface_details)
1178 PrintF("# Module %s...\n", name->ToAsciiArray()); 1181 PrintF("# Module %.*s ", name->length(), name->raw_data());
1179 #endif 1182 #endif
1180 1183
1181 Module* module = ParseModule(CHECK_OK); 1184 Module* module = ParseModule(CHECK_OK);
1182 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); 1185 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface());
1183 Declaration* declaration = 1186 Declaration* declaration =
1184 factory()->NewModuleDeclaration(proxy, module, scope_, pos); 1187 factory()->NewModuleDeclaration(proxy, module, scope_, pos);
1185 Declare(declaration, true, CHECK_OK); 1188 Declare(declaration, true, CHECK_OK);
1186 1189
1187 #ifdef DEBUG 1190 #ifdef DEBUG
1188 if (FLAG_print_interface_details) 1191 if (FLAG_print_interface_details)
1189 PrintF("# Module %s.\n", name->ToAsciiArray()); 1192 PrintF("# Module %.*s ", name->length(), name->raw_data());
1190
1191 if (FLAG_print_interfaces) { 1193 if (FLAG_print_interfaces) {
1192 PrintF("module %s : ", name->ToAsciiArray()); 1194 PrintF("module %.*s: ", name->length(), name->raw_data());
1193 module->interface()->Print(); 1195 module->interface()->Print();
1194 } 1196 }
1195 #endif 1197 #endif
1196 1198
1197 if (names) names->Add(name, zone()); 1199 if (names) names->Add(name, zone());
1198 if (module->body() == NULL) 1200 if (module->body() == NULL)
1199 return factory()->NewEmptyStatement(pos); 1201 return factory()->NewEmptyStatement(pos);
1200 else 1202 else
1201 return factory()->NewModuleStatement(proxy, module->body(), pos); 1203 return factory()->NewModuleStatement(proxy, module->body(), pos);
1202 } 1204 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 1285
1284 1286
1285 Module* Parser::ParseModulePath(bool* ok) { 1287 Module* Parser::ParseModulePath(bool* ok) {
1286 // ModulePath: 1288 // ModulePath:
1287 // Identifier 1289 // Identifier
1288 // ModulePath '.' Identifier 1290 // ModulePath '.' Identifier
1289 1291
1290 int pos = peek_position(); 1292 int pos = peek_position();
1291 Module* result = ParseModuleVariable(CHECK_OK); 1293 Module* result = ParseModuleVariable(CHECK_OK);
1292 while (Check(Token::PERIOD)) { 1294 while (Check(Token::PERIOD)) {
1293 Handle<String> name = ParseIdentifierName(CHECK_OK); 1295 const AstString* name = ParseIdentifierName(CHECK_OK);
1294 #ifdef DEBUG 1296 #ifdef DEBUG
1295 if (FLAG_print_interface_details) 1297 if (FLAG_print_interface_details)
1296 PrintF("# Path .%s ", name->ToAsciiArray()); 1298 PrintF("# Path .%.*s ", name->length(), name->raw_data());
1297 #endif 1299 #endif
1298 Module* member = factory()->NewModulePath(result, name, pos); 1300 Module* member = factory()->NewModulePath(result, name, pos);
1299 result->interface()->Add(name, member->interface(), zone(), ok); 1301 result->interface()->Add(name, member->interface(), zone(), ok);
1300 if (!*ok) { 1302 if (!*ok) {
1301 #ifdef DEBUG 1303 #ifdef DEBUG
1302 if (FLAG_print_interfaces) { 1304 if (FLAG_print_interfaces) {
1303 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); 1305 PrintF("PATH TYPE ERROR at '%.*s'\n", name->length(), name->raw_data());
1304 PrintF("result: "); 1306 PrintF("result: ");
1305 result->interface()->Print(); 1307 result->interface()->Print();
1306 PrintF("member: "); 1308 PrintF("member: ");
1307 member->interface()->Print(); 1309 member->interface()->Print();
1308 } 1310 }
1309 #endif 1311 #endif
1310 ParserTraits::ReportMessage("invalid_module_path", name); 1312 ParserTraits::ReportMessage("invalid_module_path", name);
1311 return NULL; 1313 return NULL;
1312 } 1314 }
1313 result = member; 1315 result = member;
1314 } 1316 }
1315 1317
1316 return result; 1318 return result;
1317 } 1319 }
1318 1320
1319 1321
1320 Module* Parser::ParseModuleVariable(bool* ok) { 1322 Module* Parser::ParseModuleVariable(bool* ok) {
1321 // ModulePath: 1323 // ModulePath:
1322 // Identifier 1324 // Identifier
1323 1325
1324 int pos = peek_position(); 1326 int pos = peek_position();
1325 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1327 const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1326 #ifdef DEBUG 1328 #ifdef DEBUG
1327 if (FLAG_print_interface_details) 1329 if (FLAG_print_interface_details)
1328 PrintF("# Module variable %s ", name->ToAsciiArray()); 1330 PrintF("# Module variable %.*s ", name->length(), name->raw_data());
1329 #endif 1331 #endif
1330 VariableProxy* proxy = scope_->NewUnresolved( 1332 VariableProxy* proxy = scope_->NewUnresolved(
1331 factory(), name, Interface::NewModule(zone()), 1333 factory(), name, Interface::NewModule(zone()),
1332 scanner()->location().beg_pos); 1334 scanner()->location().beg_pos);
1333 1335
1334 return factory()->NewModuleVariable(proxy, pos); 1336 return factory()->NewModuleVariable(proxy, pos);
1335 } 1337 }
1336 1338
1337 1339
1338 Module* Parser::ParseModuleUrl(bool* ok) { 1340 Module* Parser::ParseModuleUrl(bool* ok) {
1339 // Module: 1341 // Module:
1340 // String 1342 // String
1341 1343
1342 int pos = peek_position(); 1344 int pos = peek_position();
1343 Expect(Token::STRING, CHECK_OK); 1345 Expect(Token::STRING, CHECK_OK);
1344 Handle<String> symbol = GetSymbol(); 1346 const AstString* symbol = GetSymbol(scanner());
1345 1347
1346 // TODO(ES6): Request JS resource from environment... 1348 // TODO(ES6): Request JS resource from environment...
1347 1349
1348 #ifdef DEBUG 1350 #ifdef DEBUG
1349 if (FLAG_print_interface_details) PrintF("# Url "); 1351 if (FLAG_print_interface_details) PrintF("# Url ");
1350 #endif 1352 #endif
1351 1353
1352 // Create an empty literal as long as the feature isn't finished. 1354 // Create an empty literal as long as the feature isn't finished.
1353 USE(symbol); 1355 USE(symbol);
1354 Scope* scope = NewScope(scope_, MODULE_SCOPE); 1356 Scope* scope = NewScope(scope_, MODULE_SCOPE);
(...skipping 23 matching lines...) Expand all
1378 1380
1379 1381
1380 Block* Parser::ParseImportDeclaration(bool* ok) { 1382 Block* Parser::ParseImportDeclaration(bool* ok) {
1381 // ImportDeclaration: 1383 // ImportDeclaration:
1382 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' 1384 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';'
1383 // 1385 //
1384 // TODO(ES6): implement destructuring ImportSpecifiers 1386 // TODO(ES6): implement destructuring ImportSpecifiers
1385 1387
1386 int pos = peek_position(); 1388 int pos = peek_position();
1387 Expect(Token::IMPORT, CHECK_OK); 1389 Expect(Token::IMPORT, CHECK_OK);
1388 ZoneStringList names(1, zone()); 1390 ZoneList<const AstString*> names(1, zone());
1389 1391
1390 Handle<String> name = ParseIdentifierName(CHECK_OK); 1392 const AstString* name = ParseIdentifierName(CHECK_OK);
1391 names.Add(name, zone()); 1393 names.Add(name, zone());
1392 while (peek() == Token::COMMA) { 1394 while (peek() == Token::COMMA) {
1393 Consume(Token::COMMA); 1395 Consume(Token::COMMA);
1394 name = ParseIdentifierName(CHECK_OK); 1396 name = ParseIdentifierName(CHECK_OK);
1395 names.Add(name, zone()); 1397 names.Add(name, zone());
1396 } 1398 }
1397 1399
1398 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1400 ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
1399 Module* module = ParseModuleSpecifier(CHECK_OK); 1401 Module* module = ParseModuleSpecifier(CHECK_OK);
1400 ExpectSemicolon(CHECK_OK); 1402 ExpectSemicolon(CHECK_OK);
1401 1403
1402 // Generate a separate declaration for each identifier. 1404 // Generate a separate declaration for each identifier.
1403 // TODO(ES6): once we implement destructuring, make that one declaration. 1405 // TODO(ES6): once we implement destructuring, make that one declaration.
1404 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); 1406 Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
1405 for (int i = 0; i < names.length(); ++i) { 1407 for (int i = 0; i < names.length(); ++i) {
1406 #ifdef DEBUG 1408 #ifdef DEBUG
1407 if (FLAG_print_interface_details) 1409 if (FLAG_print_interface_details)
1408 PrintF("# Import %s ", names[i]->ToAsciiArray()); 1410 PrintF("# Import %.*s ", name->length(), name->raw_data());
1409 #endif 1411 #endif
1410 Interface* interface = Interface::NewUnknown(zone()); 1412 Interface* interface = Interface::NewUnknown(zone());
1411 module->interface()->Add(names[i], interface, zone(), ok); 1413 module->interface()->Add(names[i], interface, zone(), ok);
1412 if (!*ok) { 1414 if (!*ok) {
1413 #ifdef DEBUG 1415 #ifdef DEBUG
1414 if (FLAG_print_interfaces) { 1416 if (FLAG_print_interfaces) {
1415 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); 1417 PrintF("IMPORT TYPE ERROR at '%.*s'\n", name->length(),
1418 name->raw_data());
1416 PrintF("module: "); 1419 PrintF("module: ");
1417 module->interface()->Print(); 1420 module->interface()->Print();
1418 } 1421 }
1419 #endif 1422 #endif
1420 ParserTraits::ReportMessage("invalid_module_path", name); 1423 ParserTraits::ReportMessage("invalid_module_path", name);
1421 return NULL; 1424 return NULL;
1422 } 1425 }
1423 VariableProxy* proxy = NewUnresolved(names[i], LET, interface); 1426 VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
1424 Declaration* declaration = 1427 Declaration* declaration =
1425 factory()->NewImportDeclaration(proxy, module, scope_, pos); 1428 factory()->NewImportDeclaration(proxy, module, scope_, pos);
(...skipping 10 matching lines...) Expand all
1436 // 'export' VariableDeclaration 1439 // 'export' VariableDeclaration
1437 // 'export' FunctionDeclaration 1440 // 'export' FunctionDeclaration
1438 // 'export' GeneratorDeclaration 1441 // 'export' GeneratorDeclaration
1439 // 'export' ModuleDeclaration 1442 // 'export' ModuleDeclaration
1440 // 1443 //
1441 // TODO(ES6): implement structuring ExportSpecifiers 1444 // TODO(ES6): implement structuring ExportSpecifiers
1442 1445
1443 Expect(Token::EXPORT, CHECK_OK); 1446 Expect(Token::EXPORT, CHECK_OK);
1444 1447
1445 Statement* result = NULL; 1448 Statement* result = NULL;
1446 ZoneStringList names(1, zone()); 1449 ZoneList<const AstString*> names(1, zone());
1447 switch (peek()) { 1450 switch (peek()) {
1448 case Token::IDENTIFIER: { 1451 case Token::IDENTIFIER: {
1449 int pos = position(); 1452 int pos = position();
1450 Handle<String> name = 1453 const AstString* name =
1451 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1454 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1452 // Handle 'module' as a context-sensitive keyword. 1455 // Handle 'module' as a context-sensitive keyword.
1453 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { 1456 if (name != ast_value_factory_->module_string()) {
1454 names.Add(name, zone()); 1457 names.Add(name, zone());
1455 while (peek() == Token::COMMA) { 1458 while (peek() == Token::COMMA) {
1456 Consume(Token::COMMA); 1459 Consume(Token::COMMA);
1457 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1460 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1458 names.Add(name, zone()); 1461 names.Add(name, zone());
1459 } 1462 }
1460 ExpectSemicolon(CHECK_OK); 1463 ExpectSemicolon(CHECK_OK);
1461 result = factory()->NewEmptyStatement(pos); 1464 result = factory()->NewEmptyStatement(pos);
1462 } else { 1465 } else {
1463 result = ParseModuleDeclaration(&names, CHECK_OK); 1466 result = ParseModuleDeclaration(&names, CHECK_OK);
(...skipping 15 matching lines...) Expand all
1479 *ok = false; 1482 *ok = false;
1480 ReportUnexpectedToken(scanner()->current_token()); 1483 ReportUnexpectedToken(scanner()->current_token());
1481 return NULL; 1484 return NULL;
1482 } 1485 }
1483 1486
1484 // Extract declared names into export declarations and interface. 1487 // Extract declared names into export declarations and interface.
1485 Interface* interface = scope_->interface(); 1488 Interface* interface = scope_->interface();
1486 for (int i = 0; i < names.length(); ++i) { 1489 for (int i = 0; i < names.length(); ++i) {
1487 #ifdef DEBUG 1490 #ifdef DEBUG
1488 if (FLAG_print_interface_details) 1491 if (FLAG_print_interface_details)
1489 PrintF("# Export %s ", names[i]->ToAsciiArray()); 1492 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data());
1490 #endif 1493 #endif
1491 Interface* inner = Interface::NewUnknown(zone()); 1494 Interface* inner = Interface::NewUnknown(zone());
1492 interface->Add(names[i], inner, zone(), CHECK_OK); 1495 interface->Add(names[i], inner, zone(), CHECK_OK);
1493 if (!*ok) 1496 if (!*ok)
1494 return NULL; 1497 return NULL;
1495 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); 1498 VariableProxy* proxy = NewUnresolved(names[i], LET, inner);
1496 USE(proxy); 1499 USE(proxy);
1497 // TODO(rossberg): Rethink whether we actually need to store export 1500 // TODO(rossberg): Rethink whether we actually need to store export
1498 // declarations (for compilation?). 1501 // declarations (for compilation?).
1499 // ExportDeclaration* declaration = 1502 // ExportDeclaration* declaration =
1500 // factory()->NewExportDeclaration(proxy, scope_, position); 1503 // factory()->NewExportDeclaration(proxy, scope_, position);
1501 // scope_->AddDeclaration(declaration); 1504 // scope_->AddDeclaration(declaration);
1502 } 1505 }
1503 1506
1504 ASSERT(result != NULL); 1507 ASSERT(result != NULL);
1505 return result; 1508 return result;
1506 } 1509 }
1507 1510
1508 1511
1509 Statement* Parser::ParseBlockElement(ZoneStringList* labels, 1512 Statement* Parser::ParseBlockElement(ZoneList<const AstString*>* labels,
1510 bool* ok) { 1513 bool* ok) {
1511 // (Ecma 262 5th Edition, clause 14): 1514 // (Ecma 262 5th Edition, clause 14):
1512 // SourceElement: 1515 // SourceElement:
1513 // Statement 1516 // Statement
1514 // FunctionDeclaration 1517 // FunctionDeclaration
1515 // 1518 //
1516 // In harmony mode we allow additionally the following productions 1519 // In harmony mode we allow additionally the following productions
1517 // BlockElement (aka SourceElement): 1520 // BlockElement (aka SourceElement):
1518 // LetDeclaration 1521 // LetDeclaration
1519 // ConstDeclaration 1522 // ConstDeclaration
1520 // GeneratorDeclaration 1523 // GeneratorDeclaration
1521 1524
1522 switch (peek()) { 1525 switch (peek()) {
1523 case Token::FUNCTION: 1526 case Token::FUNCTION:
1524 return ParseFunctionDeclaration(NULL, ok); 1527 return ParseFunctionDeclaration(NULL, ok);
1525 case Token::LET: 1528 case Token::LET:
1526 case Token::CONST: 1529 case Token::CONST:
1527 return ParseVariableStatement(kModuleElement, NULL, ok); 1530 return ParseVariableStatement(kModuleElement, NULL, ok);
1528 default: 1531 default:
1529 return ParseStatement(labels, ok); 1532 return ParseStatement(labels, ok);
1530 } 1533 }
1531 } 1534 }
1532 1535
1533 1536
1534 Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { 1537 Statement* Parser::ParseStatement(ZoneList<const AstString*>* labels,
1538 bool* ok) {
1535 // Statement :: 1539 // Statement ::
1536 // Block 1540 // Block
1537 // VariableStatement 1541 // VariableStatement
1538 // EmptyStatement 1542 // EmptyStatement
1539 // ExpressionStatement 1543 // ExpressionStatement
1540 // IfStatement 1544 // IfStatement
1541 // IterationStatement 1545 // IterationStatement
1542 // ContinueStatement 1546 // ContinueStatement
1543 // BreakStatement 1547 // BreakStatement
1544 // ReturnStatement 1548 // ReturnStatement
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 1638
1635 case Token::DEBUGGER: 1639 case Token::DEBUGGER:
1636 return ParseDebuggerStatement(ok); 1640 return ParseDebuggerStatement(ok);
1637 1641
1638 default: 1642 default:
1639 return ParseExpressionOrLabelledStatement(labels, ok); 1643 return ParseExpressionOrLabelledStatement(labels, ok);
1640 } 1644 }
1641 } 1645 }
1642 1646
1643 1647
1644 VariableProxy* Parser::NewUnresolved( 1648 VariableProxy* Parser::NewUnresolved(const AstString* name, VariableMode mode,
1645 Handle<String> name, VariableMode mode, Interface* interface) { 1649 Interface* interface) {
1646 // If we are inside a function, a declaration of a var/const variable is a 1650 // If we are inside a function, a declaration of a var/const variable is a
1647 // truly local variable, and the scope of the variable is always the function 1651 // truly local variable, and the scope of the variable is always the function
1648 // scope. 1652 // scope.
1649 // Let/const variables in harmony mode are always added to the immediately 1653 // Let/const variables in harmony mode are always added to the immediately
1650 // enclosing scope. 1654 // enclosing scope.
1651 return DeclarationScope(mode)->NewUnresolved( 1655 return DeclarationScope(mode)->NewUnresolved(
1652 factory(), name, interface, position()); 1656 factory(), name, interface, position());
1653 } 1657 }
1654 1658
1655 1659
1656 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { 1660 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
1657 VariableProxy* proxy = declaration->proxy(); 1661 VariableProxy* proxy = declaration->proxy();
1658 Handle<String> name = proxy->name(); 1662 ASSERT(proxy->raw_name() != NULL);
1663 const AstString* name = proxy->raw_name();
1659 VariableMode mode = declaration->mode(); 1664 VariableMode mode = declaration->mode();
1660 Scope* declaration_scope = DeclarationScope(mode); 1665 Scope* declaration_scope = DeclarationScope(mode);
1661 Variable* var = NULL; 1666 Variable* var = NULL;
1662 1667
1663 // If a suitable scope exists, then we can statically declare this 1668 // If a suitable scope exists, then we can statically declare this
1664 // variable and also set its mode. In any case, a Declaration node 1669 // variable and also set its mode. In any case, a Declaration node
1665 // will be added to the scope so that the declaration can be added 1670 // will be added to the scope so that the declaration can be added
1666 // to the corresponding activation frame at runtime if necessary. 1671 // to the corresponding activation frame at runtime if necessary.
1667 // For instance declarations inside an eval scope need to be added 1672 // For instance declarations inside an eval scope need to be added
1668 // to the calling function context. 1673 // to the calling function context.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 // with a context slot index and a context chain length for this 1781 // with a context slot index and a context chain length for this
1777 // initialization code. Thus, inside the 'with' statement, we need 1782 // initialization code. Thus, inside the 'with' statement, we need
1778 // both access to the static and the dynamic context chain; the 1783 // both access to the static and the dynamic context chain; the
1779 // runtime needs to provide both. 1784 // runtime needs to provide both.
1780 if (resolve && var != NULL) { 1785 if (resolve && var != NULL) {
1781 proxy->BindTo(var); 1786 proxy->BindTo(var);
1782 1787
1783 if (FLAG_harmony_modules) { 1788 if (FLAG_harmony_modules) {
1784 bool ok; 1789 bool ok;
1785 #ifdef DEBUG 1790 #ifdef DEBUG
1786 if (FLAG_print_interface_details) 1791 if (FLAG_print_interface_details) {
1787 PrintF("# Declare %s\n", var->name()->ToAsciiArray()); 1792 PrintF("# Declare %.*s ", var->raw_name()->length(),
1793 var->raw_name()->raw_data());
1794 }
1788 #endif 1795 #endif
1789 proxy->interface()->Unify(var->interface(), zone(), &ok); 1796 proxy->interface()->Unify(var->interface(), zone(), &ok);
1790 if (!ok) { 1797 if (!ok) {
1791 #ifdef DEBUG 1798 #ifdef DEBUG
1792 if (FLAG_print_interfaces) { 1799 if (FLAG_print_interfaces) {
1793 PrintF("DECLARE TYPE ERROR\n"); 1800 PrintF("DECLARE TYPE ERROR\n");
1794 PrintF("proxy: "); 1801 PrintF("proxy: ");
1795 proxy->interface()->Print(); 1802 proxy->interface()->Print();
1796 PrintF("var: "); 1803 PrintF("var: ");
1797 var->interface()->Print(); 1804 var->interface()->Print();
1798 } 1805 }
1799 #endif 1806 #endif
1800 ParserTraits::ReportMessage("module_type_error", name); 1807 ParserTraits::ReportMessage("module_type_error", name);
1801 } 1808 }
1802 } 1809 }
1803 } 1810 }
1804 } 1811 }
1805 1812
1806 1813
1807 // Language extension which is only enabled for source files loaded 1814 // Language extension which is only enabled for source files loaded
1808 // through the API's extension mechanism. A native function 1815 // through the API's extension mechanism. A native function
1809 // declaration is resolved by looking up the function through a 1816 // declaration is resolved by looking up the function through a
1810 // callback provided by the extension. 1817 // callback provided by the extension.
1811 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1818 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1812 int pos = peek_position(); 1819 int pos = peek_position();
1813 Expect(Token::FUNCTION, CHECK_OK); 1820 Expect(Token::FUNCTION, CHECK_OK);
1814 // Allow "eval" or "arguments" for backward compatibility. 1821 // Allow "eval" or "arguments" for backward compatibility.
1815 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1822 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1816 Expect(Token::LPAREN, CHECK_OK); 1823 Expect(Token::LPAREN, CHECK_OK);
1817 bool done = (peek() == Token::RPAREN); 1824 bool done = (peek() == Token::RPAREN);
1818 while (!done) { 1825 while (!done) {
1819 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1826 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1820 done = (peek() == Token::RPAREN); 1827 done = (peek() == Token::RPAREN);
1821 if (!done) { 1828 if (!done) {
1822 Expect(Token::COMMA, CHECK_OK); 1829 Expect(Token::COMMA, CHECK_OK);
1823 } 1830 }
1824 } 1831 }
1825 Expect(Token::RPAREN, CHECK_OK); 1832 Expect(Token::RPAREN, CHECK_OK);
(...skipping 14 matching lines...) Expand all
1840 Declare(declaration, true, CHECK_OK); 1847 Declare(declaration, true, CHECK_OK);
1841 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( 1848 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(
1842 name, extension_, RelocInfo::kNoPosition); 1849 name, extension_, RelocInfo::kNoPosition);
1843 return factory()->NewExpressionStatement( 1850 return factory()->NewExpressionStatement(
1844 factory()->NewAssignment( 1851 factory()->NewAssignment(
1845 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), 1852 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition),
1846 pos); 1853 pos);
1847 } 1854 }
1848 1855
1849 1856
1850 Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { 1857 Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names,
1858 bool* ok) {
1851 // FunctionDeclaration :: 1859 // FunctionDeclaration ::
1852 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1860 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1853 // GeneratorDeclaration :: 1861 // GeneratorDeclaration ::
1854 // 'function' '*' Identifier '(' FormalParameterListopt ')' 1862 // 'function' '*' Identifier '(' FormalParameterListopt ')'
1855 // '{' FunctionBody '}' 1863 // '{' FunctionBody '}'
1856 Expect(Token::FUNCTION, CHECK_OK); 1864 Expect(Token::FUNCTION, CHECK_OK);
1857 int pos = position(); 1865 int pos = position();
1858 bool is_generator = allow_generators() && Check(Token::MUL); 1866 bool is_generator = allow_generators() && Check(Token::MUL);
1859 bool is_strict_reserved = false; 1867 bool is_strict_reserved = false;
1860 Handle<String> name = ParseIdentifierOrStrictReservedWord( 1868 const AstString* name = ParseIdentifierOrStrictReservedWord(
1861 &is_strict_reserved, CHECK_OK); 1869 &is_strict_reserved, CHECK_OK);
1862 FunctionLiteral* fun = ParseFunctionLiteral(name, 1870 FunctionLiteral* fun = ParseFunctionLiteral(name,
1863 scanner()->location(), 1871 scanner()->location(),
1864 is_strict_reserved, 1872 is_strict_reserved,
1865 is_generator, 1873 is_generator,
1866 pos, 1874 pos,
1867 FunctionLiteral::DECLARATION, 1875 FunctionLiteral::DECLARATION,
1868 CHECK_OK); 1876 CHECK_OK);
1869 // Even if we're not at the top-level of the global or a function 1877 // Even if we're not at the top-level of the global or a function
1870 // scope, we treat it as such and introduce the function with its 1878 // scope, we treat it as such and introduce the function with its
1871 // initial value upon entering the corresponding scope. 1879 // initial value upon entering the corresponding scope.
1872 // In extended mode, a function behaves as a lexical binding, except in the 1880 // In extended mode, a function behaves as a lexical binding, except in the
1873 // global scope. 1881 // global scope.
1874 VariableMode mode = 1882 VariableMode mode =
1875 allow_harmony_scoping() && 1883 allow_harmony_scoping() &&
1876 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR; 1884 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR;
1877 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); 1885 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
1878 Declaration* declaration = 1886 Declaration* declaration =
1879 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 1887 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
1880 Declare(declaration, true, CHECK_OK); 1888 Declare(declaration, true, CHECK_OK);
1881 if (names) names->Add(name, zone()); 1889 if (names) names->Add(name, zone());
1882 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1890 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1883 } 1891 }
1884 1892
1885 1893
1886 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1894 Block* Parser::ParseBlock(ZoneList<const AstString*>* labels, bool* ok) {
1887 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1895 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1888 return ParseScopedBlock(labels, ok); 1896 return ParseScopedBlock(labels, ok);
1889 } 1897 }
1890 1898
1891 // Block :: 1899 // Block ::
1892 // '{' Statement* '}' 1900 // '{' Statement* '}'
1893 1901
1894 // Note that a Block does not introduce a new execution scope! 1902 // Note that a Block does not introduce a new execution scope!
1895 // (ECMA-262, 3rd, 12.2) 1903 // (ECMA-262, 3rd, 12.2)
1896 // 1904 //
1897 // Construct block expecting 16 statements. 1905 // Construct block expecting 16 statements.
1898 Block* result = 1906 Block* result =
1899 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1907 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1900 Target target(&this->target_stack_, result); 1908 Target target(&this->target_stack_, result);
1901 Expect(Token::LBRACE, CHECK_OK); 1909 Expect(Token::LBRACE, CHECK_OK);
1902 while (peek() != Token::RBRACE) { 1910 while (peek() != Token::RBRACE) {
1903 Statement* stat = ParseStatement(NULL, CHECK_OK); 1911 Statement* stat = ParseStatement(NULL, CHECK_OK);
1904 if (stat && !stat->IsEmpty()) { 1912 if (stat && !stat->IsEmpty()) {
1905 result->AddStatement(stat, zone()); 1913 result->AddStatement(stat, zone());
1906 } 1914 }
1907 } 1915 }
1908 Expect(Token::RBRACE, CHECK_OK); 1916 Expect(Token::RBRACE, CHECK_OK);
1909 return result; 1917 return result;
1910 } 1918 }
1911 1919
1912 1920
1913 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 1921 Block* Parser::ParseScopedBlock(ZoneList<const AstString*>* labels, bool* ok) {
1914 // The harmony mode uses block elements instead of statements. 1922 // The harmony mode uses block elements instead of statements.
1915 // 1923 //
1916 // Block :: 1924 // Block ::
1917 // '{' BlockElement* '}' 1925 // '{' BlockElement* '}'
1918 1926
1919 // Construct block expecting 16 statements. 1927 // Construct block expecting 16 statements.
1920 Block* body = 1928 Block* body =
1921 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); 1929 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
1922 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 1930 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
1923 1931
(...skipping 14 matching lines...) Expand all
1938 } 1946 }
1939 Expect(Token::RBRACE, CHECK_OK); 1947 Expect(Token::RBRACE, CHECK_OK);
1940 block_scope->set_end_position(scanner()->location().end_pos); 1948 block_scope->set_end_position(scanner()->location().end_pos);
1941 block_scope = block_scope->FinalizeBlockScope(); 1949 block_scope = block_scope->FinalizeBlockScope();
1942 body->set_scope(block_scope); 1950 body->set_scope(block_scope);
1943 return body; 1951 return body;
1944 } 1952 }
1945 1953
1946 1954
1947 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, 1955 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context,
1948 ZoneStringList* names, 1956 ZoneList<const AstString*>* names,
1949 bool* ok) { 1957 bool* ok) {
1950 // VariableStatement :: 1958 // VariableStatement ::
1951 // VariableDeclarations ';' 1959 // VariableDeclarations ';'
1952 1960
1953 Handle<String> ignore; 1961 const AstString* ignore;
1954 Block* result = 1962 Block* result =
1955 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK); 1963 ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK);
1956 ExpectSemicolon(CHECK_OK); 1964 ExpectSemicolon(CHECK_OK);
1957 return result; 1965 return result;
1958 } 1966 }
1959 1967
1960 1968
1961 // If the variable declaration declares exactly one non-const 1969 // If the variable declaration declares exactly one non-const
1962 // variable, then *out is set to that variable. In all other cases, 1970 // variable, then *out is set to that variable. In all other cases,
1963 // *out is untouched; in particular, it is the caller's responsibility 1971 // *out is untouched; in particular, it is the caller's responsibility
1964 // to initialize it properly. This mechanism is used for the parsing 1972 // to initialize it properly. This mechanism is used for the parsing
1965 // of 'for-in' loops. 1973 // of 'for-in' loops.
1966 Block* Parser::ParseVariableDeclarations( 1974 Block* Parser::ParseVariableDeclarations(
1967 VariableDeclarationContext var_context, 1975 VariableDeclarationContext var_context,
1968 VariableDeclarationProperties* decl_props, 1976 VariableDeclarationProperties* decl_props,
1969 ZoneStringList* names, 1977 ZoneList<const AstString*>* names,
1970 Handle<String>* out, 1978 const AstString** out,
1971 bool* ok) { 1979 bool* ok) {
1972 // VariableDeclarations :: 1980 // VariableDeclarations ::
1973 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] 1981 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
1974 // 1982 //
1975 // The ES6 Draft Rev3 specifies the following grammar for const declarations 1983 // The ES6 Draft Rev3 specifies the following grammar for const declarations
1976 // 1984 //
1977 // ConstDeclaration :: 1985 // ConstDeclaration ::
1978 // const ConstBinding (',' ConstBinding)* ';' 1986 // const ConstBinding (',' ConstBinding)* ';'
1979 // ConstBinding :: 1987 // ConstBinding ::
1980 // Identifier '=' AssignmentExpression 1988 // Identifier '=' AssignmentExpression
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 // 2076 //
2069 // We mark the block as initializer block because we don't want the 2077 // We mark the block as initializer block because we don't want the
2070 // rewriter to add a '.result' assignment to such a block (to get compliant 2078 // rewriter to add a '.result' assignment to such a block (to get compliant
2071 // behavior for code such as print(eval('var x = 7')), and for cosmetic 2079 // behavior for code such as print(eval('var x = 7')), and for cosmetic
2072 // reasons when pretty-printing. Also, unless an assignment (initialization) 2080 // reasons when pretty-printing. Also, unless an assignment (initialization)
2073 // is inside an initializer block, it is ignored. 2081 // is inside an initializer block, it is ignored.
2074 // 2082 //
2075 // Create new block with one expected declaration. 2083 // Create new block with one expected declaration.
2076 Block* block = factory()->NewBlock(NULL, 1, true, pos); 2084 Block* block = factory()->NewBlock(NULL, 1, true, pos);
2077 int nvars = 0; // the number of variables declared 2085 int nvars = 0; // the number of variables declared
2078 Handle<String> name; 2086 const AstString* name = NULL;
2079 do { 2087 do {
2080 if (fni_ != NULL) fni_->Enter(); 2088 if (fni_ != NULL) fni_->Enter();
2081 2089
2082 // Parse variable name. 2090 // Parse variable name.
2083 if (nvars > 0) Consume(Token::COMMA); 2091 if (nvars > 0) Consume(Token::COMMA);
2084 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2092 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2085 if (fni_ != NULL) fni_->PushVariableName(name); 2093 if (fni_ != NULL) fni_->PushVariableName(name);
2086 2094
2087 // Declare variable. 2095 // Declare variable.
2088 // Note that we *always* must treat the initial value via a separate init 2096 // Note that we *always* must treat the initial value via a separate init
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 // properties in the prototype chain, but only after the variable 2195 // properties in the prototype chain, but only after the variable
2188 // declaration statement has been executed. This is important in 2196 // declaration statement has been executed. This is important in
2189 // browsers where the global object (window) has lots of 2197 // browsers where the global object (window) has lots of
2190 // properties defined in prototype objects. 2198 // properties defined in prototype objects.
2191 if (initialization_scope->is_global_scope() && 2199 if (initialization_scope->is_global_scope() &&
2192 !IsLexicalVariableMode(mode)) { 2200 !IsLexicalVariableMode(mode)) {
2193 // Compute the arguments for the runtime call. 2201 // Compute the arguments for the runtime call.
2194 ZoneList<Expression*>* arguments = 2202 ZoneList<Expression*>* arguments =
2195 new(zone()) ZoneList<Expression*>(3, zone()); 2203 new(zone()) ZoneList<Expression*>(3, zone());
2196 // We have at least 1 parameter. 2204 // We have at least 1 parameter.
2197 arguments->Add(factory()->NewLiteral(name, pos), zone()); 2205 arguments->Add(factory()->NewStringLiteral(name, pos), zone());
2198 CallRuntime* initialize; 2206 CallRuntime* initialize;
2199 2207
2200 if (is_const) { 2208 if (is_const) {
2201 arguments->Add(value, zone()); 2209 arguments->Add(value, zone());
2202 value = NULL; // zap the value to avoid the unnecessary assignment 2210 value = NULL; // zap the value to avoid the unnecessary assignment
2203 2211
2204 // Construct the call to Runtime_InitializeConstGlobal 2212 // Construct the call to Runtime_InitializeConstGlobal
2205 // and add it to the initialization statement block. 2213 // and add it to the initialization statement block.
2206 // Note that the function does different things depending on 2214 // Note that the function does different things depending on
2207 // the number of arguments (1 or 2). 2215 // the number of arguments (1 or 2).
2208 initialize = factory()->NewCallRuntime( 2216 initialize = factory()->NewCallRuntime(
2209 isolate()->factory()->InitializeConstGlobal_string(), 2217 ast_value_factory_->initialize_const_global_string(),
2210 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal), 2218 Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal),
2211 arguments, pos); 2219 arguments, pos);
2212 } else { 2220 } else {
2213 // Add strict mode. 2221 // Add strict mode.
2214 // We may want to pass singleton to avoid Literal allocations. 2222 // We may want to pass singleton to avoid Literal allocations.
2215 StrictMode strict_mode = initialization_scope->strict_mode(); 2223 StrictMode strict_mode = initialization_scope->strict_mode();
2216 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); 2224 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone());
2217 2225
2218 // Be careful not to assign a value to the global variable if 2226 // Be careful not to assign a value to the global variable if
2219 // we're in a with. The initialization value should not 2227 // we're in a with. The initialization value should not
2220 // necessarily be stored in the global object in that case, 2228 // necessarily be stored in the global object in that case,
2221 // which is why we need to generate a separate assignment node. 2229 // which is why we need to generate a separate assignment node.
2222 if (value != NULL && !inside_with()) { 2230 if (value != NULL && !inside_with()) {
2223 arguments->Add(value, zone()); 2231 arguments->Add(value, zone());
2224 value = NULL; // zap the value to avoid the unnecessary assignment 2232 value = NULL; // zap the value to avoid the unnecessary assignment
2225 } 2233 }
2226 2234
2227 // Construct the call to Runtime_InitializeVarGlobal 2235 // Construct the call to Runtime_InitializeVarGlobal
2228 // and add it to the initialization statement block. 2236 // and add it to the initialization statement block.
2229 // Note that the function does different things depending on 2237 // Note that the function does different things depending on
2230 // the number of arguments (2 or 3). 2238 // the number of arguments (2 or 3).
2231 initialize = factory()->NewCallRuntime( 2239 initialize = factory()->NewCallRuntime(
2232 isolate()->factory()->InitializeVarGlobal_string(), 2240 ast_value_factory_->initialize_var_global_string(),
2233 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 2241 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
2234 arguments, pos); 2242 arguments, pos);
2235 } 2243 }
2236 2244
2237 block->AddStatement( 2245 block->AddStatement(
2238 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), 2246 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition),
2239 zone()); 2247 zone());
2240 } else if (needs_init) { 2248 } else if (needs_init) {
2241 // Constant initializations always assign to the declared constant which 2249 // Constant initializations always assign to the declared constant which
2242 // is always at the function scope level. This is only relevant for 2250 // is always at the function scope level. This is only relevant for
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 // If there was a single non-const declaration, return it in the output 2286 // If there was a single non-const declaration, return it in the output
2279 // parameter for possible use by for/in. 2287 // parameter for possible use by for/in.
2280 if (nvars == 1 && !is_const) { 2288 if (nvars == 1 && !is_const) {
2281 *out = name; 2289 *out = name;
2282 } 2290 }
2283 2291
2284 return block; 2292 return block;
2285 } 2293 }
2286 2294
2287 2295
2288 static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) { 2296 static bool ContainsLabel(ZoneList<const AstString*>* labels,
2289 ASSERT(!label.is_null()); 2297 const AstString* label) {
2298 ASSERT(label != NULL);
2290 if (labels != NULL) { 2299 if (labels != NULL) {
2291 for (int i = labels->length(); i-- > 0; ) { 2300 for (int i = labels->length(); i-- > 0; ) {
2292 if (labels->at(i).is_identical_to(label)) { 2301 if (labels->at(i) == label) {
2293 return true; 2302 return true;
2294 } 2303 }
2295 } 2304 }
2296 } 2305 }
2297 return false; 2306 return false;
2298 } 2307 }
2299 2308
2300 2309
2301 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 2310 Statement* Parser::ParseExpressionOrLabelledStatement(
2302 bool* ok) { 2311 ZoneList<const AstString*>* labels, bool* ok) {
2303 // ExpressionStatement | LabelledStatement :: 2312 // ExpressionStatement | LabelledStatement ::
2304 // Expression ';' 2313 // Expression ';'
2305 // Identifier ':' Statement 2314 // Identifier ':' Statement
2306 int pos = peek_position(); 2315 int pos = peek_position();
2307 bool starts_with_idenfifier = peek_any_identifier(); 2316 bool starts_with_idenfifier = peek_any_identifier();
2308 Expression* expr = ParseExpression(true, CHECK_OK); 2317 Expression* expr = ParseExpression(true, CHECK_OK);
2309 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && 2318 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
2310 expr->AsVariableProxy() != NULL && 2319 expr->AsVariableProxy() != NULL &&
2311 !expr->AsVariableProxy()->is_this()) { 2320 !expr->AsVariableProxy()->is_this()) {
2312 // Expression is a single identifier, and not, e.g., a parenthesized 2321 // Expression is a single identifier, and not, e.g., a parenthesized
2313 // identifier. 2322 // identifier.
2314 VariableProxy* var = expr->AsVariableProxy(); 2323 VariableProxy* var = expr->AsVariableProxy();
2315 Handle<String> label = var->name(); 2324 const AstString* label = var->raw_name();
2316 // TODO(1240780): We don't check for redeclaration of labels 2325 // TODO(1240780): We don't check for redeclaration of labels
2317 // during preparsing since keeping track of the set of active 2326 // during preparsing since keeping track of the set of active
2318 // labels requires nontrivial changes to the way scopes are 2327 // labels requires nontrivial changes to the way scopes are
2319 // structured. However, these are probably changes we want to 2328 // structured. However, these are probably changes we want to
2320 // make later anyway so we should go back and fix this then. 2329 // make later anyway so we should go back and fix this then.
2321 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2330 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
2322 ParserTraits::ReportMessage("label_redeclaration", label); 2331 ParserTraits::ReportMessage("label_redeclaration", label);
2323 *ok = false; 2332 *ok = false;
2324 return NULL; 2333 return NULL;
2325 } 2334 }
2326 if (labels == NULL) { 2335 if (labels == NULL) {
2327 labels = new(zone()) ZoneStringList(4, zone()); 2336 labels = new(zone()) ZoneList<const AstString*>(4, zone());
2328 } 2337 }
2329 labels->Add(label, zone()); 2338 labels->Add(label, zone());
2330 // Remove the "ghost" variable that turned out to be a label 2339 // Remove the "ghost" variable that turned out to be a label
2331 // from the top scope. This way, we don't try to resolve it 2340 // from the top scope. This way, we don't try to resolve it
2332 // during the scope processing. 2341 // during the scope processing.
2333 scope_->RemoveUnresolved(var); 2342 scope_->RemoveUnresolved(var);
2334 Expect(Token::COLON, CHECK_OK); 2343 Expect(Token::COLON, CHECK_OK);
2335 return ParseStatement(labels, ok); 2344 return ParseStatement(labels, ok);
2336 } 2345 }
2337 2346
2338 // If we have an extension, we allow a native function declaration. 2347 // If we have an extension, we allow a native function declaration.
2339 // A native function declaration starts with "native function" with 2348 // A native function declaration starts with "native function" with
2340 // no line-terminator between the two words. 2349 // no line-terminator between the two words.
2341 if (extension_ != NULL && 2350 if (extension_ != NULL &&
2342 peek() == Token::FUNCTION && 2351 peek() == Token::FUNCTION &&
2343 !scanner()->HasAnyLineTerminatorBeforeNext() && 2352 !scanner()->HasAnyLineTerminatorBeforeNext() &&
2344 expr != NULL && 2353 expr != NULL &&
2345 expr->AsVariableProxy() != NULL && 2354 expr->AsVariableProxy() != NULL &&
2346 String::Equals(isolate()->factory()->native_string(), 2355 expr->AsVariableProxy()->raw_name() ==
2347 expr->AsVariableProxy()->name()) && 2356 ast_value_factory_->native_string() &&
2348 !scanner()->literal_contains_escapes()) { 2357 !scanner()->literal_contains_escapes()) {
2349 return ParseNativeDeclaration(ok); 2358 return ParseNativeDeclaration(ok);
2350 } 2359 }
2351 2360
2352 // Parsed expression statement, or the context-sensitive 'module' keyword. 2361 // Parsed expression statement, or the context-sensitive 'module' keyword.
2353 // Only expect semicolon in the former case. 2362 // Only expect semicolon in the former case.
2354 if (!FLAG_harmony_modules || 2363 if (!FLAG_harmony_modules ||
2355 peek() != Token::IDENTIFIER || 2364 peek() != Token::IDENTIFIER ||
2356 scanner()->HasAnyLineTerminatorBeforeNext() || 2365 scanner()->HasAnyLineTerminatorBeforeNext() ||
2357 expr->AsVariableProxy() == NULL || 2366 expr->AsVariableProxy() == NULL ||
2358 !String::Equals(isolate()->factory()->module_string(), 2367 expr->AsVariableProxy()->raw_name() !=
2359 expr->AsVariableProxy()->name()) || 2368 ast_value_factory_->module_string() ||
2360 scanner()->literal_contains_escapes()) { 2369 scanner()->literal_contains_escapes()) {
2361 ExpectSemicolon(CHECK_OK); 2370 ExpectSemicolon(CHECK_OK);
2362 } 2371 }
2363 return factory()->NewExpressionStatement(expr, pos); 2372 return factory()->NewExpressionStatement(expr, pos);
2364 } 2373 }
2365 2374
2366 2375
2367 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 2376 IfStatement* Parser::ParseIfStatement(ZoneList<const AstString*>* labels,
2377 bool* ok) {
2368 // IfStatement :: 2378 // IfStatement ::
2369 // 'if' '(' Expression ')' Statement ('else' Statement)? 2379 // 'if' '(' Expression ')' Statement ('else' Statement)?
2370 2380
2371 int pos = peek_position(); 2381 int pos = peek_position();
2372 Expect(Token::IF, CHECK_OK); 2382 Expect(Token::IF, CHECK_OK);
2373 Expect(Token::LPAREN, CHECK_OK); 2383 Expect(Token::LPAREN, CHECK_OK);
2374 Expression* condition = ParseExpression(true, CHECK_OK); 2384 Expression* condition = ParseExpression(true, CHECK_OK);
2375 Expect(Token::RPAREN, CHECK_OK); 2385 Expect(Token::RPAREN, CHECK_OK);
2376 Statement* then_statement = ParseStatement(labels, CHECK_OK); 2386 Statement* then_statement = ParseStatement(labels, CHECK_OK);
2377 Statement* else_statement = NULL; 2387 Statement* else_statement = NULL;
2378 if (peek() == Token::ELSE) { 2388 if (peek() == Token::ELSE) {
2379 Next(); 2389 Next();
2380 else_statement = ParseStatement(labels, CHECK_OK); 2390 else_statement = ParseStatement(labels, CHECK_OK);
2381 } else { 2391 } else {
2382 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2392 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2383 } 2393 }
2384 return factory()->NewIfStatement( 2394 return factory()->NewIfStatement(
2385 condition, then_statement, else_statement, pos); 2395 condition, then_statement, else_statement, pos);
2386 } 2396 }
2387 2397
2388 2398
2389 Statement* Parser::ParseContinueStatement(bool* ok) { 2399 Statement* Parser::ParseContinueStatement(bool* ok) {
2390 // ContinueStatement :: 2400 // ContinueStatement ::
2391 // 'continue' Identifier? ';' 2401 // 'continue' Identifier? ';'
2392 2402
2393 int pos = peek_position(); 2403 int pos = peek_position();
2394 Expect(Token::CONTINUE, CHECK_OK); 2404 Expect(Token::CONTINUE, CHECK_OK);
2395 Handle<String> label = Handle<String>::null(); 2405 const AstString* label = NULL;
2396 Token::Value tok = peek(); 2406 Token::Value tok = peek();
2397 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2407 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2398 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2408 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2399 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2409 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2400 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2410 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2401 } 2411 }
2402 IterationStatement* target = NULL; 2412 IterationStatement* target = LookupContinueTarget(label, CHECK_OK);
2403 target = LookupContinueTarget(label, CHECK_OK);
2404 if (target == NULL) { 2413 if (target == NULL) {
2405 // Illegal continue statement. 2414 // Illegal continue statement.
2406 const char* message = "illegal_continue"; 2415 const char* message = "illegal_continue";
2407 if (!label.is_null()) { 2416 if (label != NULL) {
2408 message = "unknown_label"; 2417 message = "unknown_label";
2409 } 2418 }
2410 ParserTraits::ReportMessage(message, label); 2419 ParserTraits::ReportMessage(message, label);
2411 *ok = false; 2420 *ok = false;
2412 return NULL; 2421 return NULL;
2413 } 2422 }
2414 ExpectSemicolon(CHECK_OK); 2423 ExpectSemicolon(CHECK_OK);
2415 return factory()->NewContinueStatement(target, pos); 2424 return factory()->NewContinueStatement(target, pos);
2416 } 2425 }
2417 2426
2418 2427
2419 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 2428 Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels,
2429 bool* ok) {
2420 // BreakStatement :: 2430 // BreakStatement ::
2421 // 'break' Identifier? ';' 2431 // 'break' Identifier? ';'
2422 2432
2423 int pos = peek_position(); 2433 int pos = peek_position();
2424 Expect(Token::BREAK, CHECK_OK); 2434 Expect(Token::BREAK, CHECK_OK);
2425 Handle<String> label; 2435 const AstString* label = NULL;
2426 Token::Value tok = peek(); 2436 Token::Value tok = peek();
2427 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2437 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2428 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2438 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2429 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2439 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2430 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2440 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2431 } 2441 }
2432 // Parse labeled break statements that target themselves into 2442 // Parse labeled break statements that target themselves into
2433 // empty statements, e.g. 'l1: l2: l3: break l2;' 2443 // empty statements, e.g. 'l1: l2: l3: break l2;'
2434 if (!label.is_null() && ContainsLabel(labels, label)) { 2444 if (label != NULL && ContainsLabel(labels, label)) {
2435 ExpectSemicolon(CHECK_OK); 2445 ExpectSemicolon(CHECK_OK);
2436 return factory()->NewEmptyStatement(pos); 2446 return factory()->NewEmptyStatement(pos);
2437 } 2447 }
2438 BreakableStatement* target = NULL; 2448 BreakableStatement* target = NULL;
2439 target = LookupBreakTarget(label, CHECK_OK); 2449 target = LookupBreakTarget(label, CHECK_OK);
2440 if (target == NULL) { 2450 if (target == NULL) {
2441 // Illegal break statement. 2451 // Illegal break statement.
2442 const char* message = "illegal_break"; 2452 const char* message = "illegal_break";
2443 if (!label.is_null()) { 2453 if (label != NULL) {
2444 message = "unknown_label"; 2454 message = "unknown_label";
2445 } 2455 }
2446 ParserTraits::ReportMessage(message, label); 2456 ParserTraits::ReportMessage(message, label);
2447 *ok = false; 2457 *ok = false;
2448 return NULL; 2458 return NULL;
2449 } 2459 }
2450 ExpectSemicolon(CHECK_OK); 2460 ExpectSemicolon(CHECK_OK);
2451 return factory()->NewBreakStatement(target, pos); 2461 return factory()->NewBreakStatement(target, pos);
2452 } 2462 }
2453 2463
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 Scope* decl_scope = scope_->DeclarationScope(); 2497 Scope* decl_scope = scope_->DeclarationScope();
2488 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) { 2498 if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) {
2489 ReportMessageAt(loc, "illegal_return"); 2499 ReportMessageAt(loc, "illegal_return");
2490 *ok = false; 2500 *ok = false;
2491 return NULL; 2501 return NULL;
2492 } 2502 }
2493 return result; 2503 return result;
2494 } 2504 }
2495 2505
2496 2506
2497 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2507 Statement* Parser::ParseWithStatement(ZoneList<const AstString*>* labels,
2508 bool* ok) {
2498 // WithStatement :: 2509 // WithStatement ::
2499 // 'with' '(' Expression ')' Statement 2510 // 'with' '(' Expression ')' Statement
2500 2511
2501 Expect(Token::WITH, CHECK_OK); 2512 Expect(Token::WITH, CHECK_OK);
2502 int pos = position(); 2513 int pos = position();
2503 2514
2504 if (strict_mode() == STRICT) { 2515 if (strict_mode() == STRICT) {
2505 ReportMessage("strict_mode_with"); 2516 ReportMessage("strict_mode_with");
2506 *ok = false; 2517 *ok = false;
2507 return NULL; 2518 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 peek() != Token::DEFAULT && 2560 peek() != Token::DEFAULT &&
2550 peek() != Token::RBRACE) { 2561 peek() != Token::RBRACE) {
2551 Statement* stat = ParseStatement(NULL, CHECK_OK); 2562 Statement* stat = ParseStatement(NULL, CHECK_OK);
2552 statements->Add(stat, zone()); 2563 statements->Add(stat, zone());
2553 } 2564 }
2554 2565
2555 return factory()->NewCaseClause(label, statements, pos); 2566 return factory()->NewCaseClause(label, statements, pos);
2556 } 2567 }
2557 2568
2558 2569
2559 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 2570 SwitchStatement* Parser::ParseSwitchStatement(
2560 bool* ok) { 2571 ZoneList<const AstString*>* labels, bool* ok) {
2561 // SwitchStatement :: 2572 // SwitchStatement ::
2562 // 'switch' '(' Expression ')' '{' CaseClause* '}' 2573 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2563 2574
2564 SwitchStatement* statement = 2575 SwitchStatement* statement =
2565 factory()->NewSwitchStatement(labels, peek_position()); 2576 factory()->NewSwitchStatement(labels, peek_position());
2566 Target target(&this->target_stack_, statement); 2577 Target target(&this->target_stack_, statement);
2567 2578
2568 Expect(Token::SWITCH, CHECK_OK); 2579 Expect(Token::SWITCH, CHECK_OK);
2569 Expect(Token::LPAREN, CHECK_OK); 2580 Expect(Token::LPAREN, CHECK_OK);
2570 Expression* tag = ParseExpression(true, CHECK_OK); 2581 Expression* tag = ParseExpression(true, CHECK_OK);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 } 2644 }
2634 2645
2635 // If we can break out from the catch block and there is a finally block, 2646 // If we can break out from the catch block and there is a finally block,
2636 // then we will need to collect escaping targets from the catch 2647 // then we will need to collect escaping targets from the catch
2637 // block. Since we don't know yet if there will be a finally block, we 2648 // block. Since we don't know yet if there will be a finally block, we
2638 // always collect the targets. 2649 // always collect the targets.
2639 TargetCollector catch_collector(zone()); 2650 TargetCollector catch_collector(zone());
2640 Scope* catch_scope = NULL; 2651 Scope* catch_scope = NULL;
2641 Variable* catch_variable = NULL; 2652 Variable* catch_variable = NULL;
2642 Block* catch_block = NULL; 2653 Block* catch_block = NULL;
2643 Handle<String> name; 2654 const AstString* name = NULL;
2644 if (tok == Token::CATCH) { 2655 if (tok == Token::CATCH) {
2645 Consume(Token::CATCH); 2656 Consume(Token::CATCH);
2646 2657
2647 Expect(Token::LPAREN, CHECK_OK); 2658 Expect(Token::LPAREN, CHECK_OK);
2648 catch_scope = NewScope(scope_, CATCH_SCOPE); 2659 catch_scope = NewScope(scope_, CATCH_SCOPE);
2649 catch_scope->set_start_position(scanner()->location().beg_pos); 2660 catch_scope->set_start_position(scanner()->location().beg_pos);
2650 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 2661 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
2651 2662
2652 Expect(Token::RPAREN, CHECK_OK); 2663 Expect(Token::RPAREN, CHECK_OK);
2653 2664
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2703 index, try_block, finally_block, pos); 2714 index, try_block, finally_block, pos);
2704 // Combine the jump targets of the try block and the possible catch block. 2715 // Combine the jump targets of the try block and the possible catch block.
2705 try_collector.targets()->AddAll(*catch_collector.targets(), zone()); 2716 try_collector.targets()->AddAll(*catch_collector.targets(), zone());
2706 } 2717 }
2707 2718
2708 result->set_escaping_targets(try_collector.targets()); 2719 result->set_escaping_targets(try_collector.targets());
2709 return result; 2720 return result;
2710 } 2721 }
2711 2722
2712 2723
2713 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2724 DoWhileStatement* Parser::ParseDoWhileStatement(
2714 bool* ok) { 2725 ZoneList<const AstString*>* labels, bool* ok) {
2715 // DoStatement :: 2726 // DoStatement ::
2716 // 'do' Statement 'while' '(' Expression ')' ';' 2727 // 'do' Statement 'while' '(' Expression ')' ';'
2717 2728
2718 DoWhileStatement* loop = 2729 DoWhileStatement* loop =
2719 factory()->NewDoWhileStatement(labels, peek_position()); 2730 factory()->NewDoWhileStatement(labels, peek_position());
2720 Target target(&this->target_stack_, loop); 2731 Target target(&this->target_stack_, loop);
2721 2732
2722 Expect(Token::DO, CHECK_OK); 2733 Expect(Token::DO, CHECK_OK);
2723 Statement* body = ParseStatement(NULL, CHECK_OK); 2734 Statement* body = ParseStatement(NULL, CHECK_OK);
2724 Expect(Token::WHILE, CHECK_OK); 2735 Expect(Token::WHILE, CHECK_OK);
2725 Expect(Token::LPAREN, CHECK_OK); 2736 Expect(Token::LPAREN, CHECK_OK);
2726 2737
2727 Expression* cond = ParseExpression(true, CHECK_OK); 2738 Expression* cond = ParseExpression(true, CHECK_OK);
2728 Expect(Token::RPAREN, CHECK_OK); 2739 Expect(Token::RPAREN, CHECK_OK);
2729 2740
2730 // Allow do-statements to be terminated with and without 2741 // Allow do-statements to be terminated with and without
2731 // semi-colons. This allows code such as 'do;while(0)return' to 2742 // semi-colons. This allows code such as 'do;while(0)return' to
2732 // parse, which would not be the case if we had used the 2743 // parse, which would not be the case if we had used the
2733 // ExpectSemicolon() functionality here. 2744 // ExpectSemicolon() functionality here.
2734 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); 2745 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
2735 2746
2736 if (loop != NULL) loop->Initialize(cond, body); 2747 if (loop != NULL) loop->Initialize(cond, body);
2737 return loop; 2748 return loop;
2738 } 2749 }
2739 2750
2740 2751
2741 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2752 WhileStatement* Parser::ParseWhileStatement(ZoneList<const AstString*>* labels,
2753 bool* ok) {
2742 // WhileStatement :: 2754 // WhileStatement ::
2743 // 'while' '(' Expression ')' Statement 2755 // 'while' '(' Expression ')' Statement
2744 2756
2745 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position()); 2757 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position());
2746 Target target(&this->target_stack_, loop); 2758 Target target(&this->target_stack_, loop);
2747 2759
2748 Expect(Token::WHILE, CHECK_OK); 2760 Expect(Token::WHILE, CHECK_OK);
2749 Expect(Token::LPAREN, CHECK_OK); 2761 Expect(Token::LPAREN, CHECK_OK);
2750 Expression* cond = ParseExpression(true, CHECK_OK); 2762 Expression* cond = ParseExpression(true, CHECK_OK);
2751 Expect(Token::RPAREN, CHECK_OK); 2763 Expect(Token::RPAREN, CHECK_OK);
(...skipping 18 matching lines...) Expand all
2770 } 2782 }
2771 2783
2772 2784
2773 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2785 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2774 Expression* each, 2786 Expression* each,
2775 Expression* subject, 2787 Expression* subject,
2776 Statement* body) { 2788 Statement* body) {
2777 ForOfStatement* for_of = stmt->AsForOfStatement(); 2789 ForOfStatement* for_of = stmt->AsForOfStatement();
2778 2790
2779 if (for_of != NULL) { 2791 if (for_of != NULL) {
2780 Factory* heap_factory = isolate()->factory();
2781 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2792 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2782 heap_factory->dot_iterator_string()); 2793 ast_value_factory_->dot_iterator_string());
2783 Variable* result = scope_->DeclarationScope()->NewTemporary( 2794 Variable* result = scope_->DeclarationScope()->NewTemporary(
2784 heap_factory->dot_result_string()); 2795 ast_value_factory_->dot_result_string());
2785 2796
2786 Expression* assign_iterator; 2797 Expression* assign_iterator;
2787 Expression* next_result; 2798 Expression* next_result;
2788 Expression* result_done; 2799 Expression* result_done;
2789 Expression* assign_each; 2800 Expression* assign_each;
2790 2801
2791 // var iterator = iterable; 2802 // var iterator = iterable;
2792 { 2803 {
2793 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2804 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2794 assign_iterator = factory()->NewAssignment( 2805 assign_iterator = factory()->NewAssignment(
2795 Token::ASSIGN, iterator_proxy, subject, RelocInfo::kNoPosition); 2806 Token::ASSIGN, iterator_proxy, subject, RelocInfo::kNoPosition);
2796 } 2807 }
2797 2808
2798 // var result = iterator.next(); 2809 // var result = iterator.next();
2799 { 2810 {
2800 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2811 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2801 Expression* next_literal = factory()->NewLiteral( 2812 Expression* next_literal = factory()->NewStringLiteral(
2802 heap_factory->next_string(), RelocInfo::kNoPosition); 2813 ast_value_factory_->next_string(), RelocInfo::kNoPosition);
2803 Expression* next_property = factory()->NewProperty( 2814 Expression* next_property = factory()->NewProperty(
2804 iterator_proxy, next_literal, RelocInfo::kNoPosition); 2815 iterator_proxy, next_literal, RelocInfo::kNoPosition);
2805 ZoneList<Expression*>* next_arguments = 2816 ZoneList<Expression*>* next_arguments =
2806 new(zone()) ZoneList<Expression*>(0, zone()); 2817 new(zone()) ZoneList<Expression*>(0, zone());
2807 Expression* next_call = factory()->NewCall( 2818 Expression* next_call = factory()->NewCall(
2808 next_property, next_arguments, RelocInfo::kNoPosition); 2819 next_property, next_arguments, RelocInfo::kNoPosition);
2809 Expression* result_proxy = factory()->NewVariableProxy(result); 2820 Expression* result_proxy = factory()->NewVariableProxy(result);
2810 next_result = factory()->NewAssignment( 2821 next_result = factory()->NewAssignment(
2811 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition); 2822 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition);
2812 } 2823 }
2813 2824
2814 // result.done 2825 // result.done
2815 { 2826 {
2816 Expression* done_literal = factory()->NewLiteral( 2827 Expression* done_literal = factory()->NewStringLiteral(
2817 heap_factory->done_string(), RelocInfo::kNoPosition); 2828 ast_value_factory_->done_string(), RelocInfo::kNoPosition);
2818 Expression* result_proxy = factory()->NewVariableProxy(result); 2829 Expression* result_proxy = factory()->NewVariableProxy(result);
2819 result_done = factory()->NewProperty( 2830 result_done = factory()->NewProperty(
2820 result_proxy, done_literal, RelocInfo::kNoPosition); 2831 result_proxy, done_literal, RelocInfo::kNoPosition);
2821 } 2832 }
2822 2833
2823 // each = result.value 2834 // each = result.value
2824 { 2835 {
2825 Expression* value_literal = factory()->NewLiteral( 2836 Expression* value_literal = factory()->NewStringLiteral(
2826 heap_factory->value_string(), RelocInfo::kNoPosition); 2837 ast_value_factory_->value_string(), RelocInfo::kNoPosition);
2827 Expression* result_proxy = factory()->NewVariableProxy(result); 2838 Expression* result_proxy = factory()->NewVariableProxy(result);
2828 Expression* result_value = factory()->NewProperty( 2839 Expression* result_value = factory()->NewProperty(
2829 result_proxy, value_literal, RelocInfo::kNoPosition); 2840 result_proxy, value_literal, RelocInfo::kNoPosition);
2830 assign_each = factory()->NewAssignment( 2841 assign_each = factory()->NewAssignment(
2831 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2842 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2832 } 2843 }
2833 2844
2834 for_of->Initialize(each, subject, body, 2845 for_of->Initialize(each, subject, body,
2835 assign_iterator, next_result, result_done, assign_each); 2846 assign_iterator, next_result, result_done, assign_each);
2836 } else { 2847 } else {
2837 stmt->Initialize(each, subject, body); 2848 stmt->Initialize(each, subject, body);
2838 } 2849 }
2839 } 2850 }
2840 2851
2841 2852
2842 Statement* Parser::DesugarLetBindingsInForStatement( 2853 Statement* Parser::DesugarLetBindingsInForStatement(
2843 Scope* inner_scope, ZoneStringList* names, ForStatement* loop, 2854 Scope* inner_scope, ZoneList<const AstString*>* names,
2844 Statement* init, Expression* cond, Statement* next, Statement* body, 2855 ForStatement* loop, Statement* init, Expression* cond, Statement* next,
2845 bool* ok) { 2856 Statement* body, bool* ok) {
2846 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are 2857 // ES6 13.6.3.4 specifies that on each loop iteration the let variables are
2847 // copied into a new environment. After copying, the "next" statement of the 2858 // copied into a new environment. After copying, the "next" statement of the
2848 // loop is executed to update the loop variables. The loop condition is 2859 // loop is executed to update the loop variables. The loop condition is
2849 // checked and the loop body is executed. 2860 // checked and the loop body is executed.
2850 // 2861 //
2851 // We rewrite a for statement of the form 2862 // We rewrite a for statement of the form
2852 // 2863 //
2853 // for (let x = i; cond; next) body 2864 // for (let x = i; cond; next) body
2854 // 2865 //
2855 // into 2866 // into
(...skipping 20 matching lines...) Expand all
2876 // } 2887 // }
2877 2888
2878 ASSERT(names->length() > 0); 2889 ASSERT(names->length() > 0);
2879 Scope* for_scope = scope_; 2890 Scope* for_scope = scope_;
2880 ZoneList<Variable*> temps(names->length(), zone()); 2891 ZoneList<Variable*> temps(names->length(), zone());
2881 2892
2882 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, 2893 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false,
2883 RelocInfo::kNoPosition); 2894 RelocInfo::kNoPosition);
2884 outer_block->AddStatement(init, zone()); 2895 outer_block->AddStatement(init, zone());
2885 2896
2886 Handle<String> temp_name = isolate()->factory()->dot_for_string(); 2897 const AstString* temp_name = ast_value_factory_->dot_for_string();
2887 Handle<Smi> smi0 = handle(Smi::FromInt(0), isolate());
2888 Handle<Smi> smi1 = handle(Smi::FromInt(1), isolate());
2889
2890 2898
2891 // For each let variable x: 2899 // For each let variable x:
2892 // make statement: temp_x = x. 2900 // make statement: temp_x = x.
2893 for (int i = 0; i < names->length(); i++) { 2901 for (int i = 0; i < names->length(); i++) {
2894 VariableProxy* proxy = 2902 VariableProxy* proxy =
2895 NewUnresolved(names->at(i), LET, Interface::NewValue()); 2903 NewUnresolved(names->at(i), LET, Interface::NewValue());
2896 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); 2904 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name);
2897 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2905 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2898 Assignment* assignment = factory()->NewAssignment( 2906 Assignment* assignment = factory()->NewAssignment(
2899 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 2907 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
2900 Statement* assignment_statement = factory()->NewExpressionStatement( 2908 Statement* assignment_statement = factory()->NewExpressionStatement(
2901 assignment, RelocInfo::kNoPosition); 2909 assignment, RelocInfo::kNoPosition);
2902 outer_block->AddStatement(assignment_statement, zone()); 2910 outer_block->AddStatement(assignment_statement, zone());
2903 temps.Add(temp, zone()); 2911 temps.Add(temp, zone());
2904 } 2912 }
2905 2913
2906 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name); 2914 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name);
2907 // Make statement: flag = 1. 2915 // Make statement: flag = 1.
2908 { 2916 {
2909 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2917 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2910 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2918 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2911 Assignment* assignment = factory()->NewAssignment( 2919 Assignment* assignment = factory()->NewAssignment(
2912 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); 2920 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
2913 Statement* assignment_statement = factory()->NewExpressionStatement( 2921 Statement* assignment_statement = factory()->NewExpressionStatement(
2914 assignment, RelocInfo::kNoPosition); 2922 assignment, RelocInfo::kNoPosition);
2915 outer_block->AddStatement(assignment_statement, zone()); 2923 outer_block->AddStatement(assignment_statement, zone());
2916 } 2924 }
2917 2925
2918 outer_block->AddStatement(loop, zone()); 2926 outer_block->AddStatement(loop, zone());
2919 outer_block->set_scope(for_scope); 2927 outer_block->set_scope(for_scope);
2920 scope_ = inner_scope; 2928 scope_ = inner_scope;
(...skipping 19 matching lines...) Expand all
2940 assignment, pos); 2948 assignment, pos);
2941 proxy->var()->set_initializer_position(pos); 2949 proxy->var()->set_initializer_position(pos);
2942 inner_block->AddStatement(assignment_statement, zone()); 2950 inner_block->AddStatement(assignment_statement, zone());
2943 } 2951 }
2944 2952
2945 // Make statement: if (flag == 1) { flag = 0; } else { next; }. 2953 // Make statement: if (flag == 1) { flag = 0; } else { next; }.
2946 { 2954 {
2947 Expression* compare = NULL; 2955 Expression* compare = NULL;
2948 // Make compare expresion: flag == 1. 2956 // Make compare expresion: flag == 1.
2949 { 2957 {
2950 Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); 2958 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
2951 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2959 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2952 compare = factory()->NewCompareOperation( 2960 compare = factory()->NewCompareOperation(
2953 Token::EQ, flag_proxy, const1, pos); 2961 Token::EQ, flag_proxy, const1, pos);
2954 } 2962 }
2955 Statement* clear_flag = NULL; 2963 Statement* clear_flag = NULL;
2956 // Make statement: flag = 0. 2964 // Make statement: flag = 0.
2957 { 2965 {
2958 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 2966 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
2959 Expression* const0 = factory()->NewLiteral(smi0, RelocInfo::kNoPosition); 2967 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition);
2960 Assignment* assignment = factory()->NewAssignment( 2968 Assignment* assignment = factory()->NewAssignment(
2961 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); 2969 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition);
2962 clear_flag = factory()->NewExpressionStatement(assignment, pos); 2970 clear_flag = factory()->NewExpressionStatement(assignment, pos);
2963 } 2971 }
2964 Statement* clear_flag_or_next = factory()->NewIfStatement( 2972 Statement* clear_flag_or_next = factory()->NewIfStatement(
2965 compare, clear_flag, next, RelocInfo::kNoPosition); 2973 compare, clear_flag, next, RelocInfo::kNoPosition);
2966 inner_block->AddStatement(clear_flag_or_next, zone()); 2974 inner_block->AddStatement(clear_flag_or_next, zone());
2967 } 2975 }
2968 2976
2969 2977
2970 // Make statement: if (cond) { } else { break; }. 2978 // Make statement: if (cond) { } else { break; }.
2971 { 2979 {
2972 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2980 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2973 BreakableStatement* t = LookupBreakTarget(Handle<String>(), CHECK_OK); 2981 BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK);
2974 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); 2982 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition);
2975 Statement* if_not_cond_break = factory()->NewIfStatement( 2983 Statement* if_not_cond_break = factory()->NewIfStatement(
2976 cond, empty, stop, cond->position()); 2984 cond, empty, stop, cond->position());
2977 inner_block->AddStatement(if_not_cond_break, zone()); 2985 inner_block->AddStatement(if_not_cond_break, zone());
2978 } 2986 }
2979 2987
2980 inner_block->AddStatement(body, zone()); 2988 inner_block->AddStatement(body, zone());
2981 2989
2982 // For each let variable x: 2990 // For each let variable x:
2983 // make statement: temp_x = x; 2991 // make statement: temp_x = x;
(...skipping 10 matching lines...) Expand all
2994 3002
2995 inner_scope->set_end_position(scanner()->location().end_pos); 3003 inner_scope->set_end_position(scanner()->location().end_pos);
2996 inner_block->set_scope(inner_scope); 3004 inner_block->set_scope(inner_scope);
2997 scope_ = for_scope; 3005 scope_ = for_scope;
2998 3006
2999 loop->Initialize(NULL, NULL, NULL, inner_block); 3007 loop->Initialize(NULL, NULL, NULL, inner_block);
3000 return outer_block; 3008 return outer_block;
3001 } 3009 }
3002 3010
3003 3011
3004 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 3012 Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels,
3013 bool* ok) {
3005 // ForStatement :: 3014 // ForStatement ::
3006 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 3015 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
3007 3016
3008 int pos = peek_position(); 3017 int pos = peek_position();
3009 Statement* init = NULL; 3018 Statement* init = NULL;
3010 ZoneStringList let_bindings(1, zone()); 3019 ZoneList<const AstString*> let_bindings(1, zone());
3011 3020
3012 // Create an in-between scope for let-bound iteration variables. 3021 // Create an in-between scope for let-bound iteration variables.
3013 Scope* saved_scope = scope_; 3022 Scope* saved_scope = scope_;
3014 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); 3023 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE);
3015 scope_ = for_scope; 3024 scope_ = for_scope;
3016 3025
3017 Expect(Token::FOR, CHECK_OK); 3026 Expect(Token::FOR, CHECK_OK);
3018 Expect(Token::LPAREN, CHECK_OK); 3027 Expect(Token::LPAREN, CHECK_OK);
3019 for_scope->set_start_position(scanner()->location().beg_pos); 3028 for_scope->set_start_position(scanner()->location().beg_pos);
3020 if (peek() != Token::SEMICOLON) { 3029 if (peek() != Token::SEMICOLON) {
3021 if (peek() == Token::VAR || peek() == Token::CONST) { 3030 if (peek() == Token::VAR || peek() == Token::CONST) {
3022 bool is_const = peek() == Token::CONST; 3031 bool is_const = peek() == Token::CONST;
3023 Handle<String> name; 3032 const AstString* name = NULL;
3024 VariableDeclarationProperties decl_props = kHasNoInitializers; 3033 VariableDeclarationProperties decl_props = kHasNoInitializers;
3025 Block* variable_statement = 3034 Block* variable_statement =
3026 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, 3035 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
3027 CHECK_OK); 3036 CHECK_OK);
3028 bool accept_OF = decl_props == kHasNoInitializers; 3037 bool accept_OF = decl_props == kHasNoInitializers;
3029 ForEachStatement::VisitMode mode; 3038 ForEachStatement::VisitMode mode;
3030 3039
3031 if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) { 3040 if (name != NULL && CheckInOrOf(accept_OF, &mode)) {
3032 Interface* interface = 3041 Interface* interface =
3033 is_const ? Interface::NewConst() : Interface::NewValue(); 3042 is_const ? Interface::NewConst() : Interface::NewValue();
3034 ForEachStatement* loop = 3043 ForEachStatement* loop =
3035 factory()->NewForEachStatement(mode, labels, pos); 3044 factory()->NewForEachStatement(mode, labels, pos);
3036 Target target(&this->target_stack_, loop); 3045 Target target(&this->target_stack_, loop);
3037 3046
3038 Expression* enumerable = ParseExpression(true, CHECK_OK); 3047 Expression* enumerable = ParseExpression(true, CHECK_OK);
3039 Expect(Token::RPAREN, CHECK_OK); 3048 Expect(Token::RPAREN, CHECK_OK);
3040 3049
3041 VariableProxy* each = 3050 VariableProxy* each =
3042 scope_->NewUnresolved(factory(), name, interface); 3051 scope_->NewUnresolved(factory(), name, interface);
3043 Statement* body = ParseStatement(NULL, CHECK_OK); 3052 Statement* body = ParseStatement(NULL, CHECK_OK);
3044 InitializeForEachStatement(loop, each, enumerable, body); 3053 InitializeForEachStatement(loop, each, enumerable, body);
3045 Block* result = 3054 Block* result =
3046 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 3055 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
3047 result->AddStatement(variable_statement, zone()); 3056 result->AddStatement(variable_statement, zone());
3048 result->AddStatement(loop, zone()); 3057 result->AddStatement(loop, zone());
3049 scope_ = saved_scope; 3058 scope_ = saved_scope;
3050 for_scope->set_end_position(scanner()->location().end_pos); 3059 for_scope->set_end_position(scanner()->location().end_pos);
3051 for_scope = for_scope->FinalizeBlockScope(); 3060 for_scope = for_scope->FinalizeBlockScope();
3052 ASSERT(for_scope == NULL); 3061 ASSERT(for_scope == NULL);
3053 // Parsed for-in loop w/ variable/const declaration. 3062 // Parsed for-in loop w/ variable/const declaration.
3054 return result; 3063 return result;
3055 } else { 3064 } else {
3056 init = variable_statement; 3065 init = variable_statement;
3057 } 3066 }
3058 } else if (peek() == Token::LET) { 3067 } else if (peek() == Token::LET) {
3059 Handle<String> name; 3068 const AstString* name = NULL;
3060 VariableDeclarationProperties decl_props = kHasNoInitializers; 3069 VariableDeclarationProperties decl_props = kHasNoInitializers;
3061 Block* variable_statement = 3070 Block* variable_statement =
3062 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, 3071 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings,
3063 &name, CHECK_OK); 3072 &name, CHECK_OK);
3064 bool accept_IN = !name.is_null() && decl_props != kHasInitializers; 3073 bool accept_IN = name != NULL && decl_props != kHasInitializers;
3065 bool accept_OF = decl_props == kHasNoInitializers; 3074 bool accept_OF = decl_props == kHasNoInitializers;
3066 ForEachStatement::VisitMode mode; 3075 ForEachStatement::VisitMode mode;
3067 3076
3068 if (accept_IN && CheckInOrOf(accept_OF, &mode)) { 3077 if (accept_IN && CheckInOrOf(accept_OF, &mode)) {
3069 // Rewrite a for-in statement of the form 3078 // Rewrite a for-in statement of the form
3070 // 3079 //
3071 // for (let x in e) b 3080 // for (let x in e) b
3072 // 3081 //
3073 // into 3082 // into
3074 // 3083 //
3075 // <let x' be a temporary variable> 3084 // <let x' be a temporary variable>
3076 // for (x' in e) { 3085 // for (x' in e) {
3077 // let x; 3086 // let x;
3078 // x = x'; 3087 // x = x';
3079 // b; 3088 // b;
3080 // } 3089 // }
3081 3090
3082 // TODO(keuchel): Move the temporary variable to the block scope, after 3091 // TODO(keuchel): Move the temporary variable to the block scope, after
3083 // implementing stack allocated block scoped variables. 3092 // implementing stack allocated block scoped variables.
3084 Factory* heap_factory = isolate()->factory(); 3093 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3085 Handle<String> tempstr; 3094 ast_value_factory_->dot_for_string());
3086 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3087 isolate(), tempstr,
3088 heap_factory->NewConsString(heap_factory->dot_for_string(), name),
3089 0);
3090 Handle<String> tempname = heap_factory->InternalizeString(tempstr);
3091 Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname);
3092 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3095 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3093 ForEachStatement* loop = 3096 ForEachStatement* loop =
3094 factory()->NewForEachStatement(mode, labels, pos); 3097 factory()->NewForEachStatement(mode, labels, pos);
3095 Target target(&this->target_stack_, loop); 3098 Target target(&this->target_stack_, loop);
3096 3099
3097 // The expression does not see the loop variable. 3100 // The expression does not see the loop variable.
3098 scope_ = saved_scope; 3101 scope_ = saved_scope;
3099 Expression* enumerable = ParseExpression(true, CHECK_OK); 3102 Expression* enumerable = ParseExpression(true, CHECK_OK);
3100 scope_ = for_scope; 3103 scope_ = for_scope;
3101 Expect(Token::RPAREN, CHECK_OK); 3104 Expect(Token::RPAREN, CHECK_OK);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 // DebuggerStatement :: 3215 // DebuggerStatement ::
3213 // 'debugger' ';' 3216 // 'debugger' ';'
3214 3217
3215 int pos = peek_position(); 3218 int pos = peek_position();
3216 Expect(Token::DEBUGGER, CHECK_OK); 3219 Expect(Token::DEBUGGER, CHECK_OK);
3217 ExpectSemicolon(CHECK_OK); 3220 ExpectSemicolon(CHECK_OK);
3218 return factory()->NewDebuggerStatement(pos); 3221 return factory()->NewDebuggerStatement(pos);
3219 } 3222 }
3220 3223
3221 3224
3222 void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) { 3225 void Parser::ReportInvalidCachedData(const AstString* name, bool* ok) {
3223 ParserTraits::ReportMessage("invalid_cached_data_function", name); 3226 ParserTraits::ReportMessage("invalid_cached_data_function", name);
3224 *ok = false; 3227 *ok = false;
3225 } 3228 }
3226 3229
3227 3230
3228 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3231 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
3229 if (expression->IsLiteral()) return true; 3232 if (expression->IsLiteral()) return true;
3230 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3233 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
3231 return lit != NULL && lit->is_simple(); 3234 return lit != NULL && lit->is_simple();
3232 } 3235 }
(...skipping 29 matching lines...) Expand all
3262 return static_cast<LiteralType>(literal_type->value()); 3265 return static_cast<LiteralType>(literal_type->value());
3263 } 3266 }
3264 3267
3265 3268
3266 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3269 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3267 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3270 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3268 } 3271 }
3269 3272
3270 3273
3271 FunctionLiteral* Parser::ParseFunctionLiteral( 3274 FunctionLiteral* Parser::ParseFunctionLiteral(
3272 Handle<String> function_name, 3275 const AstString* function_name,
3273 Scanner::Location function_name_location, 3276 Scanner::Location function_name_location,
3274 bool name_is_strict_reserved, 3277 bool name_is_strict_reserved,
3275 bool is_generator, 3278 bool is_generator,
3276 int function_token_pos, 3279 int function_token_pos,
3277 FunctionLiteral::FunctionType function_type, 3280 FunctionLiteral::FunctionType function_type,
3278 bool* ok) { 3281 bool* ok) {
3279 // Function :: 3282 // Function ::
3280 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3283 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3281 3284
3282 int pos = function_token_pos == RelocInfo::kNoPosition 3285 int pos = function_token_pos == RelocInfo::kNoPosition
3283 ? peek_position() : function_token_pos; 3286 ? peek_position() : function_token_pos;
3284 3287
3285 // Anonymous functions were passed either the empty symbol or a null 3288 // Anonymous functions were passed either the empty symbol or a null
3286 // handle as the function name. Remember if we were passed a non-empty 3289 // handle as the function name. Remember if we were passed a non-empty
3287 // handle to decide whether to invoke function name inference. 3290 // handle to decide whether to invoke function name inference.
3288 bool should_infer_name = function_name.is_null(); 3291 bool should_infer_name = function_name == NULL;
3289 3292
3290 // We want a non-null handle as the function name. 3293 // We want a non-null handle as the function name.
3291 if (should_infer_name) { 3294 if (should_infer_name) {
3292 function_name = isolate()->factory()->empty_string(); 3295 function_name = ast_value_factory_->empty_string();
3293 } 3296 }
3294 3297
3295 int num_parameters = 0; 3298 int num_parameters = 0;
3296 // Function declarations are function scoped in normal mode, so they are 3299 // Function declarations are function scoped in normal mode, so they are
3297 // hoisted. In harmony block scoping mode they are block scoped, so they 3300 // hoisted. In harmony block scoping mode they are block scoped, so they
3298 // are not hoisted. 3301 // are not hoisted.
3299 // 3302 //
3300 // One tricky case are function declarations in a local sloppy-mode eval: 3303 // One tricky case are function declarations in a local sloppy-mode eval:
3301 // their declaration is hoisted, but they still see the local scope. E.g., 3304 // their declaration is hoisted, but they still see the local scope. E.g.,
3302 // 3305 //
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3334 int expected_property_count = -1; 3337 int expected_property_count = -1;
3335 int handler_count = 0; 3338 int handler_count = 0;
3336 FunctionLiteral::ParameterFlag duplicate_parameters = 3339 FunctionLiteral::ParameterFlag duplicate_parameters =
3337 FunctionLiteral::kNoDuplicateParameters; 3340 FunctionLiteral::kNoDuplicateParameters;
3338 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3341 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3339 ? FunctionLiteral::kIsParenthesized 3342 ? FunctionLiteral::kIsParenthesized
3340 : FunctionLiteral::kNotParenthesized; 3343 : FunctionLiteral::kNotParenthesized;
3341 AstProperties ast_properties; 3344 AstProperties ast_properties;
3342 BailoutReason dont_optimize_reason = kNoReason; 3345 BailoutReason dont_optimize_reason = kNoReason;
3343 // Parse function body. 3346 // Parse function body.
3344 { FunctionState function_state(&function_state_, &scope_, scope, zone()); 3347 {
3348 FunctionState function_state(&function_state_, &scope_, scope, zone(),
3349 ast_value_factory_);
3345 scope_->SetScopeName(function_name); 3350 scope_->SetScopeName(function_name);
3346 3351
3347 if (is_generator) { 3352 if (is_generator) {
3348 // For generators, allocating variables in contexts is currently a win 3353 // For generators, allocating variables in contexts is currently a win
3349 // because it minimizes the work needed to suspend and resume an 3354 // because it minimizes the work needed to suspend and resume an
3350 // activation. 3355 // activation.
3351 scope_->ForceContextAllocation(); 3356 scope_->ForceContextAllocation();
3352 3357
3353 // Calling a generator returns a generator object. That object is stored 3358 // Calling a generator returns a generator object. That object is stored
3354 // in a temporary variable, a definition that is used by "yield" 3359 // in a temporary variable, a definition that is used by "yield"
3355 // expressions. This also marks the FunctionState as a generator. 3360 // expressions. This also marks the FunctionState as a generator.
3356 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3361 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3357 isolate()->factory()->dot_generator_object_string()); 3362 ast_value_factory_->dot_generator_object_string());
3358 function_state.set_generator_object_variable(temp); 3363 function_state.set_generator_object_variable(temp);
3359 } 3364 }
3360 3365
3361 // FormalParameterList :: 3366 // FormalParameterList ::
3362 // '(' (Identifier)*[','] ')' 3367 // '(' (Identifier)*[','] ')'
3363 Expect(Token::LPAREN, CHECK_OK); 3368 Expect(Token::LPAREN, CHECK_OK);
3364 scope->set_start_position(scanner()->location().beg_pos); 3369 scope->set_start_position(scanner()->location().beg_pos);
3365 3370
3366 // We don't yet know if the function will be strict, so we cannot yet 3371 // We don't yet know if the function will be strict, so we cannot yet
3367 // produce errors for parameter names or duplicates. However, we remember 3372 // produce errors for parameter names or duplicates. However, we remember
3368 // the locations of these errors if they occur and produce the errors later. 3373 // the locations of these errors if they occur and produce the errors later.
3369 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); 3374 Scanner::Location eval_args_error_log = Scanner::Location::invalid();
3370 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 3375 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
3371 Scanner::Location reserved_loc = Scanner::Location::invalid(); 3376 Scanner::Location reserved_loc = Scanner::Location::invalid();
3372 3377
3373 bool done = (peek() == Token::RPAREN); 3378 bool done = (peek() == Token::RPAREN);
3374 while (!done) { 3379 while (!done) {
3375 bool is_strict_reserved = false; 3380 bool is_strict_reserved = false;
3376 Handle<String> param_name = 3381 const AstString* param_name =
3377 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 3382 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
3378 3383
3379 // Store locations for possible future error reports. 3384 // Store locations for possible future error reports.
3380 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { 3385 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) {
3381 eval_args_error_log = scanner()->location(); 3386 eval_args_error_log = scanner()->location();
3382 } 3387 }
3383 if (!reserved_loc.IsValid() && is_strict_reserved) { 3388 if (!reserved_loc.IsValid() && is_strict_reserved) {
3384 reserved_loc = scanner()->location(); 3389 reserved_loc = scanner()->location();
3385 } 3390 }
3386 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { 3391 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) {
(...skipping 23 matching lines...) Expand all
3410 // instead of Variables and Proxis as is the case now. 3415 // instead of Variables and Proxis as is the case now.
3411 Variable* fvar = NULL; 3416 Variable* fvar = NULL;
3412 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; 3417 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
3413 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { 3418 if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
3414 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3419 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3415 fvar_init_op = Token::INIT_CONST; 3420 fvar_init_op = Token::INIT_CONST;
3416 } 3421 }
3417 VariableMode fvar_mode = 3422 VariableMode fvar_mode =
3418 allow_harmony_scoping() && strict_mode() == STRICT ? CONST 3423 allow_harmony_scoping() && strict_mode() == STRICT ? CONST
3419 : CONST_LEGACY; 3424 : CONST_LEGACY;
3425 ASSERT(function_name != NULL);
3420 fvar = new(zone()) Variable(scope_, 3426 fvar = new(zone()) Variable(scope_,
3421 function_name, fvar_mode, true /* is valid LHS */, 3427 function_name, fvar_mode, true /* is valid LHS */,
3422 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); 3428 Variable::NORMAL, kCreatedInitialized, Interface::NewConst());
3423 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 3429 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
3424 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 3430 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
3425 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); 3431 proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
3426 scope_->DeclareFunctionVar(fvar_declaration); 3432 scope_->DeclareFunctionVar(fvar_declaration);
3427 } 3433 }
3428 3434
3429 // Determine if the function can be parsed lazily. Lazy parsing is different 3435 // Determine if the function can be parsed lazily. Lazy parsing is different
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 3519
3514 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3520 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3515 CheckConflictingVarDeclarations(scope, CHECK_OK); 3521 CheckConflictingVarDeclarations(scope, CHECK_OK);
3516 } 3522 }
3517 3523
3518 FunctionLiteral::IsGeneratorFlag generator = is_generator 3524 FunctionLiteral::IsGeneratorFlag generator = is_generator
3519 ? FunctionLiteral::kIsGenerator 3525 ? FunctionLiteral::kIsGenerator
3520 : FunctionLiteral::kNotGenerator; 3526 : FunctionLiteral::kNotGenerator;
3521 FunctionLiteral* function_literal = 3527 FunctionLiteral* function_literal =
3522 factory()->NewFunctionLiteral(function_name, 3528 factory()->NewFunctionLiteral(function_name,
3529 ast_value_factory_,
3523 scope, 3530 scope,
3524 body, 3531 body,
3525 materialized_literal_count, 3532 materialized_literal_count,
3526 expected_property_count, 3533 expected_property_count,
3527 handler_count, 3534 handler_count,
3528 num_parameters, 3535 num_parameters,
3529 duplicate_parameters, 3536 duplicate_parameters,
3530 function_type, 3537 function_type,
3531 FunctionLiteral::kIsFunction, 3538 FunctionLiteral::kIsFunction,
3532 parenthesized, 3539 parenthesized,
3533 generator, 3540 generator,
3534 pos); 3541 pos);
3535 function_literal->set_function_token_position(function_token_pos); 3542 function_literal->set_function_token_position(function_token_pos);
3536 function_literal->set_ast_properties(&ast_properties); 3543 function_literal->set_ast_properties(&ast_properties);
3537 function_literal->set_dont_optimize_reason(dont_optimize_reason); 3544 function_literal->set_dont_optimize_reason(dont_optimize_reason);
3538 3545
3539 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3546 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3540 return function_literal; 3547 return function_literal;
3541 } 3548 }
3542 3549
3543 3550
3544 void Parser::SkipLazyFunctionBody(Handle<String> function_name, 3551 void Parser::SkipLazyFunctionBody(const AstString* function_name,
3545 int* materialized_literal_count, 3552 int* materialized_literal_count,
3546 int* expected_property_count, 3553 int* expected_property_count,
3547 bool* ok) { 3554 bool* ok) {
3548 int function_block_pos = position(); 3555 int function_block_pos = position();
3549 if (cached_data_mode_ == CONSUME_CACHED_DATA) { 3556 if (cached_data_mode_ == CONSUME_CACHED_DATA) {
3550 // If we have cached data, we use it to skip parsing the function body. The 3557 // If we have cached data, we use it to skip parsing the function body. The
3551 // data contains the information we need to construct the lazy function. 3558 // data contains the information we need to construct the lazy function.
3552 FunctionEntry entry = 3559 FunctionEntry entry =
3553 (*cached_data())->GetFunctionEntry(function_block_pos); 3560 (*cached_data())->GetFunctionEntry(function_block_pos);
3554 if (entry.is_valid()) { 3561 if (entry.is_valid()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3613 log_->LogFunction(function_block_pos, body_end, 3620 log_->LogFunction(function_block_pos, body_end,
3614 *materialized_literal_count, 3621 *materialized_literal_count,
3615 *expected_property_count, 3622 *expected_property_count,
3616 scope_->strict_mode()); 3623 scope_->strict_mode());
3617 } 3624 }
3618 } 3625 }
3619 } 3626 }
3620 3627
3621 3628
3622 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 3629 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
3623 Handle<String> function_name, int pos, Variable* fvar, 3630 const AstString* function_name, int pos, Variable* fvar,
3624 Token::Value fvar_init_op, bool is_generator, bool* ok) { 3631 Token::Value fvar_init_op, bool is_generator, bool* ok) {
3625 // Everything inside an eagerly parsed function will be parsed eagerly 3632 // Everything inside an eagerly parsed function will be parsed eagerly
3626 // (see comment above). 3633 // (see comment above).
3627 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 3634 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
3628 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); 3635 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone());
3629 if (fvar != NULL) { 3636 if (fvar != NULL) {
3630 VariableProxy* fproxy = scope_->NewUnresolved( 3637 VariableProxy* fproxy = scope_->NewUnresolved(
3631 factory(), function_name, Interface::NewConst()); 3638 factory(), function_name, Interface::NewConst());
3632 fproxy->BindTo(fvar); 3639 fproxy->BindTo(fvar);
3633 body->Add(factory()->NewExpressionStatement( 3640 body->Add(factory()->NewExpressionStatement(
3634 factory()->NewAssignment(fvar_init_op, 3641 factory()->NewAssignment(fvar_init_op,
3635 fproxy, 3642 fproxy,
3636 factory()->NewThisFunction(pos), 3643 factory()->NewThisFunction(pos),
3637 RelocInfo::kNoPosition), 3644 RelocInfo::kNoPosition),
3638 RelocInfo::kNoPosition), zone()); 3645 RelocInfo::kNoPosition), zone());
3639 } 3646 }
3640 3647
3641 // For generators, allocate and yield an iterator on function entry. 3648 // For generators, allocate and yield an iterator on function entry.
3642 if (is_generator) { 3649 if (is_generator) {
3643 ZoneList<Expression*>* arguments = 3650 ZoneList<Expression*>* arguments =
3644 new(zone()) ZoneList<Expression*>(0, zone()); 3651 new(zone()) ZoneList<Expression*>(0, zone());
3645 CallRuntime* allocation = factory()->NewCallRuntime( 3652 CallRuntime* allocation = factory()->NewCallRuntime(
3646 isolate()->factory()->empty_string(), 3653 ast_value_factory_->empty_string(),
3647 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject), 3654 Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject),
3648 arguments, pos); 3655 arguments, pos);
3649 VariableProxy* init_proxy = factory()->NewVariableProxy( 3656 VariableProxy* init_proxy = factory()->NewVariableProxy(
3650 function_state_->generator_object_variable()); 3657 function_state_->generator_object_variable());
3651 Assignment* assignment = factory()->NewAssignment( 3658 Assignment* assignment = factory()->NewAssignment(
3652 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 3659 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
3653 VariableProxy* get_proxy = factory()->NewVariableProxy( 3660 VariableProxy* get_proxy = factory()->NewVariableProxy(
3654 function_state_->generator_object_variable()); 3661 function_state_->generator_object_variable());
3655 Yield* yield = factory()->NewYield( 3662 Yield* yield = factory()->NewYield(
3656 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); 3663 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
3657 body->Add(factory()->NewExpressionStatement( 3664 body->Add(factory()->NewExpressionStatement(
3658 yield, RelocInfo::kNoPosition), zone()); 3665 yield, RelocInfo::kNoPosition), zone());
3659 } 3666 }
3660 3667
3661 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); 3668 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
3662 3669
3663 if (is_generator) { 3670 if (is_generator) {
3664 VariableProxy* get_proxy = factory()->NewVariableProxy( 3671 VariableProxy* get_proxy = factory()->NewVariableProxy(
3665 function_state_->generator_object_variable()); 3672 function_state_->generator_object_variable());
3666 Expression *undefined = factory()->NewLiteral( 3673 Expression* undefined = factory()->NewSpecialLiteral(
rossberg 2014/06/12 12:20:28 ...and here.
marja 2014/06/12 12:35:04 Done.
3667 isolate()->factory()->undefined_value(), RelocInfo::kNoPosition); 3674 ast_value_factory_->NewUndefined(), RelocInfo::kNoPosition);
3668 Yield* yield = factory()->NewYield( 3675 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL,
3669 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); 3676 RelocInfo::kNoPosition);
3670 body->Add(factory()->NewExpressionStatement( 3677 body->Add(factory()->NewExpressionStatement(
3671 yield, RelocInfo::kNoPosition), zone()); 3678 yield, RelocInfo::kNoPosition), zone());
3672 } 3679 }
3673 3680
3674 Expect(Token::RBRACE, CHECK_OK); 3681 Expect(Token::RBRACE, CHECK_OK);
3675 scope_->set_end_position(scanner()->location().end_pos); 3682 scope_->set_end_position(scanner()->location().end_pos);
3676 3683
3677 return body; 3684 return body;
3678 } 3685 }
3679 3686
(...skipping 23 matching lines...) Expand all
3703 } 3710 }
3704 3711
3705 3712
3706 Expression* Parser::ParseV8Intrinsic(bool* ok) { 3713 Expression* Parser::ParseV8Intrinsic(bool* ok) {
3707 // CallRuntime :: 3714 // CallRuntime ::
3708 // '%' Identifier Arguments 3715 // '%' Identifier Arguments
3709 3716
3710 int pos = peek_position(); 3717 int pos = peek_position();
3711 Expect(Token::MOD, CHECK_OK); 3718 Expect(Token::MOD, CHECK_OK);
3712 // Allow "eval" or "arguments" for backward compatibility. 3719 // Allow "eval" or "arguments" for backward compatibility.
3713 Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 3720 const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
3714 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 3721 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
3715 3722
3716 if (extension_ != NULL) { 3723 if (extension_ != NULL) {
3717 // The extension structures are only accessible while parsing the 3724 // The extension structures are only accessible while parsing the
3718 // very first time not when reparsing because of lazy compilation. 3725 // very first time not when reparsing because of lazy compilation.
3719 scope_->DeclarationScope()->ForceEagerCompilation(); 3726 scope_->DeclarationScope()->ForceEagerCompilation();
3720 } 3727 }
3721 3728
3722 const Runtime::Function* function = Runtime::FunctionForName(name); 3729 const Runtime::Function* function = Runtime::FunctionForName(name->string());
3723 3730
3724 // Check for built-in IS_VAR macro. 3731 // Check for built-in IS_VAR macro.
3725 if (function != NULL && 3732 if (function != NULL &&
3726 function->intrinsic_type == Runtime::RUNTIME && 3733 function->intrinsic_type == Runtime::RUNTIME &&
3727 function->function_id == Runtime::kIS_VAR) { 3734 function->function_id == Runtime::kIS_VAR) {
3728 // %IS_VAR(x) evaluates to x if x is a variable, 3735 // %IS_VAR(x) evaluates to x if x is a variable,
3729 // leads to a parse error otherwise. Could be implemented as an 3736 // leads to a parse error otherwise. Could be implemented as an
3730 // inline function %_IS_VAR(x) to eliminate this special case. 3737 // inline function %_IS_VAR(x) to eliminate this special case.
3731 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { 3738 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
3732 return args->at(0); 3739 return args->at(0);
3733 } else { 3740 } else {
3734 ReportMessage("not_isvar"); 3741 ReportMessage("not_isvar");
3735 *ok = false; 3742 *ok = false;
3736 return NULL; 3743 return NULL;
3737 } 3744 }
3738 } 3745 }
3739 3746
3740 // Check that the expected number of arguments are being passed. 3747 // Check that the expected number of arguments are being passed.
3741 if (function != NULL && 3748 if (function != NULL &&
3742 function->nargs != -1 && 3749 function->nargs != -1 &&
3743 function->nargs != args->length()) { 3750 function->nargs != args->length()) {
3744 ReportMessage("illegal_access"); 3751 ReportMessage("illegal_access");
3745 *ok = false; 3752 *ok = false;
3746 return NULL; 3753 return NULL;
3747 } 3754 }
3748 3755
3749 // Check that the function is defined if it's an inline runtime call. 3756 // Check that the function is defined if it's an inline runtime call.
3750 if (function == NULL && name->Get(0) == '_') { 3757 if (function == NULL && name->FirstCharacter() == '_') {
3751 ParserTraits::ReportMessage("not_defined", name); 3758 ParserTraits::ReportMessage("not_defined", name);
3752 *ok = false; 3759 *ok = false;
3753 return NULL; 3760 return NULL;
3754 } 3761 }
3755 3762
3756 // We have a valid intrinsics call or a call to a builtin. 3763 // We have a valid intrinsics call or a call to a builtin.
3757 return factory()->NewCallRuntime(name, function, args, pos); 3764 return factory()->NewCallRuntime(name, function, args, pos);
3758 } 3765 }
3759 3766
3760 3767
3761 Literal* Parser::GetLiteralUndefined(int position) { 3768 Literal* Parser::GetLiteralUndefined(int position) {
3762 return factory()->NewLiteral( 3769 return factory()->NewSpecialLiteral(ast_value_factory_->NewUndefined(),
rossberg 2014/06/12 12:20:28 ...and here.
marja 2014/06/12 12:35:04 Done.
3763 isolate()->factory()->undefined_value(), position); 3770 position);
3764 } 3771 }
3765 3772
3766 3773
3767 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 3774 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
3768 Declaration* decl = scope->CheckConflictingVarDeclarations(); 3775 Declaration* decl = scope->CheckConflictingVarDeclarations();
3769 if (decl != NULL) { 3776 if (decl != NULL) {
3770 // In harmony mode we treat conflicting variable bindinds as early 3777 // In harmony mode we treat conflicting variable bindinds as early
3771 // errors. See ES5 16 for a definition of early errors. 3778 // errors. See ES5 16 for a definition of early errors.
3772 Handle<String> name = decl->proxy()->name(); 3779 const AstString* name = decl->proxy()->raw_name();
3773 int position = decl->proxy()->position(); 3780 int position = decl->proxy()->position();
3774 Scanner::Location location = position == RelocInfo::kNoPosition 3781 Scanner::Location location = position == RelocInfo::kNoPosition
3775 ? Scanner::Location::invalid() 3782 ? Scanner::Location::invalid()
3776 : Scanner::Location(position, position + 1); 3783 : Scanner::Location(position, position + 1);
3777 ParserTraits::ReportMessageAt(location, "var_redeclaration", name); 3784 ParserTraits::ReportMessageAt(location, "var_redeclaration", name);
3778 *ok = false; 3785 *ok = false;
3779 } 3786 }
3780 } 3787 }
3781 3788
3782 3789
3783 // ---------------------------------------------------------------------------- 3790 // ----------------------------------------------------------------------------
3784 // Parser support 3791 // Parser support
3785 3792
3786 3793
3787 bool Parser::TargetStackContainsLabel(Handle<String> label) { 3794 bool Parser::TargetStackContainsLabel(const AstString* label) {
3788 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3795 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3789 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3796 BreakableStatement* stat = t->node()->AsBreakableStatement();
3790 if (stat != NULL && ContainsLabel(stat->labels(), label)) 3797 if (stat != NULL && ContainsLabel(stat->labels(), label))
3791 return true; 3798 return true;
3792 } 3799 }
3793 return false; 3800 return false;
3794 } 3801 }
3795 3802
3796 3803
3797 BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) { 3804 BreakableStatement* Parser::LookupBreakTarget(const AstString* label,
3798 bool anonymous = label.is_null(); 3805 bool* ok) {
3806 bool anonymous = label == NULL;
3799 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3807 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3800 BreakableStatement* stat = t->node()->AsBreakableStatement(); 3808 BreakableStatement* stat = t->node()->AsBreakableStatement();
3801 if (stat == NULL) continue; 3809 if (stat == NULL) continue;
3802 if ((anonymous && stat->is_target_for_anonymous()) || 3810 if ((anonymous && stat->is_target_for_anonymous()) ||
3803 (!anonymous && ContainsLabel(stat->labels(), label))) { 3811 (!anonymous && ContainsLabel(stat->labels(), label))) {
3804 RegisterTargetUse(stat->break_target(), t->previous()); 3812 RegisterTargetUse(stat->break_target(), t->previous());
3805 return stat; 3813 return stat;
3806 } 3814 }
3807 } 3815 }
3808 return NULL; 3816 return NULL;
3809 } 3817 }
3810 3818
3811 3819
3812 IterationStatement* Parser::LookupContinueTarget(Handle<String> label, 3820 IterationStatement* Parser::LookupContinueTarget(const AstString* label,
3813 bool* ok) { 3821 bool* ok) {
3814 bool anonymous = label.is_null(); 3822 bool anonymous = label == NULL;
3815 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 3823 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
3816 IterationStatement* stat = t->node()->AsIterationStatement(); 3824 IterationStatement* stat = t->node()->AsIterationStatement();
3817 if (stat == NULL) continue; 3825 if (stat == NULL) continue;
3818 3826
3819 ASSERT(stat->is_target_for_anonymous()); 3827 ASSERT(stat->is_target_for_anonymous());
3820 if (anonymous || ContainsLabel(stat->labels(), label)) { 3828 if (anonymous || ContainsLabel(stat->labels(), label)) {
3821 RegisterTargetUse(stat->continue_target(), t->previous()); 3829 RegisterTargetUse(stat->continue_target(), t->previous());
3822 return stat; 3830 return stat;
3823 } 3831 }
3824 } 3832 }
(...skipping 12 matching lines...) Expand all
3837 } 3845 }
3838 3846
3839 3847
3840 void Parser::ThrowPendingError() { 3848 void Parser::ThrowPendingError() {
3841 if (has_pending_error_) { 3849 if (has_pending_error_) {
3842 MessageLocation location(script_, 3850 MessageLocation location(script_,
3843 pending_error_location_.beg_pos, 3851 pending_error_location_.beg_pos,
3844 pending_error_location_.end_pos); 3852 pending_error_location_.end_pos);
3845 Factory* factory = isolate()->factory(); 3853 Factory* factory = isolate()->factory();
3846 bool has_arg = 3854 bool has_arg =
3847 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL; 3855 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL;
3848 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); 3856 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3849 if (!pending_error_arg_.is_null()) { 3857 if (pending_error_arg_ != NULL) {
3850 elements->set(0, *(pending_error_arg_.ToHandleChecked())); 3858 Handle<String> arg_string = pending_error_arg_->string();
3859 elements->set(0, *arg_string);
3851 } else if (pending_error_char_arg_ != NULL) { 3860 } else if (pending_error_char_arg_ != NULL) {
3852 Handle<String> arg_string = 3861 Handle<String> arg_string =
3853 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) 3862 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_))
3854 .ToHandleChecked(); 3863 .ToHandleChecked();
3855 elements->set(0, *arg_string); 3864 elements->set(0, *arg_string);
3856 } 3865 }
3857 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 3866 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
3858 Handle<Object> result = pending_error_is_reference_error_ 3867 Handle<Object> result = pending_error_is_reference_error_
3859 ? factory->NewReferenceError(pending_error_message_, array) 3868 ? factory->NewReferenceError(pending_error_message_, array)
3860 : factory->NewSyntaxError(pending_error_message_, array); 3869 : factory->NewSyntaxError(pending_error_message_, array);
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
4753 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 4762 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
4754 result->contains_anchor = parser.contains_anchor(); 4763 result->contains_anchor = parser.contains_anchor();
4755 result->capture_count = capture_count; 4764 result->capture_count = capture_count;
4756 } 4765 }
4757 return !parser.failed(); 4766 return !parser.failed();
4758 } 4767 }
4759 4768
4760 4769
4761 bool Parser::Parse() { 4770 bool Parser::Parse() {
4762 ASSERT(info()->function() == NULL); 4771 ASSERT(info()->function() == NULL);
4772 ASSERT(info()->ast_value_factory() == NULL);
4763 FunctionLiteral* result = NULL; 4773 FunctionLiteral* result = NULL;
4774 ast_value_factory_ = new AstValueFactory(zone());
4775 if (allow_natives_syntax() || extension_ != NULL) {
4776 // If intrinsics are allowed, the Parser cannot operate independent of the
4777 // V8 heap because of Rumtime. Tell the string table to internalize strings
4778 // and values right after they're created.
4779 ast_value_factory_->Internalize(isolate());
4780 }
4781
4764 if (info()->is_lazy()) { 4782 if (info()->is_lazy()) {
4765 ASSERT(!info()->is_eval()); 4783 ASSERT(!info()->is_eval());
4766 if (info()->shared_info()->is_function()) { 4784 if (info()->shared_info()->is_function()) {
4767 result = ParseLazy(); 4785 result = ParseLazy();
4768 } else { 4786 } else {
4769 result = ParseProgram(); 4787 result = ParseProgram();
4770 } 4788 }
4771 } else { 4789 } else {
4772 SetCachedData(info()->cached_data(), info()->cached_data_mode()); 4790 SetCachedData(info()->cached_data(), info()->cached_data_mode());
4773 if (info()->cached_data_mode() == CONSUME_CACHED_DATA && 4791 if (info()->cached_data_mode() == CONSUME_CACHED_DATA &&
4774 (*info()->cached_data())->has_error()) { 4792 (*info()->cached_data())->has_error()) {
4775 ScriptData* cached_data = *(info()->cached_data()); 4793 ScriptData* cached_data = *(info()->cached_data());
4776 Scanner::Location loc = cached_data->MessageLocation(); 4794 Scanner::Location loc = cached_data->MessageLocation();
4777 const char* message = cached_data->BuildMessage(); 4795 const char* message = cached_data->BuildMessage();
4778 const char* arg = cached_data->BuildArg(); 4796 const char* arg = cached_data->BuildArg();
4779 ParserTraits::ReportMessageAt(loc, message, arg, 4797 ParserTraits::ReportMessageAt(loc, message, arg,
4780 cached_data->IsReferenceError()); 4798 cached_data->IsReferenceError());
4781 DeleteArray(message); 4799 DeleteArray(message);
4782 DeleteArray(arg); 4800 DeleteArray(arg);
4783 ASSERT(info()->isolate()->has_pending_exception()); 4801 ASSERT(info()->isolate()->has_pending_exception());
4784 } else { 4802 } else {
4785 result = ParseProgram(); 4803 result = ParseProgram();
4786 } 4804 }
4787 } 4805 }
4788 info()->SetFunction(result); 4806 info()->SetFunction(result);
4807 ast_value_factory_->Internalize(isolate());
4808 // info takes ownership of ast_value_factory_.
4809 info()->SetAstValueFactory(ast_value_factory_);
4810 ast_value_factory_ = NULL;
4789 return (result != NULL); 4811 return (result != NULL);
4790 } 4812 }
4791 4813
4792 } } // namespace v8::internal 4814 } } // 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