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