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

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: 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') | src/preparser.cc » ('J')
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, 2884 bool Parser::CheckInOrOf(bool accept_OF,
marja 2015/02/19 12:34:22 ... could you move CheckInOrOf to ParserBase, seem
rossberg 2015/02/19 13:23:05 Done.
2885 ForEachStatement::VisitMode* visit_mode) { 2885 ForEachStatement::VisitMode* visit_mode, bool* ok) {
2886 if (Check(Token::IN)) { 2886 if (Check(Token::IN)) {
2887 *visit_mode = ForEachStatement::ENUMERATE; 2887 if (is_strong(language_mode())) {
2888 ReportMessageAt(scanner()->location(), "strong_for_in");
2889 *ok = false;
2890 } else {
2891 *visit_mode = ForEachStatement::ENUMERATE;
2892 }
2888 return true; 2893 return true;
2889 } else if (accept_OF && CheckContextualKeyword(CStrVector("of"))) { 2894 } else if (accept_OF && CheckContextualKeyword(CStrVector("of"))) {
2890 *visit_mode = ForEachStatement::ITERATE; 2895 *visit_mode = ForEachStatement::ITERATE;
2891 return true; 2896 return true;
2892 } 2897 }
2893 return false; 2898 return false;
2894 } 2899 }
2895 2900
2896 2901
2897 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2902 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 (peek() == Token::CONST && is_sloppy(language_mode()))) { 3220 (peek() == Token::CONST && is_sloppy(language_mode()))) {
3216 const AstRawString* name = NULL; 3221 const AstRawString* name = NULL;
3217 VariableDeclarationProperties decl_props = kHasNoInitializers; 3222 VariableDeclarationProperties decl_props = kHasNoInitializers;
3218 Block* variable_statement = 3223 Block* variable_statement =
3219 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, 3224 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name,
3220 CHECK_OK); 3225 CHECK_OK);
3221 bool accept_OF = decl_props == kHasNoInitializers; 3226 bool accept_OF = decl_props == kHasNoInitializers;
3222 ForEachStatement::VisitMode mode; 3227 ForEachStatement::VisitMode mode;
3223 int each_pos = position(); 3228 int each_pos = position();
3224 3229
3225 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { 3230 if (name != NULL && CheckInOrOf(accept_OF, &mode, ok)) {
3231 if (!*ok) return nullptr;
3226 ForEachStatement* loop = 3232 ForEachStatement* loop =
3227 factory()->NewForEachStatement(mode, labels, stmt_pos); 3233 factory()->NewForEachStatement(mode, labels, stmt_pos);
3228 Target target(&this->target_stack_, loop); 3234 Target target(&this->target_stack_, loop);
3229 3235
3230 Expression* enumerable = ParseExpression(true, CHECK_OK); 3236 Expression* enumerable = ParseExpression(true, CHECK_OK);
3231 Expect(Token::RPAREN, CHECK_OK); 3237 Expect(Token::RPAREN, CHECK_OK);
3232 3238
3233 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); 3239 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos);
3234 Statement* body = ParseSubStatement(NULL, CHECK_OK); 3240 Statement* body = ParseSubStatement(NULL, CHECK_OK);
3235 InitializeForEachStatement(loop, each, enumerable, body); 3241 InitializeForEachStatement(loop, each, enumerable, body);
(...skipping 16 matching lines...) Expand all
3252 const AstRawString* name = NULL; 3258 const AstRawString* name = NULL;
3253 VariableDeclarationProperties decl_props = kHasNoInitializers; 3259 VariableDeclarationProperties decl_props = kHasNoInitializers;
3254 Block* variable_statement = 3260 Block* variable_statement =
3255 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, 3261 ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings,
3256 &name, CHECK_OK); 3262 &name, CHECK_OK);
3257 bool accept_IN = name != NULL && decl_props != kHasInitializers; 3263 bool accept_IN = name != NULL && decl_props != kHasInitializers;
3258 bool accept_OF = decl_props == kHasNoInitializers; 3264 bool accept_OF = decl_props == kHasNoInitializers;
3259 ForEachStatement::VisitMode mode; 3265 ForEachStatement::VisitMode mode;
3260 int each_pos = position(); 3266 int each_pos = position();
3261 3267
3262 if (accept_IN && CheckInOrOf(accept_OF, &mode)) { 3268 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) {
3269 if (!*ok) return nullptr;
3270
3263 // Rewrite a for-in statement of the form 3271 // Rewrite a for-in statement of the form
3264 // 3272 //
3265 // for (let/const x in e) b 3273 // for (let/const x in e) b
3266 // 3274 //
3267 // into 3275 // into
3268 // 3276 //
3269 // <let x' be a temporary variable> 3277 // <let x' be a temporary variable>
3270 // for (x' in e) { 3278 // for (x' in e) {
3271 // let/const x; 3279 // let/const x;
3272 // x = x'; 3280 // x = x';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3314 } else { 3322 } else {
3315 Scanner::Location lhs_location = scanner()->peek_location(); 3323 Scanner::Location lhs_location = scanner()->peek_location();
3316 Expression* expression = ParseExpression(false, CHECK_OK); 3324 Expression* expression = ParseExpression(false, CHECK_OK);
3317 ForEachStatement::VisitMode mode; 3325 ForEachStatement::VisitMode mode;
3318 bool accept_OF = expression->IsVariableProxy(); 3326 bool accept_OF = expression->IsVariableProxy();
3319 is_let_identifier_expression = 3327 is_let_identifier_expression =
3320 expression->IsVariableProxy() && 3328 expression->IsVariableProxy() &&
3321 expression->AsVariableProxy()->raw_name() == 3329 expression->AsVariableProxy()->raw_name() ==
3322 ast_value_factory()->let_string(); 3330 ast_value_factory()->let_string();
3323 3331
3324 if (CheckInOrOf(accept_OF, &mode)) { 3332 if (CheckInOrOf(accept_OF, &mode, ok)) {
3333 if (!*ok) return nullptr;
3325 expression = this->CheckAndRewriteReferenceExpression( 3334 expression = this->CheckAndRewriteReferenceExpression(
3326 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK); 3335 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK);
3327 3336
3328 ForEachStatement* loop = 3337 ForEachStatement* loop =
3329 factory()->NewForEachStatement(mode, labels, stmt_pos); 3338 factory()->NewForEachStatement(mode, labels, stmt_pos);
3330 Target target(&this->target_stack_, loop); 3339 Target target(&this->target_stack_, loop);
3331 3340
3332 Expression* enumerable = ParseExpression(true, CHECK_OK); 3341 Expression* enumerable = ParseExpression(true, CHECK_OK);
3333 Expect(Token::RPAREN, CHECK_OK); 3342 Expect(Token::RPAREN, CHECK_OK);
3334 3343
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5440 } else { 5449 } else {
5441 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5450 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5442 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5451 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5443 raw_string->length()); 5452 raw_string->length());
5444 } 5453 }
5445 } 5454 }
5446 5455
5447 return running_hash; 5456 return running_hash;
5448 } 5457 }
5449 } } // namespace v8::internal 5458 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698