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 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); | 569 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
570 compilation_cache->PutEval(source, context, is_global, result); | 570 compilation_cache->PutEval(source, context, is_global, result); |
571 } | 571 } |
(...skipping 18 matching lines...) Expand all Loading... | |
590 isolate->counters()->total_compile_size()->Increment(compiled_size); | 590 isolate->counters()->total_compile_size()->Increment(compiled_size); |
591 | 591 |
592 // Generate the AST for the lazily compiled function. | 592 // Generate the AST for the lazily compiled function. |
593 if (ParserApi::Parse(info)) { | 593 if (ParserApi::Parse(info)) { |
594 // Measure how long it takes to do the lazy compilation; only take the | 594 // 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 | 595 // rest of the function into account to avoid overlap with the lazy |
596 // parsing statistics. | 596 // parsing statistics. |
597 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 597 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
598 | 598 |
599 // After parsing we know function's strict mode. Remember it. | 599 // After parsing we know function's strict mode. Remember it. |
600 if (info->function()->strict_mode()) { | 600 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); |
601 shared->set_strict_mode(true); | 601 info->SetStrictModeFlag(strict_mode); |
602 info->MarkAsStrictMode(); | 602 shared->set_strict_mode_flag(strict_mode); |
Yang
2011/10/20 14:18:59
This is not quite equivalent, I guess. The old ver
Steven
2011/10/21 13:59:00
Testing again if the parsed function literal is in
| |
603 } | |
604 | 603 |
605 // Compile the code. | 604 // Compile the code. |
606 if (!MakeCode(info)) { | 605 if (!MakeCode(info)) { |
607 if (!isolate->has_pending_exception()) { | 606 if (!isolate->has_pending_exception()) { |
608 isolate->StackOverflow(); | 607 isolate->StackOverflow(); |
609 } | 608 } |
610 } else { | 609 } else { |
611 ASSERT(!info->code().is_null()); | 610 ASSERT(!info->code().is_null()); |
612 Handle<Code> code = info->code(); | 611 Handle<Code> code = info->code(); |
613 // Set optimizable to false if this is disallowed by the shared | 612 // Set optimizable to false if this is disallowed by the shared |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 return false; | 672 return false; |
674 } | 673 } |
675 | 674 |
676 | 675 |
677 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 676 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
678 Handle<Script> script) { | 677 Handle<Script> script) { |
679 // Precondition: code has been parsed and scopes have been analyzed. | 678 // Precondition: code has been parsed and scopes have been analyzed. |
680 CompilationInfo info(script); | 679 CompilationInfo info(script); |
681 info.SetFunction(literal); | 680 info.SetFunction(literal); |
682 info.SetScope(literal->scope()); | 681 info.SetScope(literal->scope()); |
683 if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode(); | 682 info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); |
684 | 683 |
685 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 684 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
686 // Determine if the function can be lazily compiled. This is necessary to | 685 // 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 | 686 // 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 | 687 // 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 | 688 // if a function uses the special natives syntax, which is something the |
690 // parser records. | 689 // parser records. |
691 bool allow_lazy = literal->AllowsLazyCompilation() && | 690 bool allow_lazy = literal->AllowsLazyCompilation() && |
692 !LiveEditFunctionTracker::IsActive(info.isolate()); | 691 !LiveEditFunctionTracker::IsActive(info.isolate()); |
693 | 692 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 function_info->set_start_position(lit->start_position()); | 738 function_info->set_start_position(lit->start_position()); |
740 function_info->set_end_position(lit->end_position()); | 739 function_info->set_end_position(lit->end_position()); |
741 function_info->set_is_expression(lit->is_expression()); | 740 function_info->set_is_expression(lit->is_expression()); |
742 function_info->set_is_anonymous(lit->is_anonymous()); | 741 function_info->set_is_anonymous(lit->is_anonymous()); |
743 function_info->set_is_toplevel(is_toplevel); | 742 function_info->set_is_toplevel(is_toplevel); |
744 function_info->set_inferred_name(*lit->inferred_name()); | 743 function_info->set_inferred_name(*lit->inferred_name()); |
745 function_info->SetThisPropertyAssignmentsInfo( | 744 function_info->SetThisPropertyAssignmentsInfo( |
746 lit->has_only_simple_this_property_assignments(), | 745 lit->has_only_simple_this_property_assignments(), |
747 *lit->this_property_assignments()); | 746 *lit->this_property_assignments()); |
748 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 747 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
749 function_info->set_strict_mode(lit->strict_mode()); | 748 function_info->set_strict_mode_flag(lit->strict_mode_flag()); |
750 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 749 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
751 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 750 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
752 } | 751 } |
753 | 752 |
754 | 753 |
755 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 754 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
756 CompilationInfo* info, | 755 CompilationInfo* info, |
757 Handle<SharedFunctionInfo> shared) { | 756 Handle<SharedFunctionInfo> shared) { |
758 // SharedFunctionInfo is passed separately, because if CompilationInfo | 757 // SharedFunctionInfo is passed separately, because if CompilationInfo |
759 // was created using Script object, it will not have it. | 758 // was created using Script object, it will not have it. |
(...skipping 25 matching lines...) Expand all Loading... | |
785 } | 784 } |
786 } | 785 } |
787 | 786 |
788 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 787 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
789 Handle<Script>(info->script()), | 788 Handle<Script>(info->script()), |
790 Handle<Code>(info->code()), | 789 Handle<Code>(info->code()), |
791 info)); | 790 info)); |
792 } | 791 } |
793 | 792 |
794 } } // namespace v8::internal | 793 } } // namespace v8::internal |
OLD | NEW |