LCOV - code coverage report
Current view: top level - src/objects - js-generator.h (source / functions) Hit Total Coverage
Test: app.info Lines: 2 2 100.0 %
Date: 2019-01-20 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.10