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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 Handle<ScopeInfo> scope_info = | 1502 Handle<ScopeInfo> scope_info = |
1503 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1503 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1504 info.shared_info()->set_scope_info(*scope_info); | 1504 info.shared_info()->set_scope_info(*scope_info); |
1505 } | 1505 } |
1506 tracker.RecordRootFunctionInfo(info.code()); | 1506 tracker.RecordRootFunctionInfo(info.code()); |
1507 } | 1507 } |
1508 | 1508 |
1509 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1509 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
1510 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1510 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
1511 Handle<Context> context, LanguageMode language_mode, | 1511 Handle<Context> context, LanguageMode language_mode, |
1512 ParseRestriction restriction, int line_offset, int column_offset, | 1512 ParseRestriction restriction, int eval_position, int line_offset, |
1513 Handle<Object> script_name, ScriptOriginOptions options) { | 1513 int column_offset, Handle<Object> script_name, |
| 1514 ScriptOriginOptions options) { |
1514 Isolate* isolate = source->GetIsolate(); | 1515 Isolate* isolate = source->GetIsolate(); |
1515 int source_length = source->length(); | 1516 int source_length = source->length(); |
1516 isolate->counters()->total_eval_size()->Increment(source_length); | 1517 isolate->counters()->total_eval_size()->Increment(source_length); |
1517 isolate->counters()->total_compile_size()->Increment(source_length); | 1518 isolate->counters()->total_compile_size()->Increment(source_length); |
1518 | 1519 |
1519 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1520 CompilationCache* compilation_cache = isolate->compilation_cache(); |
1520 MaybeHandle<SharedFunctionInfo> maybe_shared_info = | 1521 MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
1521 compilation_cache->LookupEval(source, outer_info, context, language_mode, | 1522 compilation_cache->LookupEval(source, outer_info, context, language_mode, |
1522 line_offset); | 1523 eval_position); |
1523 Handle<SharedFunctionInfo> shared_info; | 1524 Handle<SharedFunctionInfo> shared_info; |
1524 | 1525 |
1525 Handle<Script> script; | 1526 Handle<Script> script; |
1526 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1527 if (!maybe_shared_info.ToHandle(&shared_info)) { |
1527 script = isolate->factory()->NewScript(source); | 1528 script = isolate->factory()->NewScript(source); |
1528 if (!script_name.is_null()) { | 1529 if (!script_name.is_null()) { |
1529 script->set_name(*script_name); | 1530 script->set_name(*script_name); |
1530 script->set_line_offset(line_offset); | 1531 script->set_line_offset(line_offset); |
1531 script->set_column_offset(column_offset); | 1532 script->set_column_offset(column_offset); |
1532 } | 1533 } |
1533 script->set_origin_options(options); | 1534 script->set_origin_options(options); |
| 1535 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 1536 script->set_eval_from_shared(*outer_info); |
| 1537 script->set_eval_from_position(eval_position); |
| 1538 |
1534 Zone zone(isolate->allocator()); | 1539 Zone zone(isolate->allocator()); |
1535 ParseInfo parse_info(&zone, script); | 1540 ParseInfo parse_info(&zone, script); |
1536 CompilationInfo info(&parse_info); | 1541 CompilationInfo info(&parse_info); |
1537 parse_info.set_eval(); | 1542 parse_info.set_eval(); |
1538 if (context->IsNativeContext()) parse_info.set_global(); | 1543 if (context->IsNativeContext()) parse_info.set_global(); |
1539 parse_info.set_language_mode(language_mode); | 1544 parse_info.set_language_mode(language_mode); |
1540 parse_info.set_parse_restriction(restriction); | 1545 parse_info.set_parse_restriction(restriction); |
1541 parse_info.set_context(context); | 1546 parse_info.set_context(context); |
1542 | 1547 |
1543 Debug::RecordEvalCaller(script); | |
1544 | |
1545 shared_info = CompileToplevel(&info); | 1548 shared_info = CompileToplevel(&info); |
1546 | 1549 |
1547 if (shared_info.is_null()) { | 1550 if (shared_info.is_null()) { |
1548 return MaybeHandle<JSFunction>(); | 1551 return MaybeHandle<JSFunction>(); |
1549 } else { | 1552 } else { |
1550 // Explicitly disable optimization for eval code. We're not yet prepared | 1553 // Explicitly disable optimization for eval code. We're not yet prepared |
1551 // to handle eval-code in the optimizing compiler. | 1554 // to handle eval-code in the optimizing compiler. |
1552 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { | 1555 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { |
1553 shared_info->DisableOptimization(kEval); | 1556 shared_info->DisableOptimization(kEval); |
1554 } | 1557 } |
1555 | 1558 |
1556 // If caller is strict mode, the result must be in strict mode as well. | 1559 // If caller is strict mode, the result must be in strict mode as well. |
1557 DCHECK(is_sloppy(language_mode) || | 1560 DCHECK(is_sloppy(language_mode) || |
1558 is_strict(shared_info->language_mode())); | 1561 is_strict(shared_info->language_mode())); |
1559 compilation_cache->PutEval(source, outer_info, context, shared_info, | 1562 compilation_cache->PutEval(source, outer_info, context, shared_info, |
1560 line_offset); | 1563 eval_position); |
1561 } | 1564 } |
1562 } | 1565 } |
1563 | 1566 |
1564 Handle<JSFunction> result = | 1567 Handle<JSFunction> result = |
1565 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1568 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
1566 shared_info, context, NOT_TENURED); | 1569 shared_info, context, NOT_TENURED); |
1567 | 1570 |
1568 // OnAfterCompile has to be called after we create the JSFunction, which we | 1571 // OnAfterCompile has to be called after we create the JSFunction, which we |
1569 // may require to recompile the eval for debugging, if we find a function | 1572 // may require to recompile the eval for debugging, if we find a function |
1570 // that contains break points in the eval script. | 1573 // that contains break points in the eval script. |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 MaybeHandle<Code> code; | 1960 MaybeHandle<Code> code; |
1958 if (cached.code != nullptr) code = handle(cached.code); | 1961 if (cached.code != nullptr) code = handle(cached.code); |
1959 Handle<Context> native_context(function->context()->native_context()); | 1962 Handle<Context> native_context(function->context()->native_context()); |
1960 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1963 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1961 literals, BailoutId::None()); | 1964 literals, BailoutId::None()); |
1962 } | 1965 } |
1963 } | 1966 } |
1964 | 1967 |
1965 } // namespace internal | 1968 } // namespace internal |
1966 } // namespace v8 | 1969 } // namespace v8 |
OLD | NEW |