Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: src/compiler.cc

Issue 2156303002: Implement new Function.prototype.toString and fix CreateDynamicFunction parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add DCHECK for the name anonymous Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <memory> 8 #include <memory>
9 9
10 #include "src/asmjs/asm-js.h" 10 #include "src/asmjs/asm-js.h"
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 return BASELINE; 1467 return BASELINE;
1468 } 1468 }
1469 } else { 1469 } else {
1470 return OPTIMIZED; 1470 return OPTIMIZED;
1471 } 1471 }
1472 } 1472 }
1473 1473
1474 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( 1474 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
1475 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 1475 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
1476 Handle<Context> context, LanguageMode language_mode, 1476 Handle<Context> context, LanguageMode language_mode,
1477 ParseRestriction restriction, int eval_scope_position, int eval_position, 1477 ParseRestriction restriction, int parameters_end_pos,
1478 int line_offset, int column_offset, Handle<Object> script_name, 1478 int eval_scope_position, int eval_position, int line_offset,
1479 int column_offset, Handle<Object> script_name,
1479 ScriptOriginOptions options) { 1480 ScriptOriginOptions options) {
1480 Isolate* isolate = source->GetIsolate(); 1481 Isolate* isolate = source->GetIsolate();
1481 int source_length = source->length(); 1482 int source_length = source->length();
1482 isolate->counters()->total_eval_size()->Increment(source_length); 1483 isolate->counters()->total_eval_size()->Increment(source_length);
1483 isolate->counters()->total_compile_size()->Increment(source_length); 1484 isolate->counters()->total_compile_size()->Increment(source_length);
1484 1485
1486 // The cache lookup key needs to be aware of the separation between the
1487 // parameters and the body to prevent this valid invocation:
1488 // Function("", "function anonymous(\n/**/) {\n}");
1489 // from adding an entry that falsely approves this invalid invocation:
1490 // Function("\n/**/) {\nfunction anonymous(", "}");
1491 // The actual eval_scope_position for indirect eval and CreateDynamicFunction
1492 // is unused (just 0), which means it's an available field to use to indicate
1493 // this separation. But to make sure we're not causing other false hits, we
1494 // negate the scope position.
1495 int position = eval_scope_position;
1496 if (FLAG_harmony_function_tostring &&
1497 restriction == ONLY_SINGLE_FUNCTION_LITERAL &&
1498 parameters_end_pos != kNoSourcePosition) {
1499 // use the parameters_end_pos as the eval_scope_position in the eval cache.
1500 DCHECK_EQ(eval_scope_position, 0);
1501 position = -parameters_end_pos;
1502 }
1485 CompilationCache* compilation_cache = isolate->compilation_cache(); 1503 CompilationCache* compilation_cache = isolate->compilation_cache();
1486 InfoVectorPair eval_result = compilation_cache->LookupEval( 1504 InfoVectorPair eval_result = compilation_cache->LookupEval(
1487 source, outer_info, context, language_mode, eval_scope_position); 1505 source, outer_info, context, language_mode, position);
1488 Handle<SharedFunctionInfo> shared_info; 1506 Handle<SharedFunctionInfo> shared_info;
1489 if (eval_result.has_shared()) { 1507 if (eval_result.has_shared()) {
1490 shared_info = Handle<SharedFunctionInfo>(eval_result.shared(), isolate); 1508 shared_info = Handle<SharedFunctionInfo>(eval_result.shared(), isolate);
1491 } 1509 }
1492 Handle<Cell> vector; 1510 Handle<Cell> vector;
1493 if (eval_result.has_vector()) { 1511 if (eval_result.has_vector()) {
1494 vector = Handle<Cell>(eval_result.vector(), isolate); 1512 vector = Handle<Cell>(eval_result.vector(), isolate);
1495 } 1513 }
1496 1514
1497 Handle<Script> script; 1515 Handle<Script> script;
(...skipping 11 matching lines...) Expand all
1509 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); 1527 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL);
1510 Script::SetEvalOrigin(script, outer_info, eval_position); 1528 Script::SetEvalOrigin(script, outer_info, eval_position);
1511 1529
1512 ParseInfo parse_info(script); 1530 ParseInfo parse_info(script);
1513 Zone compile_zone(isolate->allocator(), ZONE_NAME); 1531 Zone compile_zone(isolate->allocator(), ZONE_NAME);
1514 CompilationInfo info(&compile_zone, &parse_info, 1532 CompilationInfo info(&compile_zone, &parse_info,
1515 Handle<JSFunction>::null()); 1533 Handle<JSFunction>::null());
1516 parse_info.set_eval(); 1534 parse_info.set_eval();
1517 parse_info.set_language_mode(language_mode); 1535 parse_info.set_language_mode(language_mode);
1518 parse_info.set_parse_restriction(restriction); 1536 parse_info.set_parse_restriction(restriction);
1537 parse_info.set_parameters_end_pos(parameters_end_pos);
1519 if (!context->IsNativeContext()) { 1538 if (!context->IsNativeContext()) {
1520 parse_info.set_outer_scope_info(handle(context->scope_info())); 1539 parse_info.set_outer_scope_info(handle(context->scope_info()));
1521 } 1540 }
1522 1541
1523 shared_info = CompileToplevel(&info); 1542 shared_info = CompileToplevel(&info);
1524 if (shared_info.is_null()) { 1543 if (shared_info.is_null()) {
1525 return MaybeHandle<JSFunction>(); 1544 return MaybeHandle<JSFunction>();
1526 } 1545 }
1527 } 1546 }
1528 1547
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 while (SharedFunctionInfo* info = iter.Next()) { 1605 while (SharedFunctionInfo* info = iter.Next()) {
1587 if (info->HasAsmWasmData()) return true; 1606 if (info->HasAsmWasmData()) return true;
1588 } 1607 }
1589 return false; 1608 return false;
1590 } 1609 }
1591 1610
1592 } // namespace 1611 } // namespace
1593 1612
1594 MaybeHandle<JSFunction> Compiler::GetFunctionFromString( 1613 MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
1595 Handle<Context> context, Handle<String> source, 1614 Handle<Context> context, Handle<String> source,
1596 ParseRestriction restriction) { 1615 ParseRestriction restriction, int parameters_end_pos) {
1597 Isolate* const isolate = context->GetIsolate(); 1616 Isolate* const isolate = context->GetIsolate();
1598 Handle<Context> native_context(context->native_context(), isolate); 1617 Handle<Context> native_context(context->native_context(), isolate);
1599 1618
1600 // Check if native context allows code generation from 1619 // Check if native context allows code generation from
1601 // strings. Throw an exception if it doesn't. 1620 // strings. Throw an exception if it doesn't.
1602 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && 1621 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) &&
1603 !CodeGenerationFromStringsAllowed(isolate, native_context)) { 1622 !CodeGenerationFromStringsAllowed(isolate, native_context)) {
1604 Handle<Object> error_message = 1623 Handle<Object> error_message =
1605 native_context->ErrorMessageForCodeGenerationFromStrings(); 1624 native_context->ErrorMessageForCodeGenerationFromStrings();
1606 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, 1625 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings,
1607 error_message), 1626 error_message),
1608 JSFunction); 1627 JSFunction);
1609 } 1628 }
1610 1629
1611 // Compile source string in the native context. 1630 // Compile source string in the native context.
1612 int eval_scope_position = 0; 1631 int eval_scope_position = 0;
1613 int eval_position = kNoSourcePosition; 1632 int eval_position = kNoSourcePosition;
1614 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); 1633 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared());
1615 return Compiler::GetFunctionFromEval(source, outer_info, native_context, 1634 return Compiler::GetFunctionFromEval(source, outer_info, native_context,
1616 SLOPPY, restriction, eval_scope_position, 1635 SLOPPY, restriction, parameters_end_pos,
1617 eval_position); 1636 eval_scope_position, eval_position);
1618 } 1637 }
1619 1638
1620 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( 1639 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
1621 Handle<String> source, Handle<Object> script_name, int line_offset, 1640 Handle<String> source, Handle<Object> script_name, int line_offset,
1622 int column_offset, ScriptOriginOptions resource_options, 1641 int column_offset, ScriptOriginOptions resource_options,
1623 Handle<Object> source_map_url, Handle<Context> context, 1642 Handle<Object> source_map_url, Handle<Context> context,
1624 v8::Extension* extension, ScriptData** cached_data, 1643 v8::Extension* extension, ScriptData** cached_data,
1625 ScriptCompiler::CompileOptions compile_options, NativesFlag natives) { 1644 ScriptCompiler::CompileOptions compile_options, NativesFlag natives) {
1626 Isolate* isolate = source->GetIsolate(); 1645 Isolate* isolate = source->GetIsolate();
1627 if (compile_options == ScriptCompiler::kNoCompileOptions) { 1646 if (compile_options == ScriptCompiler::kNoCompileOptions) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 } 1932 }
1914 1933
1915 if (shared->is_compiled()) { 1934 if (shared->is_compiled()) {
1916 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1935 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1917 JSFunction::EnsureLiterals(function); 1936 JSFunction::EnsureLiterals(function);
1918 } 1937 }
1919 } 1938 }
1920 1939
1921 } // namespace internal 1940 } // namespace internal
1922 } // namespace v8 1941 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/debug/debug-evaluate.cc » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698