| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index 2c8e405ceea9242d23417ceb632693e9105611ac..abf09622aff6bd5c93885676620330687c4c8beb 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:
|
| @@ -574,6 +579,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.
|
| };
|
| @@ -1049,7 +1055,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();
|
| }
|
|
|
| @@ -1324,14 +1332,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_;
|
| @@ -1462,14 +1469,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);
|
| @@ -1881,7 +1887,8 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
|
| &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.
|
| @@ -1894,7 +1901,7 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
|
| 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_);
|
| break;
|
| @@ -1910,8 +1917,9 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
|
| 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));
|
| @@ -1927,9 +1935,29 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
|
| checker->CheckProperty(next, kValueProperty,
|
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
|
|
|
| - 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): 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);
|
| }
|
| @@ -2428,14 +2456,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);
|
| @@ -2596,8 +2623,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);
|
|
|