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 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 if (!Parser::ParseStatic(info.parse_info())) return; | 1217 if (!Parser::ParseStatic(info.parse_info())) return; |
1218 | 1218 |
1219 LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal()); | 1219 LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal()); |
1220 if (!CompileUnoptimizedCode(&info)) return; | 1220 if (!CompileUnoptimizedCode(&info)) return; |
1221 tracker.RecordRootFunctionInfo(info.code()); | 1221 tracker.RecordRootFunctionInfo(info.code()); |
1222 } | 1222 } |
1223 | 1223 |
1224 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1224 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
1225 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1225 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
1226 Handle<Context> context, LanguageMode language_mode, | 1226 Handle<Context> context, LanguageMode language_mode, |
1227 ParseRestriction restriction, int line_offset, int column_offset, | 1227 ParseRestriction restriction, int eval_scope_position, int eval_position, |
1228 Handle<Object> script_name, ScriptOriginOptions options) { | 1228 int line_offset, int column_offset, Handle<Object> script_name, |
| 1229 ScriptOriginOptions options) { |
1229 Isolate* isolate = source->GetIsolate(); | 1230 Isolate* isolate = source->GetIsolate(); |
1230 int source_length = source->length(); | 1231 int source_length = source->length(); |
1231 isolate->counters()->total_eval_size()->Increment(source_length); | 1232 isolate->counters()->total_eval_size()->Increment(source_length); |
1232 isolate->counters()->total_compile_size()->Increment(source_length); | 1233 isolate->counters()->total_compile_size()->Increment(source_length); |
1233 | 1234 |
1234 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1235 CompilationCache* compilation_cache = isolate->compilation_cache(); |
1235 MaybeHandle<SharedFunctionInfo> maybe_shared_info = | 1236 MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
1236 compilation_cache->LookupEval(source, outer_info, context, language_mode, | 1237 compilation_cache->LookupEval(source, outer_info, context, language_mode, |
1237 line_offset); | 1238 eval_scope_position); |
1238 Handle<SharedFunctionInfo> shared_info; | 1239 Handle<SharedFunctionInfo> shared_info; |
1239 | 1240 |
1240 Handle<Script> script; | 1241 Handle<Script> script; |
1241 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1242 if (!maybe_shared_info.ToHandle(&shared_info)) { |
1242 script = isolate->factory()->NewScript(source); | 1243 script = isolate->factory()->NewScript(source); |
1243 if (!script_name.is_null()) { | 1244 if (!script_name.is_null()) { |
1244 script->set_name(*script_name); | 1245 script->set_name(*script_name); |
1245 script->set_line_offset(line_offset); | 1246 script->set_line_offset(line_offset); |
1246 script->set_column_offset(column_offset); | 1247 script->set_column_offset(column_offset); |
1247 } | 1248 } |
1248 script->set_origin_options(options); | 1249 script->set_origin_options(options); |
| 1250 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 1251 script->set_eval_from_shared(*outer_info); |
| 1252 script->set_eval_from_position(eval_position); |
| 1253 |
1249 Zone zone(isolate->allocator()); | 1254 Zone zone(isolate->allocator()); |
1250 ParseInfo parse_info(&zone, script); | 1255 ParseInfo parse_info(&zone, script); |
1251 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1256 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1252 parse_info.set_eval(); | 1257 parse_info.set_eval(); |
1253 if (context->IsNativeContext()) parse_info.set_global(); | 1258 if (context->IsNativeContext()) parse_info.set_global(); |
1254 parse_info.set_language_mode(language_mode); | 1259 parse_info.set_language_mode(language_mode); |
1255 parse_info.set_parse_restriction(restriction); | 1260 parse_info.set_parse_restriction(restriction); |
1256 parse_info.set_context(context); | 1261 parse_info.set_context(context); |
1257 | 1262 |
1258 Debug::RecordEvalCaller(script); | |
1259 | |
1260 shared_info = CompileToplevel(&info); | 1263 shared_info = CompileToplevel(&info); |
1261 | 1264 |
1262 if (shared_info.is_null()) { | 1265 if (shared_info.is_null()) { |
1263 return MaybeHandle<JSFunction>(); | 1266 return MaybeHandle<JSFunction>(); |
1264 } else { | 1267 } else { |
1265 // Explicitly disable optimization for eval code. We're not yet prepared | 1268 // Explicitly disable optimization for eval code. We're not yet prepared |
1266 // to handle eval-code in the optimizing compiler. | 1269 // to handle eval-code in the optimizing compiler. |
1267 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { | 1270 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { |
1268 shared_info->DisableOptimization(kEval); | 1271 shared_info->DisableOptimization(kEval); |
1269 } | 1272 } |
1270 | 1273 |
1271 // If caller is strict mode, the result must be in strict mode as well. | 1274 // If caller is strict mode, the result must be in strict mode as well. |
1272 DCHECK(is_sloppy(language_mode) || | 1275 DCHECK(is_sloppy(language_mode) || |
1273 is_strict(shared_info->language_mode())); | 1276 is_strict(shared_info->language_mode())); |
1274 compilation_cache->PutEval(source, outer_info, context, shared_info, | 1277 compilation_cache->PutEval(source, outer_info, context, shared_info, |
1275 line_offset); | 1278 eval_scope_position); |
1276 } | 1279 } |
1277 } | 1280 } |
1278 | 1281 |
1279 Handle<JSFunction> result = | 1282 Handle<JSFunction> result = |
1280 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1283 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
1281 shared_info, context, NOT_TENURED); | 1284 shared_info, context, NOT_TENURED); |
1282 | 1285 |
1283 // OnAfterCompile has to be called after we create the JSFunction, which we | 1286 // OnAfterCompile has to be called after we create the JSFunction, which we |
1284 // may require to recompile the eval for debugging, if we find a function | 1287 // may require to recompile the eval for debugging, if we find a function |
1285 // that contains break points in the eval script. | 1288 // that contains break points in the eval script. |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 MaybeHandle<Code> code; | 1684 MaybeHandle<Code> code; |
1682 if (cached.code != nullptr) code = handle(cached.code); | 1685 if (cached.code != nullptr) code = handle(cached.code); |
1683 Handle<Context> native_context(function->context()->native_context()); | 1686 Handle<Context> native_context(function->context()->native_context()); |
1684 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1687 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1685 literals, BailoutId::None()); | 1688 literals, BailoutId::None()); |
1686 } | 1689 } |
1687 } | 1690 } |
1688 | 1691 |
1689 } // namespace internal | 1692 } // namespace internal |
1690 } // namespace v8 | 1693 } // namespace v8 |
OLD | NEW |