OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 context, | 551 context, |
552 is_global, | 552 is_global, |
553 strict_mode); | 553 strict_mode); |
554 | 554 |
555 if (result.is_null()) { | 555 if (result.is_null()) { |
556 // Create a script object describing the script to be compiled. | 556 // Create a script object describing the script to be compiled. |
557 Handle<Script> script = isolate->factory()->NewScript(source); | 557 Handle<Script> script = isolate->factory()->NewScript(source); |
558 CompilationInfo info(script); | 558 CompilationInfo info(script); |
559 info.MarkAsEval(); | 559 info.MarkAsEval(); |
560 if (is_global) info.MarkAsGlobal(); | 560 if (is_global) info.MarkAsGlobal(); |
561 if (strict_mode == kStrictMode) info.MarkAsStrictMode(); | 561 info.SetStrictModeFlag(strict_mode); |
562 info.SetCallingContext(context); | 562 info.SetCallingContext(context); |
563 result = MakeFunctionInfo(&info); | 563 result = MakeFunctionInfo(&info); |
564 if (!result.is_null()) { | 564 if (!result.is_null()) { |
565 CompilationCache* compilation_cache = isolate->compilation_cache(); | 565 CompilationCache* compilation_cache = isolate->compilation_cache(); |
566 // If caller is strict mode, the result must be strict as well, | 566 // If caller is strict mode, the result must be strict as well, |
567 // but not the other way around. Consider: | 567 // but not the other way around. Consider: |
568 // eval("'use strict'; ..."); | 568 // eval("'use strict'; ..."); |
569 // TODO(keuchel): adapt this for extended mode. | |
569 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); | 570 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
570 compilation_cache->PutEval(source, context, is_global, result); | 571 compilation_cache->PutEval(source, context, is_global, result); |
571 } | 572 } |
572 } | 573 } |
573 | 574 |
574 return result; | 575 return result; |
575 } | 576 } |
576 | 577 |
577 | 578 |
578 bool Compiler::CompileLazy(CompilationInfo* info) { | 579 bool Compiler::CompileLazy(CompilationInfo* info) { |
(...skipping 11 matching lines...) Expand all Loading... | |
590 isolate->counters()->total_compile_size()->Increment(compiled_size); | 591 isolate->counters()->total_compile_size()->Increment(compiled_size); |
591 | 592 |
592 // Generate the AST for the lazily compiled function. | 593 // Generate the AST for the lazily compiled function. |
593 if (ParserApi::Parse(info)) { | 594 if (ParserApi::Parse(info)) { |
594 // Measure how long it takes to do the lazy compilation; only take the | 595 // Measure how long it takes to do the lazy compilation; only take the |
595 // rest of the function into account to avoid overlap with the lazy | 596 // rest of the function into account to avoid overlap with the lazy |
596 // parsing statistics. | 597 // parsing statistics. |
597 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 598 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
598 | 599 |
599 // After parsing we know function's strict mode. Remember it. | 600 // After parsing we know function's strict mode. Remember it. |
600 if (info->function()->strict_mode()) { | 601 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); |
601 shared->set_strict_mode(true); | 602 if (strict_mode != kNonStrictMode) { |
Yang
2011/10/21 15:25:59
With the assertions in place, the if clause can ac
| |
602 info->MarkAsStrictMode(); | 603 ASSERT(info->strict_mode_flag() == kNonStrictMode || |
604 info->strict_mode_flag() == strict_mode); | |
605 ASSERT(shared->strict_mode_flag() == kNonStrictMode || | |
606 shared->strict_mode_flag() == strict_mode); | |
607 info->SetStrictModeFlag(strict_mode); | |
608 shared->set_strict_mode_flag(strict_mode); | |
609 } else { | |
610 ASSERT(info->strict_mode_flag() == strict_mode); | |
611 ASSERT(shared->strict_mode_flag() == strict_mode); | |
603 } | 612 } |
604 | 613 |
605 // Compile the code. | 614 // Compile the code. |
606 if (!MakeCode(info)) { | 615 if (!MakeCode(info)) { |
607 if (!isolate->has_pending_exception()) { | 616 if (!isolate->has_pending_exception()) { |
608 isolate->StackOverflow(); | 617 isolate->StackOverflow(); |
609 } | 618 } |
610 } else { | 619 } else { |
611 ASSERT(!info->code().is_null()); | 620 ASSERT(!info->code().is_null()); |
612 Handle<Code> code = info->code(); | 621 Handle<Code> code = info->code(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 return false; | 682 return false; |
674 } | 683 } |
675 | 684 |
676 | 685 |
677 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 686 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
678 Handle<Script> script) { | 687 Handle<Script> script) { |
679 // Precondition: code has been parsed and scopes have been analyzed. | 688 // Precondition: code has been parsed and scopes have been analyzed. |
680 CompilationInfo info(script); | 689 CompilationInfo info(script); |
681 info.SetFunction(literal); | 690 info.SetFunction(literal); |
682 info.SetScope(literal->scope()); | 691 info.SetScope(literal->scope()); |
683 if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode(); | 692 info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); |
684 | 693 |
685 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 694 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
686 // Determine if the function can be lazily compiled. This is necessary to | 695 // Determine if the function can be lazily compiled. This is necessary to |
687 // allow some of our builtin JS files to be lazily compiled. These | 696 // allow some of our builtin JS files to be lazily compiled. These |
688 // builtins cannot be handled lazily by the parser, since we have to know | 697 // builtins cannot be handled lazily by the parser, since we have to know |
689 // if a function uses the special natives syntax, which is something the | 698 // if a function uses the special natives syntax, which is something the |
690 // parser records. | 699 // parser records. |
691 bool allow_lazy = literal->AllowsLazyCompilation() && | 700 bool allow_lazy = literal->AllowsLazyCompilation() && |
692 !LiveEditFunctionTracker::IsActive(info.isolate()); | 701 !LiveEditFunctionTracker::IsActive(info.isolate()); |
693 | 702 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 function_info->set_start_position(lit->start_position()); | 748 function_info->set_start_position(lit->start_position()); |
740 function_info->set_end_position(lit->end_position()); | 749 function_info->set_end_position(lit->end_position()); |
741 function_info->set_is_expression(lit->is_expression()); | 750 function_info->set_is_expression(lit->is_expression()); |
742 function_info->set_is_anonymous(lit->is_anonymous()); | 751 function_info->set_is_anonymous(lit->is_anonymous()); |
743 function_info->set_is_toplevel(is_toplevel); | 752 function_info->set_is_toplevel(is_toplevel); |
744 function_info->set_inferred_name(*lit->inferred_name()); | 753 function_info->set_inferred_name(*lit->inferred_name()); |
745 function_info->SetThisPropertyAssignmentsInfo( | 754 function_info->SetThisPropertyAssignmentsInfo( |
746 lit->has_only_simple_this_property_assignments(), | 755 lit->has_only_simple_this_property_assignments(), |
747 *lit->this_property_assignments()); | 756 *lit->this_property_assignments()); |
748 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 757 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
749 function_info->set_strict_mode(lit->strict_mode()); | 758 function_info->set_strict_mode_flag(lit->strict_mode_flag()); |
750 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 759 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
751 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 760 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
752 } | 761 } |
753 | 762 |
754 | 763 |
755 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 764 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
756 CompilationInfo* info, | 765 CompilationInfo* info, |
757 Handle<SharedFunctionInfo> shared) { | 766 Handle<SharedFunctionInfo> shared) { |
758 // SharedFunctionInfo is passed separately, because if CompilationInfo | 767 // SharedFunctionInfo is passed separately, because if CompilationInfo |
759 // was created using Script object, it will not have it. | 768 // was created using Script object, it will not have it. |
(...skipping 25 matching lines...) Expand all Loading... | |
785 } | 794 } |
786 } | 795 } |
787 | 796 |
788 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 797 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
789 Handle<Script>(info->script()), | 798 Handle<Script>(info->script()), |
790 Handle<Code>(info->code()), | 799 Handle<Code>(info->code()), |
791 info)); | 800 info)); |
792 } | 801 } |
793 | 802 |
794 } } // namespace v8::internal | 803 } } // namespace v8::internal |
OLD | NEW |