| 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/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 bool CompileForDebugging(CompilationInfo* info) { | 1009 bool CompileForDebugging(CompilationInfo* info) { |
| 1010 info->MarkAsDebug(); | 1010 info->MarkAsDebug(); |
| 1011 if (GetUnoptimizedCodeCommon(info).is_null()) { | 1011 if (GetUnoptimizedCodeCommon(info).is_null()) { |
| 1012 info->isolate()->clear_pending_exception(); | 1012 info->isolate()->clear_pending_exception(); |
| 1013 return false; | 1013 return false; |
| 1014 } | 1014 } |
| 1015 return true; | 1015 return true; |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 | 1018 |
| 1019 static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { |
| 1020 return shared->is_toplevel() && shared->script()->IsScript() && |
| 1021 Script::cast(shared->script())->compilation_type() == |
| 1022 Script::COMPILATION_TYPE_EVAL; |
| 1023 } |
| 1024 |
| 1025 |
| 1019 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { | 1026 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { |
| 1020 Handle<SharedFunctionInfo> shared(function->shared()); | 1027 Handle<SharedFunctionInfo> shared(function->shared()); |
| 1021 if (shared->is_toplevel() && shared->script()->IsScript() && | 1028 if (IsEvalToplevel(shared)) { |
| 1022 Script::cast(shared->script())->compilation_type() == | |
| 1023 Script::COMPILATION_TYPE_EVAL) { | |
| 1024 return CompileEvalForDebugging(function, shared); | 1029 return CompileEvalForDebugging(function, shared); |
| 1025 } else { | 1030 } else { |
| 1026 CompilationInfoWithZone info(function); | 1031 CompilationInfoWithZone info(function); |
| 1027 return CompileForDebugging(&info); | 1032 return CompileForDebugging(&info); |
| 1028 } | 1033 } |
| 1029 } | 1034 } |
| 1030 | 1035 |
| 1031 | 1036 |
| 1032 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { | 1037 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { |
| 1033 DCHECK(shared->allows_lazy_compilation_without_context()); | 1038 DCHECK(shared->allows_lazy_compilation_without_context()); |
| 1039 DCHECK(!IsEvalToplevel(shared)); |
| 1034 Zone zone; | 1040 Zone zone; |
| 1035 ParseInfo parse_info(&zone, shared); | 1041 ParseInfo parse_info(&zone, shared); |
| 1036 CompilationInfo info(&parse_info); | 1042 CompilationInfo info(&parse_info); |
| 1037 return CompileForDebugging(&info); | 1043 return CompileForDebugging(&info); |
| 1038 } | 1044 } |
| 1039 | 1045 |
| 1040 | 1046 |
| 1041 void Compiler::CompileForLiveEdit(Handle<Script> script) { | 1047 void Compiler::CompileForLiveEdit(Handle<Script> script) { |
| 1042 // TODO(635): support extensions. | 1048 // TODO(635): support extensions. |
| 1043 Zone zone; | 1049 Zone zone; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 result = isolate->factory()->NewSharedFunctionInfo( | 1140 result = isolate->factory()->NewSharedFunctionInfo( |
| 1135 lit->name(), lit->materialized_literal_count(), lit->kind(), | 1141 lit->name(), lit->materialized_literal_count(), lit->kind(), |
| 1136 info->code(), | 1142 info->code(), |
| 1137 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), | 1143 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), |
| 1138 info->feedback_vector()); | 1144 info->feedback_vector()); |
| 1139 | 1145 |
| 1140 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 1146 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 1141 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); | 1147 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); |
| 1142 SharedFunctionInfo::SetScript(result, script); | 1148 SharedFunctionInfo::SetScript(result, script); |
| 1143 result->set_is_toplevel(true); | 1149 result->set_is_toplevel(true); |
| 1150 if (info->is_eval()) { |
| 1151 // Eval scripts cannot be (re-)compiled without context. |
| 1152 result->set_allows_lazy_compilation_without_context(false); |
| 1153 } |
| 1144 | 1154 |
| 1145 Handle<String> script_name = script->name()->IsString() | 1155 Handle<String> script_name = script->name()->IsString() |
| 1146 ? Handle<String>(String::cast(script->name())) | 1156 ? Handle<String>(String::cast(script->name())) |
| 1147 : isolate->factory()->empty_string(); | 1157 : isolate->factory()->empty_string(); |
| 1148 Logger::LogEventsAndTags log_tag = info->is_eval() | 1158 Logger::LogEventsAndTags log_tag = info->is_eval() |
| 1149 ? Logger::EVAL_TAG | 1159 ? Logger::EVAL_TAG |
| 1150 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1160 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
| 1151 | 1161 |
| 1152 PROFILE(isolate, CodeCreateEvent( | 1162 PROFILE(isolate, CodeCreateEvent( |
| 1153 log_tag, *info->code(), *result, info, *script_name)); | 1163 log_tag, *info->code(), *result, info, *script_name)); |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 | 1683 |
| 1674 | 1684 |
| 1675 #if DEBUG | 1685 #if DEBUG |
| 1676 void CompilationInfo::PrintAstForTesting() { | 1686 void CompilationInfo::PrintAstForTesting() { |
| 1677 PrintF("--- Source from AST ---\n%s\n", | 1687 PrintF("--- Source from AST ---\n%s\n", |
| 1678 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1688 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1679 } | 1689 } |
| 1680 #endif | 1690 #endif |
| 1681 } // namespace internal | 1691 } // namespace internal |
| 1682 } // namespace v8 | 1692 } // namespace v8 |
| OLD | NEW |