| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 log_(log), | 80 log_(log), |
| 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 82 stack_limit_(stack_limit), | 82 stack_limit_(stack_limit), |
| 83 scanner_(scanner), | 83 scanner_(scanner), |
| 84 stack_overflow_(false), | 84 stack_overflow_(false), |
| 85 allow_lazy_(false), | 85 allow_lazy_(false), |
| 86 allow_natives_(false), | 86 allow_natives_(false), |
| 87 allow_harmony_arrow_functions_(false), | 87 allow_harmony_arrow_functions_(false), |
| 88 allow_harmony_object_literals_(false), | 88 allow_harmony_object_literals_(false), |
| 89 allow_harmony_sloppy_(false), | 89 allow_harmony_sloppy_(false), |
| 90 allow_harmony_computed_property_names_(false), |
| 90 zone_(zone) {} | 91 zone_(zone) {} |
| 91 | 92 |
| 92 // Getters that indicate whether certain syntactical constructs are | 93 // Getters that indicate whether certain syntactical constructs are |
| 93 // allowed to be parsed by this instance of the parser. | 94 // allowed to be parsed by this instance of the parser. |
| 94 bool allow_lazy() const { return allow_lazy_; } | 95 bool allow_lazy() const { return allow_lazy_; } |
| 95 bool allow_natives() const { return allow_natives_; } | 96 bool allow_natives() const { return allow_natives_; } |
| 96 bool allow_harmony_arrow_functions() const { | 97 bool allow_harmony_arrow_functions() const { |
| 97 return allow_harmony_arrow_functions_; | 98 return allow_harmony_arrow_functions_; |
| 98 } | 99 } |
| 99 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 100 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
| 100 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 101 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
| 101 bool allow_harmony_numeric_literals() const { | 102 bool allow_harmony_numeric_literals() const { |
| 102 return scanner()->HarmonyNumericLiterals(); | 103 return scanner()->HarmonyNumericLiterals(); |
| 103 } | 104 } |
| 104 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } | 105 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } |
| 105 bool allow_harmony_object_literals() const { | 106 bool allow_harmony_object_literals() const { |
| 106 return allow_harmony_object_literals_; | 107 return allow_harmony_object_literals_; |
| 107 } | 108 } |
| 108 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } | 109 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } |
| 109 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } | 110 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } |
| 110 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } | 111 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } |
| 112 bool allow_harmony_computed_property_names() const { |
| 113 return allow_harmony_computed_property_names_; |
| 114 } |
| 111 | 115 |
| 112 // Setters that determine whether certain syntactical constructs are | 116 // Setters that determine whether certain syntactical constructs are |
| 113 // allowed to be parsed by this instance of the parser. | 117 // allowed to be parsed by this instance of the parser. |
| 114 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 118 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
| 115 void set_allow_natives(bool allow) { allow_natives_ = allow; } | 119 void set_allow_natives(bool allow) { allow_natives_ = allow; } |
| 116 void set_allow_harmony_arrow_functions(bool allow) { | 120 void set_allow_harmony_arrow_functions(bool allow) { |
| 117 allow_harmony_arrow_functions_ = allow; | 121 allow_harmony_arrow_functions_ = allow; |
| 118 } | 122 } |
| 119 void set_allow_harmony_modules(bool allow) { | 123 void set_allow_harmony_modules(bool allow) { |
| 120 scanner()->SetHarmonyModules(allow); | 124 scanner()->SetHarmonyModules(allow); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 } | 137 } |
| 134 void set_allow_harmony_templates(bool allow) { | 138 void set_allow_harmony_templates(bool allow) { |
| 135 scanner()->SetHarmonyTemplates(allow); | 139 scanner()->SetHarmonyTemplates(allow); |
| 136 } | 140 } |
| 137 void set_allow_harmony_sloppy(bool allow) { | 141 void set_allow_harmony_sloppy(bool allow) { |
| 138 allow_harmony_sloppy_ = allow; | 142 allow_harmony_sloppy_ = allow; |
| 139 } | 143 } |
| 140 void set_allow_harmony_unicode(bool allow) { | 144 void set_allow_harmony_unicode(bool allow) { |
| 141 scanner()->SetHarmonyUnicode(allow); | 145 scanner()->SetHarmonyUnicode(allow); |
| 142 } | 146 } |
| 147 void set_allow_harmony_computed_property_names(bool allow) { |
| 148 allow_harmony_computed_property_names_ = allow; |
| 149 } |
| 143 | 150 |
| 144 protected: | 151 protected: |
| 145 enum AllowEvalOrArgumentsAsIdentifier { | 152 enum AllowEvalOrArgumentsAsIdentifier { |
| 146 kAllowEvalOrArguments, | 153 kAllowEvalOrArguments, |
| 147 kDontAllowEvalOrArguments | 154 kDontAllowEvalOrArguments |
| 148 }; | 155 }; |
| 149 | 156 |
| 150 enum Mode { | 157 enum Mode { |
| 151 PARSE_LAZILY, | 158 PARSE_LAZILY, |
| 152 PARSE_EAGERLY | 159 PARSE_EAGERLY |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // Parses an identifier and determines whether or not it is 'get' or 'set'. | 490 // Parses an identifier and determines whether or not it is 'get' or 'set'. |
| 484 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, | 491 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 485 bool* is_set, | 492 bool* is_set, |
| 486 bool* ok); | 493 bool* ok); |
| 487 | 494 |
| 488 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); | 495 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 489 | 496 |
| 490 ExpressionT ParsePrimaryExpression(bool* ok); | 497 ExpressionT ParsePrimaryExpression(bool* ok); |
| 491 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 498 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 492 ExpressionT ParseArrayLiteral(bool* ok); | 499 ExpressionT ParseArrayLiteral(bool* ok); |
| 493 IdentifierT ParsePropertyName(bool* is_get, bool* is_set, bool* is_static, | 500 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 501 bool* is_static, bool* is_computed_name, |
| 494 bool* ok); | 502 bool* ok); |
| 495 ExpressionT ParseObjectLiteral(bool* ok); | 503 ExpressionT ParseObjectLiteral(bool* ok); |
| 496 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, | 504 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 497 bool in_class, bool is_static, | 505 bool in_class, bool is_static, |
| 506 bool* is_computed_name, |
| 498 bool* has_seen_constructor, | 507 bool* has_seen_constructor, |
| 499 bool* ok); | 508 bool* ok); |
| 500 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 509 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| 501 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 510 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 502 ExpressionT ParseYieldExpression(bool* ok); | 511 ExpressionT ParseYieldExpression(bool* ok); |
| 503 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 512 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 504 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 513 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 505 ExpressionT ParseUnaryExpression(bool* ok); | 514 ExpressionT ParseUnaryExpression(bool* ok); |
| 506 ExpressionT ParsePostfixExpression(bool* ok); | 515 ExpressionT ParsePostfixExpression(bool* ok); |
| 507 ExpressionT ParseLeftHandSideExpression(bool* ok); | 516 ExpressionT ParseLeftHandSideExpression(bool* ok); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 600 |
| 592 private: | 601 private: |
| 593 Scanner* scanner_; | 602 Scanner* scanner_; |
| 594 bool stack_overflow_; | 603 bool stack_overflow_; |
| 595 | 604 |
| 596 bool allow_lazy_; | 605 bool allow_lazy_; |
| 597 bool allow_natives_; | 606 bool allow_natives_; |
| 598 bool allow_harmony_arrow_functions_; | 607 bool allow_harmony_arrow_functions_; |
| 599 bool allow_harmony_object_literals_; | 608 bool allow_harmony_object_literals_; |
| 600 bool allow_harmony_sloppy_; | 609 bool allow_harmony_sloppy_; |
| 610 bool allow_harmony_computed_property_names_; |
| 601 | 611 |
| 602 typename Traits::Type::Zone* zone_; // Only used by Parser. | 612 typename Traits::Type::Zone* zone_; // Only used by Parser. |
| 603 }; | 613 }; |
| 604 | 614 |
| 605 | 615 |
| 606 class PreParserIdentifier { | 616 class PreParserIdentifier { |
| 607 public: | 617 public: |
| 608 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 618 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
| 609 static PreParserIdentifier Default() { | 619 static PreParserIdentifier Default() { |
| 610 return PreParserIdentifier(kUnknownIdentifier); | 620 return PreParserIdentifier(kUnknownIdentifier); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 int literal_index, | 1034 int literal_index, |
| 1025 int pos) { | 1035 int pos) { |
| 1026 return PreParserExpression::Default(); | 1036 return PreParserExpression::Default(); |
| 1027 } | 1037 } |
| 1028 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1038 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 1029 int literal_index, | 1039 int literal_index, |
| 1030 int pos) { | 1040 int pos) { |
| 1031 return PreParserExpression::Default(); | 1041 return PreParserExpression::Default(); |
| 1032 } | 1042 } |
| 1033 PreParserExpression NewObjectLiteralProperty(bool is_getter, | 1043 PreParserExpression NewObjectLiteralProperty(bool is_getter, |
| 1044 PreParserExpression key, |
| 1034 PreParserExpression value, | 1045 PreParserExpression value, |
| 1035 int pos, bool is_static) { | 1046 int pos, bool is_static, |
| 1047 bool is_computed_name) { |
| 1036 return PreParserExpression::Default(); | 1048 return PreParserExpression::Default(); |
| 1037 } | 1049 } |
| 1038 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1050 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 1039 PreParserExpression value, | 1051 PreParserExpression value, |
| 1040 bool is_static) { | 1052 bool is_static, |
| 1053 bool is_computed_name) { |
| 1041 return PreParserExpression::Default(); | 1054 return PreParserExpression::Default(); |
| 1042 } | 1055 } |
| 1043 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1056 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
| 1044 int literal_index, | 1057 int literal_index, |
| 1045 int boilerplate_properties, | 1058 int boilerplate_properties, |
| 1046 bool has_function, | 1059 bool has_function, |
| 1047 int pos) { | 1060 int pos) { |
| 1048 return PreParserExpression::Default(); | 1061 return PreParserExpression::Default(); |
| 1049 } | 1062 } |
| 1050 PreParserExpression NewVariableProxy(void* variable) { | 1063 PreParserExpression NewVariableProxy(void* variable) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 static PreParserExpression GetPropertyValue(PreParserExpression property) { | 1229 static PreParserExpression GetPropertyValue(PreParserExpression property) { |
| 1217 return PreParserExpression::Default(); | 1230 return PreParserExpression::Default(); |
| 1218 } | 1231 } |
| 1219 | 1232 |
| 1220 // Functions for encapsulating the differences between parsing and preparsing; | 1233 // Functions for encapsulating the differences between parsing and preparsing; |
| 1221 // operations interleaved with the recursive descent. | 1234 // operations interleaved with the recursive descent. |
| 1222 static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { | 1235 static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { |
| 1223 // PreParser should not use FuncNameInferrer. | 1236 // PreParser should not use FuncNameInferrer. |
| 1224 UNREACHABLE(); | 1237 UNREACHABLE(); |
| 1225 } | 1238 } |
| 1239 |
| 1226 static void PushPropertyName(FuncNameInferrer* fni, | 1240 static void PushPropertyName(FuncNameInferrer* fni, |
| 1227 PreParserExpression expression) { | 1241 PreParserExpression expression) { |
| 1228 // PreParser should not use FuncNameInferrer. | 1242 // PreParser should not use FuncNameInferrer. |
| 1229 UNREACHABLE(); | 1243 UNREACHABLE(); |
| 1230 } | 1244 } |
| 1245 |
| 1231 static void InferFunctionName(FuncNameInferrer* fni, | 1246 static void InferFunctionName(FuncNameInferrer* fni, |
| 1232 PreParserExpression expression) { | 1247 PreParserExpression expression) { |
| 1233 // PreParser should not use FuncNameInferrer. | 1248 // PreParser should not use FuncNameInferrer. |
| 1234 UNREACHABLE(); | 1249 UNREACHABLE(); |
| 1235 } | 1250 } |
| 1236 | 1251 |
| 1237 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 1252 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
| 1238 PreParserScope* scope, PreParserExpression property, bool* has_function) { | 1253 PreParserScope* scope, PreParserExpression property, bool* has_function) { |
| 1239 } | 1254 } |
| 1240 | 1255 |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 Expect(Token::RBRACK, CHECK_OK); | 1995 Expect(Token::RBRACK, CHECK_OK); |
| 1981 | 1996 |
| 1982 // Update the scope information before the pre-parsing bailout. | 1997 // Update the scope information before the pre-parsing bailout. |
| 1983 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1998 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
| 1984 | 1999 |
| 1985 return factory()->NewArrayLiteral(values, literal_index, pos); | 2000 return factory()->NewArrayLiteral(values, literal_index, pos); |
| 1986 } | 2001 } |
| 1987 | 2002 |
| 1988 | 2003 |
| 1989 template <class Traits> | 2004 template <class Traits> |
| 1990 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName( | 2005 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
| 1991 bool* is_get, bool* is_set, bool* is_static, bool* ok) { | 2006 IdentifierT* name, bool* is_get, bool* is_set, bool* is_static, |
| 1992 Token::Value next = peek(); | 2007 bool* is_computed_name, bool* ok) { |
| 1993 switch (next) { | 2008 Token::Value token = peek(); |
| 2009 int pos = peek_position(); |
| 2010 |
| 2011 // For non computed property names we normalize the name a bit: |
| 2012 // |
| 2013 // "12" -> 12 |
| 2014 // 12.3 -> "12.3" |
| 2015 // 12.30 -> "12.3" |
| 2016 // identifier -> "identifier" |
| 2017 // |
| 2018 // This is important because we use the property name as a key in a hash |
| 2019 // table when we compute constant properties. |
| 2020 switch (token) { |
| 1994 case Token::STRING: | 2021 case Token::STRING: |
| 1995 Consume(Token::STRING); | 2022 Consume(Token::STRING); |
| 1996 return this->GetSymbol(scanner_); | 2023 *name = this->GetSymbol(scanner()); |
| 2024 break; |
| 2025 |
| 1997 case Token::NUMBER: | 2026 case Token::NUMBER: |
| 1998 Consume(Token::NUMBER); | 2027 Consume(Token::NUMBER); |
| 1999 return this->GetNumberAsSymbol(scanner_); | 2028 *name = this->GetNumberAsSymbol(scanner()); |
| 2029 break; |
| 2030 |
| 2031 case Token::LBRACK: |
| 2032 if (allow_harmony_computed_property_names_) { |
| 2033 *is_computed_name = true; |
| 2034 Consume(Token::LBRACK); |
| 2035 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); |
| 2036 Expect(Token::RBRACK, CHECK_OK); |
| 2037 return expression; |
| 2038 } |
| 2039 |
| 2040 // Fall through. |
| 2000 case Token::STATIC: | 2041 case Token::STATIC: |
| 2001 *is_static = true; | 2042 *is_static = true; |
| 2002 // Fall through. | 2043 |
| 2044 // Fall through. |
| 2003 default: | 2045 default: |
| 2004 return ParseIdentifierNameOrGetOrSet(is_get, is_set, ok); | 2046 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
| 2047 break; |
| 2005 } | 2048 } |
| 2006 UNREACHABLE(); | 2049 |
| 2007 return this->EmptyIdentifier(); | 2050 uint32_t index; |
| 2051 return this->IsArrayIndex(*name, &index) |
| 2052 ? factory()->NewNumberLiteral(index, pos) |
| 2053 : factory()->NewStringLiteral(*name, pos); |
| 2008 } | 2054 } |
| 2009 | 2055 |
| 2010 | 2056 |
| 2011 template <class Traits> | 2057 template <class Traits> |
| 2012 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< | 2058 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| 2013 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, | 2059 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 2014 bool in_class, bool is_static, | 2060 bool in_class, bool is_static, |
| 2061 bool* is_computed_name, |
| 2015 bool* has_seen_constructor, bool* ok) { | 2062 bool* has_seen_constructor, bool* ok) { |
| 2016 DCHECK(!in_class || is_static || has_seen_constructor != NULL); | 2063 DCHECK(!in_class || is_static || has_seen_constructor != NULL); |
| 2017 ExpressionT value = this->EmptyExpression(); | 2064 ExpressionT value = this->EmptyExpression(); |
| 2065 IdentifierT name = this->EmptyIdentifier(); |
| 2018 bool is_get = false; | 2066 bool is_get = false; |
| 2019 bool is_set = false; | 2067 bool is_set = false; |
| 2020 bool name_is_static = false; | 2068 bool name_is_static = false; |
| 2021 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | 2069 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); |
| 2022 | 2070 |
| 2023 Token::Value name_token = peek(); | 2071 Token::Value name_token = peek(); |
| 2024 int next_pos = peek_position(); | 2072 int next_pos = peek_position(); |
| 2025 IdentifierT name = | 2073 ExpressionT name_expression = ParsePropertyName( |
| 2026 ParsePropertyName(&is_get, &is_set, &name_is_static, | 2074 &name, &is_get, &is_set, &name_is_static, is_computed_name, |
| 2027 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2075 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2028 | 2076 |
| 2029 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2077 if (fni_ != NULL && !*is_computed_name) { |
| 2078 this->PushLiteralName(fni_, name); |
| 2079 } |
| 2030 | 2080 |
| 2031 if (!in_class && !is_generator && peek() == Token::COLON) { | 2081 if (!in_class && !is_generator && peek() == Token::COLON) { |
| 2032 // PropertyDefinition : PropertyName ':' AssignmentExpression | 2082 // PropertyDefinition : PropertyName ':' AssignmentExpression |
| 2033 if (checker != NULL) { | 2083 if (!*is_computed_name && checker != NULL) { |
| 2034 checker->CheckProperty(name_token, kValueProperty, | 2084 checker->CheckProperty(name_token, kValueProperty, |
| 2035 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2085 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2036 } | 2086 } |
| 2037 Consume(Token::COLON); | 2087 Consume(Token::COLON); |
| 2038 value = this->ParseAssignmentExpression( | 2088 value = this->ParseAssignmentExpression( |
| 2039 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2089 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2040 | 2090 |
| 2041 } else if (is_generator || | 2091 } else if (is_generator || |
| 2042 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { | 2092 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { |
| 2043 // Concise Method | 2093 // Concise Method |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2061 if (*has_seen_constructor) { | 2111 if (*has_seen_constructor) { |
| 2062 ReportMessageAt(scanner()->location(), "duplicate_constructor"); | 2112 ReportMessageAt(scanner()->location(), "duplicate_constructor"); |
| 2063 *ok = false; | 2113 *ok = false; |
| 2064 return this->EmptyObjectLiteralProperty(); | 2114 return this->EmptyObjectLiteralProperty(); |
| 2065 } | 2115 } |
| 2066 | 2116 |
| 2067 *has_seen_constructor = true; | 2117 *has_seen_constructor = true; |
| 2068 kind = FunctionKind::kNormalFunction; | 2118 kind = FunctionKind::kNormalFunction; |
| 2069 } | 2119 } |
| 2070 | 2120 |
| 2071 if (checker != NULL) { | 2121 if (!*is_computed_name && checker != NULL) { |
| 2072 checker->CheckProperty(name_token, kValueProperty, | 2122 checker->CheckProperty(name_token, kValueProperty, |
| 2073 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2123 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2074 } | 2124 } |
| 2075 | 2125 |
| 2076 value = this->ParseFunctionLiteral( | 2126 value = this->ParseFunctionLiteral( |
| 2077 name, scanner()->location(), | 2127 name, scanner()->location(), |
| 2078 false, // reserved words are allowed here | 2128 false, // reserved words are allowed here |
| 2079 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 2129 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 2080 FunctionLiteral::NORMAL_ARITY, | 2130 FunctionLiteral::NORMAL_ARITY, |
| 2081 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2131 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2082 | 2132 |
| 2083 } else if (in_class && name_is_static && !is_static) { | 2133 } else if (in_class && name_is_static && !is_static) { |
| 2084 // static MethodDefinition | 2134 // static MethodDefinition |
| 2085 return ParsePropertyDefinition(checker, true, true, NULL, ok); | 2135 return ParsePropertyDefinition(checker, true, true, is_computed_name, NULL, |
| 2136 ok); |
| 2086 | 2137 |
| 2087 } else if (is_get || is_set) { | 2138 } else if (is_get || is_set) { |
| 2088 // Accessor | 2139 // Accessor |
| 2140 name = this->EmptyIdentifier(); |
| 2089 bool dont_care = false; | 2141 bool dont_care = false; |
| 2090 name_token = peek(); | 2142 name_token = peek(); |
| 2091 name = ParsePropertyName(&dont_care, &dont_care, &dont_care, | 2143 |
| 2092 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2144 name_expression = ParsePropertyName( |
| 2145 &name, &dont_care, &dont_care, &dont_care, is_computed_name, |
| 2146 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2093 | 2147 |
| 2094 // Validate the property. | 2148 // Validate the property. |
| 2095 if (is_static && this->IsPrototype(name)) { | 2149 if (is_static && this->IsPrototype(name)) { |
| 2096 ReportMessageAt(scanner()->location(), "static_prototype"); | 2150 ReportMessageAt(scanner()->location(), "static_prototype"); |
| 2097 *ok = false; | 2151 *ok = false; |
| 2098 return this->EmptyObjectLiteralProperty(); | 2152 return this->EmptyObjectLiteralProperty(); |
| 2099 } else if (in_class && !is_static && this->IsConstructor(name)) { | 2153 } else if (in_class && !is_static && this->IsConstructor(name)) { |
| 2100 ReportMessageAt(scanner()->location(), "constructor_special_method"); | 2154 ReportMessageAt(scanner()->location(), "constructor_special_method"); |
| 2101 *ok = false; | 2155 *ok = false; |
| 2102 return this->EmptyObjectLiteralProperty(); | 2156 return this->EmptyObjectLiteralProperty(); |
| 2103 } | 2157 } |
| 2104 if (checker != NULL) { | 2158 if (!*is_computed_name && checker != NULL) { |
| 2105 checker->CheckProperty(name_token, | 2159 checker->CheckProperty(name_token, |
| 2106 is_get ? kGetterProperty : kSetterProperty, | 2160 is_get ? kGetterProperty : kSetterProperty, |
| 2107 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2161 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2108 } | 2162 } |
| 2109 | 2163 |
| 2110 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 2164 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
| 2111 name, scanner()->location(), | 2165 name, scanner()->location(), |
| 2112 false, // reserved words are allowed here | 2166 false, // reserved words are allowed here |
| 2113 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, | 2167 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, |
| 2114 FunctionLiteral::ANONYMOUS_EXPRESSION, | 2168 FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 2115 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, | 2169 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, |
| 2116 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2170 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2117 return factory()->NewObjectLiteralProperty(is_get, value, next_pos, | 2171 |
| 2118 is_static); | 2172 // Make sure the name expression is a string since we need a Name for |
| 2173 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this |
| 2174 // statically we can skip the extra runtime check. |
| 2175 if (!*is_computed_name) { |
| 2176 name_expression = |
| 2177 factory()->NewStringLiteral(name, name_expression->position()); |
| 2178 } |
| 2179 |
| 2180 return factory()->NewObjectLiteralProperty( |
| 2181 is_get, name_expression, value, next_pos, is_static, *is_computed_name); |
| 2119 | 2182 |
| 2120 } else if (!in_class && allow_harmony_object_literals_ && | 2183 } else if (!in_class && allow_harmony_object_literals_ && |
| 2121 Token::IsIdentifier(name_token, strict_mode(), | 2184 Token::IsIdentifier(name_token, strict_mode(), |
| 2122 this->is_generator())) { | 2185 this->is_generator())) { |
| 2123 value = this->ExpressionFromIdentifier(name, next_pos, scope_, factory()); | 2186 value = this->ExpressionFromIdentifier(name, next_pos, scope_, factory()); |
| 2124 | 2187 |
| 2125 } else { | 2188 } else { |
| 2126 Token::Value next = Next(); | 2189 Token::Value next = Next(); |
| 2127 ReportUnexpectedToken(next); | 2190 ReportUnexpectedToken(next); |
| 2128 *ok = false; | 2191 *ok = false; |
| 2129 return this->EmptyObjectLiteralProperty(); | 2192 return this->EmptyObjectLiteralProperty(); |
| 2130 } | 2193 } |
| 2131 | 2194 |
| 2132 uint32_t index; | 2195 return factory()->NewObjectLiteralProperty(name_expression, value, is_static, |
| 2133 LiteralT key = this->IsArrayIndex(name, &index) | 2196 *is_computed_name); |
| 2134 ? factory()->NewNumberLiteral(index, next_pos) | |
| 2135 : factory()->NewStringLiteral(name, next_pos); | |
| 2136 | |
| 2137 return factory()->NewObjectLiteralProperty(key, value, is_static); | |
| 2138 } | 2197 } |
| 2139 | 2198 |
| 2140 | 2199 |
| 2141 template <class Traits> | 2200 template <class Traits> |
| 2142 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 2201 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
| 2143 bool* ok) { | 2202 bool* ok) { |
| 2144 // ObjectLiteral :: | 2203 // ObjectLiteral :: |
| 2145 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2204 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
| 2146 | 2205 |
| 2147 int pos = peek_position(); | 2206 int pos = peek_position(); |
| 2148 typename Traits::Type::PropertyList properties = | 2207 typename Traits::Type::PropertyList properties = |
| 2149 this->NewPropertyList(4, zone_); | 2208 this->NewPropertyList(4, zone_); |
| 2150 int number_of_boilerplate_properties = 0; | 2209 int number_of_boilerplate_properties = 0; |
| 2151 bool has_function = false; | 2210 bool has_function = false; |
| 2211 bool has_computed_names = false; |
| 2152 | 2212 |
| 2153 ObjectLiteralChecker checker(this, strict_mode()); | 2213 ObjectLiteralChecker checker(this, strict_mode()); |
| 2154 | 2214 |
| 2155 Expect(Token::LBRACE, CHECK_OK); | 2215 Expect(Token::LBRACE, CHECK_OK); |
| 2156 | 2216 |
| 2157 while (peek() != Token::RBRACE) { | 2217 while (peek() != Token::RBRACE) { |
| 2158 if (fni_ != NULL) fni_->Enter(); | 2218 if (fni_ != NULL) fni_->Enter(); |
| 2159 | 2219 |
| 2160 const bool in_class = false; | 2220 const bool in_class = false; |
| 2161 const bool is_static = false; | 2221 const bool is_static = false; |
| 2222 bool is_computed_name = false; |
| 2162 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 2223 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
| 2163 &checker, in_class, is_static, NULL, CHECK_OK); | 2224 &checker, in_class, is_static, &is_computed_name, NULL, CHECK_OK); |
| 2225 |
| 2226 if (is_computed_name) { |
| 2227 has_computed_names = true; |
| 2228 } |
| 2164 | 2229 |
| 2165 // Mark top-level object literals that contain function literals and | 2230 // Mark top-level object literals that contain function literals and |
| 2166 // pretenure the literal so it can be added as a constant function | 2231 // pretenure the literal so it can be added as a constant function |
| 2167 // property. (Parser only.) | 2232 // property. (Parser only.) |
| 2168 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, | 2233 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, |
| 2169 &has_function); | 2234 &has_function); |
| 2170 | 2235 |
| 2171 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 2236 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
| 2172 if (this->IsBoilerplateProperty(property)) { | 2237 if (!has_computed_names && this->IsBoilerplateProperty(property)) { |
| 2173 number_of_boilerplate_properties++; | 2238 number_of_boilerplate_properties++; |
| 2174 } | 2239 } |
| 2175 properties->Add(property, zone()); | 2240 properties->Add(property, zone()); |
| 2176 | 2241 |
| 2177 if (peek() != Token::RBRACE) { | 2242 if (peek() != Token::RBRACE) { |
| 2178 // Need {} because of the CHECK_OK macro. | 2243 // Need {} because of the CHECK_OK macro. |
| 2179 Expect(Token::COMMA, CHECK_OK); | 2244 Expect(Token::COMMA, CHECK_OK); |
| 2180 } | 2245 } |
| 2181 | 2246 |
| 2182 if (fni_ != NULL) { | 2247 if (fni_ != NULL) { |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2954 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 3019 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 2955 // Both accessors of the same type. | 3020 // Both accessors of the same type. |
| 2956 parser()->ReportMessage("accessor_get_set"); | 3021 parser()->ReportMessage("accessor_get_set"); |
| 2957 } | 3022 } |
| 2958 *ok = false; | 3023 *ok = false; |
| 2959 } | 3024 } |
| 2960 } | 3025 } |
| 2961 } } // v8::internal | 3026 } } // v8::internal |
| 2962 | 3027 |
| 2963 #endif // V8_PREPARSER_H | 3028 #endif // V8_PREPARSER_H |
| OLD | NEW |