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

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

Powered by Google App Engine
This is Rietveld 408576698