[parser] Move ParseInfo wrapped argument setup

Change wrapped argument set-up to be closer to where it's needed: setting
up a top-level SFI, or initializing a ParseInfo from a top-level SFI.

This is a generally cleaner use of the interface, avoids splitting the
setting of the funciton syntax kind and wrapped arguments (including
checking script.is_wrapped() in two places for the same behaviour), plus
it avoids unnecessarily creating wrapped_argument handles for functions
inside a wrapped script.

As a drive-by, rename ParseInfo::SetFlagsFromScript to a clearer

ParseInfo::SetFlagsForFunctionInScript, to differentiate between flags
from a script for top-level vs. non-top-level.

Bug: v8:10314
Change-Id: Ibdaad957558c13a1528dcc3da1ba8f262f357e48
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2093509
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66643}
This commit is contained in:
Leszek Swirski 2020-03-10 11:38:45 +01:00 committed by Commit Bot
parent 085c804f79
commit 4f3b0990ef
3 changed files with 11 additions and 17 deletions

View File

@ -1596,7 +1596,7 @@ bool Compiler::FinalizeBackgroundCompileTask(
Handle<Script> script(Script::cast(shared_info->script()), isolate);
// TODO(leszeks): We can probably remove this, the parse_info flags should
// already match the script's.
parse_info->SetFlagsFromScript(isolate, *script);
parse_info->SetFlagsForFunctionFromScript(*script);
task->parser()->UpdateStatistics(isolate, script);
task->parser()->HandleSourceURLComments(isolate, script);

View File

@ -104,7 +104,11 @@ ParseInfo::ParseInfo(Isolate* isolate, SharedFunctionInfo shared)
SetFunctionInfo(&shared);
Script script = Script::cast(shared.script());
SetFlagsFromScript(isolate, script);
SetFlagsForFunctionFromScript(script);
if (shared.is_wrapped()) {
DCHECK(script.is_wrapped());
set_wrapped_arguments(handle(script.wrapped_arguments(), isolate));
}
if (shared.HasOuterScopeInfo()) {
set_outer_scope_info(handle(shared.GetOuterScopeInfo(), isolate));
@ -238,19 +242,20 @@ void ParseInfo::set_character_stream(
template <typename LocalIsolate>
void ParseInfo::SetFlagsForToplevelCompileFromScript(
LocalIsolate* isolate, Script script, bool is_collecting_type_profile) {
SetFlagsFromScript(isolate, script);
SetFlagsForFunctionFromScript(script);
set_allow_lazy_parsing();
set_toplevel();
set_collect_type_profile(is_collecting_type_profile &&
script.IsUserJavaScript());
set_repl_mode(script.is_repl_mode());
if (script.is_wrapped()) {
set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
set_wrapped_arguments(handle(script.wrapped_arguments(), isolate));
}
}
template <typename LocalIsolate>
void ParseInfo::SetFlagsFromScript(LocalIsolate* isolate, Script script) {
void ParseInfo::SetFlagsForFunctionFromScript(Script script) {
DCHECK(script_id_ == -1 || script_id_ == script.id());
script_id_ = script.id();
@ -261,16 +266,6 @@ void ParseInfo::SetFlagsFromScript(LocalIsolate* isolate, Script script) {
if (block_coverage_enabled() && script.IsUserJavaScript()) {
AllocateSourceRangeMap();
}
if (script.is_wrapped()) {
// This should only ever happen on the main thread. Convert this templated
// handle into a real Handle via Handle to avoid having to
// use template specialization for this.
DCHECK((std::is_same<Isolate, v8::internal::Isolate>::value));
Handle<FixedArray> wrapped_arguments_handle =
handle(script.wrapped_arguments(), isolate);
set_wrapped_arguments(wrapped_arguments_handle);
}
}
void ParseInfo::ParallelTasks::Enqueue(ParseInfo* outer_parse_info,

View File

@ -264,8 +264,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
ParallelTasks* parallel_tasks() { return parallel_tasks_.get(); }
template <typename LocalIsolate>
void SetFlagsFromScript(LocalIsolate* isolate, Script script);
void SetFlagsForFunctionFromScript(Script script);
//--------------------------------------------------------------------------
// TODO(titzer): these should not be part of ParseInfo.