V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
runtime-generator.cc
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
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"
12 
13 namespace v8 {
14 namespace internal {
15 
16 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitCaught) {
17  // Runtime call is implemented in InterpreterIntrinsics and lowered in
18  // JSIntrinsicLowering
19  UNREACHABLE();
20 }
21 
22 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitUncaught) {
23  // Runtime call is implemented in InterpreterIntrinsics and lowered in
24  // JSIntrinsicLowering
25  UNREACHABLE();
26 }
27 
28 RUNTIME_FUNCTION(Runtime_AsyncFunctionEnter) {
29  // Runtime call is implemented in InterpreterIntrinsics and lowered in
30  // JSIntrinsicLowering
31  UNREACHABLE();
32 }
33 
34 RUNTIME_FUNCTION(Runtime_AsyncFunctionReject) {
35  // Runtime call is implemented in InterpreterIntrinsics and lowered in
36  // JSIntrinsicLowering
37  UNREACHABLE();
38 }
39 
40 RUNTIME_FUNCTION(Runtime_AsyncFunctionResolve) {
41  // Runtime call is implemented in InterpreterIntrinsics and lowered in
42  // JSIntrinsicLowering
43  UNREACHABLE();
44 }
45 
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()));
54 
55  // Underlying function needs to have bytecode available.
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);
61 
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);
71  }
72  return *generator;
73 }
74 
75 RUNTIME_FUNCTION(Runtime_GeneratorClose) {
76  // Runtime call is implemented in InterpreterIntrinsics and lowered in
77  // JSIntrinsicLowering
78  UNREACHABLE();
79 }
80 
81 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
82  HandleScope scope(isolate);
83  DCHECK_EQ(1, args.length());
84  CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
85 
86  return generator->function();
87 }
88 
89 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught) {
90  // Runtime call is implemented in InterpreterIntrinsics and lowered in
91  // JSIntrinsicLowering
92  UNREACHABLE();
93 }
94 
95 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught) {
96  // Runtime call is implemented in InterpreterIntrinsics and lowered in
97  // JSIntrinsicLowering
98  UNREACHABLE();
99 }
100 
101 RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
102  // Runtime call is implemented in InterpreterIntrinsics and lowered in
103  // JSIntrinsicLowering
104  UNREACHABLE();
105 }
106 
107 RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
108  // Runtime call is implemented in InterpreterIntrinsics and lowered in
109  // JSIntrinsicLowering
110  UNREACHABLE();
111 }
112 
113 RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
114  // Runtime call is implemented in InterpreterIntrinsics and lowered in
115  // JSIntrinsicLowering
116  UNREACHABLE();
117 }
118 
119 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
120  // Runtime call is implemented in InterpreterIntrinsics and lowered in
121  // JSIntrinsicLowering
122  UNREACHABLE();
123 }
124 
125 // Return true if {generator}'s PC has a catch handler. This allows
126 // catch prediction to happen from the AsyncGeneratorResumeNext stub.
127 RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
128  DisallowHeapAllocation no_allocation_scope;
129  DCHECK_EQ(1, args.length());
130  CONVERT_ARG_CHECKED(JSAsyncGeneratorObject, generator, 0);
131 
132  int state = generator->continuation();
133  DCHECK_NE(state, JSAsyncGeneratorObject::kGeneratorExecuting);
134 
135  // If state is 0 ("suspendedStart"), there is guaranteed to be no catch
136  // handler. Otherwise, if state is below 0, the generator is closed and will
137  // not reach a catch handler.
138  if (state < 1) return ReadOnlyRoots(isolate).false_value();
139 
140  SharedFunctionInfo* shared = generator->function()->shared();
141  DCHECK(shared->HasBytecodeArray());
142  HandlerTable handler_table(shared->GetBytecodeArray());
143 
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);
148 }
149 
150 } // namespace internal
151 } // namespace v8
Definition: libplatform.h:13