5 #include "src/arguments-inl.h" 6 #include "src/counters.h" 7 #include "src/heap/factory.h" 8 #include "src/heap/heap-inl.h" 9 #include "src/objects-inl.h" 10 #include "src/objects/js-generator-inl.h" 11 #include "src/runtime/runtime-utils.h" 16 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitCaught) {
22 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitUncaught) {
28 RUNTIME_FUNCTION(Runtime_AsyncFunctionEnter) {
34 RUNTIME_FUNCTION(Runtime_AsyncFunctionReject) {
40 RUNTIME_FUNCTION(Runtime_AsyncFunctionResolve) {
46 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) {
47 HandleScope scope(isolate);
48 DCHECK_EQ(2, args.length());
49 CONVERT_ARG_HANDLE_CHECKED(JSFunction,
function, 0);
50 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
51 CHECK_IMPLIES(IsAsyncFunction(function->shared()->kind()),
52 IsAsyncGeneratorFunction(function->shared()->kind()));
53 CHECK(IsResumableFunction(function->shared()->kind()));
56 DCHECK(function->shared()->HasBytecodeArray());
57 int size =
function->shared()->internal_formal_parameter_count() +
58 function->shared()->GetBytecodeArray()->register_count();
59 Handle<FixedArray> parameters_and_registers =
60 isolate->factory()->NewFixedArray(size);
62 Handle<JSGeneratorObject> generator =
63 isolate->factory()->NewJSGeneratorObject(
function);
64 generator->set_function(*
function);
65 generator->set_context(isolate->context());
66 generator->set_receiver(*receiver);
67 generator->set_parameters_and_registers(*parameters_and_registers);
68 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
69 if (generator->IsJSAsyncGeneratorObject()) {
70 Handle<JSAsyncGeneratorObject>::cast(generator)->set_is_awaiting(0);
75 RUNTIME_FUNCTION(Runtime_GeneratorClose) {
81 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
82 HandleScope scope(isolate);
83 DCHECK_EQ(1, args.length());
84 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
86 return generator->function();
89 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught) {
95 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught) {
101 RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
107 RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
113 RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
119 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
127 RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
128 DisallowHeapAllocation no_allocation_scope;
129 DCHECK_EQ(1, args.length());
130 CONVERT_ARG_CHECKED(JSAsyncGeneratorObject, generator, 0);
132 int state = generator->continuation();
133 DCHECK_NE(state, JSAsyncGeneratorObject::kGeneratorExecuting);
138 if (state < 1)
return ReadOnlyRoots(isolate).false_value();
140 SharedFunctionInfo* shared = generator->function()->shared();
141 DCHECK(shared->HasBytecodeArray());
142 HandlerTable handler_table(shared->GetBytecodeArray());
144 int pc = Smi::cast(generator->input_or_debug_pos())->value();
145 HandlerTable::CatchPrediction catch_prediction = HandlerTable::ASYNC_AWAIT;
146 handler_table.LookupRange(pc,
nullptr, &catch_prediction);
147 return isolate->heap()->ToBoolean(catch_prediction == HandlerTable::CAUGHT);