| 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/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) | 928 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) |
| 929 .ToHandle(&opt_code)) { | 929 .ToHandle(&opt_code)) { |
| 930 result = opt_code; | 930 result = opt_code; |
| 931 } | 931 } |
| 932 } | 932 } |
| 933 | 933 |
| 934 return result; | 934 return result; |
| 935 } | 935 } |
| 936 | 936 |
| 937 | 937 |
| 938 bool CompileEvalForDebugging(Handle<JSFunction> function, | |
| 939 Handle<SharedFunctionInfo> shared) { | |
| 940 Handle<Script> script(Script::cast(shared->script())); | |
| 941 Handle<Context> context(function->context()); | |
| 942 | |
| 943 Zone zone(function->GetIsolate()->allocator()); | |
| 944 ParseInfo parse_info(&zone, script); | |
| 945 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | |
| 946 Isolate* isolate = info.isolate(); | |
| 947 | |
| 948 parse_info.set_eval(); | |
| 949 parse_info.set_context(context); | |
| 950 if (context->IsNativeContext()) parse_info.set_global(); | |
| 951 parse_info.set_toplevel(); | |
| 952 parse_info.set_allow_lazy_parsing(false); | |
| 953 parse_info.set_language_mode(shared->language_mode()); | |
| 954 parse_info.set_parse_restriction(NO_PARSE_RESTRICTION); | |
| 955 info.MarkAsDebug(); | |
| 956 | |
| 957 VMState<COMPILER> state(info.isolate()); | |
| 958 | |
| 959 if (!Parser::ParseStatic(&parse_info)) { | |
| 960 isolate->clear_pending_exception(); | |
| 961 return false; | |
| 962 } | |
| 963 | |
| 964 FunctionLiteral* lit = parse_info.literal(); | |
| 965 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | |
| 966 | |
| 967 if (!CompileUnoptimizedCode(&info)) { | |
| 968 isolate->clear_pending_exception(); | |
| 969 return false; | |
| 970 } | |
| 971 shared->ReplaceCode(*info.code()); | |
| 972 return true; | |
| 973 } | |
| 974 | |
| 975 | |
| 976 bool CompileForDebugging(CompilationInfo* info) { | 938 bool CompileForDebugging(CompilationInfo* info) { |
| 977 info->MarkAsDebug(); | 939 info->MarkAsDebug(); |
| 978 if (GetUnoptimizedCode(info).is_null()) { | 940 if (GetUnoptimizedCode(info).is_null()) { |
| 979 info->isolate()->clear_pending_exception(); | 941 info->isolate()->clear_pending_exception(); |
| 980 return false; | 942 return false; |
| 981 } | 943 } |
| 982 return true; | 944 return true; |
| 983 } | 945 } |
| 984 | 946 |
| 985 inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { | 947 inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 function->code()->kind() == Code::OPTIMIZED_FUNCTION || | 1141 function->code()->kind() == Code::OPTIMIZED_FUNCTION || |
| 1180 (function->code()->is_interpreter_entry_trampoline() && | 1142 (function->code()->is_interpreter_entry_trampoline() && |
| 1181 function->shared()->HasBytecodeArray()) || | 1143 function->shared()->HasBytecodeArray()) || |
| 1182 function->IsInOptimizationQueue()); | 1144 function->IsInOptimizationQueue()); |
| 1183 return true; | 1145 return true; |
| 1184 } | 1146 } |
| 1185 | 1147 |
| 1186 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { | 1148 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { |
| 1187 Handle<SharedFunctionInfo> shared(function->shared()); | 1149 Handle<SharedFunctionInfo> shared(function->shared()); |
| 1188 if (IsEvalToplevel(shared)) { | 1150 if (IsEvalToplevel(shared)) { |
| 1189 return CompileEvalForDebugging(function, shared); | 1151 Handle<Script> script(Script::cast(shared->script())); |
| 1152 Handle<Context> context(function->context()); |
| 1153 |
| 1154 Zone zone(function->GetIsolate()->allocator()); |
| 1155 ParseInfo parse_info(&zone, script); |
| 1156 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1157 |
| 1158 parse_info.set_eval(); |
| 1159 parse_info.set_context(context); |
| 1160 parse_info.set_shared_info(shared); |
| 1161 if (context->IsNativeContext()) parse_info.set_global(); |
| 1162 parse_info.set_toplevel(); |
| 1163 parse_info.set_allow_lazy_parsing(false); |
| 1164 parse_info.set_language_mode(shared->language_mode()); |
| 1165 parse_info.set_parse_restriction(NO_PARSE_RESTRICTION); |
| 1166 return CompileForDebugging(&info); |
| 1190 } else { | 1167 } else { |
| 1191 CompilationInfoWithZone info(function); | 1168 CompilationInfoWithZone info(function); |
| 1192 return CompileForDebugging(&info); | 1169 return CompileForDebugging(&info); |
| 1193 } | 1170 } |
| 1194 } | 1171 } |
| 1195 | 1172 |
| 1196 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { | 1173 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { |
| 1197 DCHECK(shared->allows_lazy_compilation_without_context()); | 1174 DCHECK(shared->allows_lazy_compilation_without_context()); |
| 1198 DCHECK(!IsEvalToplevel(shared)); | 1175 DCHECK(!IsEvalToplevel(shared)); |
| 1199 Zone zone(shared->GetIsolate()->allocator()); | 1176 Zone zone(shared->GetIsolate()->allocator()); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 MaybeHandle<Code> code; | 1691 MaybeHandle<Code> code; |
| 1715 if (cached.code != nullptr) code = handle(cached.code); | 1692 if (cached.code != nullptr) code = handle(cached.code); |
| 1716 Handle<Context> native_context(function->context()->native_context()); | 1693 Handle<Context> native_context(function->context()->native_context()); |
| 1717 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1694 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1718 literals, BailoutId::None()); | 1695 literals, BailoutId::None()); |
| 1719 } | 1696 } |
| 1720 } | 1697 } |
| 1721 | 1698 |
| 1722 } // namespace internal | 1699 } // namespace internal |
| 1723 } // namespace v8 | 1700 } // namespace v8 |
| OLD | NEW |