diff options
author | James M Snell <jasnell@gmail.com> | 2018-01-12 03:14:33 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-01-19 01:06:33 +0300 |
commit | 4b9ba9b83390f351d4a9f32ffef7730f87b17d2b (patch) | |
tree | 6aff2f961d20d7450b6902306d47265267f924de /src/node_file.h | |
parent | a7a1ada5b2afd586a8b73822ae0b3f59059a3552 (diff) |
fs: encapsulate FSReqWrap more
In further preparation for the Promises enabled fs API,
further encapsulate FSReqWrap details.
The intent here is to isolate, as much as possible, the
functionality of the various fs functions from the details
of how the results are notified. The promises implementation
will use a `FSReqPromise` alternative to `FSReqWrap` that
will use the same API so that both models can be used without
changing any of the actual implementation details for the
various methods.
PR-URL: https://github.com/nodejs/node/pull/18112
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_file.h')
-rw-r--r-- | src/node_file.h | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/src/node_file.h b/src/node_file.h index db85451b67a..878d02c8ba4 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -17,60 +17,39 @@ using v8::Value; namespace fs { -class FSReqWrap: public ReqWrap<uv_fs_t> { +class FSReqWrap : public ReqWrap<uv_fs_t> { public: - enum Ownership { COPY, MOVE }; + FSReqWrap(Environment* env, Local<Object> req) + : ReqWrap(env, req, AsyncWrap::PROVIDER_FSREQWRAP) { + Wrap(object(), this); + } - inline static FSReqWrap* New(Environment* env, - Local<Object> req, - const char* syscall, - const char* data = nullptr, - enum encoding encoding = UTF8, - Ownership ownership = COPY); + virtual ~FSReqWrap() { + ClearWrap(object()); + } - inline void Dispose(); + void Init(const char* syscall, + const char* data = nullptr, + size_t len = 0, + enum encoding encoding = UTF8); + virtual void FillStatsArray(const uv_stat_t* stat); virtual void Reject(Local<Value> reject); virtual void Resolve(Local<Value> value); - - void ReleaseEarly() { - if (data_ != inline_data()) { - delete[] data_; - data_ = nullptr; - } - } + virtual void ResolveStat(); const char* syscall() const { return syscall_; } const char* data() const { return data_; } - const enum encoding encoding_; + enum encoding encoding() const { return encoding_; } size_t self_size() const override { return sizeof(*this); } - protected: - FSReqWrap(Environment* env, - Local<Object> req, - const char* syscall, - const char* data, - enum encoding encoding) - : ReqWrap(env, req, AsyncWrap::PROVIDER_FSREQWRAP), - encoding_(encoding), - syscall_(syscall), - data_(data) { - Wrap(object(), this); - } - - virtual ~FSReqWrap() { - ReleaseEarly(); - ClearWrap(object()); - } - - void* operator new(size_t size) = delete; - void* operator new(size_t size, char* storage) { return storage; } - char* inline_data() { return reinterpret_cast<char*>(this + 1); } - private: + enum encoding encoding_ = UTF8; const char* syscall_; - const char* data_; + + const char* data_ = nullptr; + MaybeStackBuffer<char> buffer_; DISALLOW_COPY_AND_ASSIGN(FSReqWrap); }; |