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

Side by Side Diff: src/x64/full-codegen-x64.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/variables.cc ('k') | no next file » | 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 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); 1244 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1245 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); 1245 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT);
1246 context()->Plug(rax); 1246 context()->Plug(rax);
1247 break; 1247 break;
1248 } 1248 }
1249 1249
1250 case Variable::PARAMETER: 1250 case Variable::PARAMETER:
1251 case Variable::LOCAL: 1251 case Variable::LOCAL:
1252 case Variable::CONTEXT: { 1252 case Variable::CONTEXT: {
1253 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); 1253 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot");
1254 if (!var->binding_needs_init()) { 1254 if (var->binding_needs_init()) {
1255 context()->Plug(var); 1255 // var->scope() may be NULL when the proxy is located in eval code and
1256 } else { 1256 // refers to a potential outside binding. Currently those bindings are
1257 // Let and const need a read barrier. 1257 // always looked up dynamically, i.e. in that case
1258 Label done; 1258 // var->location() == LOOKUP.
1259 GetVar(rax, var); 1259 // always holds.
1260 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); 1260 ASSERT(var->scope() != NULL);
1261 __ j(not_equal, &done, Label::kNear); 1261
1262 if (var->mode() == LET || var->mode() == CONST_HARMONY) { 1262 // Check if the binding really needs an initialization check. The check
1263 // Throw a reference error when using an uninitialized let/const 1263 // can be skipped in the following situation: we have a LET or CONST
1264 // binding in harmony mode. 1264 // binding in harmony mode, both the Variable and the VariableProxy have
1265 __ Push(var->name()); 1265 // the same declaration scope (i.e. they are both in global code, in the
1266 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1266 // same function or in the same eval code) and the VariableProxy is in
1267 } else { 1267 // the source physically located after the initializer of the variable.
1268 // Uninitalized const bindings outside of harmony mode are unholed. 1268 //
1269 ASSERT(var->mode() == CONST); 1269 // We cannot skip any initialization checks for CONST in non-harmony
1270 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); 1270 // mode because const variables may be declared but never initialized:
1271 // if (false) { const x; }; var y = x;
1272 //
1273 // The condition on the declaration scopes is a conservative check for
1274 // nested functions that access a binding and are called before the
1275 // binding is initialized:
1276 // function() { f(); let x = 1; function f() { x = 2; } }
1277 //
1278 // Check that we always have valid source position.
1279 ASSERT(var->initializer_position() != RelocInfo::kNoPosition);
1280 ASSERT(proxy->position() != RelocInfo::kNoPosition);
1281 bool skip_init_check =
1282 var->mode() != CONST &&
1283 var->scope()->DeclarationScope() == scope()->DeclarationScope() &&
1284 var->initializer_position() < proxy->position();
1285 if (!skip_init_check) {
1286 // Let and const need a read barrier.
1287 Label done;
1288 GetVar(rax, var);
1289 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1290 __ j(not_equal, &done, Label::kNear);
1291 if (var->mode() == LET || var->mode() == CONST_HARMONY) {
1292 // Throw a reference error when using an uninitialized let/const
1293 // binding in harmony mode.
1294 __ Push(var->name());
1295 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1296 } else {
1297 // Uninitalized const bindings outside of harmony mode are unholed.
1298 ASSERT(var->mode() == CONST);
1299 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
1300 }
1301 __ bind(&done);
1302 context()->Plug(rax);
1303 break;
1271 } 1304 }
1272 __ bind(&done);
1273 context()->Plug(rax);
1274 } 1305 }
1306 context()->Plug(var);
1275 break; 1307 break;
1276 } 1308 }
1277 1309
1278 case Variable::LOOKUP: { 1310 case Variable::LOOKUP: {
1279 Label done, slow; 1311 Label done, slow;
1280 // Generate code for loading from variables potentially shadowed 1312 // Generate code for loading from variables potentially shadowed
1281 // by eval-introduced variables. 1313 // by eval-introduced variables.
1282 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); 1314 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done);
1283 __ bind(&slow); 1315 __ bind(&slow);
1284 Comment cmnt(masm_, "Lookup slot"); 1316 Comment cmnt(masm_, "Lookup slot");
(...skipping 2969 matching lines...) Expand 10 before | Expand all | Expand 10 after
4254 *context_length = 0; 4286 *context_length = 0;
4255 return previous_; 4287 return previous_;
4256 } 4288 }
4257 4289
4258 4290
4259 #undef __ 4291 #undef __
4260 4292
4261 } } // namespace v8::internal 4293 } } // namespace v8::internal
4262 4294
4263 #endif // V8_TARGET_ARCH_X64 4295 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/variables.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698