Commit 7762b230 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Declare scope-info deserialized function var on the cache scope

Bug: chromium:905907
Change-Id: I889a47dac1f240f3d656f41f43425cd7cd764c79
Reviewed-on: https://chromium-review.googlesource.com/c/1339862Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57565}
parent 3ca32e98
......@@ -744,18 +744,20 @@ void DeclarationScope::DeclareDefaultFunctionVariables(
}
}
Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) {
Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name,
Scope* cache) {
DCHECK(is_function_scope());
DCHECK_NULL(function_);
DCHECK_NULL(variables_.Lookup(name));
if (cache == nullptr) cache = this;
DCHECK_NULL(cache->variables_.Lookup(name));
VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE
: NORMAL_VARIABLE;
function_ = new (zone())
Variable(this, name, VariableMode::kConst, kind, kCreatedInitialized);
if (calls_sloppy_eval()) {
NonLocal(name, VariableMode::kDynamic);
cache->NonLocal(name, VariableMode::kDynamic);
} else {
variables_.Add(zone(), function_);
cache->variables_.Add(zone(), function_);
}
return function_;
}
......@@ -954,7 +956,7 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name, Scope* cache) {
if (!found) {
index = scope_info_->FunctionContextSlotIndex(*name_handle);
if (index < 0) return nullptr; // Nowhere found.
Variable* var = AsDeclarationScope()->DeclareFunctionVar(name);
Variable* var = AsDeclarationScope()->DeclareFunctionVar(name, cache);
DCHECK_EQ(VariableMode::kConst, var->mode());
var->AllocateTo(VariableLocation::CONTEXT, index);
return variables_.Lookup(name);
......
......@@ -755,7 +755,8 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
// declared in the scope. It will add a variable for {name} to {variables_};
// either the function variable itself, or a non-local in case the function
// calls sloppy eval.
Variable* DeclareFunctionVar(const AstRawString* name);
Variable* DeclareFunctionVar(const AstRawString* name,
Scope* cache = nullptr);
// Declare some special internal variables which must be accessible to
// Ignition without ScopeInfo.
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var g = function f(a = 3) {
var context_allocated = undefined;
function inner() { f(); f(context_allocated) };
inner();
};
assertThrows("g()", RangeError);
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