-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream_base: remove static JSMethod declarations
Move JS methods to the stream_base-inl.h and thus define them on each use of `StreamBase::AddMethods`. Inline `AddMethods` itself, so that there won't be any need in a static declaration in stream_base.cc. NOTE: This basically allows using this API in user-land, though, some polishing is required before releasing it. PR-URL: #957 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
- Loading branch information
Showing
7 changed files
with
100 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef SRC_STREAM_BASE_INL_H_ | ||
#define SRC_STREAM_BASE_INL_H_ | ||
|
||
#include "stream_base.h" | ||
|
||
#include "node.h" | ||
#include "env.h" | ||
#include "env-inl.h" | ||
#include "v8.h" | ||
|
||
namespace node { | ||
|
||
using v8::FunctionCallbackInfo; | ||
using v8::FunctionTemplate; | ||
using v8::Handle; | ||
using v8::HandleScope; | ||
using v8::Local; | ||
using v8::PropertyAttribute; | ||
using v8::PropertyCallbackInfo; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
template <class Base> | ||
void StreamBase::AddMethods(Environment* env, Handle<FunctionTemplate> t) { | ||
HandleScope scope(env->isolate()); | ||
|
||
enum PropertyAttribute attributes = | ||
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | ||
t->InstanceTemplate()->SetAccessor(env->fd_string(), | ||
GetFD<Base>, | ||
nullptr, | ||
Handle<Value>(), | ||
v8::DEFAULT, | ||
attributes); | ||
|
||
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>); | ||
env->SetProtoMethod(t, | ||
"writeBuffer", | ||
JSMethod<Base, &StreamBase::WriteBuffer>); | ||
env->SetProtoMethod(t, | ||
"writeAsciiString", | ||
JSMethod<Base, &StreamBase::WriteString<ASCII> >); | ||
env->SetProtoMethod(t, | ||
"writeUtf8String", | ||
JSMethod<Base, &StreamBase::WriteString<UTF8> >); | ||
env->SetProtoMethod(t, | ||
"writeUcs2String", | ||
JSMethod<Base, &StreamBase::WriteString<UCS2> >); | ||
env->SetProtoMethod(t, | ||
"writeBinaryString", | ||
JSMethod<Base, &StreamBase::WriteString<BINARY> >); | ||
} | ||
|
||
|
||
template <class Base> | ||
void StreamBase::GetFD(Local<String> key, | ||
const PropertyCallbackInfo<Value>& args) { | ||
StreamBase* wrap = Unwrap<Base>(args.Holder()); | ||
|
||
if (!wrap->IsAlive()) | ||
return args.GetReturnValue().Set(UV_EINVAL); | ||
|
||
args.GetReturnValue().Set(wrap->GetFD()); | ||
} | ||
|
||
|
||
template <class Base, | ||
int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)> | ||
void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { | ||
StreamBase* wrap = Unwrap<Base>(args.Holder()); | ||
|
||
if (!wrap->IsAlive()) | ||
return args.GetReturnValue().Set(UV_EINVAL); | ||
|
||
args.GetReturnValue().Set((wrap->*Method)(args)); | ||
} | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_STREAM_BASE_INL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters