Skip to content
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
2 changes: 1 addition & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void JSStream::Initialize(Handle<Object> target,
env->SetProtoMethod(t, "readBuffer", ReadBuffer);
env->SetProtoMethod(t, "emitEOF", EmitEOF);

StreamBase::AddMethods<JSStream>(env, t);
StreamBase::AddMethods<JSStream>(env, t, StreamBase::kFlagHasWritev);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"),
t->GetFunction());
env->set_jsstream_constructor_template(t);
Expand Down
7 changes: 5 additions & 2 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ using v8::String;
using v8::Value;

template <class Base>
void StreamBase::AddMethods(Environment* env, Handle<FunctionTemplate> t) {
void StreamBase::AddMethods(Environment* env,
Handle<FunctionTemplate> t,
int flags) {
HandleScope scope(env->isolate());

enum PropertyAttribute attributes =
Expand All @@ -36,7 +38,8 @@ void StreamBase::AddMethods(Environment* env, Handle<FunctionTemplate> t) {
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
env->SetProtoMethod(t, "shutdown", JSMethod<Base, &StreamBase::Shutdown>);
env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
if ((flags & kFlagHasWritev) != 0)
env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
env->SetProtoMethod(t,
"writeBuffer",
JSMethod<Base, &StreamBase::WriteBuffer>);
Expand Down
8 changes: 7 additions & 1 deletion src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ class StreamResource {

class StreamBase : public StreamResource {
public:
enum Flags {
kFlagNone = 0x0,
kFlagHasWritev = 0x1
};

template <class Base>
static inline void AddMethods(Environment* env,
v8::Handle<v8::FunctionTemplate> target);
v8::Handle<v8::FunctionTemplate> target,
int flags = kFlagNone);

virtual void* Cast() = 0;
virtual bool IsAlive() = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ StreamWrap::StreamWrap(Environment* env,


void StreamWrap::AddMethods(Environment* env,
v8::Handle<v8::FunctionTemplate> target) {
v8::Handle<v8::FunctionTemplate> target,
int flags) {
env->SetProtoMethod(target, "setBlocking", SetBlocking);
StreamBase::AddMethods<StreamWrap>(env, target);
StreamBase::AddMethods<StreamWrap>(env, target, flags);
}


Expand Down
3 changes: 2 additions & 1 deletion src/stream_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class StreamWrap : public HandleWrap, public StreamBase {
void UpdateWriteQueueSize();

static void AddMethods(Environment* env,
v8::Handle<v8::FunctionTemplate> target);
v8::Handle<v8::FunctionTemplate> target,
int flags = StreamBase::kFlagNone);

private:
static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
2 changes: 1 addition & 1 deletion src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void TCPWrap::Initialize(Handle<Object> target,
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
env->SetProtoMethod(t, "unref", HandleWrap::Unref);

StreamWrap::AddMethods(env, t);
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);

env->SetProtoMethod(t, "open", Open);
env->SetProtoMethod(t, "bind", Bind);
Expand Down