• 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   Handle<JSFunction> function = args.at<JSFunction>(0);
50   Handle<Object> receiver = args.at(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 =
58       function->shared().internal_formal_parameter_count_without_receiver() +
59       function->shared().GetBytecodeArray(isolate).register_count();
60   Handle<FixedArray> parameters_and_registers =
61       isolate->factory()->NewFixedArray(size);
62 
63   Handle<JSGeneratorObject> generator =
64       isolate->factory()->NewJSGeneratorObject(function);
65   generator->set_function(*function);
66   generator->set_context(isolate->context());
67   generator->set_receiver(*receiver);
68   generator->set_parameters_and_registers(*parameters_and_registers);
69   generator->set_resume_mode(JSGeneratorObject::ResumeMode::kNext);
70   generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
71   if (generator->IsJSAsyncGeneratorObject()) {
72     Handle<JSAsyncGeneratorObject>::cast(generator)->set_is_awaiting(0);
73   }
74   return *generator;
75 }
76 
RUNTIME_FUNCTION(Runtime_GeneratorClose)77 RUNTIME_FUNCTION(Runtime_GeneratorClose) {
78   // Runtime call is implemented in InterpreterIntrinsics and lowered in
79   // JSIntrinsicLowering
80   UNREACHABLE();
81 }
82 
RUNTIME_FUNCTION(Runtime_GeneratorGetFunction)83 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
84   HandleScope scope(isolate);
85   DCHECK_EQ(1, args.length());
86   Handle<JSGeneratorObject> generator = args.at<JSGeneratorObject>(0);
87 
88   return generator->function();
89 }
90 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught)91 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitCaught) {
92   // Runtime call is implemented in InterpreterIntrinsics and lowered in
93   // JSIntrinsicLowering
94   UNREACHABLE();
95 }
96 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught)97 RUNTIME_FUNCTION(Runtime_AsyncGeneratorAwaitUncaught) {
98   // Runtime call is implemented in InterpreterIntrinsics and lowered in
99   // JSIntrinsicLowering
100   UNREACHABLE();
101 }
102 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve)103 RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
104   // Runtime call is implemented in InterpreterIntrinsics and lowered in
105   // JSIntrinsicLowering
106   UNREACHABLE();
107 }
108 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject)109 RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
110   // Runtime call is implemented in InterpreterIntrinsics and lowered in
111   // JSIntrinsicLowering
112   UNREACHABLE();
113 }
114 
RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield)115 RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
116   // Runtime call is implemented in InterpreterIntrinsics and lowered in
117   // JSIntrinsicLowering
118   UNREACHABLE();
119 }
120 
RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode)121 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
122   // Runtime call is implemented in InterpreterIntrinsics and lowered in
123   // JSIntrinsicLowering
124   UNREACHABLE();
125 }
126 
127 // Return true if {generator}'s PC has a catch handler. This allows
128 // catch prediction to happen from the AsyncGeneratorResumeNext stub.
RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC)129 RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
130   DisallowGarbageCollection no_gc_scope;
131   DCHECK_EQ(1, args.length());
132   auto generator = JSAsyncGeneratorObject::cast(args[0]);
133 
134   int state = generator.continuation();
135   DCHECK_NE(state, JSAsyncGeneratorObject::kGeneratorExecuting);
136 
137   // If state is 0 ("suspendedStart"), there is guaranteed to be no catch
138   // handler. Otherwise, if state is below 0, the generator is closed and will
139   // not reach a catch handler.
140   if (state < 1) return ReadOnlyRoots(isolate).false_value();
141 
142   SharedFunctionInfo shared = generator.function().shared();
143   DCHECK(shared.HasBytecodeArray());
144   HandlerTable handler_table(shared.GetBytecodeArray(isolate));
145 
146   int pc = Smi::cast(generator.input_or_debug_pos()).value();
147   HandlerTable::CatchPrediction catch_prediction = HandlerTable::ASYNC_AWAIT;
148   handler_table.LookupRange(pc, nullptr, &catch_prediction);
149   return isolate->heap()->ToBoolean(catch_prediction == HandlerTable::CAUGHT);
150 }
151 
152 }  // namespace internal
153 }  // namespace v8
154