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

Side by Side Diff: src/parser.cc

Issue 527233003: Parser cleanup: less member variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } else { 259 } else {
260 DCHECK(info_->cached_data() != NULL); 260 DCHECK(info_->cached_data() != NULL);
261 if (compile_options() == ScriptCompiler::kConsumeParserCache) { 261 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
262 cached_parse_data_ = new ParseData(*info_->cached_data()); 262 cached_parse_data_ = new ParseData(*info_->cached_data());
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267 267
268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
269 DCHECK(ast_value_factory_); 269 DCHECK(ast_value_factory());
270 Scope* result = 270 Scope* result =
271 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone()); 271 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone());
272 result->Initialize(); 272 result->Initialize();
273 return result; 273 return result;
274 } 274 }
275 275
276 276
277 // ---------------------------------------------------------------------------- 277 // ----------------------------------------------------------------------------
278 // Target is a support class to facilitate manipulation of the 278 // Target is a support class to facilitate manipulation of the
279 // Parser's target_stack_ (the stack of potential 'break' and 279 // Parser's target_stack_ (the stack of potential 'break' and
280 // 'continue' statement targets). Upon construction, a new target is 280 // 'continue' statement targets). Upon construction, a new target is
281 // added; it is removed upon destruction. 281 // added; it is removed upon destruction.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 *parser_->ast_node_id_gen_ = saved_ast_node_id_gen_; 354 *parser_->ast_node_id_gen_ = saved_ast_node_id_gen_;
355 } 355 }
356 356
357 private: 357 private:
358 ParserBase<ParserTraits>* parser_; 358 ParserBase<ParserTraits>* parser_;
359 AstNode::IdGen saved_ast_node_id_gen_; 359 AstNode::IdGen saved_ast_node_id_gen_;
360 }; 360 };
361 361
362 362
363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { 363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
364 return identifier == parser_->ast_value_factory_->eval_string() || 364 return identifier == parser_->ast_value_factory()->eval_string() ||
365 identifier == parser_->ast_value_factory_->arguments_string(); 365 identifier == parser_->ast_value_factory()->arguments_string();
366 } 366 }
367 367
368 368
369 bool ParserTraits::IsThisProperty(Expression* expression) { 369 bool ParserTraits::IsThisProperty(Expression* expression) {
370 DCHECK(expression != NULL); 370 DCHECK(expression != NULL);
371 Property* property = expression->AsProperty(); 371 Property* property = expression->AsProperty();
372 return property != NULL && 372 return property != NULL &&
373 property->obj()->AsVariableProxy() != NULL && 373 property->obj()->AsVariableProxy() != NULL &&
374 property->obj()->AsVariableProxy()->is_this(); 374 property->obj()->AsVariableProxy()->is_this();
375 } 375 }
376 376
377 377
378 bool ParserTraits::IsIdentifier(Expression* expression) { 378 bool ParserTraits::IsIdentifier(Expression* expression) {
379 VariableProxy* operand = expression->AsVariableProxy(); 379 VariableProxy* operand = expression->AsVariableProxy();
380 return operand != NULL && !operand->is_this(); 380 return operand != NULL && !operand->is_this();
381 } 381 }
382 382
383 383
384 void ParserTraits::PushPropertyName(FuncNameInferrer* fni, 384 void ParserTraits::PushPropertyName(FuncNameInferrer* fni,
385 Expression* expression) { 385 Expression* expression) {
386 if (expression->IsPropertyName()) { 386 if (expression->IsPropertyName()) {
387 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); 387 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
388 } else { 388 } else {
389 fni->PushLiteralName( 389 fni->PushLiteralName(
390 parser_->ast_value_factory_->anonymous_function_string()); 390 parser_->ast_value_factory()->anonymous_function_string());
391 } 391 }
392 } 392 }
393 393
394 394
395 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, 395 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left,
396 Expression* right) { 396 Expression* right) {
397 DCHECK(left != NULL); 397 DCHECK(left != NULL);
398 if (left->AsProperty() != NULL && 398 if (left->AsProperty() != NULL &&
399 right->AsFunctionLiteral() != NULL) { 399 right->AsFunctionLiteral() != NULL) {
400 right->AsFunctionLiteral()->set_pretenure(); 400 right->AsFunctionLiteral()->set_pretenure();
401 } 401 }
402 } 402 }
403 403
404 404
405 void ParserTraits::CheckPossibleEvalCall(Expression* expression, 405 void ParserTraits::CheckPossibleEvalCall(Expression* expression,
406 Scope* scope) { 406 Scope* scope) {
407 VariableProxy* callee = expression->AsVariableProxy(); 407 VariableProxy* callee = expression->AsVariableProxy();
408 if (callee != NULL && 408 if (callee != NULL &&
409 callee->raw_name() == parser_->ast_value_factory_->eval_string()) { 409 callee->raw_name() == parser_->ast_value_factory()->eval_string()) {
410 scope->DeclarationScope()->RecordEvalCall(); 410 scope->DeclarationScope()->RecordEvalCall();
411 } 411 }
412 } 412 }
413 413
414 414
415 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) { 415 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) {
416 VariableProxy* proxy = 416 VariableProxy* proxy =
417 expression != NULL ? expression->AsVariableProxy() : NULL; 417 expression != NULL ? expression->AsVariableProxy() : NULL;
418 if (proxy != NULL) proxy->set_is_assigned(); 418 if (proxy != NULL) proxy->set_is_assigned();
419 return expression; 419 return expression;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 if (op == Token::BIT_NOT) { 519 if (op == Token::BIT_NOT) {
520 return factory->NewBinaryOperation( 520 return factory->NewBinaryOperation(
521 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); 521 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos);
522 } 522 }
523 return factory->NewUnaryOperation(op, expression, pos); 523 return factory->NewUnaryOperation(op, expression, pos);
524 } 524 }
525 525
526 526
527 Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) { 527 Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) {
528 return NewThrowError( 528 return NewThrowError(
529 parser_->ast_value_factory_->make_reference_error_string(), message, NULL, 529 parser_->ast_value_factory()->make_reference_error_string(), message,
530 pos); 530 NULL, pos);
531 } 531 }
532 532
533 533
534 Expression* ParserTraits::NewThrowSyntaxError( 534 Expression* ParserTraits::NewThrowSyntaxError(
535 const char* message, const AstRawString* arg, int pos) { 535 const char* message, const AstRawString* arg, int pos) {
536 return NewThrowError(parser_->ast_value_factory_->make_syntax_error_string(), 536 return NewThrowError(parser_->ast_value_factory()->make_syntax_error_string(),
537 message, arg, pos); 537 message, arg, pos);
538 } 538 }
539 539
540 540
541 Expression* ParserTraits::NewThrowTypeError( 541 Expression* ParserTraits::NewThrowTypeError(
542 const char* message, const AstRawString* arg, int pos) { 542 const char* message, const AstRawString* arg, int pos) {
543 return NewThrowError(parser_->ast_value_factory_->make_type_error_string(), 543 return NewThrowError(parser_->ast_value_factory()->make_type_error_string(),
544 message, arg, pos); 544 message, arg, pos);
545 } 545 }
546 546
547 547
548 Expression* ParserTraits::NewThrowError( 548 Expression* ParserTraits::NewThrowError(
549 const AstRawString* constructor, const char* message, 549 const AstRawString* constructor, const char* message,
550 const AstRawString* arg, int pos) { 550 const AstRawString* arg, int pos) {
551 Zone* zone = parser_->zone(); 551 Zone* zone = parser_->zone();
552 int argc = arg != NULL ? 1 : 0; 552 int argc = arg != NULL ? 1 : 0;
553 const AstRawString* type = 553 const AstRawString* type =
554 parser_->ast_value_factory_->GetOneByteString(message); 554 parser_->ast_value_factory()->GetOneByteString(message);
555 ZoneList<const AstRawString*>* array = 555 ZoneList<const AstRawString*>* array =
556 new (zone) ZoneList<const AstRawString*>(argc, zone); 556 new (zone) ZoneList<const AstRawString*>(argc, zone);
557 if (arg != NULL) { 557 if (arg != NULL) {
558 array->Add(arg, zone); 558 array->Add(arg, zone);
559 } 559 }
560 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); 560 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone);
561 args->Add(parser_->factory()->NewStringLiteral(type, pos), zone); 561 args->Add(parser_->factory()->NewStringLiteral(type, pos), zone);
562 args->Add(parser_->factory()->NewStringListLiteral(array, pos), zone); 562 args->Add(parser_->factory()->NewStringListLiteral(array, pos), zone);
563 CallRuntime* call_constructor = 563 CallRuntime* call_constructor =
564 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); 564 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 parser_->pending_error_location_ = source_location; 615 parser_->pending_error_location_ = source_location;
616 parser_->pending_error_message_ = message; 616 parser_->pending_error_message_ = message;
617 parser_->pending_error_char_arg_ = NULL; 617 parser_->pending_error_char_arg_ = NULL;
618 parser_->pending_error_arg_ = arg; 618 parser_->pending_error_arg_ = arg;
619 parser_->pending_error_is_reference_error_ = is_reference_error; 619 parser_->pending_error_is_reference_error_ = is_reference_error;
620 } 620 }
621 621
622 622
623 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { 623 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
624 const AstRawString* result = 624 const AstRawString* result =
625 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory_); 625 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory());
626 DCHECK(result != NULL); 626 DCHECK(result != NULL);
627 return result; 627 return result;
628 } 628 }
629 629
630 630
631 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) { 631 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
632 double double_value = parser_->scanner()->DoubleValue(); 632 double double_value = parser_->scanner()->DoubleValue();
633 char array[100]; 633 char array[100];
634 const char* string = 634 const char* string =
635 DoubleToCString(double_value, Vector<char>(array, arraysize(array))); 635 DoubleToCString(double_value, Vector<char>(array, arraysize(array)));
636 return ast_value_factory()->GetOneByteString(string); 636 return ast_value_factory()->GetOneByteString(string);
637 } 637 }
638 638
639 639
640 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { 640 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
641 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); 641 return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
642 } 642 }
643 643
644 644
645 Expression* ParserTraits::ThisExpression( 645 Expression* ParserTraits::ThisExpression(
646 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { 646 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) {
647 return factory->NewVariableProxy(scope->receiver(), pos); 647 return factory->NewVariableProxy(scope->receiver(), pos);
648 } 648 }
649 649
650 Expression* ParserTraits::SuperReference( 650 Expression* ParserTraits::SuperReference(
651 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { 651 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 name_is_strict_reserved, is_generator, 736 name_is_strict_reserved, is_generator,
737 function_token_position, type, 737 function_token_position, type,
738 arity_restriction, ok); 738 arity_restriction, ok);
739 } 739 }
740 740
741 741
742 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) 742 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
743 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, 743 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit,
744 info->extension(), NULL, info->zone(), 744 info->extension(), NULL, info->zone(),
745 info->ast_node_id_gen(), this), 745 info->ast_node_id_gen(), this),
746 isolate_(info->isolate()),
747 script_(info->script()),
748 scanner_(parse_info->unicode_cache), 746 scanner_(parse_info->unicode_cache),
749 reusable_preparser_(NULL), 747 reusable_preparser_(NULL),
750 original_scope_(NULL), 748 original_scope_(NULL),
751 target_stack_(NULL), 749 target_stack_(NULL),
752 cached_parse_data_(NULL), 750 cached_parse_data_(NULL),
753 ast_value_factory_(info->ast_value_factory()),
754 info_(info), 751 info_(info),
755 has_pending_error_(false), 752 has_pending_error_(false),
756 pending_error_message_(NULL), 753 pending_error_message_(NULL),
757 pending_error_arg_(NULL), 754 pending_error_arg_(NULL),
758 pending_error_char_arg_(NULL), 755 pending_error_char_arg_(NULL),
759 total_preparse_skipped_(0), 756 total_preparse_skipped_(0),
760 pre_parse_timer_(NULL) { 757 pre_parse_timer_(NULL) {
761 DCHECK(!script_.is_null()); 758 DCHECK(!script().is_null());
762 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 759 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
763 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 760 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
764 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 761 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
765 set_allow_lazy(false); // Must be explicitly enabled. 762 set_allow_lazy(false); // Must be explicitly enabled.
766 set_allow_generators(FLAG_harmony_generators); 763 set_allow_generators(FLAG_harmony_generators);
767 set_allow_arrow_functions(FLAG_harmony_arrow_functions); 764 set_allow_arrow_functions(FLAG_harmony_arrow_functions);
768 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 765 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
769 set_allow_classes(FLAG_harmony_classes); 766 set_allow_classes(FLAG_harmony_classes);
770 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 767 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
771 ++feature) { 768 ++feature) {
772 use_counts_[feature] = 0; 769 use_counts_[feature] = 0;
773 } 770 }
774 if (ast_value_factory_ == NULL) { 771 if (info->ast_value_factory() == NULL) {
775 ast_value_factory_ = new AstValueFactory(zone(), parse_info->hash_seed); 772 // info takes ownership of AstValueFactory.
773 info->SetAstValueFactory(new stValueFactory(zone(), parse_info->hash_seed));
776 } 774 }
777 } 775 }
778 776
779 777
780 FunctionLiteral* Parser::ParseProgram() { 778 FunctionLiteral* Parser::ParseProgram() {
781 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 779 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
782 // see comment for HistogramTimerScope class. 780 // see comment for HistogramTimerScope class.
783 781
784 // It's OK to use the counters here, since this function is only called in 782 // It's OK to use the counters here, since this function is only called in
785 // the main thread. 783 // the main thread.
786 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); 784 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
787 Handle<String> source(String::cast(script_->source())); 785 Handle<String> source(String::cast(script()->source()));
788 isolate()->counters()->total_parse_size()->Increment(source->length()); 786 isolate()->counters()->total_parse_size()->Increment(source->length());
789 base::ElapsedTimer timer; 787 base::ElapsedTimer timer;
790 if (FLAG_trace_parse) { 788 if (FLAG_trace_parse) {
791 timer.Start(); 789 timer.Start();
792 } 790 }
793 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); 791 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
794 792
795 // Initialize parser state. 793 // Initialize parser state.
796 CompleteParserRecorder recorder; 794 CompleteParserRecorder recorder;
797 795
798 if (compile_options() == ScriptCompiler::kProduceParserCache) { 796 if (compile_options() == ScriptCompiler::kProduceParserCache) {
799 log_ = &recorder; 797 log_ = &recorder;
800 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) { 798 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) {
801 cached_parse_data_->Initialize(); 799 cached_parse_data_->Initialize();
802 } 800 }
803 801
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 844
847 FunctionLiteral* result = NULL; 845 FunctionLiteral* result = NULL;
848 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 846 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
849 info->SetGlobalScope(scope); 847 info->SetGlobalScope(scope);
850 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 848 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
851 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); 849 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone());
852 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 850 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
853 // means the Parser cannot operate independent of the V8 heap. Tell the 851 // means the Parser cannot operate independent of the V8 heap. Tell the
854 // string table to internalize strings and values right after they're 852 // string table to internalize strings and values right after they're
855 // created. 853 // created.
856 ast_value_factory_->Internalize(isolate()); 854 ast_value_factory()->Internalize(isolate());
857 } 855 }
858 original_scope_ = scope; 856 original_scope_ = scope;
859 if (info->is_eval()) { 857 if (info->is_eval()) {
860 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { 858 if (!scope->is_global_scope() || info->strict_mode() == STRICT) {
861 scope = NewScope(scope, EVAL_SCOPE); 859 scope = NewScope(scope, EVAL_SCOPE);
862 } 860 }
863 } else if (info->is_global()) { 861 } else if (info->is_global()) {
864 scope = NewScope(scope, GLOBAL_SCOPE); 862 scope = NewScope(scope, GLOBAL_SCOPE);
865 } 863 }
866 scope->set_start_position(0); 864 scope->set_start_position(0);
867 scope->set_end_position(source->length()); 865 scope->set_end_position(source->length());
868 866
869 // Compute the parsing mode. 867 // Compute the parsing mode.
870 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 868 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
871 if (allow_natives_syntax() || 869 if (allow_natives_syntax() ||
872 extension_ != NULL || 870 extension_ != NULL ||
873 scope->is_eval_scope()) { 871 scope->is_eval_scope()) {
874 mode = PARSE_EAGERLY; 872 mode = PARSE_EAGERLY;
875 } 873 }
876 ParsingModeScope parsing_mode(this, mode); 874 ParsingModeScope parsing_mode(this, mode);
877 875
878 // Enters 'scope'. 876 // Enters 'scope'.
879 FunctionState function_state(&function_state_, &scope_, scope, zone(), 877 FunctionState function_state(&function_state_, &scope_, scope, zone(),
880 ast_value_factory_, info->ast_node_id_gen()); 878 ast_value_factory(), info->ast_node_id_gen());
881 879
882 scope_->SetStrictMode(info->strict_mode()); 880 scope_->SetStrictMode(info->strict_mode());
883 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 881 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
884 bool ok = true; 882 bool ok = true;
885 int beg_pos = scanner()->location().beg_pos; 883 int beg_pos = scanner()->location().beg_pos;
886 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 884 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
887 885
888 if (ok && strict_mode() == STRICT) { 886 if (ok && strict_mode() == STRICT) {
889 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 887 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
890 } 888 }
891 889
892 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 890 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
893 CheckConflictingVarDeclarations(scope_, &ok); 891 CheckConflictingVarDeclarations(scope_, &ok);
894 } 892 }
895 893
896 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 894 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
897 if (body->length() != 1 || 895 if (body->length() != 1 ||
898 !body->at(0)->IsExpressionStatement() || 896 !body->at(0)->IsExpressionStatement() ||
899 !body->at(0)->AsExpressionStatement()-> 897 !body->at(0)->AsExpressionStatement()->
900 expression()->IsFunctionLiteral()) { 898 expression()->IsFunctionLiteral()) {
901 ReportMessage("single_function_literal"); 899 ReportMessage("single_function_literal");
902 ok = false; 900 ok = false;
903 } 901 }
904 } 902 }
905 903
906 if (ok) { 904 if (ok) {
907 result = factory()->NewFunctionLiteral( 905 result = factory()->NewFunctionLiteral(
908 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, 906 ast_value_factory()->empty_string(), ast_value_factory(), scope_,
909 function_state.materialized_literal_count(), 907 body, function_state.materialized_literal_count(),
910 function_state.expected_property_count(), 908 function_state.expected_property_count(),
911 function_state.handler_count(), 0, 909 function_state.handler_count(), 0,
912 FunctionLiteral::kNoDuplicateParameters, 910 FunctionLiteral::kNoDuplicateParameters,
913 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, 911 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
914 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction, 912 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction,
915 0); 913 0);
916 result->set_ast_properties(factory()->visitor()->ast_properties()); 914 result->set_ast_properties(factory()->visitor()->ast_properties());
917 result->set_dont_optimize_reason( 915 result->set_dont_optimize_reason(
918 factory()->visitor()->dont_optimize_reason()); 916 factory()->visitor()->dont_optimize_reason());
919 } 917 }
920 } 918 }
921 919
922 // Make sure the target stack is empty. 920 // Make sure the target stack is empty.
923 DCHECK(target_stack_ == NULL); 921 DCHECK(target_stack_ == NULL);
924 922
925 return result; 923 return result;
926 } 924 }
927 925
928 926
929 FunctionLiteral* Parser::ParseLazy() { 927 FunctionLiteral* Parser::ParseLazy() {
930 // It's OK to use the counters here, since this function is only called in 928 // It's OK to use the counters here, since this function is only called in
931 // the main thread. 929 // the main thread.
932 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); 930 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy());
933 Handle<String> source(String::cast(script_->source())); 931 Handle<String> source(String::cast(script()->source()));
934 isolate()->counters()->total_parse_size()->Increment(source->length()); 932 isolate()->counters()->total_parse_size()->Increment(source->length());
935 base::ElapsedTimer timer; 933 base::ElapsedTimer timer;
936 if (FLAG_trace_parse) { 934 if (FLAG_trace_parse) {
937 timer.Start(); 935 timer.Start();
938 } 936 }
939 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 937 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
940 938
941 // Initialize parser state. 939 // Initialize parser state.
942 source = String::Flatten(source); 940 source = String::Flatten(source);
943 FunctionLiteral* result; 941 FunctionLiteral* result;
(...skipping 19 matching lines...) Expand all
963 } 961 }
964 962
965 963
966 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { 964 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
967 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 965 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
968 scanner_.Initialize(source); 966 scanner_.Initialize(source);
969 DCHECK(scope_ == NULL); 967 DCHECK(scope_ == NULL);
970 DCHECK(target_stack_ == NULL); 968 DCHECK(target_stack_ == NULL);
971 969
972 Handle<String> name(String::cast(shared_info->name())); 970 Handle<String> name(String::cast(shared_info->name()));
973 DCHECK(ast_value_factory_); 971 DCHECK(ast_value_factory());
974 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); 972 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
975 const AstRawString* raw_name = ast_value_factory_->GetString(name); 973 const AstRawString* raw_name = ast_value_factory()->GetString(name);
976 fni_->PushEnclosingName(raw_name); 974 fni_->PushEnclosingName(raw_name);
977 975
978 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 976 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
979 977
980 // Place holder for the result. 978 // Place holder for the result.
981 FunctionLiteral* result = NULL; 979 FunctionLiteral* result = NULL;
982 980
983 { 981 {
984 // Parse the function literal. 982 // Parse the function literal.
985 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 983 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
986 info()->SetGlobalScope(scope); 984 info()->SetGlobalScope(scope);
987 if (!info()->closure().is_null()) { 985 if (!info()->closure().is_null()) {
988 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 986 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
989 zone()); 987 zone());
990 } 988 }
991 original_scope_ = scope; 989 original_scope_ = scope;
992 FunctionState function_state(&function_state_, &scope_, scope, zone(), 990 FunctionState function_state(&function_state_, &scope_, scope, zone(),
993 ast_value_factory_, info()->ast_node_id_gen()); 991 ast_value_factory(),
992 info()->ast_node_id_gen());
994 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 993 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
995 DCHECK(info()->strict_mode() == shared_info->strict_mode()); 994 DCHECK(info()->strict_mode() == shared_info->strict_mode());
996 scope->SetStrictMode(shared_info->strict_mode()); 995 scope->SetStrictMode(shared_info->strict_mode());
997 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 996 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
998 ? (shared_info->is_anonymous() 997 ? (shared_info->is_anonymous()
999 ? FunctionLiteral::ANONYMOUS_EXPRESSION 998 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1000 : FunctionLiteral::NAMED_EXPRESSION) 999 : FunctionLiteral::NAMED_EXPRESSION)
1001 : FunctionLiteral::DECLARATION; 1000 : FunctionLiteral::DECLARATION;
1002 bool is_generator = shared_info->is_generator(); 1001 bool is_generator = shared_info->is_generator();
1003 bool ok = true; 1002 bool ok = true;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 ExpressionStatement* e_stat; 1067 ExpressionStatement* e_stat;
1069 Literal* literal; 1068 Literal* literal;
1070 // Still processing directive prologue? 1069 // Still processing directive prologue?
1071 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1070 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1072 (literal = e_stat->expression()->AsLiteral()) != NULL && 1071 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1073 literal->raw_value()->IsString()) { 1072 literal->raw_value()->IsString()) {
1074 // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only 1073 // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only
1075 // one can be present. 1074 // one can be present.
1076 if (strict_mode() == SLOPPY && 1075 if (strict_mode() == SLOPPY &&
1077 literal->raw_value()->AsString() == 1076 literal->raw_value()->AsString() ==
1078 ast_value_factory_->use_strict_string() && 1077 ast_value_factory()->use_strict_string() &&
1079 token_loc.end_pos - token_loc.beg_pos == 1078 token_loc.end_pos - token_loc.beg_pos ==
1080 ast_value_factory_->use_strict_string()->length() + 2) { 1079 ast_value_factory()->use_strict_string()->length() + 2) {
1081 // TODO(mstarzinger): Global strict eval calls, need their own scope 1080 // TODO(mstarzinger): Global strict eval calls, need their own scope
1082 // as specified in ES5 10.4.2(3). The correct fix would be to always 1081 // as specified in ES5 10.4.2(3). The correct fix would be to always
1083 // add this scope in DoParseProgram(), but that requires adaptations 1082 // add this scope in DoParseProgram(), but that requires adaptations
1084 // all over the code base, so we go with a quick-fix for now. 1083 // all over the code base, so we go with a quick-fix for now.
1085 // In the same manner, we have to patch the parsing mode. 1084 // In the same manner, we have to patch the parsing mode.
1086 if (is_eval && !scope_->is_eval_scope()) { 1085 if (is_eval && !scope_->is_eval_scope()) {
1087 DCHECK(scope_->is_global_scope()); 1086 DCHECK(scope_->is_global_scope());
1088 Scope* scope = NewScope(scope_, EVAL_SCOPE); 1087 Scope* scope = NewScope(scope_, EVAL_SCOPE);
1089 scope->set_start_position(scope_->start_position()); 1088 scope->set_start_position(scope_->start_position());
1090 scope->set_end_position(scope_->end_position()); 1089 scope->set_end_position(scope_->end_position());
1091 scope_ = scope; 1090 scope_ = scope;
1092 mode_ = PARSE_EAGERLY; 1091 mode_ = PARSE_EAGERLY;
1093 } 1092 }
1094 scope_->SetStrictMode(STRICT); 1093 scope_->SetStrictMode(STRICT);
1095 // "use strict" is the only directive for now. 1094 // "use strict" is the only directive for now.
1096 directive_prologue = false; 1095 directive_prologue = false;
1097 } else if (literal->raw_value()->AsString() == 1096 } else if (literal->raw_value()->AsString() ==
1098 ast_value_factory_->use_asm_string() && 1097 ast_value_factory()->use_asm_string() &&
1099 token_loc.end_pos - token_loc.beg_pos == 1098 token_loc.end_pos - token_loc.beg_pos ==
1100 ast_value_factory_->use_asm_string()->length() + 2) { 1099 ast_value_factory()->use_asm_string()->length() + 2) {
1101 // Store the usage count; The actual use counter on the isolate is 1100 // Store the usage count; The actual use counter on the isolate is
1102 // incremented after parsing is done. 1101 // incremented after parsing is done.
1103 ++use_counts_[v8::Isolate::kUseAsm]; 1102 ++use_counts_[v8::Isolate::kUseAsm];
1104 } 1103 }
1105 } else { 1104 } else {
1106 // End of the directive prologue. 1105 // End of the directive prologue.
1107 directive_prologue = false; 1106 directive_prologue = false;
1108 } 1107 }
1109 } 1108 }
1110 1109
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 default: { 1148 default: {
1150 Statement* stmt = ParseStatement(labels, CHECK_OK); 1149 Statement* stmt = ParseStatement(labels, CHECK_OK);
1151 // Handle 'module' as a context-sensitive keyword. 1150 // Handle 'module' as a context-sensitive keyword.
1152 if (FLAG_harmony_modules && 1151 if (FLAG_harmony_modules &&
1153 peek() == Token::IDENTIFIER && 1152 peek() == Token::IDENTIFIER &&
1154 !scanner()->HasAnyLineTerminatorBeforeNext() && 1153 !scanner()->HasAnyLineTerminatorBeforeNext() &&
1155 stmt != NULL) { 1154 stmt != NULL) {
1156 ExpressionStatement* estmt = stmt->AsExpressionStatement(); 1155 ExpressionStatement* estmt = stmt->AsExpressionStatement();
1157 if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL && 1156 if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL &&
1158 estmt->expression()->AsVariableProxy()->raw_name() == 1157 estmt->expression()->AsVariableProxy()->raw_name() ==
1159 ast_value_factory_->module_string() && 1158 ast_value_factory()->module_string() &&
1160 !scanner()->literal_contains_escapes()) { 1159 !scanner()->literal_contains_escapes()) {
1161 return ParseModuleDeclaration(NULL, ok); 1160 return ParseModuleDeclaration(NULL, ok);
1162 } 1161 }
1163 } 1162 }
1164 return stmt; 1163 return stmt;
1165 } 1164 }
1166 } 1165 }
1167 } 1166 }
1168 1167
1169 1168
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 Expect(Token::EXPORT, CHECK_OK); 1446 Expect(Token::EXPORT, CHECK_OK);
1448 1447
1449 Statement* result = NULL; 1448 Statement* result = NULL;
1450 ZoneList<const AstRawString*> names(1, zone()); 1449 ZoneList<const AstRawString*> names(1, zone());
1451 switch (peek()) { 1450 switch (peek()) {
1452 case Token::IDENTIFIER: { 1451 case Token::IDENTIFIER: {
1453 int pos = position(); 1452 int pos = position();
1454 const AstRawString* name = 1453 const AstRawString* name =
1455 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1454 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1456 // Handle 'module' as a context-sensitive keyword. 1455 // Handle 'module' as a context-sensitive keyword.
1457 if (name != ast_value_factory_->module_string()) { 1456 if (name != ast_value_factory()->module_string()) {
1458 names.Add(name, zone()); 1457 names.Add(name, zone());
1459 while (peek() == Token::COMMA) { 1458 while (peek() == Token::COMMA) {
1460 Consume(Token::COMMA); 1459 Consume(Token::COMMA);
1461 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 1460 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
1462 names.Add(name, zone()); 1461 names.Add(name, zone());
1463 } 1462 }
1464 ExpectSemicolon(CHECK_OK); 1463 ExpectSemicolon(CHECK_OK);
1465 result = factory()->NewEmptyStatement(pos); 1464 result = factory()->NewEmptyStatement(pos);
1466 } else { 1465 } else {
1467 result = ParseModuleDeclaration(&names, CHECK_OK); 1466 result = ParseModuleDeclaration(&names, CHECK_OK);
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 2223
2225 if (is_const) { 2224 if (is_const) {
2226 arguments->Add(value, zone()); 2225 arguments->Add(value, zone());
2227 value = NULL; // zap the value to avoid the unnecessary assignment 2226 value = NULL; // zap the value to avoid the unnecessary assignment
2228 2227
2229 // Construct the call to Runtime_InitializeConstGlobal 2228 // Construct the call to Runtime_InitializeConstGlobal
2230 // and add it to the initialization statement block. 2229 // and add it to the initialization statement block.
2231 // Note that the function does different things depending on 2230 // Note that the function does different things depending on
2232 // the number of arguments (1 or 2). 2231 // the number of arguments (1 or 2).
2233 initialize = factory()->NewCallRuntime( 2232 initialize = factory()->NewCallRuntime(
2234 ast_value_factory_->initialize_const_global_string(), 2233 ast_value_factory()->initialize_const_global_string(),
2235 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 2234 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), arguments,
2236 arguments, pos); 2235 pos);
2237 } else { 2236 } else {
2238 // Add strict mode. 2237 // Add strict mode.
2239 // We may want to pass singleton to avoid Literal allocations. 2238 // We may want to pass singleton to avoid Literal allocations.
2240 StrictMode strict_mode = initialization_scope->strict_mode(); 2239 StrictMode strict_mode = initialization_scope->strict_mode();
2241 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); 2240 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone());
2242 2241
2243 // Be careful not to assign a value to the global variable if 2242 // Be careful not to assign a value to the global variable if
2244 // we're in a with. The initialization value should not 2243 // we're in a with. The initialization value should not
2245 // necessarily be stored in the global object in that case, 2244 // necessarily be stored in the global object in that case,
2246 // which is why we need to generate a separate assignment node. 2245 // which is why we need to generate a separate assignment node.
2247 if (value != NULL && !inside_with()) { 2246 if (value != NULL && !inside_with()) {
2248 arguments->Add(value, zone()); 2247 arguments->Add(value, zone());
2249 value = NULL; // zap the value to avoid the unnecessary assignment 2248 value = NULL; // zap the value to avoid the unnecessary assignment
2250 // Construct the call to Runtime_InitializeVarGlobal 2249 // Construct the call to Runtime_InitializeVarGlobal
2251 // and add it to the initialization statement block. 2250 // and add it to the initialization statement block.
2252 initialize = factory()->NewCallRuntime( 2251 initialize = factory()->NewCallRuntime(
2253 ast_value_factory_->initialize_var_global_string(), 2252 ast_value_factory()->initialize_var_global_string(),
2254 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments, 2253 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments,
2255 pos); 2254 pos);
2256 } else { 2255 } else {
2257 initialize = NULL; 2256 initialize = NULL;
2258 } 2257 }
2259 } 2258 }
2260 2259
2261 if (initialize != NULL) { 2260 if (initialize != NULL) {
2262 block->AddStatement(factory()->NewExpressionStatement( 2261 block->AddStatement(factory()->NewExpressionStatement(
2263 initialize, RelocInfo::kNoPosition), 2262 initialize, RelocInfo::kNoPosition),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 // from the top scope. This way, we don't try to resolve it 2357 // from the top scope. This way, we don't try to resolve it
2359 // during the scope processing. 2358 // during the scope processing.
2360 scope_->RemoveUnresolved(var); 2359 scope_->RemoveUnresolved(var);
2361 Expect(Token::COLON, CHECK_OK); 2360 Expect(Token::COLON, CHECK_OK);
2362 return ParseStatement(labels, ok); 2361 return ParseStatement(labels, ok);
2363 } 2362 }
2364 2363
2365 // If we have an extension, we allow a native function declaration. 2364 // If we have an extension, we allow a native function declaration.
2366 // A native function declaration starts with "native function" with 2365 // A native function declaration starts with "native function" with
2367 // no line-terminator between the two words. 2366 // no line-terminator between the two words.
2368 if (extension_ != NULL && 2367 if (extension_ != NULL && peek() == Token::FUNCTION &&
2369 peek() == Token::FUNCTION && 2368 !scanner()->HasAnyLineTerminatorBeforeNext() && expr != NULL &&
2370 !scanner()->HasAnyLineTerminatorBeforeNext() &&
2371 expr != NULL &&
2372 expr->AsVariableProxy() != NULL && 2369 expr->AsVariableProxy() != NULL &&
2373 expr->AsVariableProxy()->raw_name() == 2370 expr->AsVariableProxy()->raw_name() ==
2374 ast_value_factory_->native_string() && 2371 ast_value_factory()->native_string() &&
2375 !scanner()->literal_contains_escapes()) { 2372 !scanner()->literal_contains_escapes()) {
2376 return ParseNativeDeclaration(ok); 2373 return ParseNativeDeclaration(ok);
2377 } 2374 }
2378 2375
2379 // Parsed expression statement, or the context-sensitive 'module' keyword. 2376 // Parsed expression statement, or the context-sensitive 'module' keyword.
2380 // Only expect semicolon in the former case. 2377 // Only expect semicolon in the former case.
2381 if (!FLAG_harmony_modules || 2378 if (!FLAG_harmony_modules || peek() != Token::IDENTIFIER ||
2382 peek() != Token::IDENTIFIER ||
2383 scanner()->HasAnyLineTerminatorBeforeNext() || 2379 scanner()->HasAnyLineTerminatorBeforeNext() ||
2384 expr->AsVariableProxy() == NULL || 2380 expr->AsVariableProxy() == NULL ||
2385 expr->AsVariableProxy()->raw_name() != 2381 expr->AsVariableProxy()->raw_name() !=
2386 ast_value_factory_->module_string() || 2382 ast_value_factory()->module_string() ||
2387 scanner()->literal_contains_escapes()) { 2383 scanner()->literal_contains_escapes()) {
2388 ExpectSemicolon(CHECK_OK); 2384 ExpectSemicolon(CHECK_OK);
2389 } 2385 }
2390 return factory()->NewExpressionStatement(expr, pos); 2386 return factory()->NewExpressionStatement(expr, pos);
2391 } 2387 }
2392 2388
2393 2389
2394 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels, 2390 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels,
2395 bool* ok) { 2391 bool* ok) {
2396 // IfStatement :: 2392 // IfStatement ::
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 2794
2799 2795
2800 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2796 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2801 Expression* each, 2797 Expression* each,
2802 Expression* subject, 2798 Expression* subject,
2803 Statement* body) { 2799 Statement* body) {
2804 ForOfStatement* for_of = stmt->AsForOfStatement(); 2800 ForOfStatement* for_of = stmt->AsForOfStatement();
2805 2801
2806 if (for_of != NULL) { 2802 if (for_of != NULL) {
2807 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2803 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2808 ast_value_factory_->dot_iterator_string()); 2804 ast_value_factory()->dot_iterator_string());
2809 Variable* result = scope_->DeclarationScope()->NewTemporary( 2805 Variable* result = scope_->DeclarationScope()->NewTemporary(
2810 ast_value_factory_->dot_result_string()); 2806 ast_value_factory()->dot_result_string());
2811 2807
2812 Expression* assign_iterator; 2808 Expression* assign_iterator;
2813 Expression* next_result; 2809 Expression* next_result;
2814 Expression* result_done; 2810 Expression* result_done;
2815 Expression* assign_each; 2811 Expression* assign_each;
2816 2812
2817 // var iterator = subject[Symbol.iterator](); 2813 // var iterator = subject[Symbol.iterator]();
2818 assign_iterator = factory()->NewAssignment( 2814 assign_iterator = factory()->NewAssignment(
2819 Token::ASSIGN, factory()->NewVariableProxy(iterator), 2815 Token::ASSIGN, factory()->NewVariableProxy(iterator),
2820 GetIterator(subject, factory()), RelocInfo::kNoPosition); 2816 GetIterator(subject, factory()), RelocInfo::kNoPosition);
2821 2817
2822 // var result = iterator.next(); 2818 // var result = iterator.next();
2823 { 2819 {
2824 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2820 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2825 Expression* next_literal = factory()->NewStringLiteral( 2821 Expression* next_literal = factory()->NewStringLiteral(
2826 ast_value_factory_->next_string(), RelocInfo::kNoPosition); 2822 ast_value_factory()->next_string(), RelocInfo::kNoPosition);
2827 Expression* next_property = factory()->NewProperty( 2823 Expression* next_property = factory()->NewProperty(
2828 iterator_proxy, next_literal, RelocInfo::kNoPosition); 2824 iterator_proxy, next_literal, RelocInfo::kNoPosition);
2829 ZoneList<Expression*>* next_arguments = 2825 ZoneList<Expression*>* next_arguments =
2830 new(zone()) ZoneList<Expression*>(0, zone()); 2826 new(zone()) ZoneList<Expression*>(0, zone());
2831 Expression* next_call = factory()->NewCall( 2827 Expression* next_call = factory()->NewCall(
2832 next_property, next_arguments, RelocInfo::kNoPosition); 2828 next_property, next_arguments, RelocInfo::kNoPosition);
2833 Expression* result_proxy = factory()->NewVariableProxy(result); 2829 Expression* result_proxy = factory()->NewVariableProxy(result);
2834 next_result = factory()->NewAssignment( 2830 next_result = factory()->NewAssignment(
2835 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition); 2831 Token::ASSIGN, result_proxy, next_call, RelocInfo::kNoPosition);
2836 } 2832 }
2837 2833
2838 // result.done 2834 // result.done
2839 { 2835 {
2840 Expression* done_literal = factory()->NewStringLiteral( 2836 Expression* done_literal = factory()->NewStringLiteral(
2841 ast_value_factory_->done_string(), RelocInfo::kNoPosition); 2837 ast_value_factory()->done_string(), RelocInfo::kNoPosition);
2842 Expression* result_proxy = factory()->NewVariableProxy(result); 2838 Expression* result_proxy = factory()->NewVariableProxy(result);
2843 result_done = factory()->NewProperty( 2839 result_done = factory()->NewProperty(
2844 result_proxy, done_literal, RelocInfo::kNoPosition); 2840 result_proxy, done_literal, RelocInfo::kNoPosition);
2845 } 2841 }
2846 2842
2847 // each = result.value 2843 // each = result.value
2848 { 2844 {
2849 Expression* value_literal = factory()->NewStringLiteral( 2845 Expression* value_literal = factory()->NewStringLiteral(
2850 ast_value_factory_->value_string(), RelocInfo::kNoPosition); 2846 ast_value_factory()->value_string(), RelocInfo::kNoPosition);
2851 Expression* result_proxy = factory()->NewVariableProxy(result); 2847 Expression* result_proxy = factory()->NewVariableProxy(result);
2852 Expression* result_value = factory()->NewProperty( 2848 Expression* result_value = factory()->NewProperty(
2853 result_proxy, value_literal, RelocInfo::kNoPosition); 2849 result_proxy, value_literal, RelocInfo::kNoPosition);
2854 assign_each = factory()->NewAssignment( 2850 assign_each = factory()->NewAssignment(
2855 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2851 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2856 } 2852 }
2857 2853
2858 for_of->Initialize(each, subject, body, 2854 for_of->Initialize(each, subject, body,
2859 assign_iterator, 2855 assign_iterator,
2860 next_result, 2856 next_result,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2903 // } 2899 // }
2904 2900
2905 DCHECK(names->length() > 0); 2901 DCHECK(names->length() > 0);
2906 Scope* for_scope = scope_; 2902 Scope* for_scope = scope_;
2907 ZoneList<Variable*> temps(names->length(), zone()); 2903 ZoneList<Variable*> temps(names->length(), zone());
2908 2904
2909 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, 2905 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false,
2910 RelocInfo::kNoPosition); 2906 RelocInfo::kNoPosition);
2911 outer_block->AddStatement(init, zone()); 2907 outer_block->AddStatement(init, zone());
2912 2908
2913 const AstRawString* temp_name = ast_value_factory_->dot_for_string(); 2909 const AstRawString* temp_name = ast_value_factory()->dot_for_string();
2914 2910
2915 // For each let variable x: 2911 // For each let variable x:
2916 // make statement: temp_x = x. 2912 // make statement: temp_x = x.
2917 for (int i = 0; i < names->length(); i++) { 2913 for (int i = 0; i < names->length(); i++) {
2918 VariableProxy* proxy = 2914 VariableProxy* proxy =
2919 NewUnresolved(names->at(i), LET, Interface::NewValue()); 2915 NewUnresolved(names->at(i), LET, Interface::NewValue());
2920 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); 2916 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name);
2921 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2917 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2922 Assignment* assignment = factory()->NewAssignment( 2918 Assignment* assignment = factory()->NewAssignment(
2923 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 2919 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 // <let x' be a temporary variable> 3097 // <let x' be a temporary variable>
3102 // for (x' in e) { 3098 // for (x' in e) {
3103 // let x; 3099 // let x;
3104 // x = x'; 3100 // x = x';
3105 // b; 3101 // b;
3106 // } 3102 // }
3107 3103
3108 // TODO(keuchel): Move the temporary variable to the block scope, after 3104 // TODO(keuchel): Move the temporary variable to the block scope, after
3109 // implementing stack allocated block scoped variables. 3105 // implementing stack allocated block scoped variables.
3110 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3106 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3111 ast_value_factory_->dot_for_string()); 3107 ast_value_factory()->dot_for_string());
3112 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3108 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3113 ForEachStatement* loop = 3109 ForEachStatement* loop =
3114 factory()->NewForEachStatement(mode, labels, pos); 3110 factory()->NewForEachStatement(mode, labels, pos);
3115 Target target(&this->target_stack_, loop); 3111 Target target(&this->target_stack_, loop);
3116 3112
3117 // The expression does not see the loop variable. 3113 // The expression does not see the loop variable.
3118 scope_ = saved_scope; 3114 scope_ = saved_scope;
3119 Expression* enumerable = ParseExpression(true, CHECK_OK); 3115 Expression* enumerable = ParseExpression(true, CHECK_OK);
3120 scope_ = for_scope; 3116 scope_ = for_scope;
3121 Expect(Token::RPAREN, CHECK_OK); 3117 Expect(Token::RPAREN, CHECK_OK);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 int pos = function_token_pos == RelocInfo::kNoPosition 3381 int pos = function_token_pos == RelocInfo::kNoPosition
3386 ? peek_position() : function_token_pos; 3382 ? peek_position() : function_token_pos;
3387 3383
3388 // Anonymous functions were passed either the empty symbol or a null 3384 // Anonymous functions were passed either the empty symbol or a null
3389 // handle as the function name. Remember if we were passed a non-empty 3385 // handle as the function name. Remember if we were passed a non-empty
3390 // handle to decide whether to invoke function name inference. 3386 // handle to decide whether to invoke function name inference.
3391 bool should_infer_name = function_name == NULL; 3387 bool should_infer_name = function_name == NULL;
3392 3388
3393 // We want a non-null handle as the function name. 3389 // We want a non-null handle as the function name.
3394 if (should_infer_name) { 3390 if (should_infer_name) {
3395 function_name = ast_value_factory_->empty_string(); 3391 function_name = ast_value_factory()->empty_string();
3396 } 3392 }
3397 3393
3398 int num_parameters = 0; 3394 int num_parameters = 0;
3399 // Function declarations are function scoped in normal mode, so they are 3395 // Function declarations are function scoped in normal mode, so they are
3400 // hoisted. In harmony block scoping mode they are block scoped, so they 3396 // hoisted. In harmony block scoping mode they are block scoped, so they
3401 // are not hoisted. 3397 // are not hoisted.
3402 // 3398 //
3403 // One tricky case are function declarations in a local sloppy-mode eval: 3399 // One tricky case are function declarations in a local sloppy-mode eval:
3404 // their declaration is hoisted, but they still see the local scope. E.g., 3400 // their declaration is hoisted, but they still see the local scope. E.g.,
3405 // 3401 //
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 FunctionLiteral::ParameterFlag duplicate_parameters = 3435 FunctionLiteral::ParameterFlag duplicate_parameters =
3440 FunctionLiteral::kNoDuplicateParameters; 3436 FunctionLiteral::kNoDuplicateParameters;
3441 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3437 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3442 ? FunctionLiteral::kIsParenthesized 3438 ? FunctionLiteral::kIsParenthesized
3443 : FunctionLiteral::kNotParenthesized; 3439 : FunctionLiteral::kNotParenthesized;
3444 AstProperties ast_properties; 3440 AstProperties ast_properties;
3445 BailoutReason dont_optimize_reason = kNoReason; 3441 BailoutReason dont_optimize_reason = kNoReason;
3446 // Parse function body. 3442 // Parse function body.
3447 { 3443 {
3448 FunctionState function_state(&function_state_, &scope_, scope, zone(), 3444 FunctionState function_state(&function_state_, &scope_, scope, zone(),
3449 ast_value_factory_, info()->ast_node_id_gen()); 3445 ast_value_factory(),
3446 info()->ast_node_id_gen());
3450 scope_->SetScopeName(function_name); 3447 scope_->SetScopeName(function_name);
3451 3448
3452 if (is_generator) { 3449 if (is_generator) {
3453 // For generators, allocating variables in contexts is currently a win 3450 // For generators, allocating variables in contexts is currently a win
3454 // because it minimizes the work needed to suspend and resume an 3451 // because it minimizes the work needed to suspend and resume an
3455 // activation. 3452 // activation.
3456 scope_->ForceContextAllocation(); 3453 scope_->ForceContextAllocation();
3457 3454
3458 // Calling a generator returns a generator object. That object is stored 3455 // Calling a generator returns a generator object. That object is stored
3459 // in a temporary variable, a definition that is used by "yield" 3456 // in a temporary variable, a definition that is used by "yield"
3460 // expressions. This also marks the FunctionState as a generator. 3457 // expressions. This also marks the FunctionState as a generator.
3461 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3458 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3462 ast_value_factory_->dot_generator_object_string()); 3459 ast_value_factory()->dot_generator_object_string());
3463 function_state.set_generator_object_variable(temp); 3460 function_state.set_generator_object_variable(temp);
3464 } 3461 }
3465 3462
3466 // FormalParameterList :: 3463 // FormalParameterList ::
3467 // '(' (Identifier)*[','] ')' 3464 // '(' (Identifier)*[','] ')'
3468 Expect(Token::LPAREN, CHECK_OK); 3465 Expect(Token::LPAREN, CHECK_OK);
3469 scope->set_start_position(scanner()->location().beg_pos); 3466 scope->set_start_position(scanner()->location().beg_pos);
3470 3467
3471 // We don't yet know if the function will be strict, so we cannot yet 3468 // We don't yet know if the function will be strict, so we cannot yet
3472 // produce errors for parameter names or duplicates. However, we remember 3469 // produce errors for parameter names or duplicates. However, we remember
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 3607
3611 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3608 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3612 CheckConflictingVarDeclarations(scope, CHECK_OK); 3609 CheckConflictingVarDeclarations(scope, CHECK_OK);
3613 } 3610 }
3614 } 3611 }
3615 3612
3616 FunctionLiteral::KindFlag kind = is_generator 3613 FunctionLiteral::KindFlag kind = is_generator
3617 ? FunctionLiteral::kGeneratorFunction 3614 ? FunctionLiteral::kGeneratorFunction
3618 : FunctionLiteral::kNormalFunction; 3615 : FunctionLiteral::kNormalFunction;
3619 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( 3616 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
3620 function_name, ast_value_factory_, scope, body, 3617 function_name, ast_value_factory(), scope, body,
3621 materialized_literal_count, expected_property_count, handler_count, 3618 materialized_literal_count, expected_property_count, handler_count,
3622 num_parameters, duplicate_parameters, function_type, 3619 num_parameters, duplicate_parameters, function_type,
3623 FunctionLiteral::kIsFunction, parenthesized, kind, pos); 3620 FunctionLiteral::kIsFunction, parenthesized, kind, pos);
3624 function_literal->set_function_token_position(function_token_pos); 3621 function_literal->set_function_token_position(function_token_pos);
3625 function_literal->set_ast_properties(&ast_properties); 3622 function_literal->set_ast_properties(&ast_properties);
3626 function_literal->set_dont_optimize_reason(dont_optimize_reason); 3623 function_literal->set_dont_optimize_reason(dont_optimize_reason);
3627 3624
3628 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3625 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3629 return function_literal; 3626 return function_literal;
3630 } 3627 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3713 factory()->NewThisFunction(pos), 3710 factory()->NewThisFunction(pos),
3714 RelocInfo::kNoPosition), 3711 RelocInfo::kNoPosition),
3715 RelocInfo::kNoPosition), zone()); 3712 RelocInfo::kNoPosition), zone());
3716 } 3713 }
3717 3714
3718 // For generators, allocate and yield an iterator on function entry. 3715 // For generators, allocate and yield an iterator on function entry.
3719 if (is_generator) { 3716 if (is_generator) {
3720 ZoneList<Expression*>* arguments = 3717 ZoneList<Expression*>* arguments =
3721 new(zone()) ZoneList<Expression*>(0, zone()); 3718 new(zone()) ZoneList<Expression*>(0, zone());
3722 CallRuntime* allocation = factory()->NewCallRuntime( 3719 CallRuntime* allocation = factory()->NewCallRuntime(
3723 ast_value_factory_->empty_string(), 3720 ast_value_factory()->empty_string(),
3724 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), 3721 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments,
3725 arguments, pos); 3722 pos);
3726 VariableProxy* init_proxy = factory()->NewVariableProxy( 3723 VariableProxy* init_proxy = factory()->NewVariableProxy(
3727 function_state_->generator_object_variable()); 3724 function_state_->generator_object_variable());
3728 Assignment* assignment = factory()->NewAssignment( 3725 Assignment* assignment = factory()->NewAssignment(
3729 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 3726 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
3730 VariableProxy* get_proxy = factory()->NewVariableProxy( 3727 VariableProxy* get_proxy = factory()->NewVariableProxy(
3731 function_state_->generator_object_variable()); 3728 function_state_->generator_object_variable());
3732 Yield* yield = factory()->NewYield( 3729 Yield* yield = factory()->NewYield(
3733 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); 3730 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition);
3734 body->Add(factory()->NewExpressionStatement( 3731 body->Add(factory()->NewExpressionStatement(
3735 yield, RelocInfo::kNoPosition), zone()); 3732 yield, RelocInfo::kNoPosition), zone());
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 } 3925 }
3929 if (scanner_.source_mapping_url()->length() > 0) { 3926 if (scanner_.source_mapping_url()->length() > 0) {
3930 Handle<String> source_mapping_url = 3927 Handle<String> source_mapping_url =
3931 scanner_.source_mapping_url()->Internalize(isolate()); 3928 scanner_.source_mapping_url()->Internalize(isolate());
3932 info_->script()->set_source_mapping_url(*source_mapping_url); 3929 info_->script()->set_source_mapping_url(*source_mapping_url);
3933 } 3930 }
3934 } 3931 }
3935 3932
3936 3933
3937 void Parser::ThrowPendingError() { 3934 void Parser::ThrowPendingError() {
3938 DCHECK(ast_value_factory_->IsInternalized()); 3935 DCHECK(ast_value_factory()->IsInternalized());
3939 if (has_pending_error_) { 3936 if (has_pending_error_) {
3940 MessageLocation location(script_, 3937 MessageLocation location(script(), pending_error_location_.beg_pos,
3941 pending_error_location_.beg_pos,
3942 pending_error_location_.end_pos); 3938 pending_error_location_.end_pos);
3943 Factory* factory = isolate()->factory(); 3939 Factory* factory = isolate()->factory();
3944 bool has_arg = 3940 bool has_arg =
3945 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; 3941 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL;
3946 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); 3942 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3947 if (pending_error_arg_ != NULL) { 3943 if (pending_error_arg_ != NULL) {
3948 Handle<String> arg_string = pending_error_arg_->string(); 3944 Handle<String> arg_string = pending_error_arg_->string();
3949 elements->set(0, *arg_string); 3945 elements->set(0, *arg_string);
3950 } else if (pending_error_char_arg_ != NULL) { 3946 } else if (pending_error_char_arg_ != NULL) {
3951 Handle<String> arg_string = 3947 Handle<String> arg_string =
3952 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) 3948 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_))
3953 .ToHandleChecked(); 3949 .ToHandleChecked();
3954 elements->set(0, *arg_string); 3950 elements->set(0, *arg_string);
3955 } 3951 }
3956 isolate()->debug()->OnCompileError(script_); 3952 isolate()->debug()->OnCompileError(script());
3957 3953
3958 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 3954 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
3959 Handle<Object> error; 3955 Handle<Object> error;
3960 MaybeHandle<Object> maybe_error = 3956 MaybeHandle<Object> maybe_error =
3961 pending_error_is_reference_error_ 3957 pending_error_is_reference_error_
3962 ? factory->NewReferenceError(pending_error_message_, array) 3958 ? factory->NewReferenceError(pending_error_message_, array)
3963 : factory->NewSyntaxError(pending_error_message_, array); 3959 : factory->NewSyntaxError(pending_error_message_, array);
3964 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location); 3960 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location);
3965 } 3961 }
3966 } 3962 }
3967 3963
3968 3964
3969 void Parser::Internalize() { 3965 void Parser::Internalize() {
3970 // Internalize strings. 3966 // Internalize strings.
3971 ast_value_factory_->Internalize(isolate()); 3967 ast_value_factory()->Internalize(isolate());
3972 3968
3973 // Error processing. 3969 // Error processing.
3974 if (info()->function() == NULL) { 3970 if (info()->function() == NULL) {
3975 if (stack_overflow()) { 3971 if (stack_overflow()) {
3976 isolate()->StackOverflow(); 3972 isolate()->StackOverflow();
3977 } else { 3973 } else {
3978 ThrowPendingError(); 3974 ThrowPendingError();
3979 } 3975 }
3980 } 3976 }
3981 3977
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 4819
4824 4820
4825 bool Parser::Parse() { 4821 bool Parser::Parse() {
4826 DCHECK(info()->function() == NULL); 4822 DCHECK(info()->function() == NULL);
4827 FunctionLiteral* result = NULL; 4823 FunctionLiteral* result = NULL;
4828 pre_parse_timer_ = isolate()->counters()->pre_parse(); 4824 pre_parse_timer_ = isolate()->counters()->pre_parse();
4829 if (allow_natives_syntax() || extension_ != NULL) { 4825 if (allow_natives_syntax() || extension_ != NULL) {
4830 // If intrinsics are allowed, the Parser cannot operate independent of the 4826 // If intrinsics are allowed, the Parser cannot operate independent of the
4831 // V8 heap because of Runtime. Tell the string table to internalize strings 4827 // V8 heap because of Runtime. Tell the string table to internalize strings
4832 // and values right after they're created. 4828 // and values right after they're created.
4833 ast_value_factory_->Internalize(isolate()); 4829 ast_value_factory()->Internalize(isolate());
4834 } 4830 }
4835 4831
4836 if (info()->is_lazy()) { 4832 if (info()->is_lazy()) {
4837 DCHECK(!info()->is_eval()); 4833 DCHECK(!info()->is_eval());
4838 if (info()->shared_info()->is_function()) { 4834 if (info()->shared_info()->is_function()) {
4839 result = ParseLazy(); 4835 result = ParseLazy();
4840 } else { 4836 } else {
4841 result = ParseProgram(); 4837 result = ParseProgram();
4842 } 4838 }
4843 } else { 4839 } else {
4844 SetCachedData(); 4840 SetCachedData();
4845 result = ParseProgram(); 4841 result = ParseProgram();
4846 } 4842 }
4847 info()->SetFunction(result); 4843 info()->SetFunction(result);
4848 4844
4849 Internalize(); 4845 Internalize();
4850 DCHECK(ast_value_factory_->IsInternalized()); 4846 DCHECK(ast_value_factory()->IsInternalized());
4851 // info takes ownership of ast_value_factory_.
4852 if (info()->ast_value_factory() == NULL) {
4853 info()->SetAstValueFactory(ast_value_factory_);
4854 }
4855 ast_value_factory_ = NULL;
4856 return (result != NULL); 4847 return (result != NULL);
4857 } 4848 }
4858 4849
4859 } } // namespace v8::internal 4850 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698