Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime.cc

Issue 14066016: Generators can resume (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: ia32 fixups Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::EmitResume(), which is inlined into
2482 // GeneratorNext, GeneratorSend, and GeneratorThrow. EmitResume is called in
2483 // any case, as it needs to reconstruct the stack frame and make space for
2484 // 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 JSGeneratorObject::ResumeMode resume_mode =
Michael Starzinger 2013/04/21 22:45:21 Move the "resume_mode" local variable down to righ
wingo 2013/04/23 13:51:04 Done.
2492 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int);
2493 JavaScriptFrameIterator stack_iterator(isolate);
2494 JavaScriptFrame *frame = stack_iterator.frame();
2495
2496 ASSERT_EQ(frame->function(), generator_object->function());
2497
2498 byte* pc = generator_object->function()->code()->instruction_start();
Michael Starzinger 2013/04/21 22:45:21 Use "Address" instead of "byte*" here.
wingo 2013/04/23 13:51:04 Done.
2499 int offset = generator_object->continuation();
2500 ASSERT(offset > 0);
2501 frame->set_pc(pc + offset);
2502 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting);
2503
2504 if (generator_object->operand_stack()->length() != 0) {
2505 // TODO(wingo): Copy operand stack. Rewind handlers.
2506 UNIMPLEMENTED();
2507 }
2508
2509 switch (resume_mode) {
2510 default:
Michael Starzinger 2013/04/21 22:45:21 Drop the default case for enums.
wingo 2013/04/23 13:51:04 Done, though I still had to have an UNREACHABLE at
2511 UNREACHABLE();
2512 case JSGeneratorObject::kSend:
2513 return *value;
2514 case JSGeneratorObject::kThrow:
2515 return isolate->Throw(*value);
2516 }
2517 }
2518
2519
2520 RUNTIME_FUNCTION(MaybeObject*, Runtime_ThrowGeneratorStateError) {
2521 HandleScope scope(isolate);
2522 ASSERT(args.length() == 1);
2523 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
2524 int continuation = generator->continuation();
2525 const char *message = continuation == JSGeneratorObject::kGeneratorClosed ?
2526 "generator_finished" : "generator_running";
2527 Vector< Handle<Object> > argv = HandleVector<Object>(NULL, 0);
2528 Handle<Object> error = isolate->factory()->NewError(message, argv);
2529 return isolate->Throw(*error);
2530 }
2531
2532
2478 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, 2533 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate,
2479 Object* char_code) { 2534 Object* char_code) {
2480 if (char_code->IsNumber()) { 2535 if (char_code->IsNumber()) {
2481 return isolate->heap()->LookupSingleCharacterStringFromCode( 2536 return isolate->heap()->LookupSingleCharacterStringFromCode(
2482 NumberToUint32(char_code) & 0xffff); 2537 NumberToUint32(char_code) & 0xffff);
2483 } 2538 }
2484 return isolate->heap()->empty_string(); 2539 return isolate->heap()->empty_string();
2485 } 2540 }
2486 2541
2487 2542
(...skipping 10803 matching lines...) Expand 10 before | Expand all | Expand 10 after
13291 // Handle last resort GC and make sure to allow future allocations 13346 // Handle last resort GC and make sure to allow future allocations
13292 // to grow the heap without causing GCs (if possible). 13347 // to grow the heap without causing GCs (if possible).
13293 isolate->counters()->gc_last_resort_from_js()->Increment(); 13348 isolate->counters()->gc_last_resort_from_js()->Increment();
13294 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13349 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13295 "Runtime::PerformGC"); 13350 "Runtime::PerformGC");
13296 } 13351 }
13297 } 13352 }
13298 13353
13299 13354
13300 } } // namespace v8::internal 13355 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698