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

Side by Side Diff: src/preparser.h

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

Powered by Google App Engine
This is Rietveld 408576698