40 using v8::EscapableHandleScope;
42 using v8::FunctionCallbackInfo;
43 using v8::FunctionTemplate;
44 using v8::HandleScope;
53 Local<Object> PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) {
54 EscapableHandleScope handle_scope(env->isolate());
55 AsyncHooks::InitScope init_scope(env, parent->get_id());
56 CHECK_EQ(
false, env->pipe_constructor_template().IsEmpty());
57 Local<Function> constructor = env->pipe_constructor_template()->GetFunction();
58 CHECK_EQ(
false, constructor.IsEmpty());
59 Local<Object> instance =
60 constructor->NewInstance(env->context()).ToLocalChecked();
61 return handle_scope.Escape(instance);
67 Local<Context> context) {
68 Environment* env = Environment::GetCurrent(context);
70 Local<FunctionTemplate>
t = env->NewFunctionTemplate(
New);
71 Local<String> pipeString = FIXED_ONE_BYTE_STRING(env->isolate(),
"Pipe");
72 t->SetClassName(pipeString);
73 t->InstanceTemplate()->SetInternalFieldCount(1);
75 AsyncWrap::AddWrapMethods(env, t);
77 env->SetProtoMethod(t,
"close", HandleWrap::Close);
78 env->SetProtoMethod(t,
"unref", HandleWrap::Unref);
79 env->SetProtoMethod(t,
"ref", HandleWrap::Ref);
80 env->SetProtoMethod(t,
"hasRef", HandleWrap::HasRef);
83 StreamWrap::AddMethods(env, t);
85 StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
88 env->SetProtoMethod(t,
"bind", Bind);
89 env->SetProtoMethod(t,
"listen", Listen);
90 env->SetProtoMethod(t,
"connect", Connect);
91 env->SetProtoMethod(t,
"open", Open);
94 env->SetProtoMethod(t,
"setPendingInstances", SetPendingInstances);
97 target->Set(pipeString, t->GetFunction());
98 env->set_pipe_constructor_template(t);
101 auto constructor = [](
const FunctionCallbackInfo<Value>& args) {
102 CHECK(args.IsConstructCall());
103 ClearWrap(args.This());
106 cwt->InstanceTemplate()->SetInternalFieldCount(1);
107 AsyncWrap::AddWrapMethods(env, cwt);
108 Local<String> wrapString =
109 FIXED_ONE_BYTE_STRING(env->isolate(),
"PipeConnectWrap");
110 cwt->SetClassName(wrapString);
111 target->Set(wrapString, cwt->GetFunction());
115 void PipeWrap::New(
const FunctionCallbackInfo<Value>& args) {
119 CHECK(args.IsConstructCall());
120 Environment* env = Environment::GetCurrent(args);
121 new PipeWrap(env, args.This(), args[0]->IsTrue());
125 PipeWrap::PipeWrap(Environment* env,
126 Local<Object>
object,
128 : ConnectionWrap(env,
130 AsyncWrap::PROVIDER_PIPEWRAP) {
131 int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
134 UpdateWriteQueueSize();
138 void PipeWrap::Bind(
const FunctionCallbackInfo<Value>& args) {
140 ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
141 node::Utf8Value name(args.GetIsolate(), args[0]);
142 int err = uv_pipe_bind(&wrap->handle_, *name);
143 args.GetReturnValue().Set(err);
148 void PipeWrap::SetPendingInstances(
const FunctionCallbackInfo<Value>& args) {
150 ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
151 int instances = args[0]->Int32Value();
152 uv_pipe_pending_instances(&wrap->handle_, instances);
157 void PipeWrap::Listen(
const FunctionCallbackInfo<Value>& args) {
159 ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
160 int backlog = args[0]->Int32Value();
161 int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
164 args.GetReturnValue().Set(err);
169 Environment* env = Environment::GetCurrent(args);
172 ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
174 int fd = args[0]->Int32Value();
176 int err = uv_pipe_open(&wrap->handle_, fd);
179 env->isolate()->ThrowException(
UVException(err,
"uv_pipe_open"));
183 void PipeWrap::Connect(
const FunctionCallbackInfo<Value>& args) {
184 Environment* env = Environment::GetCurrent(args);
187 ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
189 CHECK(args[0]->IsObject());
190 CHECK(args[1]->IsString());
192 Local<Object> req_wrap_obj = args[0].As<Object>();
193 node::Utf8Value name(env->isolate(), args[1]);
195 ConnectWrap* req_wrap =
196 new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
197 uv_pipe_connect(req_wrap->req(),
201 req_wrap->Dispatched();
203 args.GetReturnValue().Set(0);
NODE_MODULE_CONTEXT_AWARE_BUILTIN(inspector, node::inspector::Agent::InitInspector)
void Initialize(Local< Object > target, Local< Value > unused, Local< Context > context, void *priv)
void Open(const FunctionCallbackInfo< Value > &args)
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
node::Environment::AsyncHooks AsyncHooks
Local< Value > UVException(Isolate *isolate, int errorno, const char *syscall, const char *msg, const char *path)