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 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2468 // TODO(wingo): Save the operand stack and/or the stack handlers. | 2468 // TODO(wingo): Save the operand stack and/or the stack handlers. |
2469 UNIMPLEMENTED(); | 2469 UNIMPLEMENTED(); |
2470 } | 2470 } |
2471 | 2471 |
2472 // The return value is the hole for a suspend return, and anything else for a | 2472 // The return value is the hole for a suspend return, and anything else for a |
2473 // resume return. | 2473 // resume return. |
2474 return isolate->heap()->the_hole_value(); | 2474 return isolate->heap()->the_hole_value(); |
2475 } | 2475 } |
2476 | 2476 |
2477 | 2477 |
| 2478 // Note that this function is the slow path for resuming generators. It is only |
| 2479 // called if the suspended activation had operands on the stack, stack handlers |
| 2480 // needing rewinding, or if the resume should throw an exception. The fast path |
| 2481 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is |
| 2482 // inlined into GeneratorNext, GeneratorSend, and GeneratorThrow. |
| 2483 // EmitGeneratorResumeResume is called in any case, as it needs to reconstruct |
| 2484 // the stack frame and make space for arguments and operands. |
| 2485 RUNTIME_FUNCTION(MaybeObject*, Runtime_ResumeJSGeneratorObject) { |
| 2486 HandleScope scope(isolate); |
| 2487 ASSERT(args.length() == 3); |
| 2488 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
| 2489 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 2490 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2); |
| 2491 JavaScriptFrameIterator stack_iterator(isolate); |
| 2492 JavaScriptFrame *frame = stack_iterator.frame(); |
| 2493 |
| 2494 ASSERT_EQ(frame->function(), generator_object->function()); |
| 2495 |
| 2496 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); |
| 2497 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); |
| 2498 |
| 2499 Address pc = generator_object->function()->code()->instruction_start(); |
| 2500 int offset = generator_object->continuation(); |
| 2501 ASSERT(offset > 0); |
| 2502 frame->set_pc(pc + offset); |
| 2503 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
| 2504 |
| 2505 if (generator_object->operand_stack()->length() != 0) { |
| 2506 // TODO(wingo): Copy operand stack. Rewind handlers. |
| 2507 UNIMPLEMENTED(); |
| 2508 } |
| 2509 |
| 2510 JSGeneratorObject::ResumeMode resume_mode = |
| 2511 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); |
| 2512 switch (resume_mode) { |
| 2513 case JSGeneratorObject::SEND: |
| 2514 return *value; |
| 2515 case JSGeneratorObject::THROW: |
| 2516 return isolate->Throw(*value); |
| 2517 } |
| 2518 |
| 2519 UNREACHABLE(); |
| 2520 return isolate->ThrowIllegalOperation(); |
| 2521 } |
| 2522 |
| 2523 |
| 2524 RUNTIME_FUNCTION(MaybeObject*, Runtime_ThrowGeneratorStateError) { |
| 2525 HandleScope scope(isolate); |
| 2526 ASSERT(args.length() == 1); |
| 2527 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
| 2528 int continuation = generator->continuation(); |
| 2529 const char *message = continuation == JSGeneratorObject::kGeneratorClosed ? |
| 2530 "generator_finished" : "generator_running"; |
| 2531 Vector< Handle<Object> > argv = HandleVector<Object>(NULL, 0); |
| 2532 Handle<Object> error = isolate->factory()->NewError(message, argv); |
| 2533 return isolate->Throw(*error); |
| 2534 } |
| 2535 |
| 2536 |
2478 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, | 2537 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, |
2479 Object* char_code) { | 2538 Object* char_code) { |
2480 if (char_code->IsNumber()) { | 2539 if (char_code->IsNumber()) { |
2481 return isolate->heap()->LookupSingleCharacterStringFromCode( | 2540 return isolate->heap()->LookupSingleCharacterStringFromCode( |
2482 NumberToUint32(char_code) & 0xffff); | 2541 NumberToUint32(char_code) & 0xffff); |
2483 } | 2542 } |
2484 return isolate->heap()->empty_string(); | 2543 return isolate->heap()->empty_string(); |
2485 } | 2544 } |
2486 | 2545 |
2487 | 2546 |
(...skipping 10803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13291 // Handle last resort GC and make sure to allow future allocations | 13350 // Handle last resort GC and make sure to allow future allocations |
13292 // to grow the heap without causing GCs (if possible). | 13351 // to grow the heap without causing GCs (if possible). |
13293 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13352 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13294 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13353 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13295 "Runtime::PerformGC"); | 13354 "Runtime::PerformGC"); |
13296 } | 13355 } |
13297 } | 13356 } |
13298 | 13357 |
13299 | 13358 |
13300 } } // namespace v8::internal | 13359 } } // namespace v8::internal |
OLD | NEW |