OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 if (result.is_null()) Top::ReportPendingMessages(); | 544 if (result.is_null()) Top::ReportPendingMessages(); |
545 return result; | 545 return result; |
546 } | 546 } |
547 | 547 |
548 | 548 |
549 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, | 549 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
550 Handle<Context> context, | 550 Handle<Context> context, |
551 bool is_global) { | 551 bool is_global, |
| 552 StrictModeFlag strict_mode) { |
552 int source_length = source->length(); | 553 int source_length = source->length(); |
553 Counters::total_eval_size.Increment(source_length); | 554 Counters::total_eval_size.Increment(source_length); |
554 Counters::total_compile_size.Increment(source_length); | 555 Counters::total_compile_size.Increment(source_length); |
555 | 556 |
556 // The VM is in the COMPILER state until exiting this function. | 557 // The VM is in the COMPILER state until exiting this function. |
557 VMState state(COMPILER); | 558 VMState state(COMPILER); |
558 | 559 |
559 // Do a lookup in the compilation cache; if the entry is not there, invoke | 560 // Do a lookup in the compilation cache; if the entry is not there, invoke |
560 // the compiler and add the result to the cache. | 561 // the compiler and add the result to the cache. |
561 Handle<SharedFunctionInfo> result; | 562 Handle<SharedFunctionInfo> result; |
562 result = CompilationCache::LookupEval(source, context, is_global); | 563 result = CompilationCache::LookupEval(source, |
| 564 context, |
| 565 is_global, |
| 566 strict_mode); |
563 | 567 |
564 if (result.is_null()) { | 568 if (result.is_null()) { |
565 // Create a script object describing the script to be compiled. | 569 // Create a script object describing the script to be compiled. |
566 Handle<Script> script = Factory::NewScript(source); | 570 Handle<Script> script = Factory::NewScript(source); |
567 CompilationInfo info(script); | 571 CompilationInfo info(script); |
568 info.MarkAsEval(); | 572 info.MarkAsEval(); |
569 if (is_global) info.MarkAsGlobal(); | 573 if (is_global) info.MarkAsGlobal(); |
| 574 if (strict_mode == kStrictMode) info.MarkAsStrict(); |
570 info.SetCallingContext(context); | 575 info.SetCallingContext(context); |
571 result = MakeFunctionInfo(&info); | 576 result = MakeFunctionInfo(&info); |
572 if (!result.is_null()) { | 577 if (!result.is_null()) { |
| 578 // If caller is strict mode, the result must be strict as well, |
| 579 // but not the other way around. Consider: |
| 580 // eval("'use strict'; ..."); |
| 581 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
573 CompilationCache::PutEval(source, context, is_global, result); | 582 CompilationCache::PutEval(source, context, is_global, result); |
574 } | 583 } |
575 } | 584 } |
576 | 585 |
577 return result; | 586 return result; |
578 } | 587 } |
579 | 588 |
580 | 589 |
581 bool Compiler::CompileLazy(CompilationInfo* info) { | 590 bool Compiler::CompileLazy(CompilationInfo* info) { |
582 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 591 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 function_info->set_start_position(lit->start_position()); | 764 function_info->set_start_position(lit->start_position()); |
756 function_info->set_end_position(lit->end_position()); | 765 function_info->set_end_position(lit->end_position()); |
757 function_info->set_is_expression(lit->is_expression()); | 766 function_info->set_is_expression(lit->is_expression()); |
758 function_info->set_is_toplevel(is_toplevel); | 767 function_info->set_is_toplevel(is_toplevel); |
759 function_info->set_inferred_name(*lit->inferred_name()); | 768 function_info->set_inferred_name(*lit->inferred_name()); |
760 function_info->SetThisPropertyAssignmentsInfo( | 769 function_info->SetThisPropertyAssignmentsInfo( |
761 lit->has_only_simple_this_property_assignments(), | 770 lit->has_only_simple_this_property_assignments(), |
762 *lit->this_property_assignments()); | 771 *lit->this_property_assignments()); |
763 function_info->set_try_full_codegen(lit->try_full_codegen()); | 772 function_info->set_try_full_codegen(lit->try_full_codegen()); |
764 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 773 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| 774 function_info->set_strict_mode(lit->strict_mode()); |
765 } | 775 } |
766 | 776 |
767 | 777 |
768 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 778 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
769 Handle<String> name, | 779 Handle<String> name, |
770 int start_position, | 780 int start_position, |
771 CompilationInfo* info) { | 781 CompilationInfo* info) { |
772 // Log the code generation. If source information is available include | 782 // Log the code generation. If source information is available include |
773 // script name and line number. Check explicitly whether logging is | 783 // script name and line number. Check explicitly whether logging is |
774 // enabled as finding the line number is not free. | 784 // enabled as finding the line number is not free. |
(...skipping 24 matching lines...) Expand all Loading... |
799 code->instruction_size())); | 809 code->instruction_size())); |
800 } | 810 } |
801 } | 811 } |
802 | 812 |
803 GDBJIT(AddCode(name, | 813 GDBJIT(AddCode(name, |
804 Handle<Script>(info->script()), | 814 Handle<Script>(info->script()), |
805 Handle<Code>(info->code()))); | 815 Handle<Code>(info->code()))); |
806 } | 816 } |
807 | 817 |
808 } } // namespace v8::internal | 818 } } // namespace v8::internal |
OLD | NEW |