Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use offset calc. instead of req->data in node_file #21839

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ inline MaybeLocal<Promise> 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<CloseReq*>(req->data);
CloseReq* close = CloseReq::from_req(req);
CHECK_NOT_NULL(close);
close->file_handle()->AfterClose();
Isolate* isolate = close->env()->isolate();
Expand Down Expand Up @@ -477,15 +477,15 @@ bool FSReqAfterScope::Proceed() {
}

void AfterNoArgs(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

if (after.Proceed())
req_wrap->Resolve(Undefined(req_wrap->env()->isolate()));
}

void AfterStat(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

if (after.Proceed()) {
Expand All @@ -494,15 +494,15 @@ void AfterStat(uv_fs_t* req) {
}

void AfterInteger(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

if (after.Proceed())
req_wrap->Resolve(Integer::New(req_wrap->env()->isolate(), req->result));
}

void AfterOpenFileHandle(uv_fs_t* req) {
FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

if (after.Proceed()) {
Expand All @@ -512,7 +512,7 @@ void AfterOpenFileHandle(uv_fs_t* req) {
}

void AfterStringPath(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

MaybeLocal<Value> link;
Expand All @@ -531,7 +531,7 @@ void AfterStringPath(uv_fs_t* req) {
}

void AfterStringPtr(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

MaybeLocal<Value> link;
Expand All @@ -550,7 +550,7 @@ void AfterStringPtr(uv_fs_t* req) {
}

void AfterScanDir(uv_fs_t* req) {
FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data);
FSReqBase* req_wrap = FSReqBase::from_req(req);
FSReqAfterScope after(req_wrap, req);

if (after.Proceed()) {
Expand Down
8 changes: 8 additions & 0 deletions src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class FSReqBase : public ReqWrap<uv_fs_t> {

bool use_bigint() const { return use_bigint_; }

static FSReqBase* from_req(uv_fs_t* req) {
return static_cast<FSReqBase*>(ReqWrap::from_req(req));
}

private:
enum encoding encoding_ = UTF8;
bool has_data_ = false;
Expand Down Expand Up @@ -284,6 +288,10 @@ class FileHandle : public AsyncWrap, public StreamBase {

void Reject(Local<Value> reason);

static CloseReq* from_req(uv_fs_t* req) {
return static_cast<CloseReq*>(ReqWrap::from_req(req));
}

private:
Persistent<Promise> promise_;
Persistent<Value> ref_;
Expand Down