GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_main_instance.h Lines: 1 1 100.0 %
Date: 2022-04-26 04:15:06 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
struct SnapshotData;
19
20
// TODO(joyeecheung): align this with the Worker/WorkerThreadData class.
21
// We may be able to create an abstract class to reuse some of the routines.
22
class NodeMainInstance {
23
 public:
24
  // To create a main instance that does not own the isolate,
25
  // The caller needs to do:
26
  //
27
  //   Isolate* isolate = Isolate::Allocate();
28
  //   platform->RegisterIsolate(isolate, loop);
29
  //   isolate->Initialize(...);
30
  //   isolate->Enter();
31
  //   std::unique_ptr<NodeMainInstance> main_instance =
32
  //       NodeMainInstance::Create(isolate, loop, args, exec_args);
33
  //
34
  // When tearing it down:
35
  //
36
  //   main_instance->Cleanup();  // While the isolate is entered
37
  //   isolate->Exit();
38
  //   isolate->Dispose();
39
  //   platform->UnregisterIsolate(isolate);
40
  //
41
  // After calling Dispose() the main_instance is no longer accessible.
42
  static std::unique_ptr<NodeMainInstance> Create(
43
      v8::Isolate* isolate,
44
      uv_loop_t* event_loop,
45
      MultiIsolatePlatform* platform,
46
      const std::vector<std::string>& args,
47
      const std::vector<std::string>& exec_args);
48
49
  void Dispose();
50
51
  // Create a main instance that owns the isolate
52
  NodeMainInstance(const SnapshotData* snapshot_data,
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
  ~NodeMainInstance();
58
59
  // Start running the Node.js instances, return the exit code when finished.
60
  int Run();
61
  void Run(int* exit_code, Environment* env);
62
63
12
  IsolateData* isolate_data() { return isolate_data_.get(); }
64
65
  DeleteFnPtr<Environment, FreeEnvironment> CreateMainEnvironment(
66
      int* exit_code);
67
68
  static const size_t kNodeContextIndex = 0;
69
  NodeMainInstance(const NodeMainInstance&) = delete;
70
  NodeMainInstance& operator=(const NodeMainInstance&) = delete;
71
  NodeMainInstance(NodeMainInstance&&) = delete;
72
  NodeMainInstance& operator=(NodeMainInstance&&) = delete;
73
74
 private:
75
  NodeMainInstance(v8::Isolate* isolate,
76
                   uv_loop_t* event_loop,
77
                   MultiIsolatePlatform* platform,
78
                   const std::vector<std::string>& args,
79
                   const std::vector<std::string>& exec_args);
80
81
  static std::unique_ptr<ExternalReferenceRegistry> registry_;
82
  std::vector<std::string> args_;
83
  std::vector<std::string> exec_args_;
84
  std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_;
85
  v8::Isolate* isolate_;
86
  MultiIsolatePlatform* platform_;
87
  std::unique_ptr<IsolateData> isolate_data_;
88
  std::unique_ptr<v8::Isolate::CreateParams> isolate_params_;
89
  const SnapshotData* snapshot_data_ = nullptr;
90
};
91
92
}  // namespace node
93
94
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
95
#endif  // SRC_NODE_MAIN_INSTANCE_H_