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

Side by Side Diff: src/parser.cc

Issue 939063002: [strong] Deprecate for-in (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments 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/parser.h ('k') | src/preparser.h » ('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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 Expect(Token::LPAREN, CHECK_OK); 2874 Expect(Token::LPAREN, CHECK_OK);
2875 Expression* cond = ParseExpression(true, CHECK_OK); 2875 Expression* cond = ParseExpression(true, CHECK_OK);
2876 Expect(Token::RPAREN, CHECK_OK); 2876 Expect(Token::RPAREN, CHECK_OK);
2877 Statement* body = ParseSubStatement(NULL, CHECK_OK); 2877 Statement* body = ParseSubStatement(NULL, CHECK_OK);
2878 2878
2879 if (loop != NULL) loop->Initialize(cond, body); 2879 if (loop != NULL) loop->Initialize(cond, body);
2880 return loop; 2880 return loop;
2881 } 2881 }
2882 2882
2883 2883
2884 bool Parser::CheckInOrOf(bool accept_OF,
2885 ForEachStatement::VisitMode* visit_mode) {
2886 if (Check(Token::IN)) {
2887 *visit_mode = ForEachStatement::ENUMERATE;
2888 return true;
2889 } else if (accept_OF && CheckContextualKeyword(CStrVector("of"))) {
2890 *visit_mode = ForEachStatement::ITERATE;
2891 return true;
2892 }
2893 return false;
2894 }
2895
2896
2897 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2884 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2898 Expression* each, 2885 Expression* each,
2899 Expression* subject, 2886 Expression* subject,
2900 Statement* body) { 2887 Statement* body) {
2901 ForOfStatement* for_of = stmt->AsForOfStatement(); 2888 ForOfStatement* for_of = stmt->AsForOfStatement();
2902 2889
2903 if (for_of != NULL) { 2890 if (for_of != NULL) {
2904 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2891 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2905 ast_value_factory()->dot_iterator_string()); 2892 ast_value_factory()->dot_iterator_string());
2906 Variable* result = scope_->DeclarationScope()->NewTemporary( 2893 Variable* result = scope_->DeclarationScope()->NewTemporary(
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 (peek() == Token::CONST && is_sloppy(language_mode()))) { 3202 (peek() == Token::CONST && is_sloppy(language_mode()))) {
3216 const AstRawString* name = NULL; 3203 const AstRawString* name = NULL;
3217 VariableDeclarationProperties decl_props = kHasNoInitializers; 3204 VariableDeclarationProperties decl_props = kHasNoInitializers;
3218 Block* variable_statement = 3205 Block* variable_statement =
3219 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, 3206 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
3220 CHECK_OK); 3207 CHECK_OK);
3221 bool accept_OF = decl_props == kHasNoInitializers; 3208 bool accept_OF = decl_props == kHasNoInitializers;
3222 ForEachStatement::VisitMode mode; 3209 ForEachStatement::VisitMode mode;
3223 int each_pos = position(); 3210 int each_pos = position();
3224 3211
3225 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { 3212 if (name != NULL && CheckInOrOf(accept_OF, &mode, ok)) {
3213 if (!*ok) return nullptr;
3226 ForEachStatement* loop = 3214 ForEachStatement* loop =
3227 factory()->NewForEachStatement(mode, labels, stmt_pos); 3215 factory()->NewForEachStatement(mode, labels, stmt_pos);
3228 Target target(&this->target_stack_, loop); 3216 Target target(&this->target_stack_, loop);
3229 3217
3230 Expression* enumerable = ParseExpression(true, CHECK_OK); 3218 Expression* enumerable = ParseExpression(true, CHECK_OK);
3231 Expect(Token::RPAREN, CHECK_OK); 3219 Expect(Token::RPAREN, CHECK_OK);
3232 3220
3233 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); 3221 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos);
3234 Statement* body = ParseSubStatement(NULL, CHECK_OK); 3222 Statement* body = ParseSubStatement(NULL, CHECK_OK);
3235 InitializeForEachStatement(loop, each, enumerable, body); 3223 InitializeForEachStatement(loop, each, enumerable, body);
(...skipping 16 matching lines...) Expand all
3252 const AstRawString* name = NULL; 3240 const AstRawString* name = NULL;
3253 VariableDeclarationProperties decl_props = kHasNoInitializers; 3241 VariableDeclarationProperties decl_props = kHasNoInitializers;
3254 Block* variable_statement = 3242 Block* variable_statement =
3255 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, 3243 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings,
3256 &name, CHECK_OK); 3244 &name, CHECK_OK);
3257 bool accept_IN = name != NULL && decl_props != kHasInitializers; 3245 bool accept_IN = name != NULL && decl_props != kHasInitializers;
3258 bool accept_OF = decl_props == kHasNoInitializers; 3246 bool accept_OF = decl_props == kHasNoInitializers;
3259 ForEachStatement::VisitMode mode; 3247 ForEachStatement::VisitMode mode;
3260 int each_pos = position(); 3248 int each_pos = position();
3261 3249
3262 if (accept_IN && CheckInOrOf(accept_OF, &mode)) { 3250 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) {
3251 if (!*ok) return nullptr;
3252
3263 // Rewrite a for-in statement of the form 3253 // Rewrite a for-in statement of the form
3264 // 3254 //
3265 // for (let/const x in e) b 3255 // for (let/const x in e) b
3266 // 3256 //
3267 // into 3257 // into
3268 // 3258 //
3269 // <let x' be a temporary variable> 3259 // <let x' be a temporary variable>
3270 // for (x' in e) { 3260 // for (x' in e) {
3271 // let/const x; 3261 // let/const x;
3272 // x = x'; 3262 // x = x';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3314 } else { 3304 } else {
3315 Scanner::Location lhs_location = scanner()->peek_location(); 3305 Scanner::Location lhs_location = scanner()->peek_location();
3316 Expression* expression = ParseExpression(false, CHECK_OK); 3306 Expression* expression = ParseExpression(false, CHECK_OK);
3317 ForEachStatement::VisitMode mode; 3307 ForEachStatement::VisitMode mode;
3318 bool accept_OF = expression->IsVariableProxy(); 3308 bool accept_OF = expression->IsVariableProxy();
3319 is_let_identifier_expression = 3309 is_let_identifier_expression =
3320 expression->IsVariableProxy() && 3310 expression->IsVariableProxy() &&
3321 expression->AsVariableProxy()->raw_name() == 3311 expression->AsVariableProxy()->raw_name() ==
3322 ast_value_factory()->let_string(); 3312 ast_value_factory()->let_string();
3323 3313
3324 if (CheckInOrOf(accept_OF, &mode)) { 3314 if (CheckInOrOf(accept_OF, &mode, ok)) {
3315 if (!*ok) return nullptr;
3325 expression = this->CheckAndRewriteReferenceExpression( 3316 expression = this->CheckAndRewriteReferenceExpression(
3326 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK); 3317 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK);
3327 3318
3328 ForEachStatement* loop = 3319 ForEachStatement* loop =
3329 factory()->NewForEachStatement(mode, labels, stmt_pos); 3320 factory()->NewForEachStatement(mode, labels, stmt_pos);
3330 Target target(&this->target_stack_, loop); 3321 Target target(&this->target_stack_, loop);
3331 3322
3332 Expression* enumerable = ParseExpression(true, CHECK_OK); 3323 Expression* enumerable = ParseExpression(true, CHECK_OK);
3333 Expect(Token::RPAREN, CHECK_OK); 3324 Expect(Token::RPAREN, CHECK_OK);
3334 3325
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5440 } else { 5431 } else {
5441 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5432 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5442 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5433 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5443 raw_string->length()); 5434 raw_string->length());
5444 } 5435 }
5445 } 5436 }
5446 5437
5447 return running_hash; 5438 return running_hash;
5448 } 5439 }
5449 } } // namespace v8::internal 5440 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698