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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); | 1178 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); |
1179 } | 1179 } |
1180 | 1180 |
1181 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1181 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
1182 shared_info, context, NOT_TENURED); | 1182 shared_info, context, NOT_TENURED); |
1183 } | 1183 } |
1184 | 1184 |
1185 | 1185 |
1186 Handle<SharedFunctionInfo> Compiler::CompileScript( | 1186 Handle<SharedFunctionInfo> Compiler::CompileScript( |
1187 Handle<String> source, Handle<Object> script_name, int line_offset, | 1187 Handle<String> source, Handle<Object> script_name, int line_offset, |
1188 int column_offset, ScriptOriginOptions resource_options, | 1188 int column_offset, bool is_embedder_debug_script, |
1189 Handle<Object> source_map_url, Handle<Context> context, | 1189 bool is_shared_cross_origin, Handle<Object> source_map_url, |
1190 v8::Extension* extension, ScriptData** cached_data, | 1190 Handle<Context> context, v8::Extension* extension, ScriptData** cached_data, |
1191 ScriptCompiler::CompileOptions compile_options, NativesFlag natives, | 1191 ScriptCompiler::CompileOptions compile_options, NativesFlag natives, |
1192 bool is_module) { | 1192 bool is_module) { |
1193 Isolate* isolate = source->GetIsolate(); | 1193 Isolate* isolate = source->GetIsolate(); |
1194 if (compile_options == ScriptCompiler::kNoCompileOptions) { | 1194 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
1195 cached_data = NULL; | 1195 cached_data = NULL; |
1196 } else if (compile_options == ScriptCompiler::kProduceParserCache || | 1196 } else if (compile_options == ScriptCompiler::kProduceParserCache || |
1197 compile_options == ScriptCompiler::kProduceCodeCache) { | 1197 compile_options == ScriptCompiler::kProduceCodeCache) { |
1198 DCHECK(cached_data && !*cached_data); | 1198 DCHECK(cached_data && !*cached_data); |
1199 DCHECK(extension == NULL); | 1199 DCHECK(extension == NULL); |
1200 DCHECK(!isolate->debug()->is_loaded()); | 1200 DCHECK(!isolate->debug()->is_loaded()); |
(...skipping 14 matching lines...) Expand all Loading... |
1215 construct_language_mode(FLAG_use_strict, use_strong); | 1215 construct_language_mode(FLAG_use_strict, use_strong); |
1216 | 1216 |
1217 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1217 CompilationCache* compilation_cache = isolate->compilation_cache(); |
1218 | 1218 |
1219 // Do a lookup in the compilation cache but not for extensions. | 1219 // Do a lookup in the compilation cache but not for extensions. |
1220 MaybeHandle<SharedFunctionInfo> maybe_result; | 1220 MaybeHandle<SharedFunctionInfo> maybe_result; |
1221 Handle<SharedFunctionInfo> result; | 1221 Handle<SharedFunctionInfo> result; |
1222 if (extension == NULL) { | 1222 if (extension == NULL) { |
1223 // First check per-isolate compilation cache. | 1223 // First check per-isolate compilation cache. |
1224 maybe_result = compilation_cache->LookupScript( | 1224 maybe_result = compilation_cache->LookupScript( |
1225 source, script_name, line_offset, column_offset, resource_options, | 1225 source, script_name, line_offset, column_offset, |
1226 context, language_mode); | 1226 is_embedder_debug_script, is_shared_cross_origin, context, |
| 1227 language_mode); |
1227 if (maybe_result.is_null() && FLAG_serialize_toplevel && | 1228 if (maybe_result.is_null() && FLAG_serialize_toplevel && |
1228 compile_options == ScriptCompiler::kConsumeCodeCache && | 1229 compile_options == ScriptCompiler::kConsumeCodeCache && |
1229 !isolate->debug()->is_loaded()) { | 1230 !isolate->debug()->is_loaded()) { |
1230 // Then check cached code provided by embedder. | 1231 // Then check cached code provided by embedder. |
1231 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); | 1232 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); |
1232 Handle<SharedFunctionInfo> result; | 1233 Handle<SharedFunctionInfo> result; |
1233 if (CodeSerializer::Deserialize(isolate, *cached_data, source) | 1234 if (CodeSerializer::Deserialize(isolate, *cached_data, source) |
1234 .ToHandle(&result)) { | 1235 .ToHandle(&result)) { |
1235 // Promote to per-isolate compilation cache. | 1236 // Promote to per-isolate compilation cache. |
1236 DCHECK(!result->dont_cache()); | 1237 DCHECK(!result->dont_cache()); |
(...skipping 16 matching lines...) Expand all Loading... |
1253 // Create a script object describing the script to be compiled. | 1254 // Create a script object describing the script to be compiled. |
1254 Handle<Script> script = isolate->factory()->NewScript(source); | 1255 Handle<Script> script = isolate->factory()->NewScript(source); |
1255 if (natives == NATIVES_CODE) { | 1256 if (natives == NATIVES_CODE) { |
1256 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 1257 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
1257 } | 1258 } |
1258 if (!script_name.is_null()) { | 1259 if (!script_name.is_null()) { |
1259 script->set_name(*script_name); | 1260 script->set_name(*script_name); |
1260 script->set_line_offset(Smi::FromInt(line_offset)); | 1261 script->set_line_offset(Smi::FromInt(line_offset)); |
1261 script->set_column_offset(Smi::FromInt(column_offset)); | 1262 script->set_column_offset(Smi::FromInt(column_offset)); |
1262 } | 1263 } |
1263 script->set_origin_options(resource_options); | 1264 script->set_is_shared_cross_origin(is_shared_cross_origin); |
| 1265 script->set_is_embedder_debug_script(is_embedder_debug_script); |
1264 if (!source_map_url.is_null()) { | 1266 if (!source_map_url.is_null()) { |
1265 script->set_source_mapping_url(*source_map_url); | 1267 script->set_source_mapping_url(*source_map_url); |
1266 } | 1268 } |
1267 | 1269 |
1268 // Compile the function and add it to the cache. | 1270 // Compile the function and add it to the cache. |
1269 Zone zone; | 1271 Zone zone; |
1270 ParseInfo parse_info(&zone, script); | 1272 ParseInfo parse_info(&zone, script); |
1271 CompilationInfo info(&parse_info); | 1273 CompilationInfo info(&parse_info); |
1272 if (FLAG_harmony_modules && is_module) { | 1274 if (FLAG_harmony_modules && is_module) { |
1273 parse_info.set_module(); | 1275 parse_info.set_module(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 } | 1566 } |
1565 | 1567 |
1566 | 1568 |
1567 #if DEBUG | 1569 #if DEBUG |
1568 void CompilationInfo::PrintAstForTesting() { | 1570 void CompilationInfo::PrintAstForTesting() { |
1569 PrintF("--- Source from AST ---\n%s\n", | 1571 PrintF("--- Source from AST ---\n%s\n", |
1570 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1572 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1571 } | 1573 } |
1572 #endif | 1574 #endif |
1573 } } // namespace v8::internal | 1575 } } // namespace v8::internal |
OLD | NEW |