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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 | 1143 |
1144 isolate->debug()->OnAfterCompile(script); | 1144 isolate->debug()->OnAfterCompile(script); |
1145 | 1145 |
1146 return result; | 1146 return result; |
1147 } | 1147 } |
1148 | 1148 |
1149 | 1149 |
1150 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1150 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
1151 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1151 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
1152 Handle<Context> context, LanguageMode language_mode, | 1152 Handle<Context> context, LanguageMode language_mode, |
1153 ParseRestriction restriction, int scope_position) { | 1153 ParseRestriction restriction, int line_offset, int column_offset, |
| 1154 Handle<Object> script_name, ScriptOriginOptions options) { |
1154 Isolate* isolate = source->GetIsolate(); | 1155 Isolate* isolate = source->GetIsolate(); |
1155 int source_length = source->length(); | 1156 int source_length = source->length(); |
1156 isolate->counters()->total_eval_size()->Increment(source_length); | 1157 isolate->counters()->total_eval_size()->Increment(source_length); |
1157 isolate->counters()->total_compile_size()->Increment(source_length); | 1158 isolate->counters()->total_compile_size()->Increment(source_length); |
1158 | 1159 |
1159 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1160 CompilationCache* compilation_cache = isolate->compilation_cache(); |
1160 MaybeHandle<SharedFunctionInfo> maybe_shared_info = | 1161 MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
1161 compilation_cache->LookupEval(source, outer_info, context, language_mode, | 1162 compilation_cache->LookupEval(source, outer_info, context, language_mode, |
1162 scope_position); | 1163 line_offset); |
1163 Handle<SharedFunctionInfo> shared_info; | 1164 Handle<SharedFunctionInfo> shared_info; |
1164 | 1165 |
1165 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1166 if (!maybe_shared_info.ToHandle(&shared_info)) { |
1166 Handle<Script> script = isolate->factory()->NewScript(source); | 1167 Handle<Script> script = isolate->factory()->NewScript(source); |
| 1168 if (!script_name.is_null()) { |
| 1169 script->set_name(*script_name); |
| 1170 script->set_line_offset(Smi::FromInt(line_offset)); |
| 1171 script->set_column_offset(Smi::FromInt(column_offset)); |
| 1172 } |
| 1173 script->set_origin_options(options); |
1167 Zone zone; | 1174 Zone zone; |
1168 ParseInfo parse_info(&zone, script); | 1175 ParseInfo parse_info(&zone, script); |
1169 CompilationInfo info(&parse_info); | 1176 CompilationInfo info(&parse_info); |
1170 parse_info.set_eval(); | 1177 parse_info.set_eval(); |
1171 if (context->IsNativeContext()) parse_info.set_global(); | 1178 if (context->IsNativeContext()) parse_info.set_global(); |
1172 parse_info.set_language_mode(language_mode); | 1179 parse_info.set_language_mode(language_mode); |
1173 parse_info.set_parse_restriction(restriction); | 1180 parse_info.set_parse_restriction(restriction); |
1174 parse_info.set_context(context); | 1181 parse_info.set_context(context); |
1175 | 1182 |
1176 Debug::RecordEvalCaller(script); | 1183 Debug::RecordEvalCaller(script); |
1177 | 1184 |
1178 shared_info = CompileToplevel(&info); | 1185 shared_info = CompileToplevel(&info); |
1179 | 1186 |
1180 if (shared_info.is_null()) { | 1187 if (shared_info.is_null()) { |
1181 return MaybeHandle<JSFunction>(); | 1188 return MaybeHandle<JSFunction>(); |
1182 } else { | 1189 } else { |
1183 // Explicitly disable optimization for eval code. We're not yet prepared | 1190 // Explicitly disable optimization for eval code. We're not yet prepared |
1184 // to handle eval-code in the optimizing compiler. | 1191 // to handle eval-code in the optimizing compiler. |
1185 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { | 1192 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { |
1186 shared_info->DisableOptimization(kEval); | 1193 shared_info->DisableOptimization(kEval); |
1187 } | 1194 } |
1188 | 1195 |
1189 // If caller is strict mode, the result must be in strict mode as well. | 1196 // If caller is strict mode, the result must be in strict mode as well. |
1190 DCHECK(is_sloppy(language_mode) || | 1197 DCHECK(is_sloppy(language_mode) || |
1191 is_strict(shared_info->language_mode())); | 1198 is_strict(shared_info->language_mode())); |
1192 compilation_cache->PutEval(source, outer_info, context, shared_info, | 1199 compilation_cache->PutEval(source, outer_info, context, shared_info, |
1193 scope_position); | 1200 line_offset); |
1194 } | 1201 } |
1195 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { | 1202 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { |
1196 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); | 1203 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); |
1197 } | 1204 } |
1198 | 1205 |
1199 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1206 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
1200 shared_info, context, NOT_TENURED); | 1207 shared_info, context, NOT_TENURED); |
1201 } | 1208 } |
1202 | 1209 |
1203 | 1210 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 | 1636 |
1630 | 1637 |
1631 #if DEBUG | 1638 #if DEBUG |
1632 void CompilationInfo::PrintAstForTesting() { | 1639 void CompilationInfo::PrintAstForTesting() { |
1633 PrintF("--- Source from AST ---\n%s\n", | 1640 PrintF("--- Source from AST ---\n%s\n", |
1634 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1641 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1635 } | 1642 } |
1636 #endif | 1643 #endif |
1637 } // namespace internal | 1644 } // namespace internal |
1638 } // namespace v8 | 1645 } // namespace v8 |
OLD | NEW |