Skip to content

Commit

Permalink
src: make StreamBase::GetAsyncWrap pure virtual
Browse files Browse the repository at this point in the history
PR-URL: #13174
Reviewed-By: Andreas Madsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
  • Loading branch information
addaleax authored and jasnell committed May 28, 2017
1 parent 597aff0 commit b4f6ea0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 5 additions & 19 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
Local<Object> req_wrap_obj = args[0].As<Object>();

AsyncWrap* wrap = GetAsyncWrap();
if (wrap != nullptr)
env->set_init_trigger_id(wrap->get_id());
CHECK_NE(wrap, nullptr);
env->set_init_trigger_id(wrap->get_id());
ShutdownWrap* req_wrap = new ShutdownWrap(env,
req_wrap_obj,
this,
Expand Down Expand Up @@ -133,8 +133,6 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
return UV_ENOBUFS;

AsyncWrap* wrap = GetAsyncWrap();
// NOTE: All tests show that GetAsyncWrap() never returns nullptr here. If it
// can then replace the CHECK_NE() with if (wrap != nullptr).
CHECK_NE(wrap, nullptr);
env->set_init_trigger_id(wrap->get_id());
WriteWrap* req_wrap = WriteWrap::New(env,
Expand Down Expand Up @@ -425,16 +423,9 @@ void StreamBase::EmitData(ssize_t nread,
if (argv[2].IsEmpty())
argv[2] = Undefined(env->isolate());

AsyncWrap* async = GetAsyncWrap();
if (async == nullptr) {
node::MakeCallback(env,
GetObject(),
env->onread_string(),
arraysize(argv),
argv);
} else {
async->MakeCallback(env->onread_string(), arraysize(argv), argv);
}
AsyncWrap* wrap = GetAsyncWrap();
CHECK_NE(wrap, nullptr);
wrap->MakeCallback(env->onread_string(), arraysize(argv), argv);
}


Expand All @@ -448,11 +439,6 @@ int StreamBase::GetFD() {
}


AsyncWrap* StreamBase::GetAsyncWrap() {
return nullptr;
}


Local<Object> StreamBase::GetObject() {
return GetAsyncWrap()->object();
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class StreamBase : public StreamResource {
virtual ~StreamBase() = default;

// One of these must be implemented
virtual AsyncWrap* GetAsyncWrap();
virtual AsyncWrap* GetAsyncWrap() = 0;
virtual v8::Local<v8::Object> GetObject();

// Libuv callbacks
Expand Down

0 comments on commit b4f6ea0

Please sign in to comment.