| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 frame_->SpillAll(); | 1292 frame_->SpillAll(); |
| 1293 frame_->EmitPush(Immediate(pairs)); | 1293 frame_->EmitPush(Immediate(pairs)); |
| 1294 frame_->EmitPush(esi); | 1294 frame_->EmitPush(esi); |
| 1295 frame_->EmitPush(Immediate(Smi::FromInt(is_eval() ? 1 : 0))); | 1295 frame_->EmitPush(Immediate(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1296 frame_->CallRuntime(Runtime::kDeclareGlobals, 3); | 1296 frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
| 1297 // Return value is ignored. | 1297 // Return value is ignored. |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 | 1300 |
| 1301 void CodeGenerator::VisitDeclaration(Declaration* node) { | 1301 void CodeGenerator::VisitDeclaration(Declaration* node) { |
| 1302 frame_->SpillAll(); | |
| 1303 | |
| 1304 Comment cmnt(masm_, "[ Declaration"); | 1302 Comment cmnt(masm_, "[ Declaration"); |
| 1305 Variable* var = node->proxy()->var(); | 1303 Variable* var = node->proxy()->var(); |
| 1306 ASSERT(var != NULL); // must have been resolved | 1304 ASSERT(var != NULL); // must have been resolved |
| 1307 Slot* slot = var->slot(); | 1305 Slot* slot = var->slot(); |
| 1308 | 1306 |
| 1309 // If it was not possible to allocate the variable at compile time, | 1307 // If it was not possible to allocate the variable at compile time, |
| 1310 // we need to "declare" it at runtime to make sure it actually | 1308 // we need to "declare" it at runtime to make sure it actually |
| 1311 // exists in the local context. | 1309 // exists in the local context. |
| 1312 if (slot != NULL && slot->type() == Slot::LOOKUP) { | 1310 if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1313 // Variables with a "LOOKUP" slot were introduced as non-locals | 1311 // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1314 // during variable resolution and must have mode DYNAMIC. | 1312 // during variable resolution and must have mode DYNAMIC. |
| 1315 ASSERT(var->mode() == Variable::DYNAMIC); | 1313 ASSERT(var->mode() == Variable::DYNAMIC); |
| 1316 // For now, just do a runtime call. | 1314 // For now, just do a runtime call. |
| 1315 frame_->SpillAll(); |
| 1317 frame_->EmitPush(esi); | 1316 frame_->EmitPush(esi); |
| 1318 frame_->EmitPush(Immediate(var->name())); | 1317 frame_->EmitPush(Immediate(var->name())); |
| 1319 // Declaration nodes are always introduced in one of two modes. | 1318 // Declaration nodes are always introduced in one of two modes. |
| 1320 ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); | 1319 ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1321 PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; | 1320 PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
| 1322 frame_->EmitPush(Immediate(Smi::FromInt(attr))); | 1321 frame_->EmitPush(Immediate(Smi::FromInt(attr))); |
| 1323 // Push initial value, if any. | 1322 // Push initial value, if any. |
| 1324 // Note: For variables we must not push an initial value (such as | 1323 // Note: For variables we must not push an initial value (such as |
| 1325 // 'undefined') because we may have a (legal) redeclaration and we | 1324 // 'undefined') because we may have a (legal) redeclaration and we |
| 1326 // must not destroy the current value. | 1325 // must not destroy the current value. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1341 | 1340 |
| 1342 // If we have a function or a constant, we need to initialize the variable. | 1341 // If we have a function or a constant, we need to initialize the variable. |
| 1343 Expression* val = NULL; | 1342 Expression* val = NULL; |
| 1344 if (node->mode() == Variable::CONST) { | 1343 if (node->mode() == Variable::CONST) { |
| 1345 val = new Literal(Factory::the_hole_value()); | 1344 val = new Literal(Factory::the_hole_value()); |
| 1346 } else { | 1345 } else { |
| 1347 val = node->fun(); // NULL if we don't have a function | 1346 val = node->fun(); // NULL if we don't have a function |
| 1348 } | 1347 } |
| 1349 | 1348 |
| 1350 if (val != NULL) { | 1349 if (val != NULL) { |
| 1350 frame_->SpillAll(); |
| 1351 // Set initial value. | 1351 // Set initial value. |
| 1352 Reference target(this, node->proxy()); | 1352 Reference target(this, node->proxy()); |
| 1353 ASSERT(target.is_slot()); | 1353 ASSERT(target.is_slot()); |
| 1354 Load(val); | 1354 Load(val); |
| 1355 frame_->SpillAll(); | 1355 frame_->SpillAll(); |
| 1356 target.SetValue(NOT_CONST_INIT); | 1356 target.SetValue(NOT_CONST_INIT); |
| 1357 // Get rid of the assigned value (declarations are statements). It's | 1357 // Get rid of the assigned value (declarations are statements). It's |
| 1358 // safe to pop the value lying on top of the reference before unloading | 1358 // safe to pop the value lying on top of the reference before unloading |
| 1359 // the reference itself (which preserves the top of stack) because we | 1359 // the reference itself (which preserves the top of stack) because we |
| 1360 // know that it is a zero-sized reference. | 1360 // know that it is a zero-sized reference. |
| (...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5488 | 5488 |
| 5489 // Slow-case: Go through the JavaScript implementation. | 5489 // Slow-case: Go through the JavaScript implementation. |
| 5490 __ bind(&slow); | 5490 __ bind(&slow); |
| 5491 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); | 5491 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5492 } | 5492 } |
| 5493 | 5493 |
| 5494 | 5494 |
| 5495 #undef __ | 5495 #undef __ |
| 5496 | 5496 |
| 5497 } } // namespace v8::internal | 5497 } } // namespace v8::internal |
| OLD | NEW |