diff options
author | Trevor Norris <trev.norris@gmail.com> | 2014-12-09 05:29:47 +0100 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2014-12-09 17:57:15 +0100 |
commit | 819690fd983d61f90cdf05714a30782fe3b553cd (patch) | |
tree | d4dad55e559776cb72e7e79fb55586393e396a21 /src/pipe_wrap.cc | |
parent | 8f41db6104deca82d74f55501a7f2689357fb45d (diff) | |
download | node-new-819690fd983d61f90cdf05714a30782fe3b553cd.tar.gz |
src: all wraps now use actual FunctionTemplate
Instead of simply creating a new v8::Object to contain the connection
information, instantiate a new instance of a FunctionTemplate. This will
allow future improvements for debugging and performance probes.
Additionally, the "provider" argument in the ReqWrap constructor is no
longer optional.
PR-URL: https://github.com/joyent/node/pull/8110
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
Diffstat (limited to 'src/pipe_wrap.cc')
-rw-r--r-- | src/pipe_wrap.cc | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index c99114b77a..a46060cb8b 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -50,8 +50,23 @@ using v8::String; using v8::Undefined; using v8::Value; + // TODO(bnoordhuis) share with TCPWrap? -typedef class ReqWrap<uv_connect_t> ConnectWrap; +class PipeConnectWrap : public ReqWrap<uv_connect_t> { + public: + PipeConnectWrap(Environment* env, Local<Object> req_wrap_obj); +}; + + +PipeConnectWrap::PipeConnectWrap(Environment* env, Local<Object> req_wrap_obj) + : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPEWRAP) { + Wrap<PipeConnectWrap>(req_wrap_obj, this); +} + + +static void NewPipeConnectWrap(const FunctionCallbackInfo<Value>& args) { + CHECK(args.IsConstructCall()); +} uv_pipe_t* PipeWrap::UVHandle() { @@ -115,6 +130,14 @@ void PipeWrap::Initialize(Handle<Object> target, target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe"), t->GetFunction()); env->set_pipe_constructor_template(t); + + // Create FunctionTemplate for PipeConnectWrap. + Local<FunctionTemplate> cwt = + FunctionTemplate::New(env->isolate(), NewPipeConnectWrap); + cwt->InstanceTemplate()->SetInternalFieldCount(1); + cwt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap")); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"), + cwt->GetFunction()); } @@ -206,7 +229,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { // TODO(bnoordhuis) Maybe share this with TCPWrap? void PipeWrap::AfterConnect(uv_connect_t* req, int status) { - ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data); + PipeConnectWrap* req_wrap = static_cast<PipeConnectWrap*>(req->data); PipeWrap* wrap = static_cast<PipeWrap*>(req->handle->data); CHECK_EQ(req_wrap->env(), wrap->env()); Environment* env = wrap->env(); @@ -267,9 +290,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) { Local<Object> req_wrap_obj = args[0].As<Object>(); node::Utf8Value name(args[1]); - ConnectWrap* req_wrap = new ConnectWrap(env, - req_wrap_obj, - AsyncWrap::PROVIDER_CONNECTWRAP); + PipeConnectWrap* req_wrap = new PipeConnectWrap(env, req_wrap_obj); uv_pipe_connect(&req_wrap->req_, &wrap->handle_, *name, |