Commit b03e7a62 authored by marja's avatar marja Committed by Commit bot

Revert of Eagerly declare eval scopes, even for sloppy scopes (patchset #2...

Revert of Eagerly declare eval scopes, even for sloppy scopes (patchset #2 id:20001 of https://codereview.chromium.org/1085263003/)

Reason for revert:
Regresses CodeLoad (crbug.com/480774).

Original issue's description:
> Eagerly declare eval scopes, even for sloppy scopes
>
> R=marja@chromium.org, mstarzinger@chromium.org
> LOG=N
> BUG=N
>
> Committed: https://crrev.com/fe9efc121c8cba8b6aee1a9cf36c68ee97c44d99
> Cr-Commit-Position: refs/heads/master@{#28027}

TBR=mstarzinger@chromium.org,verwaest@chromium.org,wingo@igalia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=N

Review URL: https://codereview.chromium.org/1082013003

Cr-Commit-Position: refs/heads/master@{#28037}
parent 6398e8d8
......@@ -977,7 +977,9 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
}
original_scope_ = scope;
if (info->is_eval()) {
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);
}
......@@ -1004,7 +1006,10 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
DCHECK(allow_harmony_modules());
ParseModuleItemList(body, &ok);
} else {
ParseStatementList(body, Token::EOS, &ok);
Scope* eval_scope = nullptr;
ParseStatementList(body, Token::EOS, info->is_eval(), &eval_scope, &ok);
if (eval_scope != nullptr)
eval_scope->set_end_position(scanner()->peek_location().beg_pos);
}
// The parser will peek but not consume EOS. Our scope logically goes all
......@@ -1190,7 +1195,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
bool* ok) {
bool is_eval, Scope** eval_scope, bool* ok) {
// StatementList ::
// (StatementListItem)* <end_token>
......@@ -1262,6 +1267,23 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// Strong mode implies strict mode. If there are several "use strict"
// / "use strong" directives, do the strict mode changes only once.
if (is_sloppy(scope_->language_mode())) {
// TODO(mstarzinger): Global strict eval calls, need their own scope
// as specified in ES5 10.4.2(3). The correct fix would be to always
// add this scope in DoParseProgram(), but that requires adaptations
// all over the code base, so we go with a quick-fix for now.
// In the same manner, we have to patch the parsing mode.
if (is_eval && !scope_->is_eval_scope()) {
DCHECK(scope_->is_script_scope());
Scope* scope = NewScope(scope_, EVAL_SCOPE);
scope->set_start_position(scope_->start_position());
scope->set_end_position(scope_->end_position());
scope_ = scope;
if (eval_scope != NULL) {
// Caller will correct the positions of the ad hoc eval scope.
*eval_scope = scope;
}
mode_ = PARSE_EAGERLY;
}
scope_->SetLanguageMode(static_cast<LanguageMode>(
scope_->language_mode() | STRICT_BIT));
}
......@@ -4249,7 +4271,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
yield, RelocInfo::kNoPosition), zone());
}
ParseStatementList(body, Token::RBRACE, CHECK_OK);
ParseStatementList(body, Token::RBRACE, false, NULL, CHECK_OK);
if (IsGeneratorFunction(kind)) {
VariableProxy* get_proxy = factory()->NewVariableProxy(
......
......@@ -910,7 +910,8 @@ class Parser : public ParserBase<ParserTraits> {
// which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites.
void* ParseStatementList(ZoneList<Statement*>* body, int end_token, bool* ok);
void* ParseStatementList(ZoneList<Statement*>* body, int end_token,
bool is_eval, Scope** ad_hoc_eval_scope, bool* ok);
Statement* ParseStatementListItem(bool* ok);
void* ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
Statement* ParseModuleItem(bool* ok);
......
......@@ -240,17 +240,12 @@ RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) {
// TODO(verwaest): This case should probably not be covered by this function,
// but by DeclareGlobals instead.
if (attributes != ABSENT && holder->IsJSGlobalObject()) {
if ((attributes != ABSENT && holder->IsJSGlobalObject()) ||
(context_arg->has_extension() &&
context_arg->extension()->IsJSGlobalObject())) {
return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name,
value, attr, is_var, is_const, is_function);
}
if (context_arg->has_extension() &&
context_arg->extension()->IsJSGlobalObject()) {
Handle<JSGlobalObject> global(
JSGlobalObject::cast(context_arg->extension()), isolate);
return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
is_function);
}
if (attributes != ABSENT) {
// The name was declared before; check for conflicting re-declarations.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment