Commit 82c0f925 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Compute IsPrivateName from the underlying string on-the-fly

Change-Id: Ib9f51cab17a3ed9e8960857e77fc80a9a08df798
Reviewed-on: https://chromium-review.googlesource.com/c/1400841Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58660}
parent ec2f4acf
......@@ -1628,9 +1628,8 @@ class VariableProxy final : public Expression {
HoleCheckModeField::update(bit_field_, HoleCheckMode::kRequired);
}
bool is_private_name() const { return IsPrivateName::decode(bit_field_); }
void set_is_private_name() {
bit_field_ = IsPrivateName::update(bit_field_, true);
bool IsPrivateName() const {
return raw_name()->length() > 0 && raw_name()->FirstCharacter() == '#';
}
// Bind this proxy to the variable var.
......@@ -1687,8 +1686,7 @@ class VariableProxy final : public Expression {
IsAssignedField::encode(false) |
IsResolvedField::encode(false) |
IsRemovedFromUnresolvedField::encode(false) |
HoleCheckModeField::encode(HoleCheckMode::kElided) |
IsPrivateName::encode(false);
HoleCheckModeField::encode(HoleCheckMode::kElided);
}
explicit VariableProxy(const VariableProxy* copy_from);
......@@ -1703,7 +1701,6 @@ class VariableProxy final : public Expression {
: public BitField<bool, IsRemovedFromUnresolvedField::kNext, 1> {};
class HoleCheckModeField
: public BitField<HoleCheckMode, IsNewTargetField::kNext, 1> {};
class IsPrivateName : public BitField<bool, HoleCheckModeField::kNext, 1> {};
union {
const AstRawString* raw_name_; // if !is_resolved_
......
......@@ -1421,7 +1421,7 @@ void Scope::AnalyzePartially(DeclarationScope* max_outer_scope,
// reference to a private name or method. In that case keep it so we
// can fail later.
if (!max_outer_scope->outer_scope()->is_script_scope() ||
proxy->is_private_name()) {
proxy->IsPrivateName()) {
VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy);
new_unresolved_list->Add(copy);
}
......@@ -1845,7 +1845,7 @@ Variable* Scope::Lookup(VariableProxy* proxy, Scope* scope,
if (mode == kParsedScope && !scope->is_script_scope()) {
return nullptr;
}
if (V8_UNLIKELY(proxy->is_private_name())) return nullptr;
if (V8_UNLIKELY(proxy->IsPrivateName())) return nullptr;
// No binding has been found. Declare a variable on the global object.
return scope->AsDeclarationScope()->DeclareDynamicGlobal(
......@@ -1954,7 +1954,7 @@ bool Scope::ResolveVariable(ParseInfo* info, VariableProxy* proxy) {
DCHECK(!proxy->is_resolved());
Variable* var = Lookup<kParsedScope>(proxy, this, nullptr);
if (var == nullptr) {
DCHECK(proxy->is_private_name());
DCHECK(proxy->IsPrivateName());
info->pending_error_handler()->ReportMessageAt(
proxy->position(), proxy->position() + 1,
MessageTemplate::kInvalidPrivateFieldResolution, proxy->raw_name(),
......@@ -2072,7 +2072,7 @@ bool Scope::ResolveVariablesRecursively(ParseInfo* info) {
proxy->position(), proxy->position() + 1,
MessageTemplate::kInvalidPrivateFieldResolution, proxy->raw_name(),
kSyntaxError);
DCHECK(proxy->is_private_name());
DCHECK(proxy->IsPrivateName());
return false;
}
if (!var->is_dynamic()) {
......
......@@ -1509,10 +1509,7 @@ ParserBase<Impl>::ParsePropertyOrPrivatePropertyName() {
key = factory()->NewStringLiteral(name, pos);
} else if (allow_harmony_private_fields() && next == Token::PRIVATE_NAME) {
name = impl()->GetSymbol();
auto key_proxy =
impl()->ExpressionFromIdentifier(name, pos, InferName::kNo);
key_proxy->set_is_private_name();
key = key_proxy;
key = impl()->ExpressionFromIdentifier(name, pos, InferName::kNo);
} else {
ReportUnexpectedToken(next);
return impl()->FailureExpression();
......
......@@ -3158,7 +3158,7 @@ bool Parser::IsPropertyWithPrivateFieldKey(Expression* expression) {
if (!property->key()->IsVariableProxy()) return false;
VariableProxy* key = property->key()->AsVariableProxy();
return key->is_private_name();
return key->IsPrivateName();
}
void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) {
......
......@@ -325,15 +325,6 @@ class PreParserExpression {
// and PreParser.
PreParserExpression* operator->() { return this; }
void set_is_private_name() {
if (variables_ != nullptr) {
DCHECK(IsIdentifier());
DCHECK(AsIdentifier().IsPrivateName());
DCHECK_EQ(1, variables_->LengthForTest());
variables_->first()->set_is_private_name();
}
}
// More dummy implementations of things PreParser doesn't need to track:
void SetShouldEagerCompile() {}
void mark_as_iife() {}
......
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