diff --git a/src/node_file.cc b/src/node_file.cc index f08833b201b19d..49e2a6aa0d93e3 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -223,7 +223,7 @@ inline MaybeLocal FileHandle::ClosePromise() { closing_ = true; CloseReq* req = new CloseReq(env(), promise, object()); auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) { - CloseReq* close = static_cast(req->data); + CloseReq* close = CloseReq::from_req(req); CHECK_NOT_NULL(close); close->file_handle()->AfterClose(); Isolate* isolate = close->env()->isolate(); @@ -477,7 +477,7 @@ bool FSReqAfterScope::Proceed() { } void AfterNoArgs(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) @@ -485,7 +485,7 @@ void AfterNoArgs(uv_fs_t* req) { } void AfterStat(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { @@ -494,7 +494,7 @@ void AfterStat(uv_fs_t* req) { } void AfterInteger(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) @@ -502,7 +502,7 @@ void AfterInteger(uv_fs_t* req) { } void AfterOpenFileHandle(uv_fs_t* req) { - FSReqWrap* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { @@ -512,7 +512,7 @@ void AfterOpenFileHandle(uv_fs_t* req) { } void AfterStringPath(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); MaybeLocal link; @@ -531,7 +531,7 @@ void AfterStringPath(uv_fs_t* req) { } void AfterStringPtr(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); MaybeLocal link; @@ -550,7 +550,7 @@ void AfterStringPtr(uv_fs_t* req) { } void AfterScanDir(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { diff --git a/src/node_file.h b/src/node_file.h index 6b45dc881750a7..141d1d42d744a2 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -68,6 +68,10 @@ class FSReqBase : public ReqWrap { bool use_bigint() const { return use_bigint_; } + static FSReqBase* from_req(uv_fs_t* req) { + return static_cast(ReqWrap::from_req(req)); + } + private: enum encoding encoding_ = UTF8; bool has_data_ = false; @@ -284,6 +288,10 @@ class FileHandle : public AsyncWrap, public StreamBase { void Reject(Local reason); + static CloseReq* from_req(uv_fs_t* req) { + return static_cast(ReqWrap::from_req(req)); + } + private: Persistent promise_; Persistent ref_;