OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 2565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2576 } | 2576 } |
2577 | 2577 |
2578 | 2578 |
2579 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) { | 2579 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) { |
2580 SealHandleScope shs(isolate); | 2580 SealHandleScope shs(isolate); |
2581 ASSERT(args.length() == 1); | 2581 ASSERT(args.length() == 1); |
2582 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); | 2582 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); |
2583 | 2583 |
2584 JavaScriptFrameIterator stack_iterator(isolate); | 2584 JavaScriptFrameIterator stack_iterator(isolate); |
2585 JavaScriptFrame* frame = stack_iterator.frame(); | 2585 JavaScriptFrame* frame = stack_iterator.frame(); |
2586 JSFunction* function = JSFunction::cast(frame->function()); | 2586 RUNTIME_ASSERT(JSFunction::cast(frame->function())->shared()->is_generator()); |
2587 RUNTIME_ASSERT(function->shared()->is_generator()); | 2587 ASSERT_EQ(JSFunction::cast(frame->function()), generator_object->function()); |
2588 ASSERT_EQ(function, generator_object->function()); | |
2589 | 2588 |
2590 // We expect there to be at least two values on the operand stack: the return | 2589 // We expect there to be at least two values on the operand stack: the return |
2591 // value of the yield expression, and the argument to this runtime call. | 2590 // value of the yield expression, and the argument to this runtime call. |
2592 // Neither of those should be saved. | 2591 // Neither of those should be saved. |
2593 int operands_count = frame->ComputeOperandsCount(); | 2592 int operands_count = frame->ComputeOperandsCount(); |
2594 ASSERT(operands_count >= 2); | 2593 ASSERT(operands_count >= 2); |
2595 operands_count -= 2; | 2594 operands_count -= 2; |
2596 | 2595 |
2597 if (operands_count == 0) { | 2596 if (operands_count == 0) { |
2597 // Although it's semantically harmless to call this function with an | |
2598 // operands_count of zero, it is also unnecessary. | |
2598 ASSERT_EQ(generator_object->operand_stack(), | 2599 ASSERT_EQ(generator_object->operand_stack(), |
2599 isolate->heap()->empty_fixed_array()); | 2600 isolate->heap()->empty_fixed_array()); |
2600 ASSERT_EQ(generator_object->stack_handler_index(), -1); | 2601 ASSERT_EQ(generator_object->stack_handler_index(), -1); |
2601 // If there are no operands on the stack, there shouldn't be a handler | 2602 // If there are no operands on the stack, there shouldn't be a handler |
2602 // active either. | 2603 // active either. |
2603 ASSERT(!frame->HasHandler()); | 2604 ASSERT(!frame->HasHandler()); |
2604 } else { | 2605 } else { |
2605 int stack_handler_index = -1; | 2606 int stack_handler_index = -1; |
2606 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count); | 2607 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count); |
2607 FixedArray* operand_stack; | 2608 FixedArray* operand_stack; |
2608 if (!alloc->To(&operand_stack)) return alloc; | 2609 if (!alloc->To(&operand_stack)) return alloc; |
2609 frame->SaveOperandStack(operand_stack, &stack_handler_index); | 2610 frame->SaveOperandStack(operand_stack, &stack_handler_index); |
2610 generator_object->set_operand_stack(operand_stack); | 2611 generator_object->set_operand_stack(operand_stack); |
2611 generator_object->set_stack_handler_index(stack_handler_index); | 2612 generator_object->set_stack_handler_index(stack_handler_index); |
2612 } | 2613 } |
2613 | 2614 |
Michael Starzinger
2013/06/20 12:08:32
Can we leave a short comment here saying that JSGe
| |
2614 // Set continuation down here to avoid side effects if the operand stack | 2615 return isolate->heap()->undefined_value(); |
2615 // allocation fails. | |
2616 intptr_t offset = frame->pc() - function->code()->instruction_start(); | |
2617 ASSERT(offset > 0 && Smi::IsValid(offset)); | |
2618 generator_object->set_continuation(static_cast<int>(offset)); | |
2619 | |
2620 // It's possible for the context to be other than the initial context even if | |
2621 // there is no stack handler active. For example, this is the case in the | |
2622 // body of a "with" statement. Therefore we always save the context. | |
2623 generator_object->set_context(Context::cast(frame->context())); | |
2624 | |
2625 // The return value is the hole for a suspend return, and anything else for a | |
2626 // resume return. | |
2627 return isolate->heap()->the_hole_value(); | |
2628 } | 2616 } |
2629 | 2617 |
2630 | 2618 |
2631 // Note that this function is the slow path for resuming generators. It is only | 2619 // Note that this function is the slow path for resuming generators. It is only |
2632 // called if the suspended activation had operands on the stack, stack handlers | 2620 // called if the suspended activation had operands on the stack, stack handlers |
2633 // needing rewinding, or if the resume should throw an exception. The fast path | 2621 // needing rewinding, or if the resume should throw an exception. The fast path |
2634 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is | 2622 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is |
2635 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is | 2623 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is |
2636 // called in any case, as it needs to reconstruct the stack frame and make space | 2624 // called in any case, as it needs to reconstruct the stack frame and make space |
2637 // for arguments and operands. | 2625 // for arguments and operands. |
(...skipping 11005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13643 // Handle last resort GC and make sure to allow future allocations | 13631 // Handle last resort GC and make sure to allow future allocations |
13644 // to grow the heap without causing GCs (if possible). | 13632 // to grow the heap without causing GCs (if possible). |
13645 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13633 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13646 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13634 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13647 "Runtime::PerformGC"); | 13635 "Runtime::PerformGC"); |
13648 } | 13636 } |
13649 } | 13637 } |
13650 | 13638 |
13651 | 13639 |
13652 } } // namespace v8::internal | 13640 } } // namespace v8::internal |
OLD | NEW |