OLD | NEW |
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/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 Handle<Script> script = info->script(); | 905 Handle<Script> script = info->script(); |
906 | 906 |
907 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 907 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
908 FixedArray* array = isolate->native_context()->embedder_data(); | 908 FixedArray* array = isolate->native_context()->embedder_data(); |
909 script->set_context_data(array->get(0)); | 909 script->set_context_data(array->get(0)); |
910 | 910 |
911 isolate->debug()->OnBeforeCompile(script); | 911 isolate->debug()->OnBeforeCompile(script); |
912 | 912 |
913 DCHECK(info->is_eval() || info->is_global()); | 913 DCHECK(info->is_eval() || info->is_global()); |
914 | 914 |
| 915 info->MarkAsToplevel(); |
| 916 |
915 Handle<SharedFunctionInfo> result; | 917 Handle<SharedFunctionInfo> result; |
916 | 918 |
917 { VMState<COMPILER> state(info->isolate()); | 919 { VMState<COMPILER> state(info->isolate()); |
918 if (info->function() == NULL) { | 920 if (info->function() == NULL) { |
919 // Parse the script if needed (if it's already parsed, function() is | 921 // Parse the script if needed (if it's already parsed, function() is |
920 // non-NULL). | 922 // non-NULL). |
921 bool parse_allow_lazy = | 923 bool parse_allow_lazy = |
922 (info->compile_options() == ScriptCompiler::kConsumeParserCache || | 924 (info->compile_options() == ScriptCompiler::kConsumeParserCache || |
923 String::cast(script->source())->length() > | 925 String::cast(script->source())->length() > |
924 FLAG_min_preparse_length) && | 926 FLAG_min_preparse_length) && |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 // if a function uses the special natives syntax, which is something the | 1173 // if a function uses the special natives syntax, which is something the |
1172 // parser records. | 1174 // parser records. |
1173 // If the debugger requests compilation for break points, we cannot be | 1175 // If the debugger requests compilation for break points, we cannot be |
1174 // aggressive about lazy compilation, because it might trigger compilation | 1176 // aggressive about lazy compilation, because it might trigger compilation |
1175 // of functions without an outer context when setting a breakpoint through | 1177 // of functions without an outer context when setting a breakpoint through |
1176 // Debug::FindSharedFunctionInfoInScript. | 1178 // Debug::FindSharedFunctionInfoInScript. |
1177 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1179 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
1178 bool allow_lazy = literal->AllowsLazyCompilation() && | 1180 bool allow_lazy = literal->AllowsLazyCompilation() && |
1179 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); | 1181 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); |
1180 | 1182 |
| 1183 |
| 1184 if (outer_info->is_toplevel() && outer_info->will_serialize()) { |
| 1185 // Make sure that if the toplevel code (possibly to be serialized), |
| 1186 // the inner unction must be allowed to be compiled lazily. |
| 1187 DCHECK(allow_lazy); |
| 1188 } |
| 1189 |
1181 // Generate code | 1190 // Generate code |
1182 Handle<ScopeInfo> scope_info; | 1191 Handle<ScopeInfo> scope_info; |
1183 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1192 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
1184 Handle<Code> code = isolate->builtins()->CompileLazy(); | 1193 Handle<Code> code = isolate->builtins()->CompileLazy(); |
1185 info.SetCode(code); | 1194 info.SetCode(code); |
1186 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1195 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
1187 } else if (FullCodeGenerator::MakeCode(&info)) { | 1196 } else if (FullCodeGenerator::MakeCode(&info)) { |
1188 DCHECK(!info.code().is_null()); | 1197 DCHECK(!info.code().is_null()); |
1189 scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 1198 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
1190 } else { | 1199 } else { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 AllowHandleDereference allow_deref; | 1460 AllowHandleDereference allow_deref; |
1452 bool tracing_on = info()->IsStub() | 1461 bool tracing_on = info()->IsStub() |
1453 ? FLAG_trace_hydrogen_stubs | 1462 ? FLAG_trace_hydrogen_stubs |
1454 : (FLAG_trace_hydrogen && | 1463 : (FLAG_trace_hydrogen && |
1455 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1464 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1456 return (tracing_on && | 1465 return (tracing_on && |
1457 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1466 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1458 } | 1467 } |
1459 | 1468 |
1460 } } // namespace v8::internal | 1469 } } // namespace v8::internal |
OLD | NEW |