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

Unified Diff: src/parser.cc

Issue 1089623002: Revert of Simplify DoParseProgram (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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/parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 2838fbc03500f185cc6e253b3b2202ec68901bec..77c98b77e4c0cd6aadb003ec1965f82d879c30c8 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -914,6 +914,8 @@
source = String::Flatten(source);
FunctionLiteral* result;
+ Scope* top_scope = NULL;
+ Scope* eval_scope = NULL;
if (source->IsExternalTwoByteString()) {
// Notice that the stream is destroyed at the end of the branch block.
// The last line of the blocks can't be moved outside, even though they're
@@ -921,11 +923,15 @@
ExternalTwoByteStringUtf16CharacterStream stream(
Handle<ExternalTwoByteString>::cast(source), 0, source->length());
scanner_.Initialize(&stream);
- result = DoParseProgram(info);
+ result = DoParseProgram(info, &top_scope, &eval_scope);
} else {
GenericStringUtf16CharacterStream stream(source, 0, source->length());
scanner_.Initialize(&stream);
- result = DoParseProgram(info);
+ result = DoParseProgram(info, &top_scope, &eval_scope);
+ }
+ top_scope->set_end_position(source->length());
+ if (eval_scope != NULL) {
+ eval_scope->set_end_position(source->length());
}
HandleSourceURLComments(isolate, info->script());
@@ -950,7 +956,8 @@
}
-FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
+FunctionLiteral* Parser::DoParseProgram(ParseInfo* info, Scope** scope,
+ Scope** eval_scope) {
// Note that this function can be called from the main thread or from a
// background thread. We should not access anything Isolate / heap dependent
// via ParseInfo, and also not pass it forward.
@@ -959,11 +966,11 @@
FunctionLiteral* result = NULL;
{
- Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
- info->set_script_scope(scope);
+ *scope = NewScope(scope_, SCRIPT_SCOPE);
+ info->set_script_scope(*scope);
if (!info->context().is_null() && !info->context()->IsNativeContext()) {
- scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
- *info->context(), scope);
+ *scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
+ *info->context(), *scope);
// 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
@@ -971,27 +978,28 @@
DCHECK(parsing_on_main_thread_);
ast_value_factory()->Internalize(info->isolate());
}
- original_scope_ = scope;
+ original_scope_ = *scope;
if (info->is_eval()) {
- if (!scope->is_script_scope() || is_strict(info->language_mode())) {
- scope = NewScope(scope, EVAL_SCOPE);
+ if (!(*scope)->is_script_scope() || is_strict(info->language_mode())) {
+ *scope = NewScope(*scope, EVAL_SCOPE);
}
} else if (info->is_module()) {
- scope = NewScope(scope, MODULE_SCOPE);
- }
-
- scope->set_start_position(0);
+ *scope = NewScope(*scope, MODULE_SCOPE);
+ }
+ (*scope)->set_start_position(0);
+ // End position will be set by the caller.
// Compute the parsing mode.
Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
- if (allow_natives() || extension_ != NULL || scope->is_eval_scope()) {
+ if (allow_natives() || extension_ != NULL ||
+ (*scope)->is_eval_scope()) {
mode = PARSE_EAGERLY;
}
ParsingModeScope parsing_mode(this, mode);
// Enters 'scope'.
AstNodeFactory function_factory(ast_value_factory());
- FunctionState function_state(&function_state_, &scope_, scope,
+ FunctionState function_state(&function_state_, &scope_, *scope,
kNormalFunction, &function_factory);
scope_->SetLanguageMode(info->language_mode());
@@ -1002,13 +1010,8 @@
DCHECK(allow_harmony_modules());
ParseModuleItemList(body, &ok);
} else {
- Scope* eval_scope = nullptr;
- ParseStatementList(body, Token::EOS, info->is_eval(), &eval_scope, &ok);
- if (eval_scope != nullptr)
- eval_scope->set_end_position(scanner()->location().end_pos);
- }
-
- scope->set_end_position(scanner()->location().end_pos);
+ ParseStatementList(body, Token::EOS, info->is_eval(), eval_scope, &ok);
+ }
if (ok && is_strict(language_mode())) {
CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
@@ -5521,7 +5524,14 @@
// don't). We work around this by storing all the scopes which need their end
// position set at the end of the script (the top scope and possible eval
// scopes) and set their end position after we know the script length.
- result = DoParseProgram(info);
+ Scope* top_scope = NULL;
+ Scope* eval_scope = NULL;
+ result = DoParseProgram(info, &top_scope, &eval_scope);
+
+ top_scope->set_end_position(scanner()->location().end_pos);
+ if (eval_scope != NULL) {
+ eval_scope->set_end_position(scanner()->location().end_pos);
+ }
info->set_literal(result);
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698