Home | History | Annotate | Download | only in objects
      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.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 class JSGeneratorObject : public JSObject {
     17  public:
     18   // [function]: The function corresponding to this generator object.
     19   DECL_ACCESSORS(function, JSFunction)
     20 
     21   // [context]: The context of the suspended computation.
     22   DECL_ACCESSORS(context, Context)
     23 
     24   // [receiver]: The receiver of the suspended computation.
     25   DECL_ACCESSORS(receiver, Object)
     26 
     27   // [input_or_debug_pos]
     28   // For executing generators: the most recent input value.
     29   // For suspended generators: debug information (bytecode offset).
     30   // There is currently no need to remember the most recent input value for a
     31   // suspended generator.
     32   DECL_ACCESSORS(input_or_debug_pos, Object)
     33 
     34   // [resume_mode]: The most recent resume mode.
     35   enum ResumeMode { kNext, kReturn, kThrow };
     36   DECL_INT_ACCESSORS(resume_mode)
     37 
     38   // [continuation]
     39   //
     40   // A positive value indicates a suspended generator.  The special
     41   // kGeneratorExecuting and kGeneratorClosed values indicate that a generator
     42   // cannot be resumed.
     43   inline int continuation() const;
     44   inline void set_continuation(int continuation);
     45   inline bool is_closed() const;
     46   inline bool is_executing() const;
     47   inline bool is_suspended() const;
     48 
     49   // For suspended generators: the source position at which the generator
     50   // is suspended.
     51   int source_position() const;
     52 
     53   // [parameters_and_registers]: Saved interpreter register file.
     54   DECL_ACCESSORS(parameters_and_registers, FixedArray)
     55 
     56   DECL_CAST(JSGeneratorObject)
     57 
     58   // Dispatched behavior.
     59   DECL_PRINTER(JSGeneratorObject)
     60   DECL_VERIFIER(JSGeneratorObject)
     61 
     62   // Magic sentinel values for the continuation.
     63   static const int kGeneratorExecuting = -2;
     64   static const int kGeneratorClosed = -1;
     65 
     66   // Layout description.
     67   static const int kFunctionOffset = JSObject::kHeaderSize;
     68   static const int kContextOffset = kFunctionOffset + kPointerSize;
     69   static const int kReceiverOffset = kContextOffset + kPointerSize;
     70   static const int kInputOrDebugPosOffset = kReceiverOffset + kPointerSize;
     71   static const int kResumeModeOffset = kInputOrDebugPosOffset + kPointerSize;
     72   static const int kContinuationOffset = kResumeModeOffset + kPointerSize;
     73   static const int kParametersAndRegistersOffset =
     74       kContinuationOffset + kPointerSize;
     75   static const int kSize = kParametersAndRegistersOffset + kPointerSize;
     76 
     77  private:
     78   DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject);
     79 };
     80 
     81 class JSAsyncGeneratorObject : public JSGeneratorObject {
     82  public:
     83   DECL_CAST(JSAsyncGeneratorObject)
     84 
     85   // Dispatched behavior.
     86   DECL_VERIFIER(JSAsyncGeneratorObject)
     87 
     88   // [queue]
     89   // Pointer to the head of a singly linked list of AsyncGeneratorRequest, or
     90   // undefined.
     91   DECL_ACCESSORS(queue, HeapObject)
     92 
     93   // [is_awaiting]
     94   // Whether or not the generator is currently awaiting.
     95   DECL_INT_ACCESSORS(is_awaiting)
     96 
     97   // Layout description.
     98   static const int kQueueOffset = JSGeneratorObject::kSize;
     99   static const int kIsAwaitingOffset = kQueueOffset + kPointerSize;
    100   static const int kSize = kIsAwaitingOffset + kPointerSize;
    101 
    102  private:
    103   DISALLOW_IMPLICIT_CONSTRUCTORS(JSAsyncGeneratorObject);
    104 };
    105 
    106 }  // namespace internal
    107 }  // namespace v8
    108 
    109 #include "src/objects/object-macros-undef.h"
    110 
    111 #endif  // V8_OBJECTS_JS_GENERATOR_H_
    112