Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Unified Diff: src/parsing/parser-base.h

Issue 2329703002: Private fields
Patch Set: some comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 22c09d54a103876ec7eb6742c1c65596f01b021f..878538c784f5674b30884340fe637f25bf655c73 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -198,7 +198,8 @@ class ParserBase {
allow_harmony_async_await_(false),
allow_harmony_restrictive_generators_(false),
allow_harmony_trailing_commas_(false),
- allow_harmony_class_fields_(false) {}
+ allow_harmony_class_fields_(false),
+ allow_harmony_private_class_fields_(false) {}
#define ALLOW_ACCESSORS(name) \
bool allow_##name() const { return allow_##name##_; } \
@@ -215,6 +216,7 @@ class ParserBase {
ALLOW_ACCESSORS(harmony_restrictive_generators);
ALLOW_ACCESSORS(harmony_trailing_commas);
ALLOW_ACCESSORS(harmony_class_fields);
+ ALLOW_ACCESSORS(harmony_private_class_fields);
#undef ALLOW_ACCESSORS
@@ -1105,8 +1107,8 @@ class ParserBase {
bool* ok);
ExpressionT ParseObjectLiteral(bool* ok);
ClassLiteralPropertyT ParseClassPropertyDefinition(
- ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
- bool* has_seen_constructor, bool* ok);
+ ClassLiteralChecker* checker, bool has_extends, IdentifierT* private_name,
+ bool* is_computed_name, bool* has_seen_constructor, bool* ok);
FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer,
bool* ok);
ObjectLiteralPropertyT ParseObjectPropertyDefinition(
@@ -1341,6 +1343,7 @@ class ParserBase {
bool allow_harmony_restrictive_generators_;
bool allow_harmony_trailing_commas_;
bool allow_harmony_class_fields_;
+ bool allow_harmony_private_class_fields_;
friend class DiscardableZoneScope;
};
@@ -1605,6 +1608,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
// TemplateLiteral
// do Block
// AsyncFunctionExpression
+ // PrivateName
int beg_pos = peek_position();
switch (peek()) {
@@ -1728,6 +1732,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
}
break;
+ case Token::HASH:
+ if (allow_harmony_private_class_fields()) {
+ BindingPatternUnexpectedToken();
+ return impl()->ParsePrivateFieldReference(
+ impl()->ThisExpression(beg_pos), ok);
+ }
+ break;
+
default:
break;
}
@@ -2014,11 +2026,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
template <typename Impl>
typename ParserBase<Impl>::ClassLiteralPropertyT
-ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker,
- bool has_extends,
- bool* is_computed_name,
- bool* has_seen_constructor,
- bool* ok) {
+ParserBase<Impl>::ParseClassPropertyDefinition(
+ ClassLiteralChecker* checker, bool has_extends, IdentifierT* private_name,
+ bool* is_computed_name, bool* has_seen_constructor, bool* ok) {
+ DCHECK(!allow_harmony_private_class_fields() || private_name != nullptr);
DCHECK(has_seen_constructor != nullptr);
bool is_get = false;
bool is_set = false;
@@ -2047,6 +2058,21 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker,
&name, &kind, &is_generator, &is_get, &is_set, &is_async,
is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
}
+ } else if (allow_harmony_private_class_fields() &&
+ name_token == Token::HASH) {
+ Consume(Token::HASH);
+ // Private field
+ *private_name = ParseIdentifierName(CHECK_OK_CUSTOM(
+ EmptyClassLiteralProperty)); // TODO(bakkot) IdentifierPart
+ name_expression = impl()->EmptyExpression();
+
+ bool has_initializer = Check(Token::ASSIGN);
+ FunctionLiteralT function_literal = ParseClassFieldForInitializer(
+ has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
+ ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
+ return factory()->NewClassLiteralProperty(name_expression, function_literal,
+ ClassLiteralProperty::FIELD,
+ false, false);
} else {
name_expression = ParsePropertyName(
&name, &kind, &is_generator, &is_get, &is_set, &is_async,
@@ -3373,6 +3399,10 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
ArrowFormalParametersUnexpectedToken();
Consume(Token::PERIOD);
+ if (allow_harmony_private_class_fields() && peek() == Token::HASH) {
+ expression = impl()->ParsePrivateFieldReference(expression, CHECK_OK);
+ break;
+ }
int pos = position();
IdentifierT name = ParseIdentifierName(CHECK_OK);
expression = factory()->NewProperty(
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698