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

Side by Side Diff: src/parser.cc

Issue 8423005: Remove some unnecessary binding initialization checks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/scopeinfo.h » ('j') | src/scopes.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 // the caller's scope so we declare all locals, too. 1378 // the caller's scope so we declare all locals, too.
1379 // Also for block scoped let/const bindings the variable can be 1379 // Also for block scoped let/const bindings the variable can be
1380 // statically declared. 1380 // statically declared.
1381 if (declaration_scope->is_function_scope() || 1381 if (declaration_scope->is_function_scope() ||
1382 declaration_scope->is_strict_mode_eval_scope() || 1382 declaration_scope->is_strict_mode_eval_scope() ||
1383 declaration_scope->is_block_scope()) { 1383 declaration_scope->is_block_scope()) {
1384 // Declare the variable in the function scope. 1384 // Declare the variable in the function scope.
1385 var = declaration_scope->LocalLookup(name); 1385 var = declaration_scope->LocalLookup(name);
1386 if (var == NULL) { 1386 if (var == NULL) {
1387 // Declare the name. 1387 // Declare the name.
1388 var = declaration_scope->DeclareLocal(name, mode); 1388 InitializationFlag init_flag = (fun != NULL || mode == VAR)
1389 ? CREATED_INITIALIZED : NEEDS_INITIALIZATION;
1390 var = declaration_scope->DeclareLocal(name, mode, init_flag);
1389 } else { 1391 } else {
1390 // The name was declared in this scope before; check for conflicting 1392 // The name was declared in this scope before; check for conflicting
1391 // re-declarations. We have a conflict if either of the declarations is 1393 // re-declarations. We have a conflict if either of the declarations is
1392 // not a var. There is similar code in runtime.cc in the Declare 1394 // not a var. There is similar code in runtime.cc in the Declare
1393 // functions. The function CheckNonConflictingScope checks for conflicting 1395 // functions. The function CheckNonConflictingScope checks for conflicting
1394 // var and let bindings from different scopes whereas this is a check for 1396 // var and let bindings from different scopes whereas this is a check for
1395 // conflicting declarations within the same scope. This check also covers 1397 // conflicting declarations within the same scope. This check also covers
1396 // 1398 //
1397 // function () { let x; { var x; } } 1399 // function () { let x; { var x; } }
1398 // 1400 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 VariableProxy* proxy = declaration_scope->NewUnresolved( 1447 VariableProxy* proxy = declaration_scope->NewUnresolved(
1446 name, scanner().location().beg_pos); 1448 name, scanner().location().beg_pos);
1447 declaration_scope->AddDeclaration( 1449 declaration_scope->AddDeclaration(
1448 new(zone()) Declaration(proxy, mode, fun, top_scope_)); 1450 new(zone()) Declaration(proxy, mode, fun, top_scope_));
1449 1451
1450 // For global const variables we bind the proxy to a variable. 1452 // For global const variables we bind the proxy to a variable.
1451 if ((mode == CONST || mode == CONST_HARMONY) && 1453 if ((mode == CONST || mode == CONST_HARMONY) &&
1452 declaration_scope->is_global_scope()) { 1454 declaration_scope->is_global_scope()) {
1453 ASSERT(resolve); // should be set by all callers 1455 ASSERT(resolve); // should be set by all callers
1454 Variable::Kind kind = Variable::NORMAL; 1456 Variable::Kind kind = Variable::NORMAL;
1455 var = new(zone()) Variable(declaration_scope, name, CONST, true, kind); 1457 var = new(zone()) Variable(declaration_scope,
1458 name,
1459 CONST,
1460 true,
1461 kind,
1462 NEEDS_INITIALIZATION);
1456 } 1463 }
1457 1464
1458 // If requested and we have a local variable, bind the proxy to the variable 1465 // If requested and we have a local variable, bind the proxy to the variable
1459 // at parse-time. This is used for functions (and consts) declared inside 1466 // at parse-time. This is used for functions (and consts) declared inside
1460 // statements: the corresponding function (or const) variable must be in the 1467 // statements: the corresponding function (or const) variable must be in the
1461 // function scope and not a statement-local scope, e.g. as provided with a 1468 // function scope and not a statement-local scope, e.g. as provided with a
1462 // 'with' statement: 1469 // 'with' statement:
1463 // 1470 //
1464 // with (obj) { 1471 // with (obj) {
1465 // function f() {} 1472 // function f() {}
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); 2283 ReportMessage("strict_catch_variable", Vector<const char*>::empty());
2277 *ok = false; 2284 *ok = false;
2278 return NULL; 2285 return NULL;
2279 } 2286 }
2280 2287
2281 Expect(Token::RPAREN, CHECK_OK); 2288 Expect(Token::RPAREN, CHECK_OK);
2282 2289
2283 if (peek() == Token::LBRACE) { 2290 if (peek() == Token::LBRACE) {
2284 Target target(&this->target_stack_, &catch_collector); 2291 Target target(&this->target_stack_, &catch_collector);
2285 VariableMode mode = harmony_scoping_ ? LET : VAR; 2292 VariableMode mode = harmony_scoping_ ? LET : VAR;
2286 catch_variable = catch_scope->DeclareLocal(name, mode); 2293 catch_variable =
2294 catch_scope->DeclareLocal(name, mode, CREATED_INITIALIZED);
2287 2295
2288 SaveScope save_scope(this, catch_scope); 2296 SaveScope save_scope(this, catch_scope);
2289 catch_block = ParseBlock(NULL, CHECK_OK); 2297 catch_block = ParseBlock(NULL, CHECK_OK);
2290 } else { 2298 } else {
2291 Expect(Token::LBRACE, CHECK_OK); 2299 Expect(Token::LBRACE, CHECK_OK);
2292 } 2300 }
2293 catch_scope->set_end_position(scanner().location().end_pos); 2301 catch_scope->set_end_position(scanner().location().end_pos);
2294 tok = peek(); 2302 tok = peek();
2295 } 2303 }
2296 2304
(...skipping 3113 matching lines...) Expand 10 before | Expand all | Expand 10 after
5410 result = parser.ParseProgram(source, 5418 result = parser.ParseProgram(source,
5411 info->is_global(), 5419 info->is_global(),
5412 info->strict_mode_flag()); 5420 info->strict_mode_flag());
5413 } 5421 }
5414 } 5422 }
5415 info->SetFunction(result); 5423 info->SetFunction(result);
5416 return (result != NULL); 5424 return (result != NULL);
5417 } 5425 }
5418 5426
5419 } } // namespace v8::internal 5427 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/scopeinfo.h » ('j') | src/scopes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698