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

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: fix async function constructor Created 4 years, 1 month 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 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 return BASELINE; 1383 return BASELINE;
1384 } 1384 }
1385 } else { 1385 } else {
1386 return OPTIMIZED; 1386 return OPTIMIZED;
1387 } 1387 }
1388 } 1388 }
1389 1389
1390 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( 1390 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
1391 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 1391 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
1392 Handle<Context> context, LanguageMode language_mode, 1392 Handle<Context> context, LanguageMode language_mode,
1393 ParseRestriction restriction, int eval_scope_position, int eval_position, 1393 ParseRestriction restriction, int parameters_end_pos,
1394 int line_offset, int column_offset, Handle<Object> script_name, 1394 int eval_scope_position, int eval_position, int line_offset,
1395 int column_offset, Handle<Object> script_name,
1395 ScriptOriginOptions options) { 1396 ScriptOriginOptions options) {
1396 Isolate* isolate = source->GetIsolate(); 1397 Isolate* isolate = source->GetIsolate();
1397 int source_length = source->length(); 1398 int source_length = source->length();
1398 isolate->counters()->total_eval_size()->Increment(source_length); 1399 isolate->counters()->total_eval_size()->Increment(source_length);
1399 isolate->counters()->total_compile_size()->Increment(source_length); 1400 isolate->counters()->total_compile_size()->Increment(source_length);
1400 1401
1402 // The cache lookup key needs to be aware of the separation between the
1403 // parameters and the body to prevent this valid invocation:
1404 // Function("", "function anonymous(\n/**/) {\n}");
1405 // from adding an entry that falsely approves this invalid invocation:
1406 // Function("\n/**/) {\nfunction anonymous(", "}");
1407 // The actual eval_scope_position for indirect eval and CreateDynamicFunction
1408 // is unused (just 0), which means it's an available field to use to indicate
1409 // this separation. But to make sure we're not causing other false hits, we
1410 // negate the scope position.
1411 if (FLAG_harmony_function_tostring &&
1412 restriction == ONLY_SINGLE_FUNCTION_LITERAL &&
1413 parameters_end_pos != kNoSourcePosition) {
1414 // use the parameters_end_pos as the eval_scope_position in the eval cache.
1415 DCHECK_EQ(eval_scope_position, 0);
1416 eval_scope_position = -parameters_end_pos;
1417 }
1401 CompilationCache* compilation_cache = isolate->compilation_cache(); 1418 CompilationCache* compilation_cache = isolate->compilation_cache();
1402 MaybeHandle<SharedFunctionInfo> maybe_shared_info = 1419 MaybeHandle<SharedFunctionInfo> maybe_shared_info =
1403 compilation_cache->LookupEval(source, outer_info, context, language_mode, 1420 compilation_cache->LookupEval(source, outer_info, context, language_mode,
1404 eval_scope_position); 1421 eval_scope_position);
1405 Handle<SharedFunctionInfo> shared_info; 1422 Handle<SharedFunctionInfo> shared_info;
1406 1423
1407 Handle<Script> script; 1424 Handle<Script> script;
1408 if (!maybe_shared_info.ToHandle(&shared_info)) { 1425 if (!maybe_shared_info.ToHandle(&shared_info)) {
1409 script = isolate->factory()->NewScript(source); 1426 script = isolate->factory()->NewScript(source);
1410 if (!script_name.is_null()) { 1427 if (!script_name.is_null()) {
1411 script->set_name(*script_name); 1428 script->set_name(*script_name);
1412 script->set_line_offset(line_offset); 1429 script->set_line_offset(line_offset);
1413 script->set_column_offset(column_offset); 1430 script->set_column_offset(column_offset);
1414 } 1431 }
1415 script->set_origin_options(options); 1432 script->set_origin_options(options);
1416 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); 1433 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL);
1417 Script::SetEvalOrigin(script, outer_info, eval_position); 1434 Script::SetEvalOrigin(script, outer_info, eval_position);
1418 1435
1419 Zone zone(isolate->allocator(), ZONE_NAME); 1436 Zone zone(isolate->allocator(), ZONE_NAME);
1420 ParseInfo parse_info(&zone, script); 1437 ParseInfo parse_info(&zone, script);
1421 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1438 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1422 parse_info.set_eval(); 1439 parse_info.set_eval();
1423 parse_info.set_language_mode(language_mode); 1440 parse_info.set_language_mode(language_mode);
1424 parse_info.set_parse_restriction(restriction); 1441 parse_info.set_parse_restriction(restriction);
1442 parse_info.set_parameters_end_pos(parameters_end_pos);
1425 if (!context->IsNativeContext()) { 1443 if (!context->IsNativeContext()) {
1426 parse_info.set_outer_scope_info(handle(context->scope_info())); 1444 parse_info.set_outer_scope_info(handle(context->scope_info()));
1427 } 1445 }
1428 1446
1429 shared_info = CompileToplevel(&info); 1447 shared_info = CompileToplevel(&info);
1430 1448
1431 if (shared_info.is_null()) { 1449 if (shared_info.is_null()) {
1432 return MaybeHandle<JSFunction>(); 1450 return MaybeHandle<JSFunction>();
1433 } else { 1451 } else {
1434 // If caller is strict mode, the result must be in strict mode as well. 1452 // If caller is strict mode, the result must be in strict mode as well.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 // Callback set. Let it decide if code generation is allowed. 1484 // Callback set. Let it decide if code generation is allowed.
1467 VMState<EXTERNAL> state(isolate); 1485 VMState<EXTERNAL> state(isolate);
1468 return callback(v8::Utils::ToLocal(context)); 1486 return callback(v8::Utils::ToLocal(context));
1469 } 1487 }
1470 } 1488 }
1471 1489
1472 } // namespace 1490 } // namespace
1473 1491
1474 MaybeHandle<JSFunction> Compiler::GetFunctionFromString( 1492 MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
1475 Handle<Context> context, Handle<String> source, 1493 Handle<Context> context, Handle<String> source,
1476 ParseRestriction restriction) { 1494 ParseRestriction restriction, int parameters_end_pos) {
1477 Isolate* const isolate = context->GetIsolate(); 1495 Isolate* const isolate = context->GetIsolate();
1478 Handle<Context> native_context(context->native_context(), isolate); 1496 Handle<Context> native_context(context->native_context(), isolate);
1479 1497
1480 // Check if native context allows code generation from 1498 // Check if native context allows code generation from
1481 // strings. Throw an exception if it doesn't. 1499 // strings. Throw an exception if it doesn't.
1482 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && 1500 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) &&
1483 !CodeGenerationFromStringsAllowed(isolate, native_context)) { 1501 !CodeGenerationFromStringsAllowed(isolate, native_context)) {
1484 Handle<Object> error_message = 1502 Handle<Object> error_message =
1485 native_context->ErrorMessageForCodeGenerationFromStrings(); 1503 native_context->ErrorMessageForCodeGenerationFromStrings();
1486 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, 1504 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings,
1487 error_message), 1505 error_message),
1488 JSFunction); 1506 JSFunction);
1489 } 1507 }
1490 1508
1491 // Compile source string in the native context. 1509 // Compile source string in the native context.
1492 int eval_scope_position = 0; 1510 int eval_scope_position = 0;
1493 int eval_position = kNoSourcePosition; 1511 int eval_position = kNoSourcePosition;
1494 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); 1512 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared());
1495 return Compiler::GetFunctionFromEval(source, outer_info, native_context, 1513 return Compiler::GetFunctionFromEval(source, outer_info, native_context,
1496 SLOPPY, restriction, eval_scope_position, 1514 SLOPPY, restriction, parameters_end_pos,
1497 eval_position); 1515 eval_scope_position, eval_position);
1498 } 1516 }
1499 1517
1500 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( 1518 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
1501 Handle<String> source, Handle<Object> script_name, int line_offset, 1519 Handle<String> source, Handle<Object> script_name, int line_offset,
1502 int column_offset, ScriptOriginOptions resource_options, 1520 int column_offset, ScriptOriginOptions resource_options,
1503 Handle<Object> source_map_url, Handle<Context> context, 1521 Handle<Object> source_map_url, Handle<Context> context,
1504 v8::Extension* extension, ScriptData** cached_data, 1522 v8::Extension* extension, ScriptData** cached_data,
1505 ScriptCompiler::CompileOptions compile_options, NativesFlag natives, 1523 ScriptCompiler::CompileOptions compile_options, NativesFlag natives,
1506 bool is_module) { 1524 bool is_module) {
1507 Isolate* isolate = source->GetIsolate(); 1525 Isolate* isolate = source->GetIsolate();
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 DCHECK(shared->is_compiled()); 1846 DCHECK(shared->is_compiled());
1829 function->set_literals(cached.literals); 1847 function->set_literals(cached.literals);
1830 } else if (shared->is_compiled()) { 1848 } else if (shared->is_compiled()) {
1831 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1849 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1832 JSFunction::EnsureLiterals(function); 1850 JSFunction::EnsureLiterals(function);
1833 } 1851 }
1834 } 1852 }
1835 1853
1836 } // namespace internal 1854 } // namespace internal
1837 } // namespace v8 1855 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/debug/debug-evaluate.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698