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

Unified Diff: src/parsing/parser.cc

Issue 2198043002: Add a mode to completely deserialize scope chains (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 603b6c8a33cc78ddbd753511bf0661fe29536845..8cc02b4da358e84883a4a9141856545aab729dcc 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -857,6 +857,31 @@ Parser::Parser(ParseInfo* info)
}
}
+void Parser::DeserializeScopeChain(
+ ParseInfo* info, Handle<Context> context,
+ Scope::DeserializationMode deserialization_mode) {
+ // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
+ // context, which will have the "this" binding for script scopes.
+ Scope* scope = NewScriptScope();
+ info->set_script_scope(scope);
+ if (!context.is_null() && !context->IsNativeContext()) {
+ scope =
+ Scope::DeserializeScopeChain(info->isolate(), zone(), *context, scope,
+ ast_value_factory(), deserialization_mode);
+ if (info->context().is_null()) {
+ DCHECK(deserialization_mode ==
+ Scope::DeserializationMode::kDeserializeOffHeap);
+ } else {
+ // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
+ // means the Parser cannot operate independent of the V8 heap. Tell the
+ // string table to internalize strings and values right after they're
+ // created. This kind of parsing can only be done in the main thread.
+ DCHECK(parsing_on_main_thread_);
+ ast_value_factory()->Internalize(info->isolate());
+ }
+ }
+ original_scope_ = scope;
+}
FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
// TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
@@ -886,6 +911,9 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
cached_parse_data_->Initialize();
}
+ DeserializeScopeChain(info, info->context(),
+ Scope::DeserializationMode::kKeepScopeInfo);
+
source = String::Flatten(source);
FunctionLiteral* result;
@@ -942,22 +970,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
FunctionLiteral* result = NULL;
{
- // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
- // context, which will have the "this" binding for script scopes.
- Scope* scope = NewScriptScope();
- info->set_script_scope(scope);
- if (!info->context().is_null() && !info->context()->IsNativeContext()) {
- scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
- *info->context(), scope,
- ast_value_factory());
- // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
- // means the Parser cannot operate independent of the V8 heap. Tell the
- // string table to internalize strings and values right after they're
- // created. This kind of parsing can only be done in the main thread.
- DCHECK(parsing_on_main_thread_);
- ast_value_factory()->Internalize(info->isolate());
- }
- original_scope_ = scope;
+ Scope* scope = original_scope_;
+ DCHECK(scope);
if (info->is_eval()) {
if (!scope->is_script_scope() || is_strict(info->language_mode())) {
parsing_mode = PARSE_EAGERLY;
@@ -1048,6 +1062,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info) {
timer.Start();
}
Handle<SharedFunctionInfo> shared_info = info->shared_info();
+ DeserializeScopeChain(info, info->context(),
+ Scope::DeserializationMode::kKeepScopeInfo);
// Initialize parser state.
source = String::Flatten(source);
@@ -1110,16 +1126,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
{
// Parse the function literal.
- Scope* scope = NewScriptScope();
- info->set_script_scope(scope);
- if (!info->context().is_null()) {
- // Ok to use Isolate here, since lazy function parsing is only done in the
- // main thread.
- DCHECK(parsing_on_main_thread_);
- scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(),
- scope, ast_value_factory());
- }
- original_scope_ = scope;
+ Scope* scope = original_scope_;
+ DCHECK(scope);
FunctionState function_state(&function_state_, &scope_state_, scope,
shared_info->kind());
DCHECK(is_sloppy(scope->language_mode()) ||
@@ -5469,6 +5477,8 @@ void Parser::ParseOnBackground(ParseInfo* info) {
scanner_.Initialize(stream_ptr);
DCHECK(info->context().is_null() || info->context()->IsNativeContext());
+ DCHECK(original_scope_);
+
// When streaming, we don't know the length of the source until we have parsed
// it. The raw data can be UTF-8, so we wouldn't know the source length until
// we have decoded it anyway even if we knew the raw data length (which we
« no previous file with comments | « src/parsing/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698