1 #ifndef SRC_STREAM_BASE_INL_H_ 2 #define SRC_STREAM_BASE_INL_H_ 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 16 using v8::FunctionCallbackInfo;
17 using v8::FunctionTemplate;
18 using v8::HandleScope;
21 using v8::PropertyAttribute;
22 using v8::PropertyCallbackInfo;
29 void StreamBase::AddMethods(Environment* env,
30 Local<FunctionTemplate>
t,
32 HandleScope scope(env->isolate());
34 enum PropertyAttribute attributes =
35 static_cast<PropertyAttribute
>(v8::ReadOnly | v8::DontDelete);
36 t->InstanceTemplate()->SetAccessor(env->fd_string(),
43 t->InstanceTemplate()->SetAccessor(env->external_stream_string(),
50 t->InstanceTemplate()->SetAccessor(env->bytes_read_string(),
57 env->SetProtoMethod(t,
"readStart", JSMethod<Base, &StreamBase::ReadStart>);
58 env->SetProtoMethod(t,
"readStop", JSMethod<Base, &StreamBase::ReadStop>);
59 if ((flags & kFlagNoShutdown) == 0)
60 env->SetProtoMethod(t,
"shutdown", JSMethod<Base, &StreamBase::Shutdown>);
61 if ((flags & kFlagHasWritev) != 0)
62 env->SetProtoMethod(t,
"writev", JSMethod<Base, &StreamBase::Writev>);
63 env->SetProtoMethod(t,
65 JSMethod<Base, &StreamBase::WriteBuffer>);
66 env->SetProtoMethod(t,
68 JSMethod<Base, &StreamBase::WriteString<ASCII> >);
69 env->SetProtoMethod(t,
71 JSMethod<Base, &StreamBase::WriteString<UTF8> >);
72 env->SetProtoMethod(t,
74 JSMethod<Base, &StreamBase::WriteString<UCS2> >);
75 env->SetProtoMethod(t,
77 JSMethod<Base, &StreamBase::WriteString<LATIN1> >);
82 void StreamBase::GetFD(Local<String> key,
83 const PropertyCallbackInfo<Value>& args) {
84 Base* handle = Unwrap<Base>(args.Holder());
87 ASSIGN_OR_RETURN_UNWRAP(&handle,
89 args.GetReturnValue().Set(UV_EINVAL));
91 StreamBase*
wrap =
static_cast<StreamBase*
>(handle);
93 return args.GetReturnValue().Set(UV_EINVAL);
95 args.GetReturnValue().Set(wrap->GetFD());
100 void StreamBase::GetBytesRead(Local<String> key,
101 const PropertyCallbackInfo<Value>& args) {
102 Base* handle = Unwrap<Base>(args.Holder());
105 ASSIGN_OR_RETURN_UNWRAP(&handle,
107 args.GetReturnValue().Set(0));
109 StreamBase* wrap =
static_cast<StreamBase*
>(handle);
111 args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
115 template <
class Base>
116 void StreamBase::GetExternal(Local<String> key,
117 const PropertyCallbackInfo<Value>& args) {
118 Base* handle = Unwrap<Base>(args.Holder());
120 ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder());
122 StreamBase* wrap =
static_cast<StreamBase*
>(handle);
124 args.GetReturnValue().Set(ext);
128 template <
class Base,
129 int (StreamBase::*Method)(
const FunctionCallbackInfo<Value>& args)>
130 void StreamBase::JSMethod(
const FunctionCallbackInfo<Value>& args) {
131 Base* handle = Unwrap<Base>(args.Holder());
133 ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder());
135 StreamBase* wrap =
static_cast<StreamBase*
>(handle);
136 if (!wrap->IsAlive())
137 return args.GetReturnValue().Set(UV_EINVAL);
139 AsyncHooks::InitScope init_scope(handle->env(), handle->get_id());
140 args.GetReturnValue().Set((wrap->*Method)(args));
149 size_t storage_size = ROUND_UP(
sizeof(WriteWrap), kAlignSize) + extra;
150 char* storage =
new char[storage_size];
152 return new(storage) WriteWrap(env, obj, wrap, cb, storage_size);
156 void WriteWrap::Dispose() {
158 delete[]
reinterpret_cast<char*
>(
this);
162 char* WriteWrap::Extra(
size_t offset) {
163 return reinterpret_cast<char*
>(
this) +
164 ROUND_UP(
sizeof(*
this), kAlignSize) +
170 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 172 #endif // SRC_STREAM_BASE_INL_H_
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
node::Environment::AsyncHooks AsyncHooks