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, bool is_embedder_debug_script, | 1188 int column_offset, ScriptOriginOptions resource_options, |
1189 bool is_shared_cross_origin, Handle<Object> source_map_url, | 1189 Handle<Object> source_map_url, Handle<Context> context, |
1190 Handle<Context> context, v8::Extension* extension, ScriptData** cached_data, | 1190 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, | 1225 source, script_name, line_offset, column_offset, resource_options, |
1226 is_embedder_debug_script, is_shared_cross_origin, context, | 1226 context, language_mode); |
1227 language_mode); | |
1228 if (maybe_result.is_null() && FLAG_serialize_toplevel && | 1227 if (maybe_result.is_null() && FLAG_serialize_toplevel && |
1229 compile_options == ScriptCompiler::kConsumeCodeCache && | 1228 compile_options == ScriptCompiler::kConsumeCodeCache && |
1230 !isolate->debug()->is_loaded()) { | 1229 !isolate->debug()->is_loaded()) { |
1231 // Then check cached code provided by embedder. | 1230 // Then check cached code provided by embedder. |
1232 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); | 1231 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); |
1233 Handle<SharedFunctionInfo> result; | 1232 Handle<SharedFunctionInfo> result; |
1234 if (CodeSerializer::Deserialize(isolate, *cached_data, source) | 1233 if (CodeSerializer::Deserialize(isolate, *cached_data, source) |
1235 .ToHandle(&result)) { | 1234 .ToHandle(&result)) { |
1236 // Promote to per-isolate compilation cache. | 1235 // Promote to per-isolate compilation cache. |
1237 DCHECK(!result->dont_cache()); | 1236 DCHECK(!result->dont_cache()); |
(...skipping 16 matching lines...) Expand all Loading... |
1254 // Create a script object describing the script to be compiled. | 1253 // Create a script object describing the script to be compiled. |
1255 Handle<Script> script = isolate->factory()->NewScript(source); | 1254 Handle<Script> script = isolate->factory()->NewScript(source); |
1256 if (natives == NATIVES_CODE) { | 1255 if (natives == NATIVES_CODE) { |
1257 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 1256 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
1258 } | 1257 } |
1259 if (!script_name.is_null()) { | 1258 if (!script_name.is_null()) { |
1260 script->set_name(*script_name); | 1259 script->set_name(*script_name); |
1261 script->set_line_offset(Smi::FromInt(line_offset)); | 1260 script->set_line_offset(Smi::FromInt(line_offset)); |
1262 script->set_column_offset(Smi::FromInt(column_offset)); | 1261 script->set_column_offset(Smi::FromInt(column_offset)); |
1263 } | 1262 } |
1264 script->set_is_shared_cross_origin(is_shared_cross_origin); | 1263 script->set_is_embedder_debug_script( |
1265 script->set_is_embedder_debug_script(is_embedder_debug_script); | 1264 resource_options.IsEmbedderDebugScript()); |
| 1265 script->set_is_shared_cross_origin(resource_options.IsSharedCrossOrigin()); |
| 1266 script->set_is_opaque(resource_options.IsOpaque()); |
1266 if (!source_map_url.is_null()) { | 1267 if (!source_map_url.is_null()) { |
1267 script->set_source_mapping_url(*source_map_url); | 1268 script->set_source_mapping_url(*source_map_url); |
1268 } | 1269 } |
1269 | 1270 |
1270 // Compile the function and add it to the cache. | 1271 // Compile the function and add it to the cache. |
1271 Zone zone; | 1272 Zone zone; |
1272 ParseInfo parse_info(&zone, script); | 1273 ParseInfo parse_info(&zone, script); |
1273 CompilationInfo info(&parse_info); | 1274 CompilationInfo info(&parse_info); |
1274 if (FLAG_harmony_modules && is_module) { | 1275 if (FLAG_harmony_modules && is_module) { |
1275 parse_info.set_module(); | 1276 parse_info.set_module(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 } | 1567 } |
1567 | 1568 |
1568 | 1569 |
1569 #if DEBUG | 1570 #if DEBUG |
1570 void CompilationInfo::PrintAstForTesting() { | 1571 void CompilationInfo::PrintAstForTesting() { |
1571 PrintF("--- Source from AST ---\n%s\n", | 1572 PrintF("--- Source from AST ---\n%s\n", |
1572 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1573 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1573 } | 1574 } |
1574 #endif | 1575 #endif |
1575 } } // namespace v8::internal | 1576 } } // namespace v8::internal |
OLD | NEW |