1 #ifndef SRC_STREAM_BASE_INL_H_
2 #define SRC_STREAM_BASE_INL_H_
4 #include "stream_base.h"
14 using v8::FunctionCallbackInfo;
15 using v8::FunctionTemplate;
16 using v8::HandleScope;
19 using v8::PropertyAttribute;
20 using v8::PropertyCallbackInfo;
25 void StreamBase::AddMethods(Environment* env,
26 Local<FunctionTemplate> t,
28 HandleScope scope(env->isolate());
30 enum PropertyAttribute attributes =
31 static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
32 t->InstanceTemplate()->SetAccessor(env->fd_string(),
39 t->InstanceTemplate()->SetAccessor(env->external_stream_string(),
46 env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
47 env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
48 if ((flags & kFlagNoShutdown) == 0)
49 env->SetProtoMethod(t, "shutdown", JSMethod<Base, &StreamBase::Shutdown>);
50 if ((flags & kFlagHasWritev) != 0)
51 env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
52 env->SetProtoMethod(t,
54 JSMethod<Base, &StreamBase::WriteBuffer>);
55 env->SetProtoMethod(t,
57 JSMethod<Base, &StreamBase::WriteString<ASCII> >);
58 env->SetProtoMethod(t,
60 JSMethod<Base, &StreamBase::WriteString<UTF8> >);
61 env->SetProtoMethod(t,
63 JSMethod<Base, &StreamBase::WriteString<UCS2> >);
64 env->SetProtoMethod(t,
66 JSMethod<Base, &StreamBase::WriteString<BINARY> >);
71 void StreamBase::GetFD(Local<String> key,
72 const PropertyCallbackInfo<Value>& args) {
73 StreamBase* wrap = Unwrap<Base>(args.Holder());
76 return args.GetReturnValue().Set(UV_EINVAL);
78 args.GetReturnValue().Set(wrap->GetFD());
83 void StreamBase::GetExternal(Local<String> key,
84 const PropertyCallbackInfo<Value>& args) {
85 StreamBase* wrap = Unwrap<Base>(args.Holder());
87 Local<External> ext = External::New(args.GetIsolate(), wrap);
88 args.GetReturnValue().Set(ext);
93 int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
94 void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
95 StreamBase* wrap = Unwrap<Base>(args.Holder());
98 return args.GetReturnValue().Set(UV_EINVAL);
100 args.GetReturnValue().Set((wrap->*Method)(args));
104 WriteWrap* WriteWrap::New(Environment* env,
109 size_t storage_size = ROUND_UP(sizeof(WriteWrap), kAlignSize) + extra;
110 char* storage = new char[storage_size];
112 return new(storage) WriteWrap(env, obj, wrap, cb, storage_size);
116 void WriteWrap::Dispose() {
118 delete[] reinterpret_cast<char*>(this);
122 char* WriteWrap::Extra(size_t offset) {
123 return reinterpret_cast<char*>(this) +
124 ROUND_UP(sizeof(*this), kAlignSize) +
130 #endif // SRC_STREAM_BASE_INL_H_