summaryrefslogtreecommitdiff
path: root/src/process_wrap.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-09-23 19:24:33 +0200
committerAnna Henningsen <anna@addaleax.net>2018-10-03 13:43:42 -0700
commitd527dde3600655eae7ce0ba5da9263ec4560cd11 (patch)
treecb9186b8b85a696ec7f916f40fcec935ba86fdc9 /src/process_wrap.cc
parent2ebdba12297348649620e3d302b156c149d85a6e (diff)
downloadandroid-node-v8-d527dde3600655eae7ce0ba5da9263ec4560cd11.tar.gz
android-node-v8-d527dde3600655eae7ce0ba5da9263ec4560cd11.tar.bz2
android-node-v8-d527dde3600655eae7ce0ba5da9263ec4560cd11.zip
src: use JS inheritance for `AsyncWrap`
For all classes descending from `AsyncWrap`, use JS inheritance instead of manually adding methods to the individual classes. This allows cleanup of some code around transferring handles over IPC. PR-URL: https://github.com/nodejs/node/pull/23094 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/process_wrap.cc')
-rw-r--r--src/process_wrap.cc33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/process_wrap.cc b/src/process_wrap.cc
index 1daa437b29..af6cbfb4e5 100644
--- a/src/process_wrap.cc
+++ b/src/process_wrap.cc
@@ -20,10 +20,9 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "env-inl.h"
-#include "handle_wrap.h"
#include "node_internals.h"
-#include "node_wrap.h"
#include "stream_base-inl.h"
+#include "stream_wrap.h"
#include "util-inl.h"
#include <string.h>
@@ -58,8 +57,7 @@ class ProcessWrap : public HandleWrap {
FIXED_ONE_BYTE_STRING(env->isolate(), "Process");
constructor->SetClassName(processString);
- AsyncWrap::AddWrapMethods(env, constructor);
- HandleWrap::AddWrapMethods(env, constructor);
+ constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(constructor, "spawn", Spawn);
env->SetProtoMethod(constructor, "kill", Kill);
@@ -92,6 +90,17 @@ class ProcessWrap : public HandleWrap {
MarkAsUninitialized();
}
+ static uv_stream_t* StreamForWrap(Environment* env, Local<Object> stdio) {
+ Local<String> handle_key = env->handle_string();
+ // This property has always been set by JS land if we are in this code path.
+ Local<Object> handle =
+ stdio->Get(env->context(), handle_key).ToLocalChecked().As<Object>();
+
+ uv_stream_t* stream = LibuvStreamWrap::From(env, handle)->stream();
+ CHECK_NOT_NULL(stream);
+ return stream;
+ }
+
static void ParseStdioOptions(Environment* env,
Local<Object> js_options,
uv_process_options_t* options) {
@@ -115,22 +124,10 @@ class ProcessWrap : public HandleWrap {
} else if (type->StrictEquals(env->pipe_string())) {
options->stdio[i].flags = static_cast<uv_stdio_flags>(
UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE);
- Local<String> handle_key = env->handle_string();
- Local<Object> handle =
- stdio->Get(context, handle_key).ToLocalChecked().As<Object>();
- CHECK(!handle.IsEmpty());
- options->stdio[i].data.stream =
- reinterpret_cast<uv_stream_t*>(
- Unwrap<PipeWrap>(handle)->UVHandle());
+ options->stdio[i].data.stream = StreamForWrap(env, stdio);
} else if (type->StrictEquals(env->wrap_string())) {
- Local<String> handle_key = env->handle_string();
- Local<Object> handle =
- stdio->Get(context, handle_key).ToLocalChecked().As<Object>();
- uv_stream_t* stream = HandleToStream(env, handle);
- CHECK_NOT_NULL(stream);
-
options->stdio[i].flags = UV_INHERIT_STREAM;
- options->stdio[i].data.stream = stream;
+ options->stdio[i].data.stream = StreamForWrap(env, stdio);
} else {
Local<String> fd_key = env->fd_string();
Local<Value> fd_value = stdio->Get(context, fd_key).ToLocalChecked();