Commit 948b02ce authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Throw unresolved private reference outside of Lookup

Change-Id: I81e14fd1b9b46181c44e2176dd0917966742d9d4
Reviewed-on: https://chromium-review.googlesource.com/c/1322910Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57384}
parent 0526f498
......@@ -32,7 +32,7 @@ void Scope::ResolveScopesThenForEachVariable(DeclarationScope* max_outer_scope,
next = proxy->next_unresolved();
DCHECK(!proxy->is_resolved());
Variable* var = Lookup(info, proxy, lookup, max_outer_scope->outer_scope());
Variable* var = Lookup(proxy, lookup, max_outer_scope->outer_scope());
if (var == nullptr) {
variable_proxy_stackvisitor(proxy);
} else if (var != Scope::kDummyPreParserVariable &&
......
......@@ -1766,7 +1766,7 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
}
// static
Variable* Scope::Lookup(ParseInfo* info, VariableProxy* proxy, Scope* scope,
Variable* Scope::Lookup(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end, bool force_context_allocation) {
while (true) {
DCHECK_NE(outer_scope_end, scope);
......@@ -1798,12 +1798,12 @@ Variable* Scope::Lookup(ParseInfo* info, VariableProxy* proxy, Scope* scope,
DCHECK(!scope->is_script_scope());
if (V8_UNLIKELY(scope->is_with_scope())) {
return LookupWith(info, proxy, scope, outer_scope_end,
return LookupWith(proxy, scope, outer_scope_end,
force_context_allocation);
}
if (V8_UNLIKELY(scope->is_declaration_scope() &&
scope->AsDeclarationScope()->calls_sloppy_eval())) {
return LookupSloppyEval(info, proxy, scope, outer_scope_end,
return LookupSloppyEval(proxy, scope, outer_scope_end,
force_context_allocation);
}
......@@ -1815,14 +1815,7 @@ Variable* Scope::Lookup(ParseInfo* info, VariableProxy* proxy, Scope* scope,
// declare them in the outer scope.
// TODO(marja): Separate Lookup for preparsed scopes better.
if (!scope->is_script_scope()) return nullptr;
if (V8_UNLIKELY(proxy->is_private_name())) {
info->pending_error_handler()->ReportMessageAt(
proxy->position(), proxy->position() + 1,
MessageTemplate::kInvalidPrivateFieldAccess, proxy->raw_name(),
kSyntaxError);
return nullptr;
}
if (V8_UNLIKELY(proxy->is_private_name())) return nullptr;
// No binding has been found. Declare a variable on the global object.
return scope->AsDeclarationScope()->DeclareDynamicGlobal(proxy->raw_name(),
......@@ -1846,12 +1839,12 @@ bool CanBeShadowed(Scope* scope, Variable* var) {
}
}; // namespace
Variable* Scope::LookupWith(ParseInfo* info, VariableProxy* proxy, Scope* scope,
Variable* Scope::LookupWith(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end,
bool force_context_allocation) {
DCHECK(scope->is_with_scope());
Variable* var = Lookup(info, proxy, scope->outer_scope_, outer_scope_end,
Variable* var = Lookup(proxy, scope->outer_scope_, outer_scope_end,
force_context_allocation);
if (!CanBeShadowed(scope, var)) return var;
......@@ -1870,13 +1863,13 @@ Variable* Scope::LookupWith(ParseInfo* info, VariableProxy* proxy, Scope* scope,
return scope->NonLocal(proxy->raw_name(), VariableMode::kDynamic);
}
Variable* Scope::LookupSloppyEval(ParseInfo* info, VariableProxy* proxy,
Scope* scope, Scope* outer_scope_end,
Variable* Scope::LookupSloppyEval(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end,
bool force_context_allocation) {
DCHECK(scope->is_declaration_scope() &&
scope->AsDeclarationScope()->calls_sloppy_eval());
Variable* var = Lookup(info, proxy, scope->outer_scope_, outer_scope_end,
Variable* var = Lookup(proxy, scope->outer_scope_, outer_scope_end,
force_context_allocation);
if (!CanBeShadowed(scope, var)) return var;
......@@ -1903,9 +1896,13 @@ Variable* Scope::LookupSloppyEval(ParseInfo* info, VariableProxy* proxy,
bool Scope::ResolveVariable(ParseInfo* info, VariableProxy* proxy) {
DCHECK(info->script_scope()->is_script_scope());
DCHECK(!proxy->is_resolved());
Variable* var = Lookup(info, proxy, this, nullptr);
Variable* var = Lookup(proxy, this, nullptr);
if (var == nullptr) {
DCHECK(proxy->is_private_name());
info->pending_error_handler()->ReportMessageAt(
proxy->position(), proxy->position() + 1,
MessageTemplate::kInvalidPrivateFieldAccess, proxy->raw_name(),
kSyntaxError);
return false;
}
ResolveTo(info, proxy, var);
......@@ -2013,8 +2010,12 @@ bool Scope::ResolveVariablesRecursively(ParseInfo* info) {
if (is_declaration_scope() && AsDeclarationScope()->was_lazily_parsed()) {
DCHECK_EQ(variables_.occupancy(), 0);
for (VariableProxy* proxy : unresolved_list_) {
Variable* var = Lookup(info, proxy, outer_scope(), nullptr);
Variable* var = Lookup(proxy, outer_scope(), nullptr);
if (var == nullptr) {
info->pending_error_handler()->ReportMessageAt(
proxy->position(), proxy->position() + 1,
MessageTemplate::kInvalidPrivateFieldAccess, proxy->raw_name(),
kSyntaxError);
DCHECK(proxy->is_private_name());
return false;
}
......
......@@ -591,18 +591,18 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
Variable* NonLocal(const AstRawString* name, VariableMode mode);
// Variable resolution.
// Lookup a variable reference given by name recursively starting with this
// scope, and stopping when reaching the outer_scope_end scope. If the code is
// executed because of a call to 'eval', the context parameter should be set
// to the calling context of 'eval'.
static Variable* Lookup(ParseInfo* info, VariableProxy* proxy, Scope* scope,
// Lookup a variable reference given by name starting with this scope, and
// stopping when reaching the outer_scope_end scope. If the code is executed
// because of a call to 'eval', the context parameter should be set to the
// calling context of 'eval'.
static Variable* Lookup(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end,
bool force_context_allocation = false);
static Variable* LookupWith(ParseInfo* info, VariableProxy* proxy,
Scope* scope, Scope* outer_scope_end,
static Variable* LookupWith(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end,
bool force_context_allocation);
static Variable* LookupSloppyEval(ParseInfo* info, VariableProxy* proxy,
Scope* scope, Scope* outer_scope_end,
static Variable* LookupSloppyEval(VariableProxy* proxy, Scope* scope,
Scope* outer_scope_end,
bool force_context_allocation);
void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var);
V8_WARN_UNUSED_RESULT bool ResolveVariable(ParseInfo* info,
......
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