xref: /third_party/node/src/node_process.h (revision 1cb0ef41)
1#ifndef SRC_NODE_PROCESS_H_
2#define SRC_NODE_PROCESS_H_
3
4#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6#include "node_snapshotable.h"
7#include "v8-fast-api-calls.h"
8#include "v8.h"
9
10namespace node {
11
12class Environment;
13class IsolateData;
14class MemoryTracker;
15class ExternalReferenceRegistry;
16class Realm;
17
18void CreateEnvProxyTemplate(v8::Isolate* isolate, IsolateData* isolate_data);
19
20// Most of the time, it's best to use `console.error` to write
21// to the process.stderr stream.  However, in some cases, such as
22// when debugging the stream.Writable class or the process.nextTick
23// function, it is useful to bypass JavaScript entirely.
24void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);
25
26v8::MaybeLocal<v8::Value> ProcessEmit(Environment* env,
27                                      const char* event,
28                                      v8::Local<v8::Value> message);
29
30v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
31                                          const char* warning,
32                                          const char* type = nullptr,
33                                          const char* code = nullptr);
34
35template <typename... Args>
36inline v8::Maybe<bool> ProcessEmitWarning(Environment* env,
37                                          const char* fmt,
38                                          Args&&... args);
39v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env,
40                                              const char* warning);
41v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
42                                              const char* warning,
43                                              const char* deprecation_code);
44
45v8::MaybeLocal<v8::Object> CreateProcessObject(Realm* env);
46void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args);
47
48namespace process {
49class BindingData : public SnapshotableObject {
50 public:
51  void AddMethods();
52  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
53
54  using InternalFieldInfo = InternalFieldInfoBase;
55
56  SERIALIZABLE_OBJECT_METHODS()
57  SET_BINDING_ID(process_binding_data)
58
59  BindingData(Realm* realm, v8::Local<v8::Object> object);
60
61  void MemoryInfo(MemoryTracker* tracker) const override;
62  SET_MEMORY_INFO_NAME(BindingData)
63  SET_SELF_SIZE(BindingData)
64
65  static BindingData* FromV8Value(v8::Local<v8::Value> receiver);
66  static void NumberImpl(BindingData* receiver);
67
68  static void FastNumber(v8::Local<v8::Value> receiver) {
69    NumberImpl(FromV8Value(receiver));
70  }
71
72  static void SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args);
73
74  static void BigIntImpl(BindingData* receiver);
75
76  static void FastBigInt(v8::Local<v8::Value> receiver) {
77    BigIntImpl(FromV8Value(receiver));
78  }
79
80  static void SlowBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
81
82 private:
83  static constexpr size_t kBufferSize =
84      std::max(sizeof(uint64_t), sizeof(uint32_t) * 3);
85  v8::Global<v8::ArrayBuffer> array_buffer_;
86  std::shared_ptr<v8::BackingStore> backing_store_;
87
88  // These need to be static so that we have their addresses available to
89  // register as external references in the snapshot at environment creation
90  // time.
91  static v8::CFunction fast_number_;
92  static v8::CFunction fast_bigint_;
93};
94
95}  // namespace process
96}  // namespace node
97#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
98#endif  // SRC_NODE_PROCESS_H_
99