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