| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 505 |
| 506 ExpressionT ParsePrimaryExpression(bool* ok); | 506 ExpressionT ParsePrimaryExpression(bool* ok); |
| 507 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 507 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 508 ExpressionT ParseArrayLiteral(bool* ok); | 508 ExpressionT ParseArrayLiteral(bool* ok); |
| 509 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 509 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 510 bool* is_static, bool* is_computed_name, | 510 bool* is_static, bool* is_computed_name, |
| 511 bool* ok); | 511 bool* ok); |
| 512 ExpressionT ParseObjectLiteral(bool* ok); | 512 ExpressionT ParseObjectLiteral(bool* ok); |
| 513 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, | 513 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 514 bool in_class, bool is_static, | 514 bool in_class, bool is_static, |
| 515 bool has_extends, |
| 515 bool* is_computed_name, | 516 bool* is_computed_name, |
| 516 bool* has_seen_constructor, | 517 bool* has_seen_constructor, |
| 517 bool* ok); | 518 bool* ok); |
| 518 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 519 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| 519 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 520 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 520 ExpressionT ParseYieldExpression(bool* ok); | 521 ExpressionT ParseYieldExpression(bool* ok); |
| 521 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 522 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 522 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 523 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 523 ExpressionT ParseUnaryExpression(bool* ok); | 524 ExpressionT ParseUnaryExpression(bool* ok); |
| 524 ExpressionT ParsePostfixExpression(bool* ok); | 525 ExpressionT ParsePostfixExpression(bool* ok); |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 return PreParserExpression::Default(); | 1295 return PreParserExpression::Default(); |
| 1295 } | 1296 } |
| 1296 PreParserExpression NewThrowSyntaxError( | 1297 PreParserExpression NewThrowSyntaxError( |
| 1297 const char* type, Handle<Object> arg, int pos) { | 1298 const char* type, Handle<Object> arg, int pos) { |
| 1298 return PreParserExpression::Default(); | 1299 return PreParserExpression::Default(); |
| 1299 } | 1300 } |
| 1300 PreParserExpression NewThrowTypeError( | 1301 PreParserExpression NewThrowTypeError( |
| 1301 const char* type, Handle<Object> arg, int pos) { | 1302 const char* type, Handle<Object> arg, int pos) { |
| 1302 return PreParserExpression::Default(); | 1303 return PreParserExpression::Default(); |
| 1303 } | 1304 } |
| 1304 PreParserScope NewScope(PreParserScope* outer_scope, ScopeType scope_type) { | 1305 PreParserScope NewScope(PreParserScope* outer_scope, ScopeType scope_type, |
| 1306 FunctionKind kind = kNormalFunction) { |
| 1305 return PreParserScope(outer_scope, scope_type); | 1307 return PreParserScope(outer_scope, scope_type); |
| 1306 } | 1308 } |
| 1307 | 1309 |
| 1308 // Reporting errors. | 1310 // Reporting errors. |
| 1309 void ReportMessageAt(Scanner::Location location, | 1311 void ReportMessageAt(Scanner::Location location, |
| 1310 const char* message, | 1312 const char* message, |
| 1311 const char* arg = NULL, | 1313 const char* arg = NULL, |
| 1312 bool is_reference_error = false); | 1314 bool is_reference_error = false); |
| 1313 void ReportMessageAt(int start_pos, | 1315 void ReportMessageAt(int start_pos, |
| 1314 int end_pos, | 1316 int end_pos, |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 return this->IsArrayIndex(*name, &index) | 2063 return this->IsArrayIndex(*name, &index) |
| 2062 ? factory()->NewNumberLiteral(index, pos) | 2064 ? factory()->NewNumberLiteral(index, pos) |
| 2063 : factory()->NewStringLiteral(*name, pos); | 2065 : factory()->NewStringLiteral(*name, pos); |
| 2064 } | 2066 } |
| 2065 | 2067 |
| 2066 | 2068 |
| 2067 template <class Traits> | 2069 template <class Traits> |
| 2068 typename ParserBase<Traits>::ObjectLiteralPropertyT | 2070 typename ParserBase<Traits>::ObjectLiteralPropertyT |
| 2069 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, | 2071 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 2070 bool in_class, bool is_static, | 2072 bool in_class, bool is_static, |
| 2073 bool has_extends, |
| 2071 bool* is_computed_name, | 2074 bool* is_computed_name, |
| 2072 bool* has_seen_constructor, | 2075 bool* has_seen_constructor, |
| 2073 bool* ok) { | 2076 bool* ok) { |
| 2074 DCHECK(!in_class || is_static || has_seen_constructor != NULL); | 2077 DCHECK(!in_class || is_static || has_seen_constructor != NULL); |
| 2075 ExpressionT value = this->EmptyExpression(); | 2078 ExpressionT value = this->EmptyExpression(); |
| 2076 IdentifierT name = this->EmptyIdentifier(); | 2079 IdentifierT name = this->EmptyIdentifier(); |
| 2077 bool is_get = false; | 2080 bool is_get = false; |
| 2078 bool is_set = false; | 2081 bool is_set = false; |
| 2079 bool name_is_static = false; | 2082 bool name_is_static = false; |
| 2080 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | 2083 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 return this->EmptyObjectLiteralProperty(); | 2122 return this->EmptyObjectLiteralProperty(); |
| 2120 } | 2123 } |
| 2121 | 2124 |
| 2122 if (*has_seen_constructor) { | 2125 if (*has_seen_constructor) { |
| 2123 ReportMessageAt(scanner()->location(), "duplicate_constructor"); | 2126 ReportMessageAt(scanner()->location(), "duplicate_constructor"); |
| 2124 *ok = false; | 2127 *ok = false; |
| 2125 return this->EmptyObjectLiteralProperty(); | 2128 return this->EmptyObjectLiteralProperty(); |
| 2126 } | 2129 } |
| 2127 | 2130 |
| 2128 *has_seen_constructor = true; | 2131 *has_seen_constructor = true; |
| 2129 kind = FunctionKind::kNormalFunction; | 2132 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 2133 : FunctionKind::kNormalFunction; |
| 2130 } | 2134 } |
| 2131 | 2135 |
| 2132 if (!*is_computed_name && checker != NULL) { | 2136 if (!*is_computed_name && checker != NULL) { |
| 2133 checker->CheckProperty(name_token, kValueProperty, | 2137 checker->CheckProperty(name_token, kValueProperty, |
| 2134 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2138 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2135 } | 2139 } |
| 2136 | 2140 |
| 2137 value = this->ParseFunctionLiteral( | 2141 value = this->ParseFunctionLiteral( |
| 2138 name, scanner()->location(), | 2142 name, scanner()->location(), |
| 2139 false, // reserved words are allowed here | 2143 false, // reserved words are allowed here |
| 2140 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 2144 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 2141 FunctionLiteral::NORMAL_ARITY, | 2145 FunctionLiteral::NORMAL_ARITY, |
| 2142 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2146 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2143 | 2147 |
| 2144 return factory()->NewObjectLiteralProperty(name_expression, value, | 2148 return factory()->NewObjectLiteralProperty(name_expression, value, |
| 2145 ObjectLiteralProperty::COMPUTED, | 2149 ObjectLiteralProperty::COMPUTED, |
| 2146 is_static, *is_computed_name); | 2150 is_static, *is_computed_name); |
| 2147 | 2151 |
| 2148 } else if (in_class && name_is_static && !is_static) { | 2152 } else if (in_class && name_is_static && !is_static) { |
| 2149 // static MethodDefinition | 2153 // static MethodDefinition |
| 2150 return ParsePropertyDefinition(checker, true, true, is_computed_name, NULL, | 2154 return ParsePropertyDefinition(checker, true, true, has_extends, |
| 2151 ok); | 2155 is_computed_name, nullptr, ok); |
| 2152 | 2156 |
| 2153 } else if (is_get || is_set) { | 2157 } else if (is_get || is_set) { |
| 2154 // Accessor | 2158 // Accessor |
| 2155 name = this->EmptyIdentifier(); | 2159 name = this->EmptyIdentifier(); |
| 2156 bool dont_care = false; | 2160 bool dont_care = false; |
| 2157 name_token = peek(); | 2161 name_token = peek(); |
| 2158 | 2162 |
| 2159 name_expression = ParsePropertyName( | 2163 name_expression = ParsePropertyName( |
| 2160 &name, &dont_care, &dont_care, &dont_care, is_computed_name, | 2164 &name, &dont_care, &dont_care, &dont_care, is_computed_name, |
| 2161 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2165 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 | 2237 |
| 2234 ObjectLiteralChecker checker(this, strict_mode()); | 2238 ObjectLiteralChecker checker(this, strict_mode()); |
| 2235 | 2239 |
| 2236 Expect(Token::LBRACE, CHECK_OK); | 2240 Expect(Token::LBRACE, CHECK_OK); |
| 2237 | 2241 |
| 2238 while (peek() != Token::RBRACE) { | 2242 while (peek() != Token::RBRACE) { |
| 2239 if (fni_ != NULL) fni_->Enter(); | 2243 if (fni_ != NULL) fni_->Enter(); |
| 2240 | 2244 |
| 2241 const bool in_class = false; | 2245 const bool in_class = false; |
| 2242 const bool is_static = false; | 2246 const bool is_static = false; |
| 2247 const bool has_extends = false; |
| 2243 bool is_computed_name = false; | 2248 bool is_computed_name = false; |
| 2244 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 2249 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
| 2245 &checker, in_class, is_static, &is_computed_name, NULL, CHECK_OK); | 2250 &checker, in_class, is_static, has_extends, &is_computed_name, NULL, |
| 2251 CHECK_OK); |
| 2246 | 2252 |
| 2247 if (is_computed_name) { | 2253 if (is_computed_name) { |
| 2248 has_computed_names = true; | 2254 has_computed_names = true; |
| 2249 } | 2255 } |
| 2250 | 2256 |
| 2251 // Mark top-level object literals that contain function literals and | 2257 // Mark top-level object literals that contain function literals and |
| 2252 // pretenure the literal so it can be added as a constant function | 2258 // pretenure the literal so it can be added as a constant function |
| 2253 // property. (Parser only.) | 2259 // property. (Parser only.) |
| 2254 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, | 2260 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, |
| 2255 &has_function); | 2261 &has_function); |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 3062 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 3057 // Both accessors of the same type. | 3063 // Both accessors of the same type. |
| 3058 parser()->ReportMessage("accessor_get_set"); | 3064 parser()->ReportMessage("accessor_get_set"); |
| 3059 } | 3065 } |
| 3060 *ok = false; | 3066 *ok = false; |
| 3061 } | 3067 } |
| 3062 } | 3068 } |
| 3063 } } // v8::internal | 3069 } } // v8::internal |
| 3064 | 3070 |
| 3065 #endif // V8_PREPARSER_H | 3071 #endif // V8_PREPARSER_H |
| OLD | NEW |