V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-generator.h
1 // Copyright 2018 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 #ifndef V8_OBJECTS_JS_GENERATOR_H_
6 #define V8_OBJECTS_JS_GENERATOR_H_
7 
8 #include "src/objects/js-objects.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // Forward declarations.
17 class JSPromise;
18 
19 class JSGeneratorObject : public JSObject {
20  public:
21  // [function]: The function corresponding to this generator object.
22  DECL_ACCESSORS(function, JSFunction)
23 
24  // [context]: The context of the suspended computation.
25  DECL_ACCESSORS2(context, Context)
26 
27  // [receiver]: The receiver of the suspended computation.
28  DECL_ACCESSORS(receiver, Object)
29 
30  // [input_or_debug_pos]
31  // For executing generators: the most recent input value.
32  // For suspended generators: debug information (bytecode offset).
33  // There is currently no need to remember the most recent input value for a
34  // suspended generator.
35  DECL_ACCESSORS(input_or_debug_pos, Object)
36 
37  // [resume_mode]: The most recent resume mode.
38  enum ResumeMode { kNext, kReturn, kThrow };
39  DECL_INT_ACCESSORS(resume_mode)
40 
41  // [continuation]
42  //
43  // A positive value indicates a suspended generator. The special
44  // kGeneratorExecuting and kGeneratorClosed values indicate that a generator
45  // cannot be resumed.
46  inline int continuation() const;
47  inline void set_continuation(int continuation);
48  inline bool is_closed() const;
49  inline bool is_executing() const;
50  inline bool is_suspended() const;
51 
52  // For suspended generators: the source position at which the generator
53  // is suspended.
54  int source_position() const;
55 
56  // [parameters_and_registers]: Saved interpreter register file.
57  DECL_ACCESSORS2(parameters_and_registers, FixedArray)
58 
59  DECL_CAST(JSGeneratorObject)
60 
61  // Dispatched behavior.
62  DECL_PRINTER(JSGeneratorObject)
63  DECL_VERIFIER(JSGeneratorObject)
64 
65  // Magic sentinel values for the continuation.
66  static const int kGeneratorExecuting = -2;
67  static const int kGeneratorClosed = -1;
68 
69  // Layout description.
70 #define JS_GENERATOR_FIELDS(V) \
71  V(kFunctionOffset, kTaggedSize) \
72  V(kContextOffset, kTaggedSize) \
73  V(kReceiverOffset, kTaggedSize) \
74  V(kInputOrDebugPosOffset, kTaggedSize) \
75  V(kResumeModeOffset, kTaggedSize) \
76  V(kContinuationOffset, kTaggedSize) \
77  V(kParametersAndRegistersOffset, kTaggedSize) \
78  /* Header size. */ \
79  V(kSize, 0)
80 
81  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_GENERATOR_FIELDS)
82 #undef JS_GENERATOR_FIELDS
83 
84  private:
85  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject);
86 };
87 
89  public:
90  DECL_CAST(JSAsyncFunctionObject)
91 
92  // Dispatched behavior.
93  DECL_VERIFIER(JSAsyncFunctionObject)
94 
95  // [promise]: The promise of the async function.
96  DECL_ACCESSORS(promise, JSPromise)
97 
98  // Layout description.
99 #define JS_ASYNC_FUNCTION_FIELDS(V) \
100  V(kPromiseOffset, kTaggedSize) \
101  /* Header size. */ \
102  V(kSize, 0)
103 
104  DEFINE_FIELD_OFFSET_CONSTANTS(JSGeneratorObject::kSize,
105  JS_ASYNC_FUNCTION_FIELDS)
106 #undef JS_ASYNC_FUNCTION_FIELDS
107 
108  private:
109  DISALLOW_IMPLICIT_CONSTRUCTORS(JSAsyncFunctionObject);
110 };
111 
113  public:
114  DECL_CAST(JSAsyncGeneratorObject)
115 
116  // Dispatched behavior.
117  DECL_VERIFIER(JSAsyncGeneratorObject)
118 
119  // [queue]
120  // Pointer to the head of a singly linked list of AsyncGeneratorRequest, or
121  // undefined.
122  DECL_ACCESSORS(queue, HeapObject)
123 
124  // [is_awaiting]
125  // Whether or not the generator is currently awaiting.
126  DECL_INT_ACCESSORS(is_awaiting)
127 
128  // Layout description.
129 #define JS_ASYNC_GENERATOR_FIELDS(V) \
130  V(kQueueOffset, kTaggedSize) \
131  V(kIsAwaitingOffset, kTaggedSize) \
132  /* Header size. */ \
133  V(kSize, 0)
134 
135  DEFINE_FIELD_OFFSET_CONSTANTS(JSGeneratorObject::kSize,
136  JS_ASYNC_GENERATOR_FIELDS)
137 #undef JS_ASYNC_GENERATOR_FIELDS
138 
139  private:
140  DISALLOW_IMPLICIT_CONSTRUCTORS(JSAsyncGeneratorObject);
141 };
142 
144  public:
145  // Holds an AsyncGeneratorRequest, or Undefined.
146  DECL_ACCESSORS(next, Object)
147  DECL_INT_ACCESSORS(resume_mode)
148  DECL_ACCESSORS(value, Object)
149  DECL_ACCESSORS(promise, Object)
150 
151  static const int kNextOffset = Struct::kHeaderSize;
152  static const int kResumeModeOffset = kNextOffset + kPointerSize;
153  static const int kValueOffset = kResumeModeOffset + kPointerSize;
154  static const int kPromiseOffset = kValueOffset + kPointerSize;
155  static const int kSize = kPromiseOffset + kPointerSize;
156 
157  DECL_CAST(AsyncGeneratorRequest)
158  DECL_PRINTER(AsyncGeneratorRequest)
159  DECL_VERIFIER(AsyncGeneratorRequest)
160 
161  private:
162  DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncGeneratorRequest);
163 };
164 
165 } // namespace internal
166 } // namespace v8
167 
168 #include "src/objects/object-macros-undef.h"
169 
170 #endif // V8_OBJECTS_JS_GENERATOR_H_
Definition: libplatform.h:13