GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_main_instance.h Lines: 1 1 100.0 %
Date: 2020-07-19 22:14:24 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_MAIN_INSTANCE_H_
2
#define SRC_NODE_MAIN_INSTANCE_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include <cstddef>
7
#include <memory>
8
9
#include "node.h"
10
#include "util.h"
11
#include "uv.h"
12
#include "v8.h"
13
14
namespace node {
15
16
class ExternalReferenceRegistry;
17
struct EnvSerializeInfo;
18
19
// TODO(joyeecheung): align this with the Worker/WorkerThreadData class.
20
// We may be able to create an abstract class to reuse some of the routines.
21
class NodeMainInstance {
22
 public:
23
  // To create a main instance that does not own the isolate,
24
  // The caller needs to do:
25
  //
26
  //   Isolate* isolate = Isolate::Allocate();
27
  //   platform->RegisterIsolate(isolate, loop);
28
  //   isolate->Initialize(...);
29
  //   isolate->Enter();
30
  //   std::unique_ptr<NodeMainInstance> main_instance =
31
  //       NodeMainInstance::Create(isolate, loop, args, exec_args);
32
  //
33
  // When tearing it down:
34
  //
35
  //   main_instance->Cleanup();  // While the isolate is entered
36
  //   isolate->Exit();
37
  //   isolate->Dispose();
38
  //   platform->UnregisterIsolate(isolate);
39
  //
40
  // After calling Dispose() the main_instance is no longer accessible.
41
  static std::unique_ptr<NodeMainInstance> Create(
42
      v8::Isolate* isolate,
43
      uv_loop_t* event_loop,
44
      MultiIsolatePlatform* platform,
45
      const std::vector<std::string>& args,
46
      const std::vector<std::string>& exec_args);
47
48
  void Dispose();
49
50
  // Create a main instance that owns the isolate
51
  NodeMainInstance(
52
      v8::Isolate::CreateParams* params,
53
      uv_loop_t* event_loop,
54
      MultiIsolatePlatform* platform,
55
      const std::vector<std::string>& args,
56
      const std::vector<std::string>& exec_args,
57
      const std::vector<size_t>* per_isolate_data_indexes = nullptr);
58
  ~NodeMainInstance();
59
60
  // Start running the Node.js instances, return the exit code when finished.
61
  int Run(const EnvSerializeInfo* env_info);
62
63
2
  IsolateData* isolate_data() { return isolate_data_.get(); }
64
65
  DeleteFnPtr<Environment, FreeEnvironment> CreateMainEnvironment(
66
      int* exit_code, const EnvSerializeInfo* env_info);
67
68
  // If nullptr is returned, the binary is not built with embedded
69
  // snapshot.
70
  static const std::vector<size_t>* GetIsolateDataIndexes();
71
  static v8::StartupData* GetEmbeddedSnapshotBlob();
72
  static const EnvSerializeInfo* GetEnvSerializeInfo();
73
  static const std::vector<intptr_t>& CollectExternalReferences();
74
75
  static const size_t kNodeContextIndex = 0;
76
  NodeMainInstance(const NodeMainInstance&) = delete;
77
  NodeMainInstance& operator=(const NodeMainInstance&) = delete;
78
  NodeMainInstance(NodeMainInstance&&) = delete;
79
  NodeMainInstance& operator=(NodeMainInstance&&) = delete;
80
81
 private:
82
  NodeMainInstance(v8::Isolate* isolate,
83
                   uv_loop_t* event_loop,
84
                   MultiIsolatePlatform* platform,
85
                   const std::vector<std::string>& args,
86
                   const std::vector<std::string>& exec_args);
87
88
  static std::unique_ptr<ExternalReferenceRegistry> registry_;
89
  std::vector<std::string> args_;
90
  std::vector<std::string> exec_args_;
91
  std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_;
92
  v8::Isolate* isolate_;
93
  MultiIsolatePlatform* platform_;
94
  std::unique_ptr<IsolateData> isolate_data_;
95
  bool owns_isolate_ = false;
96
  bool deserialize_mode_ = false;
97
};
98
99
}  // namespace node
100
101
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
102
#endif  // SRC_NODE_MAIN_INSTANCE_H_