Index: src/runtime/runtime-generator.cc |
diff --git a/src/runtime/runtime-generator.cc b/src/runtime/runtime-generator.cc |
index eeac3ad6b64b934b897387313139d88ccaa6eb4e..9c875300c6ba1aaf3d2fc90564f32d65bffaf2ef 100644 |
--- a/src/runtime/runtime-generator.cc |
+++ b/src/runtime/runtime-generator.cc |
@@ -68,6 +68,7 @@ RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
return isolate->heap()->undefined_value(); |
} |
+ |
RUNTIME_FUNCTION(Runtime_GeneratorClose) { |
HandleScope scope(isolate); |
DCHECK(args.length() == 1); |
@@ -109,6 +110,16 @@ RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { |
} |
+// Returns resume mode of generator activation. |
+RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 1); |
+ CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
+ |
+ return Smi::FromInt(generator->resume_mode()); |
+} |
+ |
+ |
// Returns generator continuation as a PC offset, or the magic -1 or 0 values. |
RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) { |
HandleScope scope(isolate); |
@@ -134,5 +145,60 @@ RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) { |
return isolate->heap()->undefined_value(); |
} |
+ |
+RUNTIME_FUNCTION(Runtime_SuspendIgnitionGenerator) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
+ CONVERT_ARG_HANDLE_CHECKED(Smi, state, 1); |
+ |
+ JavaScriptFrameIterator it(isolate); |
+ JavaScriptFrame* frame = it.frame(); |
+ Handle<JSFunction> function(frame->function()); |
+ CHECK(function->shared()->is_generator()); |
+ CHECK_EQ(frame->type(), StackFrame::INTERPRETED); |
+ |
+ // Save register file. |
+ int size = function->shared()->bytecode_array()->register_count(); |
+ Handle<FixedArray> register_file = isolate->factory()->NewFixedArray(size); |
+ for (int i = 0; i < size; ++i) { |
+ Object* value = |
+ static_cast<InterpretedFrame*>(frame)->ReadInterpreterRegister(i); |
+ register_file->set(i, value); |
+ } |
+ |
+ generator->set_operand_stack(*register_file); |
+ generator->set_context(Context::cast(frame->context())); |
+ generator->set_continuation(state->value()); |
+ |
+ return isolate->heap()->undefined_value(); |
+} |
+ |
+ |
+RUNTIME_FUNCTION(Runtime_ResumeIgnitionGenerator) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 1); |
+ CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
+ |
+ JavaScriptFrameIterator it(isolate); |
+ JavaScriptFrame* frame = it.frame(); |
+ Handle<JSFunction> function(frame->function()); |
+ CHECK(function->shared()->is_generator()); |
+ CHECK_EQ(frame->type(), StackFrame::INTERPRETED); |
+ |
+ // Restore register file. |
+ int size = function->shared()->bytecode_array()->register_count(); |
+ DCHECK_EQ(size, generator->operand_stack()->length()); |
+ for (int i = 0; i < size; ++i) { |
+ Object* value = generator->operand_stack()->get(i); |
+ static_cast<InterpretedFrame*>(frame)->WriteInterpreterRegister(i, value); |
+ } |
+ generator->set_operand_stack(isolate->heap()->empty_fixed_array()); |
+ |
+ int state = generator->continuation(); |
+ generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
+ return Smi::FromInt(state); |
+} |
+ |
} // namespace internal |
} // namespace v8 |