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

Unified Diff: src/preparser.h

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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
« src/ast.h ('K') | « 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 5ca161d94925e885fe811d7fe565512a555593c4..c745be1c9581c4309d8d16b4be0d3a0cb07293ca 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -84,6 +84,7 @@ class ParserBase : public Traits {
allow_natives_syntax_(false),
allow_generators_(false),
allow_arrow_functions_(false),
+ allow_harmony_object_literals_(false),
zone_(zone) {}
// Getters that indicate whether certain syntactical constructs are
@@ -98,6 +99,9 @@ class ParserBase : public Traits {
return scanner()->HarmonyNumericLiterals();
}
bool allow_classes() const { return scanner()->HarmonyClasses(); }
+ bool allow_harmony_object_literals() const {
+ return allow_harmony_object_literals_;
+ }
// Setters that determine whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser.
@@ -112,8 +116,9 @@ class ParserBase : public Traits {
void set_allow_harmony_numeric_literals(bool allow) {
scanner()->SetHarmonyNumericLiterals(allow);
}
- void set_allow_classes(bool allow) {
- scanner()->SetHarmonyClasses(allow);
+ void set_allow_classes(bool allow) { scanner()->SetHarmonyClasses(allow); }
+ void set_allow_harmony_object_literals(bool allow) {
+ allow_harmony_object_literals_ = allow;
}
protected:
@@ -521,6 +526,7 @@ class ParserBase : public Traits {
bool allow_natives_syntax_;
bool allow_generators_;
bool allow_arrow_functions_;
+ bool allow_harmony_object_literals_;
typename Traits::Type::Zone* zone_; // Only used by Parser.
};
@@ -996,7 +1002,9 @@ class PreParserFactory {
FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function,
FunctionLiteral::IsParenthesizedFlag is_parenthesized,
- FunctionLiteral::KindFlag kind, int position) {
+ FunctionLiteral::IsGeneratorFlag is_generator,
+ FunctionLiteral::IsArrowFlag is_arrow,
+ FunctionLiteral::IsConciseMethodFlag is_concise_method, int position) {
return PreParserExpression::Default();
}
@@ -1276,14 +1284,13 @@ class PreParserTraits {
// Temporary glue; these functions will move to ParserBase.
PreParserExpression ParseV8Intrinsic(bool* ok);
PreParserExpression ParseFunctionLiteral(
- PreParserIdentifier name,
- Scanner::Location function_name_location,
+ PreParserIdentifier name, Scanner::Location function_name_location,
bool name_is_strict_reserved,
- bool is_generator,
- int function_token_position,
- FunctionLiteral::FunctionType type,
- FunctionLiteral::ArityRestriction arity_restriction,
- bool* ok);
+ FunctionLiteral::IsGeneratorFlag is_generator,
+ FunctionLiteral::IsArrowFlag is_arrow,
+ FunctionLiteral::IsConciseMethodFlag is_concise_method,
+ int function_token_position, FunctionLiteral::FunctionType type,
+ FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
private:
PreParser* pre_parser_;
@@ -1414,14 +1421,13 @@ class PreParser : public ParserBase<PreParserTraits> {
bool is_generator, bool* ok);
Expression ParseFunctionLiteral(
- Identifier name,
- Scanner::Location function_name_location,
+ Identifier name, Scanner::Location function_name_location,
bool name_is_strict_reserved,
- bool is_generator,
- int function_token_pos,
- FunctionLiteral::FunctionType function_type,
- FunctionLiteral::ArityRestriction arity_restriction,
- bool* ok);
+ FunctionLiteral::IsGeneratorFlag is_generator,
+ FunctionLiteral::IsArrowFlag is_arrow,
+ FunctionLiteral::IsConciseMethodFlag is_concise_method,
+ int function_token_pos, FunctionLiteral::FunctionType function_type,
+ FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
void ParseLazyFunctionLiteralBody(bool* ok);
bool CheckInOrOf(bool accept_OF);
@@ -1833,7 +1839,8 @@ ParserBase<Traits>::ParsePropertyDefinition(bool* ok) {
&is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
if (fni_ != NULL) this->PushLiteralName(fni_, id);
- if ((is_getter || is_setter) && peek() != Token::COLON) {
+ if ((is_getter || is_setter) && peek() != Token::COLON &&
+ (!allow_harmony_object_literals_ || peek() != Token::LPAREN)) {
// Special handling of getter and setter syntax:
// { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... }
// We have already read the "get" or "set" keyword.
@@ -1841,14 +1848,14 @@ ParserBase<Traits>::ParsePropertyDefinition(bool* ok) {
switch (peek()) {
case Token::STRING:
Consume(Token::STRING);
- name = this->GetSymbol(scanner_);
+ name = this->GetSymbol(scanner());
break;
case Token::NUMBER:
Consume(Token::NUMBER);
// TODO(arv): Fix issue with numeric keys. get 1.0() should be
- // treated as if the key was '1'
+ // treated as if the key was '1'.
// https://code.google.com/p/v8/issues/detail?id=3507
- name = this->GetSymbol(scanner_);
+ name = this->GetSymbol(scanner());
break;
default:
name = ParseIdentifierName(
@@ -1858,8 +1865,9 @@ ParserBase<Traits>::ParsePropertyDefinition(bool* ok) {
this->ParseFunctionLiteral(
name, scanner()->location(),
false, // reserved words are allowed here
- false, // not a generator
- RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION,
+ FunctionLiteral::kNotGenerator, FunctionLiteral::kNotArrow,
+ FunctionLiteral::kNotConciseMethod, RelocInfo::kNoPosition,
+ FunctionLiteral::ANONYMOUS_EXPRESSION,
is_getter ? FunctionLiteral::GETTER_ARITY
: FunctionLiteral::SETTER_ARITY,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
@@ -1871,9 +1879,30 @@ ParserBase<Traits>::ParsePropertyDefinition(bool* ok) {
}
}
- Expect(Token::COLON, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
- ExpressionT value = this->ParseAssignmentExpression(
- true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ ExpressionT value = this->EmptyExpression();
+
+ if (allow_harmony_object_literals_ && peek() == Token::LPAREN) {
+ // TODO(arv): Parameters should use StrictFormalParameters.
+ // TODO(arv): If the FunctionBody references super we need to call
+ // MakeMethod.
+
+ // TODO(arv): Fix issue with numeric keys. 1.0() should be treated as if the
+ // key was '1'.
+ // https://code.google.com/p/v8/issues/detail?id=3507
+ IdentifierT name = this->GetSymbol(scanner());
+
+ value = this->ParseFunctionLiteral(
+ name, scanner()->location(),
+ false, // reserved words are allowed here
+ FunctionLiteral::kNotGenerator, FunctionLiteral::kNotArrow,
+ FunctionLiteral::kIsConciseMethod, RelocInfo::kNoPosition,
+ FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY,
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ } else {
+ Expect(Token::COLON, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ value = this->ParseAssignmentExpression(
+ true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ }
return factory()->NewObjectLiteralProperty(key, value);
}
@@ -2369,14 +2398,13 @@ ParserBase<Traits>::ParseMemberExpression(bool* ok) {
function_name_location = scanner()->location();
function_type = FunctionLiteral::NAMED_EXPRESSION;
}
- result = this->ParseFunctionLiteral(name,
- function_name_location,
- is_strict_reserved_name,
- is_generator,
- function_token_position,
- function_type,
- FunctionLiteral::NORMAL_ARITY,
- CHECK_OK);
+ result = this->ParseFunctionLiteral(
+ name, function_name_location, is_strict_reserved_name,
+ is_generator ? FunctionLiteral::kIsGenerator
+ : FunctionLiteral::kNotGenerator,
+ FunctionLiteral::kNotArrow, FunctionLiteral::kNotConciseMethod,
+ function_token_position, function_type, FunctionLiteral::NORMAL_ARITY,
+ CHECK_OK);
} else if (peek() == Token::SUPER) {
int beg_pos = position();
Consume(Token::SUPER);
@@ -2537,8 +2565,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
materialized_literal_count, expected_property_count, handler_count,
num_parameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
- FunctionLiteral::kNotParenthesized, FunctionLiteral::kArrowFunction,
- start_pos);
+ FunctionLiteral::kNotParenthesized, FunctionLiteral::kNotGenerator,
+ FunctionLiteral::kIsArrow, FunctionLiteral::kNotConciseMethod, start_pos);
function_literal->set_function_token_position(start_pos);
function_literal->set_ast_properties(&ast_properties);
« src/ast.h ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698