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