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

Unified Diff: src/preparser.h

Issue 811593004: Revert of ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index c79f6a675618d3e63ec1b9ee3b6acb680f09ca6c..3b221ac09235654af5ff7fe241b6a507e6839df7 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -87,7 +87,6 @@
allow_harmony_arrow_functions_(false),
allow_harmony_object_literals_(false),
allow_harmony_sloppy_(false),
- allow_harmony_computed_property_names_(false),
zone_(zone) {}
// Getters that indicate whether certain syntactical constructs are
@@ -109,9 +108,6 @@
bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); }
bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; }
bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); }
- bool allow_harmony_computed_property_names() const {
- return allow_harmony_computed_property_names_;
- }
// Setters that determine whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser.
@@ -143,9 +139,6 @@
}
void set_allow_harmony_unicode(bool allow) {
scanner()->SetHarmonyUnicode(allow);
- }
- void set_allow_harmony_computed_property_names(bool allow) {
- allow_harmony_computed_property_names_ = allow;
}
protected:
@@ -497,13 +490,11 @@
ExpressionT ParsePrimaryExpression(bool* ok);
ExpressionT ParseExpression(bool accept_IN, bool* ok);
ExpressionT ParseArrayLiteral(bool* ok);
- ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set,
- bool* is_static, bool* is_computed_name,
+ IdentifierT ParsePropertyName(bool* is_get, bool* is_set, bool* is_static,
bool* ok);
ExpressionT ParseObjectLiteral(bool* ok);
ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker,
bool in_class, bool is_static,
- bool* is_computed_name,
bool* has_seen_constructor,
bool* ok);
typename Traits::Type::ExpressionList ParseArguments(bool* ok);
@@ -607,7 +598,6 @@
bool allow_harmony_arrow_functions_;
bool allow_harmony_object_literals_;
bool allow_harmony_sloppy_;
- bool allow_harmony_computed_property_names_;
typename Traits::Type::Zone* zone_; // Only used by Parser.
};
@@ -1041,16 +1031,13 @@
return PreParserExpression::Default();
}
PreParserExpression NewObjectLiteralProperty(bool is_getter,
- PreParserExpression key,
PreParserExpression value,
- int pos, bool is_static,
- bool is_computed_name) {
+ int pos, bool is_static) {
return PreParserExpression::Default();
}
PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
PreParserExpression value,
- bool is_static,
- bool is_computed_name) {
+ bool is_static) {
return PreParserExpression::Default();
}
PreParserExpression NewObjectLiteral(PreParserExpressionList properties,
@@ -1236,13 +1223,11 @@
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
-
static void PushPropertyName(FuncNameInferrer* fni,
PreParserExpression expression) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
-
static void InferFunctionName(FuncNameInferrer* fni,
PreParserExpression expression) {
// PreParser should not use FuncNameInferrer.
@@ -2002,55 +1987,24 @@
template <class Traits>
-typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
- IdentifierT* name, bool* is_get, bool* is_set, bool* is_static,
- bool* is_computed_name, bool* ok) {
- Token::Value token = peek();
- int pos = peek_position();
-
- // For non computed property names we normalize the name a bit:
- //
- // "12" -> 12
- // 12.3 -> "12.3"
- // 12.30 -> "12.3"
- // identifier -> "identifier"
- //
- // This is important because we use the property name as a key in a hash
- // table when we compute constant properties.
- switch (token) {
+typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName(
+ bool* is_get, bool* is_set, bool* is_static, bool* ok) {
+ Token::Value next = peek();
+ switch (next) {
case Token::STRING:
Consume(Token::STRING);
- *name = this->GetSymbol(scanner());
- break;
-
+ return this->GetSymbol(scanner_);
case Token::NUMBER:
Consume(Token::NUMBER);
- *name = this->GetNumberAsSymbol(scanner());
- break;
-
- case Token::LBRACK:
- if (allow_harmony_computed_property_names_) {
- *is_computed_name = true;
- Consume(Token::LBRACK);
- ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK);
- Expect(Token::RBRACK, CHECK_OK);
- return expression;
- }
-
- // Fall through.
+ return this->GetNumberAsSymbol(scanner_);
case Token::STATIC:
*is_static = true;
-
- // Fall through.
+ // Fall through.
default:
- *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK);
- break;
- }
-
- uint32_t index;
- return this->IsArrayIndex(*name, &index)
- ? factory()->NewNumberLiteral(index, pos)
- : factory()->NewStringLiteral(*name, pos);
+ return ParseIdentifierNameOrGetOrSet(is_get, is_set, ok);
+ }
+ UNREACHABLE();
+ return this->EmptyIdentifier();
}
@@ -2058,11 +2012,9 @@
typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker,
bool in_class, bool is_static,
- bool* is_computed_name,
bool* has_seen_constructor, bool* ok) {
DCHECK(!in_class || is_static || has_seen_constructor != NULL);
ExpressionT value = this->EmptyExpression();
- IdentifierT name = this->EmptyIdentifier();
bool is_get = false;
bool is_set = false;
bool name_is_static = false;
@@ -2070,17 +2022,15 @@
Token::Value name_token = peek();
int next_pos = peek_position();
- ExpressionT name_expression = ParsePropertyName(
- &name, &is_get, &is_set, &name_is_static, is_computed_name,
- CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
-
- if (fni_ != NULL && !*is_computed_name) {
- this->PushLiteralName(fni_, name);
- }
+ IdentifierT name =
+ ParsePropertyName(&is_get, &is_set, &name_is_static,
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+
+ if (fni_ != NULL) this->PushLiteralName(fni_, name);
if (!in_class && !is_generator && peek() == Token::COLON) {
// PropertyDefinition : PropertyName ':' AssignmentExpression
- if (!*is_computed_name && checker != NULL) {
+ if (checker != NULL) {
checker->CheckProperty(name_token, kValueProperty,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
}
@@ -2118,7 +2068,7 @@
kind = FunctionKind::kNormalFunction;
}
- if (!*is_computed_name && checker != NULL) {
+ if (checker != NULL) {
checker->CheckProperty(name_token, kValueProperty,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
}
@@ -2132,18 +2082,14 @@
} else if (in_class && name_is_static && !is_static) {
// static MethodDefinition
- return ParsePropertyDefinition(checker, true, true, is_computed_name, NULL,
- ok);
+ return ParsePropertyDefinition(checker, true, true, NULL, ok);
} else if (is_get || is_set) {
// Accessor
- name = this->EmptyIdentifier();
bool dont_care = false;
name_token = peek();
-
- name_expression = ParsePropertyName(
- &name, &dont_care, &dont_care, &dont_care, is_computed_name,
- CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ name = ParsePropertyName(&dont_care, &dont_care, &dont_care,
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
// Validate the property.
if (is_static && this->IsPrototype(name)) {
@@ -2155,7 +2101,7 @@
*ok = false;
return this->EmptyObjectLiteralProperty();
}
- if (!*is_computed_name && checker != NULL) {
+ if (checker != NULL) {
checker->CheckProperty(name_token,
is_get ? kGetterProperty : kSetterProperty,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
@@ -2168,17 +2114,8 @@
FunctionLiteral::ANONYMOUS_EXPRESSION,
is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
-
- // Make sure the name expression is a string since we need a Name for
- // Runtime_DefineAccessorPropertyUnchecked and since we can determine this
- // statically we can skip the extra runtime check.
- if (!*is_computed_name) {
- name_expression =
- factory()->NewStringLiteral(name, name_expression->position());
- }
-
- return factory()->NewObjectLiteralProperty(
- is_get, name_expression, value, next_pos, is_static, *is_computed_name);
+ return factory()->NewObjectLiteralProperty(is_get, value, next_pos,
+ is_static);
} else if (!in_class && allow_harmony_object_literals_ &&
Token::IsIdentifier(name_token, strict_mode(),
@@ -2192,8 +2129,12 @@
return this->EmptyObjectLiteralProperty();
}
- return factory()->NewObjectLiteralProperty(name_expression, value, is_static,
- *is_computed_name);
+ uint32_t index;
+ LiteralT key = this->IsArrayIndex(name, &index)
+ ? factory()->NewNumberLiteral(index, next_pos)
+ : factory()->NewStringLiteral(name, next_pos);
+
+ return factory()->NewObjectLiteralProperty(key, value, is_static);
}
@@ -2208,7 +2149,6 @@
this->NewPropertyList(4, zone_);
int number_of_boilerplate_properties = 0;
bool has_function = false;
- bool has_computed_names = false;
ObjectLiteralChecker checker(this, strict_mode());
@@ -2219,13 +2159,8 @@
const bool in_class = false;
const bool is_static = false;
- bool is_computed_name = false;
ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
- &checker, in_class, is_static, &is_computed_name, NULL, CHECK_OK);
-
- if (is_computed_name) {
- has_computed_names = true;
- }
+ &checker, in_class, is_static, NULL, CHECK_OK);
// Mark top-level object literals that contain function literals and
// pretenure the literal so it can be added as a constant function
@@ -2234,7 +2169,7 @@
&has_function);
// Count CONSTANT or COMPUTED properties to maintain the enumeration order.
- if (!has_computed_names && this->IsBoilerplateProperty(property)) {
+ if (this->IsBoilerplateProperty(property)) {
number_of_boilerplate_properties++;
}
properties->Add(property, zone());
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698