OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 562 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
563 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 563 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
564 set_allow_lazy(false); // Must be explicitly enabled. | 564 set_allow_lazy(false); // Must be explicitly enabled. |
565 set_allow_generators(FLAG_harmony_generators); | 565 set_allow_generators(FLAG_harmony_generators); |
566 set_allow_for_of(FLAG_harmony_iteration); | 566 set_allow_for_of(FLAG_harmony_iteration); |
567 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 567 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
568 } | 568 } |
569 | 569 |
570 | 570 |
571 FunctionLiteral* Parser::ParseProgram() { | 571 FunctionLiteral* Parser::ParseProgram() { |
572 HistogramTimerScope timer_scope(isolate()->counters()->parse()); | 572 HistogramTimerScope timer(isolate()->counters()->parse()); |
573 Handle<String> source(String::cast(script_->source())); | 573 Handle<String> source(String::cast(script_->source())); |
574 isolate()->counters()->total_parse_size()->Increment(source->length()); | 574 isolate()->counters()->total_parse_size()->Increment(source->length()); |
575 ElapsedTimer timer; | 575 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; |
576 if (FLAG_trace_parse) { | |
577 timer.Start(); | |
578 } | |
579 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); | 576 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
580 | 577 |
581 // Initialize parser state. | 578 // Initialize parser state. |
582 source->TryFlatten(); | 579 source->TryFlatten(); |
583 FunctionLiteral* result; | 580 FunctionLiteral* result; |
584 if (source->IsExternalTwoByteString()) { | 581 if (source->IsExternalTwoByteString()) { |
585 // Notice that the stream is destroyed at the end of the branch block. | 582 // Notice that the stream is destroyed at the end of the branch block. |
586 // The last line of the blocks can't be moved outside, even though they're | 583 // The last line of the blocks can't be moved outside, even though they're |
587 // identical calls. | 584 // identical calls. |
588 ExternalTwoByteStringUtf16CharacterStream stream( | 585 ExternalTwoByteStringUtf16CharacterStream stream( |
589 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 586 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
590 scanner_.Initialize(&stream); | 587 scanner_.Initialize(&stream); |
591 result = DoParseProgram(info(), source); | 588 result = DoParseProgram(info(), source); |
592 } else { | 589 } else { |
593 GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 590 GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
594 scanner_.Initialize(&stream); | 591 scanner_.Initialize(&stream); |
595 result = DoParseProgram(info(), source); | 592 result = DoParseProgram(info(), source); |
596 } | 593 } |
597 | 594 |
598 if (FLAG_trace_parse && result != NULL) { | 595 if (FLAG_trace_parse && result != NULL) { |
599 double ms = timer.Elapsed().InMillisecondsF(); | 596 double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
600 if (info()->is_eval()) { | 597 if (info()->is_eval()) { |
601 PrintF("[parsing eval"); | 598 PrintF("[parsing eval"); |
602 } else if (info()->script()->name()->IsString()) { | 599 } else if (info()->script()->name()->IsString()) { |
603 String* name = String::cast(info()->script()->name()); | 600 String* name = String::cast(info()->script()->name()); |
604 SmartArrayPointer<char> name_chars = name->ToCString(); | 601 SmartArrayPointer<char> name_chars = name->ToCString(); |
605 PrintF("[parsing script: %s", *name_chars); | 602 PrintF("[parsing script: %s", *name_chars); |
606 } else { | 603 } else { |
607 PrintF("[parsing script"); | 604 PrintF("[parsing script"); |
608 } | 605 } |
609 PrintF(" - took %0.3f ms]\n", ms); | 606 PrintF(" - took %0.3f ms]\n", ms); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 690 } |
694 | 691 |
695 // Make sure the target stack is empty. | 692 // Make sure the target stack is empty. |
696 ASSERT(target_stack_ == NULL); | 693 ASSERT(target_stack_ == NULL); |
697 | 694 |
698 return result; | 695 return result; |
699 } | 696 } |
700 | 697 |
701 | 698 |
702 FunctionLiteral* Parser::ParseLazy() { | 699 FunctionLiteral* Parser::ParseLazy() { |
703 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); | 700 HistogramTimerScope timer(isolate()->counters()->parse_lazy()); |
704 Handle<String> source(String::cast(script_->source())); | 701 Handle<String> source(String::cast(script_->source())); |
705 isolate()->counters()->total_parse_size()->Increment(source->length()); | 702 isolate()->counters()->total_parse_size()->Increment(source->length()); |
706 ElapsedTimer timer; | 703 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; |
707 if (FLAG_trace_parse) { | |
708 timer.Start(); | |
709 } | |
710 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | 704 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
711 | 705 |
712 // Initialize parser state. | 706 // Initialize parser state. |
713 source->TryFlatten(); | 707 source->TryFlatten(); |
714 FunctionLiteral* result; | 708 FunctionLiteral* result; |
715 if (source->IsExternalTwoByteString()) { | 709 if (source->IsExternalTwoByteString()) { |
716 ExternalTwoByteStringUtf16CharacterStream stream( | 710 ExternalTwoByteStringUtf16CharacterStream stream( |
717 Handle<ExternalTwoByteString>::cast(source), | 711 Handle<ExternalTwoByteString>::cast(source), |
718 shared_info->start_position(), | 712 shared_info->start_position(), |
719 shared_info->end_position()); | 713 shared_info->end_position()); |
720 result = ParseLazy(&stream); | 714 result = ParseLazy(&stream); |
721 } else { | 715 } else { |
722 GenericStringUtf16CharacterStream stream(source, | 716 GenericStringUtf16CharacterStream stream(source, |
723 shared_info->start_position(), | 717 shared_info->start_position(), |
724 shared_info->end_position()); | 718 shared_info->end_position()); |
725 result = ParseLazy(&stream); | 719 result = ParseLazy(&stream); |
726 } | 720 } |
727 | 721 |
728 if (FLAG_trace_parse && result != NULL) { | 722 if (FLAG_trace_parse && result != NULL) { |
729 double ms = timer.Elapsed().InMillisecondsF(); | 723 double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
730 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); | 724 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); |
731 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); | 725 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); |
732 } | 726 } |
733 return result; | 727 return result; |
734 } | 728 } |
735 | 729 |
736 | 730 |
737 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { | 731 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { |
738 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | 732 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
739 scanner_.Initialize(source); | 733 scanner_.Initialize(source); |
(...skipping 5230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5970 ASSERT(info()->isolate()->has_pending_exception()); | 5964 ASSERT(info()->isolate()->has_pending_exception()); |
5971 } else { | 5965 } else { |
5972 result = ParseProgram(); | 5966 result = ParseProgram(); |
5973 } | 5967 } |
5974 } | 5968 } |
5975 info()->SetFunction(result); | 5969 info()->SetFunction(result); |
5976 return (result != NULL); | 5970 return (result != NULL); |
5977 } | 5971 } |
5978 | 5972 |
5979 } } // namespace v8::internal | 5973 } } // namespace v8::internal |
OLD | NEW |