diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-05 05:02:57 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-04-06 03:06:43 +0300 |
commit | f4c2dff4e61570e6b8512f2a41ac2d17c2473a5e (patch) | |
tree | 1aafd878ebf5d5019b99f2cfa0d78a0a2410f98a /src/node_file.h | |
parent | 1216e8f7773c14b12e93e97ed19655c248c4c6bb (diff) |
src: move fs state out of Environment
Moves state that is specific to the `fs` binding into the
`fs` binding implementation as a cleanup.
PR-URL: https://github.com/nodejs/node/pull/32538
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_file.h')
-rw-r--r-- | src/node_file.h | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/node_file.h b/src/node_file.h index 1ebfe06c1fb..1fda81361fe 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -11,6 +11,26 @@ namespace node { namespace fs { +class FileHandleReadWrap; + +class BindingData : public BaseObject { + public: + explicit BindingData(Environment* env, v8::Local<v8::Object> wrap) + : BaseObject(env, wrap), + stats_field_array(env->isolate(), kFsStatsBufferLength), + stats_field_bigint_array(env->isolate(), kFsStatsBufferLength) {} + + AliasedFloat64Array stats_field_array; + AliasedBigUint64Array stats_field_bigint_array; + + std::vector<BaseObjectPtr<FileHandleReadWrap>> + file_handle_read_wrap_freelist; + + void MemoryInfo(MemoryTracker* tracker) const override; + SET_SELF_SIZE(BindingData) + SET_MEMORY_INFO_NAME(BindingData) +}; + // structure used to store state during a complex operation, e.g., mkdirp. class FSContinuationData : public MemoryRetainer { public: @@ -43,7 +63,7 @@ class FSReqBase : public ReqWrap<uv_fs_t> { public: typedef MaybeStackBuffer<char, 64> FSReqBuffer; - inline FSReqBase(Environment* env, + inline FSReqBase(BindingData* binding_data, v8::Local<v8::Object> req, AsyncWrap::ProviderType type, bool use_bigint); @@ -83,12 +103,16 @@ class FSReqBase : public ReqWrap<uv_fs_t> { void MemoryInfo(MemoryTracker* tracker) const override; + BindingData* binding_data() { return binding_data_.get(); } + private: std::unique_ptr<FSContinuationData> continuation_data_; enum encoding encoding_ = UTF8; bool has_data_ = false; - const char* syscall_ = nullptr; bool use_bigint_ = false; + const char* syscall_ = nullptr; + + BaseObjectPtr<BindingData> binding_data_; // Typically, the content of buffer_ is something like a file name, so // something around 64 bytes should be enough. @@ -97,7 +121,7 @@ class FSReqBase : public ReqWrap<uv_fs_t> { class FSReqCallback final : public FSReqBase { public: - inline FSReqCallback(Environment* env, + inline FSReqCallback(BindingData* binding_data, v8::Local<v8::Object> req, bool use_bigint); @@ -118,7 +142,7 @@ void FillStatsArray(AliasedBufferBase<NativeT, V8T>* fields, const uv_stat_t* s, const size_t offset = 0); -inline v8::Local<v8::Value> FillGlobalStatsArray(Environment* env, +inline v8::Local<v8::Value> FillGlobalStatsArray(BindingData* binding_data, const bool use_bigint, const uv_stat_t* s, const bool second = false); @@ -126,7 +150,8 @@ inline v8::Local<v8::Value> FillGlobalStatsArray(Environment* env, template <typename AliasedBufferT> class FSReqPromise final : public FSReqBase { public: - static inline FSReqPromise* New(Environment* env, bool use_bigint); + static inline FSReqPromise* New(BindingData* binding_data, + bool use_bigint); inline ~FSReqPromise() override; inline void Reject(v8::Local<v8::Value> reject) override; @@ -145,7 +170,7 @@ class FSReqPromise final : public FSReqBase { FSReqPromise& operator=(const FSReqPromise&&) = delete; private: - inline FSReqPromise(Environment* env, + inline FSReqPromise(BindingData* binding_data, v8::Local<v8::Object> obj, bool use_bigint); @@ -202,7 +227,7 @@ class FileHandleReadWrap final : public ReqWrap<uv_fs_t> { // the object is garbage collected class FileHandle final : public AsyncWrap, public StreamBase { public: - static FileHandle* New(Environment* env, + static FileHandle* New(BindingData* binding_data, int fd, v8::Local<v8::Object> obj = v8::Local<v8::Object>()); ~FileHandle() override; @@ -246,7 +271,7 @@ class FileHandle final : public AsyncWrap, public StreamBase { FileHandle& operator=(const FileHandle&&) = delete; private: - FileHandle(Environment* env, v8::Local<v8::Object> obj, int fd); + FileHandle(BindingData* binding_data, v8::Local<v8::Object> obj, int fd); // Synchronous close that emits a warning void Close(); @@ -295,7 +320,9 @@ class FileHandle final : public AsyncWrap, public StreamBase { int64_t read_length_ = -1; bool reading_ = false; - std::unique_ptr<FileHandleReadWrap> current_read_ = nullptr; + BaseObjectPtr<FileHandleReadWrap> current_read_; + + BaseObjectPtr<BindingData> binding_data_; }; int MKDirpSync(uv_loop_t* loop, @@ -327,7 +354,8 @@ class FSReqWrapSync { // TODO(addaleax): Currently, callers check the return value and assume // that nullptr indicates a synchronous call, rather than a failure. // Failure conditions should be disambiguated and handled appropriately. -inline FSReqBase* GetReqWrap(Environment* env, v8::Local<v8::Value> value, +inline FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args, + int index, bool use_bigint = false); // Returns nullptr if the operation fails from the start. |