From 973f324463a91721cc8a1158a5ab10ad0dd69019 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 29 Oct 2019 15:15:36 +0100 Subject: child_process,cluster: allow using V8 serialization API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an `serialization` option that allows child process IPC to use the (typically more powerful) V8 serialization API. Fixes: https://github.com/nodejs/node/issues/10965 PR-URL: https://github.com/nodejs/node/pull/30162 Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: David Carlier Reviewed-By: Michaƫl Zasso --- src/stream_base.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/stream_base.cc') diff --git a/src/stream_base.cc b/src/stream_base.cc index 52163e2e43..eaccfc995c 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -180,12 +180,26 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo& args) { } Local req_wrap_obj = args[0].As(); - uv_buf_t buf; buf.base = Buffer::Data(args[1]); buf.len = Buffer::Length(args[1]); - StreamWriteResult res = Write(&buf, 1, nullptr, req_wrap_obj); + uv_stream_t* send_handle = nullptr; + + if (args[2]->IsObject() && IsIPCPipe()) { + Local send_handle_obj = args[2].As(); + + HandleWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, send_handle_obj, UV_EINVAL); + send_handle = reinterpret_cast(wrap->GetHandle()); + // Reference LibuvStreamWrap instance to prevent it from being garbage + // collected before `AfterWrite` is called. + req_wrap_obj->Set(env->context(), + env->handle_string(), + send_handle_obj).Check(); + } + + StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); SetWriteResult(res); return res.err; -- cgit v1.2.3