| 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); | 513 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 514 | 514 |
| 515 ExpressionT ParsePrimaryExpression(bool* ok); | 515 ExpressionT ParsePrimaryExpression(bool* ok); |
| 516 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 516 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 517 ExpressionT ParseArrayLiteral(bool* ok); | 517 ExpressionT ParseArrayLiteral(bool* ok); |
| 518 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 518 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 519 bool* is_static, bool* is_computed_name, | 519 bool* is_static, bool* is_computed_name, |
| 520 bool* ok); | 520 bool* ok); |
| 521 ExpressionT ParseObjectLiteral(bool* ok); | 521 ExpressionT ParseObjectLiteral(bool* ok); |
| 522 ObjectLiteralPropertyT ParsePropertyDefinition( | 522 ObjectLiteralPropertyT ParsePropertyDefinition( |
| 523 ObjectLiteralCheckerBase* checker, bool in_class, bool is_static, | 523 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 524 bool* is_computed_name, bool* has_seen_constructor, bool* ok); | 524 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
| 525 bool* ok); |
| 525 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 526 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| 526 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 527 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 527 ExpressionT ParseYieldExpression(bool* ok); | 528 ExpressionT ParseYieldExpression(bool* ok); |
| 528 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 529 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 529 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 530 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 530 ExpressionT ParseUnaryExpression(bool* ok); | 531 ExpressionT ParseUnaryExpression(bool* ok); |
| 531 ExpressionT ParsePostfixExpression(bool* ok); | 532 ExpressionT ParsePostfixExpression(bool* ok); |
| 532 ExpressionT ParseLeftHandSideExpression(bool* ok); | 533 ExpressionT ParseLeftHandSideExpression(bool* ok); |
| 533 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 534 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
| 534 ExpressionT ParseMemberExpression(bool* ok); | 535 ExpressionT ParseMemberExpression(bool* ok); |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 return PreParserExpression::Default(); | 1309 return PreParserExpression::Default(); |
| 1309 } | 1310 } |
| 1310 PreParserExpression NewThrowSyntaxError( | 1311 PreParserExpression NewThrowSyntaxError( |
| 1311 const char* type, Handle<Object> arg, int pos) { | 1312 const char* type, Handle<Object> arg, int pos) { |
| 1312 return PreParserExpression::Default(); | 1313 return PreParserExpression::Default(); |
| 1313 } | 1314 } |
| 1314 PreParserExpression NewThrowTypeError( | 1315 PreParserExpression NewThrowTypeError( |
| 1315 const char* type, Handle<Object> arg, int pos) { | 1316 const char* type, Handle<Object> arg, int pos) { |
| 1316 return PreParserExpression::Default(); | 1317 return PreParserExpression::Default(); |
| 1317 } | 1318 } |
| 1318 PreParserScope NewScope(PreParserScope* outer_scope, ScopeType scope_type) { | 1319 PreParserScope NewScope(PreParserScope* outer_scope, ScopeType scope_type, |
| 1320 FunctionKind kind = kNormalFunction) { |
| 1319 return PreParserScope(outer_scope, scope_type); | 1321 return PreParserScope(outer_scope, scope_type); |
| 1320 } | 1322 } |
| 1321 | 1323 |
| 1322 // Reporting errors. | 1324 // Reporting errors. |
| 1323 void ReportMessageAt(Scanner::Location location, | 1325 void ReportMessageAt(Scanner::Location location, |
| 1324 const char* message, | 1326 const char* message, |
| 1325 const char* arg = NULL, | 1327 const char* arg = NULL, |
| 1326 bool is_reference_error = false); | 1328 bool is_reference_error = false); |
| 1327 void ReportMessageAt(int start_pos, | 1329 void ReportMessageAt(int start_pos, |
| 1328 int end_pos, | 1330 int end_pos, |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2075 uint32_t index; | 2077 uint32_t index; |
| 2076 return this->IsArrayIndex(*name, &index) | 2078 return this->IsArrayIndex(*name, &index) |
| 2077 ? factory()->NewNumberLiteral(index, pos) | 2079 ? factory()->NewNumberLiteral(index, pos) |
| 2078 : factory()->NewStringLiteral(*name, pos); | 2080 : factory()->NewStringLiteral(*name, pos); |
| 2079 } | 2081 } |
| 2080 | 2082 |
| 2081 | 2083 |
| 2082 template <class Traits> | 2084 template <class Traits> |
| 2083 typename ParserBase<Traits>::ObjectLiteralPropertyT | 2085 typename ParserBase<Traits>::ObjectLiteralPropertyT |
| 2084 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker, | 2086 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker, |
| 2085 bool in_class, bool is_static, | 2087 bool in_class, bool has_extends, |
| 2088 bool is_static, |
| 2086 bool* is_computed_name, | 2089 bool* is_computed_name, |
| 2087 bool* has_seen_constructor, | 2090 bool* has_seen_constructor, |
| 2088 bool* ok) { | 2091 bool* ok) { |
| 2089 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); | 2092 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); |
| 2090 ExpressionT value = this->EmptyExpression(); | 2093 ExpressionT value = this->EmptyExpression(); |
| 2091 IdentifierT name = this->EmptyIdentifier(); | 2094 IdentifierT name = this->EmptyIdentifier(); |
| 2092 bool is_get = false; | 2095 bool is_get = false; |
| 2093 bool is_set = false; | 2096 bool is_set = false; |
| 2094 bool name_is_static = false; | 2097 bool name_is_static = false; |
| 2095 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | 2098 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2122 checker->CheckProperty(name_token, kMethodProperty, is_static, | 2125 checker->CheckProperty(name_token, kMethodProperty, is_static, |
| 2123 is_generator, | 2126 is_generator, |
| 2124 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2127 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2125 } | 2128 } |
| 2126 | 2129 |
| 2127 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 2130 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
| 2128 : FunctionKind::kConciseMethod; | 2131 : FunctionKind::kConciseMethod; |
| 2129 | 2132 |
| 2130 if (in_class && !is_static && this->IsConstructor(name)) { | 2133 if (in_class && !is_static && this->IsConstructor(name)) { |
| 2131 *has_seen_constructor = true; | 2134 *has_seen_constructor = true; |
| 2132 kind = FunctionKind::kNormalFunction; | 2135 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 2136 : FunctionKind::kNormalFunction; |
| 2133 } | 2137 } |
| 2134 | 2138 |
| 2135 value = this->ParseFunctionLiteral( | 2139 value = this->ParseFunctionLiteral( |
| 2136 name, scanner()->location(), | 2140 name, scanner()->location(), |
| 2137 false, // reserved words are allowed here | 2141 false, // reserved words are allowed here |
| 2138 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 2142 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 2139 FunctionLiteral::NORMAL_ARITY, | 2143 FunctionLiteral::NORMAL_ARITY, |
| 2140 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2144 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2141 | 2145 |
| 2142 return factory()->NewObjectLiteralProperty(name_expression, value, | 2146 return factory()->NewObjectLiteralProperty(name_expression, value, |
| 2143 ObjectLiteralProperty::COMPUTED, | 2147 ObjectLiteralProperty::COMPUTED, |
| 2144 is_static, *is_computed_name); | 2148 is_static, *is_computed_name); |
| 2145 | 2149 |
| 2146 } else if (in_class && name_is_static && !is_static) { | 2150 } else if (in_class && name_is_static && !is_static) { |
| 2147 // static MethodDefinition | 2151 // static MethodDefinition |
| 2148 return ParsePropertyDefinition(checker, true, true, is_computed_name, | 2152 return ParsePropertyDefinition(checker, true, has_extends, true, |
| 2149 nullptr, ok); | 2153 is_computed_name, nullptr, ok); |
| 2150 | |
| 2151 } else if (is_get || is_set) { | 2154 } else if (is_get || is_set) { |
| 2152 // Accessor | 2155 // Accessor |
| 2153 name = this->EmptyIdentifier(); | 2156 name = this->EmptyIdentifier(); |
| 2154 bool dont_care = false; | 2157 bool dont_care = false; |
| 2155 name_token = peek(); | 2158 name_token = peek(); |
| 2156 | 2159 |
| 2157 name_expression = ParsePropertyName( | 2160 name_expression = ParsePropertyName( |
| 2158 &name, &dont_care, &dont_care, &dont_care, is_computed_name, | 2161 &name, &dont_care, &dont_care, &dont_care, is_computed_name, |
| 2159 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2162 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2160 | 2163 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 bool has_computed_names = false; | 2223 bool has_computed_names = false; |
| 2221 ObjectLiteralChecker checker(this); | 2224 ObjectLiteralChecker checker(this); |
| 2222 | 2225 |
| 2223 Expect(Token::LBRACE, CHECK_OK); | 2226 Expect(Token::LBRACE, CHECK_OK); |
| 2224 | 2227 |
| 2225 while (peek() != Token::RBRACE) { | 2228 while (peek() != Token::RBRACE) { |
| 2226 if (fni_ != nullptr) fni_->Enter(); | 2229 if (fni_ != nullptr) fni_->Enter(); |
| 2227 | 2230 |
| 2228 const bool in_class = false; | 2231 const bool in_class = false; |
| 2229 const bool is_static = false; | 2232 const bool is_static = false; |
| 2233 const bool has_extends = false; |
| 2230 bool is_computed_name = false; | 2234 bool is_computed_name = false; |
| 2231 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 2235 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
| 2232 &checker, in_class, is_static, &is_computed_name, nullptr, CHECK_OK); | 2236 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, |
| 2237 CHECK_OK); |
| 2233 | 2238 |
| 2234 if (is_computed_name) { | 2239 if (is_computed_name) { |
| 2235 has_computed_names = true; | 2240 has_computed_names = true; |
| 2236 } | 2241 } |
| 2237 | 2242 |
| 2238 // Mark top-level object literals that contain function literals and | 2243 // Mark top-level object literals that contain function literals and |
| 2239 // pretenure the literal so it can be added as a constant function | 2244 // pretenure the literal so it can be added as a constant function |
| 2240 // property. (Parser only.) | 2245 // property. (Parser only.) |
| 2241 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, | 2246 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, |
| 2242 &has_function); | 2247 &has_function); |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3068 *ok = false; | 3073 *ok = false; |
| 3069 return; | 3074 return; |
| 3070 } | 3075 } |
| 3071 has_seen_constructor_ = true; | 3076 has_seen_constructor_ = true; |
| 3072 return; | 3077 return; |
| 3073 } | 3078 } |
| 3074 } | 3079 } |
| 3075 } } // v8::internal | 3080 } } // v8::internal |
| 3076 | 3081 |
| 3077 #endif // V8_PREPARSER_H | 3082 #endif // V8_PREPARSER_H |
| OLD | NEW |