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

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: Add strict formal param checking 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
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index db4e0fed2416554afc676609979d00e0317acf46..165c3bad6c4e5b2d19b1a340b6454a6b702a5d94 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -716,18 +716,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);
}
@@ -758,6 +756,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;
@@ -898,8 +897,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());
@@ -997,11 +996,16 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
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.
+ 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));
@@ -1890,14 +1894,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.
@@ -3361,14 +3363,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,7 +3589,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
}
// Validate strict mode.
- if (strict_mode() == STRICT) {
+ // Concise methods use StrictFormalParameters.
+ if (strict_mode() == STRICT || is_concise_method) {
CheckStrictFunctionNameAndParameters(function_name,
name_is_strict_reserved,
function_name_location,
@@ -3597,6 +3598,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
dupe_error_loc,
reserved_loc,
CHECK_OK);
+ }
+ if (strict_mode() == STRICT) {
CheckOctalLiteral(scope->start_position(),
scope->end_position(),
CHECK_OK);
@@ -3609,14 +3612,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);
@@ -3770,6 +3771,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(),

Powered by Google App Engine
This is Rietveld 408576698