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