OLD | NEW |
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 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 1233 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
1234 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); | 1234 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
1235 context()->Plug(rax); | 1235 context()->Plug(rax); |
1236 break; | 1236 break; |
1237 } | 1237 } |
1238 | 1238 |
1239 case Variable::PARAMETER: | 1239 case Variable::PARAMETER: |
1240 case Variable::LOCAL: | 1240 case Variable::LOCAL: |
1241 case Variable::CONTEXT: { | 1241 case Variable::CONTEXT: { |
1242 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); | 1242 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); |
1243 if (!var->binding_needs_init()) { | 1243 if (var->binding_needs_init()) { |
1244 context()->Plug(var); | 1244 // var->scope() may be NULL when the proxy is located in eval code and |
1245 } else { | 1245 // refers to a potential outside binding. Currently those bindings are |
1246 // Let and const need a read barrier. | 1246 // always looked up dynamically, i.e. in that case |
1247 Label done; | 1247 // var->location() == LOOKUP. |
1248 GetVar(rax, var); | 1248 // always holds. |
1249 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1249 ASSERT(var->scope() != NULL); |
1250 __ j(not_equal, &done, Label::kNear); | 1250 |
1251 if (var->mode() == LET || var->mode() == CONST_HARMONY) { | 1251 // Check if the binding really needs an initialization check. The check |
1252 // Throw a reference error when using an uninitialized let/const | 1252 // can be skipped in the following situation: we have a LET or CONST |
1253 // binding in harmony mode. | 1253 // binding in harmony mode, both the Variable and the VariableProxy have |
1254 __ Push(var->name()); | 1254 // the same declaration scope (i.e. they are both in global code, in the |
1255 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1255 // same function or in the same eval code) and the VariableProxy is in |
| 1256 // the source physically located after the initializer of the variable. |
| 1257 // |
| 1258 // We cannot skip any initialization checks for CONST in non-harmony |
| 1259 // mode because const variables may be declared but never initialized: |
| 1260 // if (false) { const x; }; var y = x; |
| 1261 // |
| 1262 // The condition on the declaration scopes is a conservative check for |
| 1263 // nested functions that access a binding and are called before the |
| 1264 // binding is initialized: |
| 1265 // function() { f(); let x = 1; function f() { x = 2; } } |
| 1266 // |
| 1267 bool skip_init_check; |
| 1268 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1269 skip_init_check = false; |
1256 } else { | 1270 } else { |
1257 // Uninitalized const bindings outside of harmony mode are unholed. | 1271 // Check that we always have valid source position. |
1258 ASSERT(var->mode() == CONST); | 1272 ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
1259 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 1273 ASSERT(proxy->position() != RelocInfo::kNoPosition); |
| 1274 skip_init_check = var->mode() != CONST && |
| 1275 var->initializer_position() < proxy->position(); |
1260 } | 1276 } |
1261 __ bind(&done); | 1277 |
1262 context()->Plug(rax); | 1278 if (!skip_init_check) { |
| 1279 // Let and const need a read barrier. |
| 1280 Label done; |
| 1281 GetVar(rax, var); |
| 1282 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 1283 __ j(not_equal, &done, Label::kNear); |
| 1284 if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1285 // Throw a reference error when using an uninitialized let/const |
| 1286 // binding in harmony mode. |
| 1287 __ Push(var->name()); |
| 1288 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1289 } else { |
| 1290 // Uninitalized const bindings outside of harmony mode are unholed. |
| 1291 ASSERT(var->mode() == CONST); |
| 1292 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1293 } |
| 1294 __ bind(&done); |
| 1295 context()->Plug(rax); |
| 1296 break; |
| 1297 } |
1263 } | 1298 } |
| 1299 context()->Plug(var); |
1264 break; | 1300 break; |
1265 } | 1301 } |
1266 | 1302 |
1267 case Variable::LOOKUP: { | 1303 case Variable::LOOKUP: { |
1268 Label done, slow; | 1304 Label done, slow; |
1269 // Generate code for loading from variables potentially shadowed | 1305 // Generate code for loading from variables potentially shadowed |
1270 // by eval-introduced variables. | 1306 // by eval-introduced variables. |
1271 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); | 1307 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
1272 __ bind(&slow); | 1308 __ bind(&slow); |
1273 Comment cmnt(masm_, "Lookup slot"); | 1309 Comment cmnt(masm_, "Lookup slot"); |
(...skipping 3030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4304 *context_length = 0; | 4340 *context_length = 0; |
4305 return previous_; | 4341 return previous_; |
4306 } | 4342 } |
4307 | 4343 |
4308 | 4344 |
4309 #undef __ | 4345 #undef __ |
4310 | 4346 |
4311 } } // namespace v8::internal | 4347 } } // namespace v8::internal |
4312 | 4348 |
4313 #endif // V8_TARGET_ARCH_X64 | 4349 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |