• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/execution/arguments-inl.h"
6 #include "src/heap/factory.h"
7 #include "src/heap/heap-inl.h"
8 #include "src/logging/counters.h"
9 #include "src/objects/js-generator-inl.h"
10 #include "src/objects/objects-inl.h"
11 #include "src/runtime/runtime-utils.h"
12 
13 namespace v8 {
14 namespace internal {
15 
RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitCaught)16 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitCaught) {
17   // Runtime call is implemented in InterpreterIntrinsics and lowered in
18   // JSIntrinsicLowering
19   UNREACHABLE();
20 }
21 
RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitUncaught)22 RUNTIME_FUNCTION(Runtime_AsyncFunctionAwaitUncaught) {
23   // Runtime call is implemented in InterpreterIntrinsics and lowered in
24   // JSIntrinsicLowering
25   UNREACHABLE();
26 }
27 
RUNTIME_FUNCTION(Runtime_AsyncFunctionEnter)28 RUNTIME_FUNCTION(Runtime_AsyncFunctionEnter) {
29   // Runtime call is implemented in InterpreterIntrinsics and lowered in
30   // JSIntrinsicLowering
31   UNREACHABLE();
32 }
33 
RUNTIME_FUNCTION(Runtime_AsyncFunctionReject)34 RUNTIME_FUNCTION(Runtime_AsyncFunctionReject) {
35   // Runtime call is implemented in InterpreterIntrinsics and lowered in
36   // JSIntrinsicLowering
37   UNREACHABLE();
38 }
39 
RUNTIME_FUNCTION(Runtime_AsyncFunctionResolve)40 RUNTIME_FUNCTION(Runtime_AsyncFunctionResolve) {
41   // Runtime call is implemented in InterpreterIntrinsics and lowered in
42   // JSIntrinsicLowering
43   UNREACHABLE();
44 }
45 
RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject)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_resume_mode(JSGeneratorObject::ResumeMode::kNext);
69   generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
70   if (generator->IsJSAsyncGeneratorObject()) {
71     Handle<JSAsyncGeneratorObject>::cast(generator)->set_is_awaiting(0);
72   }
73   return *generator;
74 }
75 
RUNTIME_FUNCTION(Runtime_GeneratorClose)76 RUNTIME_FUNCTION(Runtime_GeneratorClose) {
77   // Runtime call is implemented in InterpreterIntrinsics and lowered in
78   // JSIntrinsicLowering
79   UNREACHABLE();
80 }
81 
RUNTIME_FUNCTION(Runtime_GeneratorGetFunction)82 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
83   HandleScope scope(isolate);
84   DCHECK_EQ(1, args.length());
85   CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
86 
87   return generator->function();
88 }
89 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught)90 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught) {
91   // Runtime call is implemented in InterpreterIntrinsics and lowered in
92   // JSIntrinsicLowering
93   UNREACHABLE();
94 }
95 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught)96 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught) {
97   // Runtime call is implemented in InterpreterIntrinsics and lowered in
98   // JSIntrinsicLowering
99   UNREACHABLE();
100 }
101 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve)102 RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
103   // Runtime call is implemented in InterpreterIntrinsics and lowered in
104   // JSIntrinsicLowering
105   UNREACHABLE();
106 }
107 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject)108 RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
109   // Runtime call is implemented in InterpreterIntrinsics and lowered in
110   // JSIntrinsicLowering
111   UNREACHABLE();
112 }
113 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield)114 RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
115   // Runtime call is implemented in InterpreterIntrinsics and lowered in
116   // JSIntrinsicLowering
117   UNREACHABLE();
118 }
119 
RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode)120 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
121   // Runtime call is implemented in InterpreterIntrinsics and lowered in
122   // JSIntrinsicLowering
123   UNREACHABLE();
124 }
125 
126 // Return true if {generator}'s PC has a catch handler. This allows
127 // catch prediction to happen from the AsyncGeneratorResumeNext stub.
RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC)128 RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
129   DisallowHeapAllocation no_allocation_scope;
130   DCHECK_EQ(1, args.length());
131   CONVERT_ARG_CHECKED(JSAsyncGeneratorObject, generator, 0);
132 
133   int state = generator.continuation();
134   DCHECK_NE(state, JSAsyncGeneratorObject::kGeneratorExecuting);
135 
136   // If state is 0 ("suspendedStart"), there is guaranteed to be no catch
137   // handler. Otherwise, if state is below 0, the generator is closed and will
138   // not reach a catch handler.
139   if (state < 1) return ReadOnlyRoots(isolate).false_value();
140 
141   SharedFunctionInfo shared = generator.function().shared();
142   DCHECK(shared.HasBytecodeArray());
143   HandlerTable handler_table(shared.GetBytecodeArray());
144 
145   int pc = Smi::cast(generator.input_or_debug_pos()).value();
146   HandlerTable::CatchPrediction catch_prediction = HandlerTable::ASYNC_AWAIT;
147   handler_table.LookupRange(pc, nullptr, &catch_prediction);
148   return isolate->heap()->ToBoolean(catch_prediction == HandlerTable::CAUGHT);
149 }
150 
151 }  // namespace internal
152 }  // namespace v8
153