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

Unified Diff: src/parser.cc

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.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 41667c2eacd66793dcadc43b65547f807a8c9db3..9a0201b2c2159b057fd8a9ce219a6ed04baa9614 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -696,18 +696,16 @@ Expression* ParserTraits::ParseV8Intrinsic(bool* ok) {
FunctionLiteral* ParserTraits::ParseFunctionLiteral(
- const AstRawString* 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) {
- return parser_->ParseFunctionLiteral(name, function_name_location,
- name_is_strict_reserved, is_generator,
- function_token_position, type,
- arity_restriction, ok);
+ const AstRawString* name, Scanner::Location function_name_location,
+ bool name_is_strict_reserved, 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) {
+ return parser_->ParseFunctionLiteral(
+ name, function_name_location, name_is_strict_reserved, is_generator,
+ is_arrow, is_concise_method, function_token_position, type,
+ arity_restriction, ok);
}
@@ -738,6 +736,7 @@ Parser::Parser(CompilationInfo* info)
set_allow_arrow_functions(FLAG_harmony_arrow_functions);
set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
set_allow_classes(FLAG_harmony_classes);
+ set_allow_harmony_object_literals(FLAG_harmony_object_literals);
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
++feature) {
use_counts_[feature] = 0;
@@ -878,8 +877,8 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
function_state.handler_count(), 0,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
- FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction,
- 0);
+ FunctionLiteral::kNotParenthesized, FunctionLiteral::kNotGenerator,
+ FunctionLiteral::kNotArrow, FunctionLiteral::kNotConciseMethod, 0);
result->set_ast_properties(factory()->visitor()->ast_properties());
result->set_dont_optimize_reason(
factory()->visitor()->dont_optimize_reason());
@@ -968,20 +967,25 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
? FunctionLiteral::ANONYMOUS_EXPRESSION
: FunctionLiteral::NAMED_EXPRESSION)
: FunctionLiteral::DECLARATION;
- bool is_generator = shared_info->is_generator();
+
bool ok = true;
if (shared_info->is_arrow()) {
- DCHECK(!is_generator);
+ DCHECK(!shared_info->is_generator());
Expression* expression = ParseExpression(false, &ok);
DCHECK(expression->IsFunctionLiteral());
result = expression->AsFunctionLiteral();
} else {
- result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
- false, // Strict mode name already checked.
- is_generator, RelocInfo::kNoPosition,
- function_type,
- FunctionLiteral::NORMAL_ARITY, &ok);
+ result = ParseFunctionLiteral(
+ raw_name, Scanner::Location::invalid(),
+ false, // Strict mode name already checked.
+ shared_info->is_generator() ? FunctionLiteral::kIsGenerator
+ : FunctionLiteral::kNotGenerator,
+ FunctionLiteral::kNotArrow,
+ shared_info->is_concise_method() ? FunctionLiteral::kIsConciseMethod
+ : FunctionLiteral::kNotConciseMethod,
+ RelocInfo::kNoPosition, function_type, FunctionLiteral::NORMAL_ARITY,
+ &ok);
}
// Make sure the results agree.
DCHECK(ok == (result != NULL));
@@ -1870,14 +1874,12 @@ Statement* Parser::ParseFunctionDeclaration(
bool is_strict_reserved = false;
const AstRawString* name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK);
- FunctionLiteral* fun = ParseFunctionLiteral(name,
- scanner()->location(),
- is_strict_reserved,
- is_generator,
- pos,
- FunctionLiteral::DECLARATION,
- FunctionLiteral::NORMAL_ARITY,
- CHECK_OK);
+ FunctionLiteral* fun = ParseFunctionLiteral(
+ name, scanner()->location(), is_strict_reserved,
+ is_generator ? FunctionLiteral::kIsGenerator
+ : FunctionLiteral::kNotGenerator,
+ FunctionLiteral::kNotArrow, FunctionLiteral::kNotConciseMethod, pos,
+ FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, CHECK_OK);
// Even if we're not at the top-level of the global or a function
// scope, we treat it as such and introduce the function with its
// initial value upon entering the corresponding scope.
@@ -3341,14 +3343,12 @@ int ParserTraits::DeclareArrowParametersFromExpression(
FunctionLiteral* Parser::ParseFunctionLiteral(
- const AstRawString* function_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) {
+ const AstRawString* function_name, Scanner::Location function_name_location,
+ bool name_is_strict_reserved, 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) {
// Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}'
//
@@ -3589,14 +3589,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
}
}
- FunctionLiteral::KindFlag kind = is_generator
- ? FunctionLiteral::kGeneratorFunction
- : FunctionLiteral::kNormalFunction;
FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
function_name, ast_value_factory_, scope, body,
materialized_literal_count, expected_property_count, handler_count,
num_parameters, duplicate_parameters, function_type,
- FunctionLiteral::kIsFunction, parenthesized, kind, pos);
+ FunctionLiteral::kIsFunction, parenthesized, is_generator, is_arrow,
+ is_concise_method, pos);
function_literal->set_function_token_position(function_token_pos);
function_literal->set_ast_properties(&ast_properties);
function_literal->set_dont_optimize_reason(dont_optimize_reason);
@@ -3750,6 +3748,8 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
reusable_preparser_->set_allow_harmony_numeric_literals(
allow_harmony_numeric_literals());
reusable_preparser_->set_allow_classes(allow_classes());
+ reusable_preparser_->set_allow_harmony_object_literals(
+ allow_harmony_object_literals());
}
PreParser::PreParseResult result =
reusable_preparser_->PreParseLazyFunction(strict_mode(),
« src/ast.h ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698