diff options
author | Fedor Indutny <fedor@indutny.com> | 2015-08-11 12:27:22 -0700 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2015-08-20 01:14:37 -0700 |
commit | 291b310e219023c4d93b216b1081ef47386f8750 (patch) | |
tree | f9f28676798681673642bee1156185b15809e911 /src/stream_base-inl.h | |
parent | 0d39d35739828afdc388140ccb30420aea3d3484 (diff) | |
download | node-new-291b310e219023c4d93b216b1081ef47386f8750.tar.gz |
stream_base: various improvements
Expose and use in TLSWrap an `v8::External` wrap of the
`StreamBase*` pointer instead of guessing the ancestor C++ class in
`node_wrap.h`.
Make use of `StreamBase::Callback` structure for storing/passing both
callback and context in a single object.
Introduce `GetObject()` for future user-land usage, when a child class
is not going to be inherited from AsyncWrap.
PR-URL: https://github.com/nodejs/node/pull/2351
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index d74b47de60..dd0bbcfbd8 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -10,6 +10,7 @@ namespace node { +using v8::External; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Handle; @@ -36,6 +37,13 @@ void StreamBase::AddMethods(Environment* env, v8::DEFAULT, attributes); + t->InstanceTemplate()->SetAccessor(env->external_stream_string(), + GetExternal<Base>, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); + env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>); env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>); if ((flags & kFlagNoShutdown) == 0) @@ -72,6 +80,16 @@ void StreamBase::GetFD(Local<String> key, } +template <class Base> +void StreamBase::GetExternal(Local<String> key, + const PropertyCallbackInfo<Value>& args) { + StreamBase* wrap = Unwrap<Base>(args.Holder()); + + Local<External> ext = External::New(args.GetIsolate(), wrap); + args.GetReturnValue().Set(ext); +} + + template <class Base, int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)> void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { |