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

Side by Side Diff: src/preparser.h

Issue 873823003: Move object literal checking into checker classes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix assert Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/ppc/full-codegen-ppc.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 kAllowEvalOrArguments, 154 kAllowEvalOrArguments,
155 kDontAllowEvalOrArguments 155 kDontAllowEvalOrArguments
156 }; 156 };
157 157
158 enum Mode { 158 enum Mode {
159 PARSE_LAZILY, 159 PARSE_LAZILY,
160 PARSE_EAGERLY 160 PARSE_EAGERLY
161 }; 161 };
162 162
163 class Checkpoint; 163 class Checkpoint;
164 class ObjectLiteralChecker; 164 class ObjectLiteralCheckerBase;
165 165
166 // --------------------------------------------------------------------------- 166 // ---------------------------------------------------------------------------
167 // FunctionState and BlockState together implement the parser's scope stack. 167 // FunctionState and BlockState together implement the parser's scope stack.
168 // The parser's current scope is in scope_. BlockState and FunctionState 168 // The parser's current scope is in scope_. BlockState and FunctionState
169 // constructors push on the scope stack and the destructors pop. They are also 169 // constructors push on the scope stack and the destructors pop. They are also
170 // used to hold the parser's per-function and per-block state. 170 // used to hold the parser's per-function and per-block state.
171 class BlockState BASE_EMBEDDED { 171 class BlockState BASE_EMBEDDED {
172 public: 172 public:
173 BlockState(typename Traits::Type::Scope** scope_stack, 173 BlockState(typename Traits::Type::Scope** scope_stack,
174 typename Traits::Type::Scope* scope) 174 typename Traits::Type::Scope* scope)
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 505
506 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); 506 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok);
507 507
508 ExpressionT ParsePrimaryExpression(bool* ok); 508 ExpressionT ParsePrimaryExpression(bool* ok);
509 ExpressionT ParseExpression(bool accept_IN, bool* ok); 509 ExpressionT ParseExpression(bool accept_IN, bool* ok);
510 ExpressionT ParseArrayLiteral(bool* ok); 510 ExpressionT ParseArrayLiteral(bool* ok);
511 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, 511 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set,
512 bool* is_static, bool* is_computed_name, 512 bool* is_static, bool* is_computed_name,
513 bool* ok); 513 bool* ok);
514 ExpressionT ParseObjectLiteral(bool* ok); 514 ExpressionT ParseObjectLiteral(bool* ok);
515 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, 515 ObjectLiteralPropertyT ParsePropertyDefinition(
516 bool in_class, bool is_static, 516 ObjectLiteralCheckerBase* checker, bool in_class, bool is_static,
517 bool* is_computed_name, 517 bool* is_computed_name, bool* has_seen_constructor, bool* ok);
518 bool* has_seen_constructor,
519 bool* ok);
520 typename Traits::Type::ExpressionList ParseArguments(bool* ok); 518 typename Traits::Type::ExpressionList ParseArguments(bool* ok);
521 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); 519 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok);
522 ExpressionT ParseYieldExpression(bool* ok); 520 ExpressionT ParseYieldExpression(bool* ok);
523 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); 521 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok);
524 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 522 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
525 ExpressionT ParseUnaryExpression(bool* ok); 523 ExpressionT ParseUnaryExpression(bool* ok);
526 ExpressionT ParsePostfixExpression(bool* ok); 524 ExpressionT ParsePostfixExpression(bool* ok);
527 ExpressionT ParseLeftHandSideExpression(bool* ok); 525 ExpressionT ParseLeftHandSideExpression(bool* ok);
528 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); 526 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok);
529 ExpressionT ParseMemberExpression(bool* ok); 527 ExpressionT ParseMemberExpression(bool* ok);
530 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 528 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
531 bool* ok); 529 bool* ok);
532 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, 530 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast,
533 bool* ok); 531 bool* ok);
534 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); 532 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
535 void AddTemplateExpression(ExpressionT); 533 void AddTemplateExpression(ExpressionT);
536 534
537 // Checks if the expression is a valid reference expression (e.g., on the 535 // Checks if the expression is a valid reference expression (e.g., on the
538 // left-hand side of assignments). Although ruled out by ECMA as early errors, 536 // left-hand side of assignments). Although ruled out by ECMA as early errors,
539 // we allow calls for web compatibility and rewrite them to a runtime throw. 537 // we allow calls for web compatibility and rewrite them to a runtime throw.
540 ExpressionT CheckAndRewriteReferenceExpression( 538 ExpressionT CheckAndRewriteReferenceExpression(
541 ExpressionT expression, 539 ExpressionT expression,
542 Scanner::Location location, const char* message, bool* ok); 540 Scanner::Location location, const char* message, bool* ok);
543 541
544 // Used to detect duplicates in object literals. Each of the values 542 // Used to validate property names in object literals and class literals
545 // kGetterProperty, kSetterProperty and kValueProperty represents
546 // a type of object literal property. When parsing a property, its
547 // type value is stored in the DuplicateFinder for the property name.
548 // Values are chosen so that having intersection bits means the there is
549 // an incompatibility.
550 // I.e., you can add a getter to a property that already has a setter, since
551 // kGetterProperty and kSetterProperty doesn't intersect, but not if it
552 // already has a getter or a value. Adding the getter to an existing
553 // setter will store the value (kGetterProperty | kSetterProperty), which
554 // is incompatible with adding any further properties.
555 enum PropertyKind { 543 enum PropertyKind {
556 kNone = 0, 544 kAccessorProperty,
557 // Bit patterns representing different object literal property types. 545 kValueProperty,
558 kGetterProperty = 1, 546 kMethodProperty
559 kSetterProperty = 2,
560 kValueProperty = 7,
561 // Helper constants.
562 kValueFlag = 4
563 }; 547 };
564 548
565 // Validation per ECMA 262 - 11.1.5 "Object Initializer". 549 class ObjectLiteralCheckerBase {
566 class ObjectLiteralChecker {
567 public: 550 public:
568 ObjectLiteralChecker(ParserBase* parser, StrictMode strict_mode) 551 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {}
569 : parser_(parser),
570 finder_(scanner()->unicode_cache()),
571 strict_mode_(strict_mode) {}
572 552
573 void CheckProperty(Token::Value property, PropertyKind type, bool* ok); 553 virtual void CheckProperty(Token::Value property, PropertyKind type,
554 bool is_static, bool is_generator, bool* ok) = 0;
574 555
575 private: 556 virtual ~ObjectLiteralCheckerBase() {}
557
558 protected:
576 ParserBase* parser() const { return parser_; } 559 ParserBase* parser() const { return parser_; }
577 Scanner* scanner() const { return parser_->scanner(); } 560 Scanner* scanner() const { return parser_->scanner(); }
578 561
579 // Checks the type of conflict based on values coming from PropertyType. 562 private:
580 bool HasConflict(PropertyKind type1, PropertyKind type2) { 563 ParserBase* parser_;
581 return (type1 & type2) != 0; 564 };
565
566 // Validation per ES6 object literals.
567 class ObjectLiteralChecker : public ObjectLiteralCheckerBase {
568 public:
569 explicit ObjectLiteralChecker(ParserBase* parser)
570 : ObjectLiteralCheckerBase(parser), has_seen_proto_(false) {}
571
572 void CheckProperty(Token::Value property, PropertyKind type, bool is_static,
573 bool is_generator, bool* ok) OVERRIDE;
574
575 private:
576 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); }
577
578 bool has_seen_proto_;
579 };
580
581 // Validation per ES6 class literals.
582 class ClassLiteralChecker : public ObjectLiteralCheckerBase {
583 public:
584 explicit ClassLiteralChecker(ParserBase* parser)
585 : ObjectLiteralCheckerBase(parser), has_seen_constructor_(false) {}
586
587 void CheckProperty(Token::Value property, PropertyKind type, bool is_static,
588 bool is_generator, bool* ok) OVERRIDE;
589
590 private:
591 bool IsConstructor() {
592 return this->scanner()->LiteralMatches("constructor", 11);
582 } 593 }
583 bool IsDataDataConflict(PropertyKind type1, PropertyKind type2) { 594 bool IsPrototype() {
584 return ((type1 & type2) & kValueFlag) != 0; 595 return this->scanner()->LiteralMatches("prototype", 9);
585 }
586 bool IsDataAccessorConflict(PropertyKind type1, PropertyKind type2) {
587 return ((type1 ^ type2) & kValueFlag) != 0;
588 }
589 bool IsAccessorAccessorConflict(PropertyKind type1, PropertyKind type2) {
590 return ((type1 | type2) & kValueFlag) == 0;
591 } 596 }
592 597
593 ParserBase* parser_; 598 bool has_seen_constructor_;
594 DuplicateFinder finder_;
595 StrictMode strict_mode_;
596 }; 599 };
597 600
598 // If true, the next (and immediately following) function literal is 601 // If true, the next (and immediately following) function literal is
599 // preceded by a parenthesis. 602 // preceded by a parenthesis.
600 // Heuristically that means that the function will be called immediately, 603 // Heuristically that means that the function will be called immediately,
601 // so never lazily compile it. 604 // so never lazily compile it.
602 bool parenthesized_function_; 605 bool parenthesized_function_;
603 606
604 typename Traits::Type::Scope* scope_; // Scope stack. 607 typename Traits::Type::Scope* scope_; // Scope stack.
605 FunctionState* function_state_; // Function state stack. 608 FunctionState* function_state_; // Function state stack.
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2066
2064 uint32_t index; 2067 uint32_t index;
2065 return this->IsArrayIndex(*name, &index) 2068 return this->IsArrayIndex(*name, &index)
2066 ? factory()->NewNumberLiteral(index, pos) 2069 ? factory()->NewNumberLiteral(index, pos)
2067 : factory()->NewStringLiteral(*name, pos); 2070 : factory()->NewStringLiteral(*name, pos);
2068 } 2071 }
2069 2072
2070 2073
2071 template <class Traits> 2074 template <class Traits>
2072 typename ParserBase<Traits>::ObjectLiteralPropertyT 2075 typename ParserBase<Traits>::ObjectLiteralPropertyT
2073 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, 2076 ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker,
2074 bool in_class, bool is_static, 2077 bool in_class, bool is_static,
2075 bool* is_computed_name, 2078 bool* is_computed_name,
2076 bool* has_seen_constructor, 2079 bool* has_seen_constructor,
2077 bool* ok) { 2080 bool* ok) {
2078 DCHECK(!in_class || is_static || has_seen_constructor != NULL); 2081 DCHECK(!in_class || is_static || has_seen_constructor != nullptr);
2079 ExpressionT value = this->EmptyExpression(); 2082 ExpressionT value = this->EmptyExpression();
2080 IdentifierT name = this->EmptyIdentifier(); 2083 IdentifierT name = this->EmptyIdentifier();
2081 bool is_get = false; 2084 bool is_get = false;
2082 bool is_set = false; 2085 bool is_set = false;
2083 bool name_is_static = false; 2086 bool name_is_static = false;
2084 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); 2087 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL);
2085 2088
2086 Token::Value name_token = peek(); 2089 Token::Value name_token = peek();
2087 int next_pos = peek_position(); 2090 int next_pos = peek_position();
2088 ExpressionT name_expression = ParsePropertyName( 2091 ExpressionT name_expression = ParsePropertyName(
2089 &name, &is_get, &is_set, &name_is_static, is_computed_name, 2092 &name, &is_get, &is_set, &name_is_static, is_computed_name,
2090 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2093 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2091 2094
2092 if (fni_ != NULL && !*is_computed_name) { 2095 if (fni_ != nullptr && !*is_computed_name) {
2093 this->PushLiteralName(fni_, name); 2096 this->PushLiteralName(fni_, name);
2094 } 2097 }
2095 2098
2096 if (!in_class && !is_generator && peek() == Token::COLON) { 2099 if (!in_class && !is_generator && peek() == Token::COLON) {
2097 // PropertyDefinition : PropertyName ':' AssignmentExpression 2100 // PropertyDefinition : PropertyName ':' AssignmentExpression
2098 if (!*is_computed_name && checker != NULL) { 2101 if (!*is_computed_name) {
2099 checker->CheckProperty(name_token, kValueProperty, 2102 checker->CheckProperty(name_token, kValueProperty, is_static,
2103 is_generator,
2100 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2104 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2101 } 2105 }
2102 Consume(Token::COLON); 2106 Consume(Token::COLON);
2103 value = this->ParseAssignmentExpression( 2107 value = this->ParseAssignmentExpression(
2104 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2108 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2105 2109
2106 } else if (is_generator || 2110 } else if (is_generator ||
2107 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { 2111 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) {
2108 // Concise Method 2112 // Concise Method
2109 2113 if (!*is_computed_name) {
2110 if (is_static && this->IsPrototype(name)) { 2114 checker->CheckProperty(name_token, kMethodProperty, is_static,
2111 ReportMessageAt(scanner()->location(), "static_prototype"); 2115 is_generator,
2112 *ok = false; 2116 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2113 return this->EmptyObjectLiteralProperty();
2114 } 2117 }
2115 2118
2116 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod 2119 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod
2117 : FunctionKind::kConciseMethod; 2120 : FunctionKind::kConciseMethod;
2118 2121
2119 if (in_class && !is_static && this->IsConstructor(name)) { 2122 if (in_class && !is_static && this->IsConstructor(name)) {
2120 if (is_generator) {
2121 ReportMessageAt(scanner()->location(), "constructor_special_method");
2122 *ok = false;
2123 return this->EmptyObjectLiteralProperty();
2124 }
2125
2126 if (*has_seen_constructor) {
2127 ReportMessageAt(scanner()->location(), "duplicate_constructor");
2128 *ok = false;
2129 return this->EmptyObjectLiteralProperty();
2130 }
2131
2132 *has_seen_constructor = true; 2123 *has_seen_constructor = true;
2133 kind = FunctionKind::kNormalFunction; 2124 kind = FunctionKind::kNormalFunction;
2134 } 2125 }
2135 2126
2136 if (!*is_computed_name && checker != NULL) {
2137 checker->CheckProperty(name_token, kValueProperty,
2138 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2139 }
2140
2141 value = this->ParseFunctionLiteral( 2127 value = this->ParseFunctionLiteral(
2142 name, scanner()->location(), 2128 name, scanner()->location(),
2143 false, // reserved words are allowed here 2129 false, // reserved words are allowed here
2144 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, 2130 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION,
2145 FunctionLiteral::NORMAL_ARITY, 2131 FunctionLiteral::NORMAL_ARITY,
2146 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2132 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2147 2133
2148 return factory()->NewObjectLiteralProperty(name_expression, value, 2134 return factory()->NewObjectLiteralProperty(name_expression, value,
2149 ObjectLiteralProperty::COMPUTED, 2135 ObjectLiteralProperty::COMPUTED,
2150 is_static, *is_computed_name); 2136 is_static, *is_computed_name);
2151 2137
2152 } else if (in_class && name_is_static && !is_static) { 2138 } else if (in_class && name_is_static && !is_static) {
2153 // static MethodDefinition 2139 // static MethodDefinition
2154 return ParsePropertyDefinition(checker, true, true, is_computed_name, NULL, 2140 return ParsePropertyDefinition(checker, true, true, is_computed_name,
2155 ok); 2141 nullptr, ok);
2156 2142
2157 } else if (is_get || is_set) { 2143 } else if (is_get || is_set) {
2158 // Accessor 2144 // Accessor
2159 name = this->EmptyIdentifier(); 2145 name = this->EmptyIdentifier();
2160 bool dont_care = false; 2146 bool dont_care = false;
2161 name_token = peek(); 2147 name_token = peek();
2162 2148
2163 name_expression = ParsePropertyName( 2149 name_expression = ParsePropertyName(
2164 &name, &dont_care, &dont_care, &dont_care, is_computed_name, 2150 &name, &dont_care, &dont_care, &dont_care, is_computed_name,
2165 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2151 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2166 2152
2167 // Validate the property. 2153 if (!*is_computed_name) {
2168 if (is_static && this->IsPrototype(name)) { 2154 checker->CheckProperty(name_token, kAccessorProperty, is_static,
2169 ReportMessageAt(scanner()->location(), "static_prototype"); 2155 is_generator,
2170 *ok = false;
2171 return this->EmptyObjectLiteralProperty();
2172 } else if (in_class && !is_static && this->IsConstructor(name)) {
2173 ReportMessageAt(scanner()->location(), "constructor_special_method");
2174 *ok = false;
2175 return this->EmptyObjectLiteralProperty();
2176 }
2177 if (!*is_computed_name && checker != NULL) {
2178 checker->CheckProperty(name_token,
2179 is_get ? kGetterProperty : kSetterProperty,
2180 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2156 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2181 } 2157 }
2182 2158
2183 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( 2159 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral(
2184 name, scanner()->location(), 2160 name, scanner()->location(),
2185 false, // reserved words are allowed here 2161 false, // reserved words are allowed here
2186 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, 2162 FunctionKind::kNormalFunction, RelocInfo::kNoPosition,
2187 FunctionLiteral::ANONYMOUS_EXPRESSION, 2163 FunctionLiteral::ANONYMOUS_EXPRESSION,
2188 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, 2164 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY,
2189 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2165 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 bool* ok) { 2203 bool* ok) {
2228 // ObjectLiteral :: 2204 // ObjectLiteral ::
2229 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2205 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2230 2206
2231 int pos = peek_position(); 2207 int pos = peek_position();
2232 typename Traits::Type::PropertyList properties = 2208 typename Traits::Type::PropertyList properties =
2233 this->NewPropertyList(4, zone_); 2209 this->NewPropertyList(4, zone_);
2234 int number_of_boilerplate_properties = 0; 2210 int number_of_boilerplate_properties = 0;
2235 bool has_function = false; 2211 bool has_function = false;
2236 bool has_computed_names = false; 2212 bool has_computed_names = false;
2237 2213 ObjectLiteralChecker checker(this);
2238 ObjectLiteralChecker checker(this, strict_mode());
2239 2214
2240 Expect(Token::LBRACE, CHECK_OK); 2215 Expect(Token::LBRACE, CHECK_OK);
2241 2216
2242 while (peek() != Token::RBRACE) { 2217 while (peek() != Token::RBRACE) {
2243 if (fni_ != NULL) fni_->Enter(); 2218 if (fni_ != nullptr) fni_->Enter();
2244 2219
2245 const bool in_class = false; 2220 const bool in_class = false;
2246 const bool is_static = false; 2221 const bool is_static = false;
2247 bool is_computed_name = false; 2222 bool is_computed_name = false;
2248 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2223 ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
2249 &checker, in_class, is_static, &is_computed_name, NULL, CHECK_OK); 2224 &checker, in_class, is_static, &is_computed_name, nullptr, CHECK_OK);
2250 2225
2251 if (is_computed_name) { 2226 if (is_computed_name) {
2252 has_computed_names = true; 2227 has_computed_names = true;
2253 } 2228 }
2254 2229
2255 // Mark top-level object literals that contain function literals and 2230 // Mark top-level object literals that contain function literals and
2256 // 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
2257 // property. (Parser only.) 2232 // property. (Parser only.)
2258 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, 2233 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property,
2259 &has_function); 2234 &has_function);
2260 2235
2261 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 2236 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
2262 if (!has_computed_names && this->IsBoilerplateProperty(property)) { 2237 if (!has_computed_names && this->IsBoilerplateProperty(property)) {
2263 number_of_boilerplate_properties++; 2238 number_of_boilerplate_properties++;
2264 } 2239 }
2265 properties->Add(property, zone()); 2240 properties->Add(property, zone());
2266 2241
2267 if (peek() != Token::RBRACE) { 2242 if (peek() != Token::RBRACE) {
2268 // Need {} because of the CHECK_OK macro. 2243 // Need {} because of the CHECK_OK macro.
2269 Expect(Token::COMMA, CHECK_OK); 2244 Expect(Token::COMMA, CHECK_OK);
2270 } 2245 }
2271 2246
2272 if (fni_ != NULL) { 2247 if (fni_ != nullptr) {
2273 fni_->Infer(); 2248 fni_->Infer();
2274 fni_->Leave(); 2249 fni_->Leave();
2275 } 2250 }
2276 } 2251 }
2277 Expect(Token::RBRACE, CHECK_OK); 2252 Expect(Token::RBRACE, CHECK_OK);
2278 2253
2279 // Computation of literal_index must happen before pre parse bailout. 2254 // Computation of literal_index must happen before pre parse bailout.
2280 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2255 int literal_index = function_state_->NextMaterializedLiteralIndex();
2281 2256
2282 return factory()->NewObjectLiteral(properties, 2257 return factory()->NewObjectLiteral(properties,
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 } 3009 }
3035 } 3010 }
3036 3011
3037 3012
3038 #undef CHECK_OK 3013 #undef CHECK_OK
3039 #undef CHECK_OK_CUSTOM 3014 #undef CHECK_OK_CUSTOM
3040 3015
3041 3016
3042 template <typename Traits> 3017 template <typename Traits>
3043 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( 3018 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
3044 Token::Value property, PropertyKind type, bool* ok) { 3019 Token::Value property, PropertyKind type, bool is_static, bool is_generator,
3045 int old; 3020 bool* ok) {
3046 if (property == Token::NUMBER) { 3021 DCHECK(!is_static);
3047 old = scanner()->FindNumber(&finder_, type); 3022 DCHECK(!is_generator || type == kMethodProperty);
3048 } else { 3023
3049 old = scanner()->FindSymbol(&finder_, type); 3024 if (property == Token::NUMBER) return;
3025
3026 if (type == kValueProperty && IsProto()) {
3027 if (has_seen_proto_) {
3028 this->parser()->ReportMessage("duplicate_proto");
3029 *ok = false;
3030 return;
3031 }
3032 has_seen_proto_ = true;
3033 return;
3050 } 3034 }
3051 PropertyKind old_type = static_cast<PropertyKind>(old); 3035 }
3052 if (HasConflict(old_type, type)) { 3036
3053 if (IsDataDataConflict(old_type, type)) { 3037
3054 // Both are data properties. 3038 template <typename Traits>
3055 if (strict_mode_ == SLOPPY) return; 3039 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty(
3056 parser()->ReportMessage("strict_duplicate_property"); 3040 Token::Value property, PropertyKind type, bool is_static, bool is_generator,
3057 } else if (IsDataAccessorConflict(old_type, type)) { 3041 bool* ok) {
3058 // Both a data and an accessor property with the same name. 3042 DCHECK(type == kMethodProperty || type == kAccessorProperty);
3059 parser()->ReportMessage("accessor_data_property"); 3043
3060 } else { 3044 if (property == Token::NUMBER) return;
3061 DCHECK(IsAccessorAccessorConflict(old_type, type)); 3045
3062 // Both accessors of the same type. 3046 if (is_static) {
3063 parser()->ReportMessage("accessor_get_set"); 3047 if (IsPrototype()) {
3048 this->parser()->ReportMessage("static_prototype");
3049 *ok = false;
3050 return;
3064 } 3051 }
3065 *ok = false; 3052 } else if (IsConstructor()) {
3053 if (is_generator || type == kAccessorProperty) {
3054 this->parser()->ReportMessage("constructor_special_method");
3055 *ok = false;
3056 return;
3057 }
3058 if (has_seen_constructor_) {
3059 this->parser()->ReportMessage("duplicate_constructor");
3060 *ok = false;
3061 return;
3062 }
3063 has_seen_constructor_ = true;
3064 return;
3066 } 3065 }
3067 } 3066 }
3068 } } // v8::internal 3067 } } // v8::internal
3069 3068
3070 #endif // V8_PREPARSER_H 3069 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/ppc/full-codegen-ppc.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698