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 2347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2358 // eval-introduced variables. Eval is used a lot without | 2358 // eval-introduced variables. Eval is used a lot without |
2359 // introducing variables. In those cases, we do not want to | 2359 // introducing variables. In those cases, we do not want to |
2360 // perform a runtime call for all variables in the scope | 2360 // perform a runtime call for all variables in the scope |
2361 // containing the eval. | 2361 // containing the eval. |
2362 if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { | 2362 if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
2363 LoadFromGlobalSlotCheckExtensions(slot, typeof_state, ebx, &slow); | 2363 LoadFromGlobalSlotCheckExtensions(slot, typeof_state, ebx, &slow); |
2364 __ jmp(&done); | 2364 __ jmp(&done); |
2365 | 2365 |
2366 } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { | 2366 } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
2367 Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); | 2367 Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); |
2368 __ mov(eax, | 2368 // Only generate the fast case for locals that rewrite to slots. |
2369 ContextSlotOperandCheckExtensions(potential_slot, | 2369 // This rules out argument loads. |
2370 ebx, | 2370 if (potential_slot != NULL) { |
2371 &slow)); | 2371 __ mov(eax, |
2372 __ jmp(&done); | 2372 ContextSlotOperandCheckExtensions(potential_slot, |
| 2373 ebx, |
| 2374 &slow)); |
| 2375 __ jmp(&done); |
| 2376 } |
2373 } | 2377 } |
2374 | 2378 |
2375 __ bind(&slow); | 2379 __ bind(&slow); |
2376 frame_->Push(esi); | 2380 frame_->Push(esi); |
2377 frame_->Push(Immediate(slot->var()->name())); | 2381 frame_->Push(Immediate(slot->var()->name())); |
2378 if (typeof_state == INSIDE_TYPEOF) { | 2382 if (typeof_state == INSIDE_TYPEOF) { |
2379 __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); | 2383 __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
2380 } else { | 2384 } else { |
2381 __ CallRuntime(Runtime::kLoadContextSlot, 2); | 2385 __ CallRuntime(Runtime::kLoadContextSlot, 2); |
2382 } | 2386 } |
(...skipping 24 matching lines...) Expand all Loading... |
2407 } | 2411 } |
2408 | 2412 |
2409 | 2413 |
2410 void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, | 2414 void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
2411 TypeofState typeof_state, | 2415 TypeofState typeof_state, |
2412 Register tmp, | 2416 Register tmp, |
2413 Label* slow) { | 2417 Label* slow) { |
2414 // Check that no extension objects have been created by calls to | 2418 // Check that no extension objects have been created by calls to |
2415 // eval from the current scope to the global scope. | 2419 // eval from the current scope to the global scope. |
2416 Register context = esi; | 2420 Register context = esi; |
2417 for (Scope* s = scope(); s != NULL; s = s->outer_scope()) { | 2421 Scope* s = scope(); |
| 2422 while (s != NULL) { |
2418 if (s->num_heap_slots() > 0) { | 2423 if (s->num_heap_slots() > 0) { |
2419 if (s->calls_eval()) { | 2424 if (s->calls_eval()) { |
2420 // Check that extension is NULL. | 2425 // Check that extension is NULL. |
2421 __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); | 2426 __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
2422 __ j(not_equal, slow, not_taken); | 2427 __ j(not_equal, slow, not_taken); |
2423 } | 2428 } |
2424 // Load next context in chain. | 2429 // Load next context in chain. |
2425 __ mov(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); | 2430 __ mov(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
2426 __ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset)); | 2431 __ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset)); |
2427 context = tmp; | 2432 context = tmp; |
2428 } | 2433 } |
2429 // If no outer scope calls eval, we do not need to check more | 2434 // If no outer scope calls eval, we do not need to check more |
2430 // context extensions. | 2435 // context extensions. If we have reached an eval scope, we check |
2431 if (!s->outer_scope_calls_eval()) break; | 2436 // all extensions from this point. |
| 2437 if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 2438 s = s->outer_scope(); |
| 2439 } |
| 2440 |
| 2441 if (s->is_eval_scope()) { |
| 2442 Label next, fast; |
| 2443 if (!context.is(tmp)) __ mov(tmp, Operand(context)); |
| 2444 __ bind(&next); |
| 2445 // Terminate at global context. |
| 2446 __ cmp(FieldOperand(tmp, HeapObject::kMapOffset), |
| 2447 Immediate(Factory::global_context_map())); |
| 2448 __ j(equal, &fast); |
| 2449 // Check that extension is NULL. |
| 2450 __ cmp(ContextOperand(tmp, Context::EXTENSION_INDEX), Immediate(0)); |
| 2451 __ j(not_equal, slow, not_taken); |
| 2452 // Load next context in chain. |
| 2453 __ mov(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 2454 __ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset)); |
| 2455 __ jmp(&next); |
| 2456 __ bind(&fast); |
2432 } | 2457 } |
2433 | 2458 |
2434 // All extension objects were empty and it is safe to use a global | 2459 // All extension objects were empty and it is safe to use a global |
2435 // load IC call. | 2460 // load IC call. |
2436 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | 2461 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
2437 // Load the global object. | 2462 // Load the global object. |
2438 LoadGlobal(); | 2463 LoadGlobal(); |
2439 // Setup the name register. | 2464 // Setup the name register. |
2440 __ mov(ecx, slot->var()->name()); | 2465 __ mov(ecx, slot->var()->name()); |
2441 // Call IC stub. | 2466 // Call IC stub. |
(...skipping 2980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5422 | 5447 |
5423 // Slow-case: Go through the JavaScript implementation. | 5448 // Slow-case: Go through the JavaScript implementation. |
5424 __ bind(&slow); | 5449 __ bind(&slow); |
5425 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); | 5450 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
5426 } | 5451 } |
5427 | 5452 |
5428 | 5453 |
5429 #undef __ | 5454 #undef __ |
5430 | 5455 |
5431 } } // namespace v8::internal | 5456 } } // namespace v8::internal |
OLD | NEW |