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

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 8422010: Remove some initialization checks based on source positions. (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/arm/full-codegen-arm.cc ('k') | src/parser.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 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 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 context()->Plug(eax); 1270 context()->Plug(eax);
1271 break; 1271 break;
1272 } 1272 }
1273 1273
1274 case Variable::PARAMETER: 1274 case Variable::PARAMETER:
1275 case Variable::LOCAL: 1275 case Variable::LOCAL:
1276 case Variable::CONTEXT: { 1276 case Variable::CONTEXT: {
1277 Comment cmnt(masm_, var->IsContextSlot() 1277 Comment cmnt(masm_, var->IsContextSlot()
1278 ? "Context variable" 1278 ? "Context variable"
1279 : "Stack variable"); 1279 : "Stack variable");
1280 if (!var->binding_needs_init()) { 1280 if (var->binding_needs_init()) {
1281 context()->Plug(var); 1281 // var->scope() may be NULL when the proxy is located in eval code and
1282 } else { 1282 // refers to a potential outside binding. Currently those bindings are
1283 // Let and const need a read barrier. 1283 // always looked up dynamically, i.e. in that case
1284 Label done; 1284 // var->location() == LOOKUP.
1285 GetVar(eax, var); 1285 // always holds.
1286 __ cmp(eax, isolate()->factory()->the_hole_value()); 1286 ASSERT(var->scope() != NULL);
1287 __ j(not_equal, &done, Label::kNear); 1287
1288 if (var->mode() == LET || var->mode() == CONST_HARMONY) { 1288 // Check if the binding really needs an initialization check. The check
1289 // Throw a reference error when using an uninitialized let/const 1289 // can be skipped in the following situation: we have a LET or CONST
1290 // binding in harmony mode. 1290 // binding in harmony mode, both the Variable and the VariableProxy have
1291 __ push(Immediate(var->name())); 1291 // the same declaration scope (i.e. they are both in global code, in the
1292 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1292 // same function or in the same eval code) and the VariableProxy is in
1293 } else { 1293 // the source physically located after the initializer of the variable.
1294 // Uninitalized const bindings outside of harmony mode are unholed. 1294 //
1295 ASSERT(var->mode() == CONST); 1295 // We cannot skip any initialization checks for CONST in non-harmony
1296 __ mov(eax, isolate()->factory()->undefined_value()); 1296 // mode because const variables may be declared but never initialized:
1297 // if (false) { const x; }; var y = x;
1298 //
1299 // The condition on the declaration scopes is a conservative check for
1300 // nested functions that access a binding and are called before the
1301 // binding is initialized:
1302 // function() { f(); let x = 1; function f() { x = 2; } }
1303 //
1304 // Check that we always have valid source position.
1305 ASSERT(var->initializer_position() != RelocInfo::kNoPosition);
1306 ASSERT(proxy->position() != RelocInfo::kNoPosition);
1307 bool skip_init_check =
1308 var->mode() != CONST &&
1309 var->scope()->DeclarationScope() == scope()->DeclarationScope() &&
1310 var->initializer_position() < proxy->position();
1311 if (!skip_init_check) {
1312 // Let and const need a read barrier.
1313 Label done;
1314 GetVar(eax, var);
1315 __ cmp(eax, isolate()->factory()->the_hole_value());
1316 __ j(not_equal, &done, Label::kNear);
1317 if (var->mode() == LET || var->mode() == CONST_HARMONY) {
1318 // Throw a reference error when using an uninitialized let/const
1319 // binding in harmony mode.
1320 __ push(Immediate(var->name()));
1321 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1322 } else {
1323 // Uninitalized const bindings outside of harmony mode are unholed.
1324 ASSERT(var->mode() == CONST);
1325 __ mov(eax, isolate()->factory()->undefined_value());
1326 }
1327 __ bind(&done);
1328 context()->Plug(eax);
1329 break;
1297 } 1330 }
1298 __ bind(&done);
1299 context()->Plug(eax);
1300 } 1331 }
1332 context()->Plug(var);
1301 break; 1333 break;
1302 } 1334 }
1303 1335
1304 case Variable::LOOKUP: { 1336 case Variable::LOOKUP: {
1305 Label done, slow; 1337 Label done, slow;
1306 // Generate code for loading from variables potentially shadowed 1338 // Generate code for loading from variables potentially shadowed
1307 // by eval-introduced variables. 1339 // by eval-introduced variables.
1308 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); 1340 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done);
1309 __ bind(&slow); 1341 __ bind(&slow);
1310 Comment cmnt(masm_, "Lookup variable"); 1342 Comment cmnt(masm_, "Lookup variable");
(...skipping 3093 matching lines...) Expand 10 before | Expand all | Expand 10 after
4404 *context_length = 0; 4436 *context_length = 0;
4405 return previous_; 4437 return previous_;
4406 } 4438 }
4407 4439
4408 4440
4409 #undef __ 4441 #undef __
4410 4442
4411 } } // namespace v8::internal 4443 } } // namespace v8::internal
4412 4444
4413 #endif // V8_TARGET_ARCH_IA32 4445 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/arm/full-codegen-arm.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698