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: slightly simplify FSEventWrap #21533

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
19 changes: 3 additions & 16 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class FSEventWrap: public HandleWrap {
Local<Context> context);
static void New(const FunctionCallbackInfo<Value>& args);
static void Start(const FunctionCallbackInfo<Value>& args);
static void Close(const FunctionCallbackInfo<Value>& args);
static void GetInitialized(const FunctionCallbackInfo<Value>& args);
size_t self_size() const override { return sizeof(*this); }

Expand All @@ -69,7 +68,6 @@ class FSEventWrap: public HandleWrap {
int status);

uv_fs_event_t handle_;
bool initialized_ = false;
enum encoding encoding_ = kDefaultEncoding;
};

Expand All @@ -89,7 +87,7 @@ FSEventWrap::~FSEventWrap() {
void FSEventWrap::GetInitialized(const FunctionCallbackInfo<Value>& args) {
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
CHECK_NOT_NULL(wrap);
args.GetReturnValue().Set(wrap->initialized_);
args.GetReturnValue().Set(!wrap->IsHandleClosing());
}

void FSEventWrap::Initialize(Local<Object> target,
Expand All @@ -104,7 +102,7 @@ void FSEventWrap::Initialize(Local<Object> target,

AsyncWrap::AddWrapMethods(env, t);
env->SetProtoMethod(t, "start", Start);
env->SetProtoMethod(t, "close", Close);
env->SetProtoMethod(t, "close", HandleWrap::Close);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use unqualified Close, that turns it into a build error if FSEventWrap stops being a HandleWrap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


Local<FunctionTemplate> get_initialized_templ =
FunctionTemplate::New(env->isolate(),
Expand Down Expand Up @@ -134,7 +132,7 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {

FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
CHECK_NOT_NULL(wrap);
CHECK(!wrap->initialized_);
CHECK(wrap->IsHandleClosing()); // Check that Start() has not been called.

const int argc = args.Length();
CHECK_GE(argc, 4);
Expand All @@ -155,7 +153,6 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {

err = uv_fs_event_start(&wrap->handle_, OnEvent, *path, flags);
wrap->MarkAsInitialized();
wrap->initialized_ = true;

if (err != 0) {
FSEventWrap::Close(args);
Expand Down Expand Up @@ -230,16 +227,6 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv);
}


void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
CHECK_NOT_NULL(wrap);
CHECK(wrap->initialized_);

wrap->initialized_ = false;
HandleWrap::Close(args);
}

} // anonymous namespace
} // namespace node

Expand Down