Line data Source code
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 0 : RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitCaught) {
17 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
18 : // JSIntrinsicLowering
19 0 : UNREACHABLE();
20 : }
21 :
22 0 : RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitUncaught) {
23 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
24 : // JSIntrinsicLowering
25 0 : UNREACHABLE();
26 : }
27 :
28 0 : RUNTIME_FUNCTION(Runtime_AsyncFunctionEnter) {
29 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
30 : // JSIntrinsicLowering
31 0 : UNREACHABLE();
32 : }
33 :
34 0 : RUNTIME_FUNCTION(Runtime_AsyncFunctionReject) {
35 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
36 : // JSIntrinsicLowering
37 0 : UNREACHABLE();
38 : }
39 :
40 0 : RUNTIME_FUNCTION(Runtime_AsyncFunctionResolve) {
41 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
42 : // JSIntrinsicLowering
43 0 : UNREACHABLE();
44 : }
45 :
46 17360 : RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) {
47 : HandleScope scope(isolate);
48 : DCHECK_EQ(2, args.length());
49 8680 : CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
50 : CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
51 10055 : CHECK_IMPLIES(IsAsyncFunction(function->shared()->kind()),
52 : IsAsyncGeneratorFunction(function->shared()->kind()));
53 8680 : CHECK(IsResumableFunction(function->shared()->kind()));
54 :
55 : // Underlying function needs to have bytecode available.
56 : DCHECK(function->shared()->HasBytecodeArray());
57 8680 : int size = function->shared()->internal_formal_parameter_count() +
58 17360 : function->shared()->GetBytecodeArray()->register_count();
59 : Handle<FixedArray> parameters_and_registers =
60 8680 : isolate->factory()->NewFixedArray(size);
61 :
62 : Handle<JSGeneratorObject> generator =
63 8680 : isolate->factory()->NewJSGeneratorObject(function);
64 : generator->set_function(*function);
65 8680 : generator->set_context(isolate->context());
66 8680 : generator->set_receiver(*receiver);
67 8680 : generator->set_parameters_and_registers(*parameters_and_registers);
68 : generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
69 8680 : if (generator->IsJSAsyncGeneratorObject()) {
70 : Handle<JSAsyncGeneratorObject>::cast(generator)->set_is_awaiting(0);
71 : }
72 : return *generator;
73 : }
74 :
75 0 : RUNTIME_FUNCTION(Runtime_GeneratorClose) {
76 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
77 : // JSIntrinsicLowering
78 0 : UNREACHABLE();
79 : }
80 :
81 3402 : RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
82 : HandleScope scope(isolate);
83 : DCHECK_EQ(1, args.length());
84 1701 : CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
85 :
86 : return generator->function();
87 : }
88 :
89 0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught) {
90 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
91 : // JSIntrinsicLowering
92 0 : UNREACHABLE();
93 : }
94 :
95 0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught) {
96 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
97 : // JSIntrinsicLowering
98 0 : UNREACHABLE();
99 : }
100 :
101 0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
102 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
103 : // JSIntrinsicLowering
104 0 : UNREACHABLE();
105 : }
106 :
107 0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
108 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
109 : // JSIntrinsicLowering
110 0 : UNREACHABLE();
111 : }
112 :
113 0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
114 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
115 : // JSIntrinsicLowering
116 0 : UNREACHABLE();
117 : }
118 :
119 0 : RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
120 : // Runtime call is implemented in InterpreterIntrinsics and lowered in
121 : // JSIntrinsicLowering
122 0 : 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 450 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
128 : DisallowHeapAllocation no_allocation_scope;
129 : DCHECK_EQ(1, args.length());
130 225 : 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 225 : if (state < 1) return ReadOnlyRoots(isolate).false_value();
139 :
140 63 : SharedFunctionInfo shared = generator->function()->shared();
141 : DCHECK(shared->HasBytecodeArray());
142 63 : HandlerTable handler_table(shared->GetBytecodeArray());
143 :
144 : int pc = Smi::cast(generator->input_or_debug_pos())->value();
145 63 : HandlerTable::CatchPrediction catch_prediction = HandlerTable::ASYNC_AWAIT;
146 63 : handler_table.LookupRange(pc, nullptr, &catch_prediction);
147 63 : return isolate->heap()->ToBoolean(catch_prediction == HandlerTable::CAUGHT);
148 : }
149 :
150 : } // namespace internal
151 122036 : } // namespace v8
|