| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 482bd53 commit 2e181f6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | #include "env-inl.h" | |
| 26 | 26 | #include "handle_wrap.h" | |
| 27 | 27 | #include "node_buffer.h" | |
| 28 | + #include "node_errors.h" | ||
| 28 | 29 | #include "node_external_reference.h" | |
| 29 | 30 | #include "pipe_wrap.h" | |
| 30 | 31 | #include "req_wrap-inl.h" | |
@@ -38,14 +39,18 @@ | |||
| 38 | 39 | ||
| 39 | 40 | namespace node { | |
| 40 | 41 | ||
| 42 | + using errors::TryCatchScope; | ||
| 41 | 43 | using v8::Context; | |
| 42 | 44 | using v8::DontDelete; | |
| 43 | 45 | using v8::EscapableHandleScope; | |
| 44 | 46 | using v8::FunctionCallbackInfo; | |
| 45 | 47 | using v8::FunctionTemplate; | |
| 46 | 48 | using v8::HandleScope; | |
| 49 | + using v8::JustVoid; | ||
| 47 | 50 | using v8::Local; | |
| 51 | + using v8::Maybe; | ||
| 48 | 52 | using v8::MaybeLocal; | |
| 53 | + using v8::Nothing; | ||
| 49 | 54 | using v8::Object; | |
| 50 | 55 | using v8::PropertyAttribute; | |
| 51 | 56 | using v8::ReadOnly; | |
@@ -191,15 +196,19 @@ bool LibuvStreamWrap::IsIPCPipe() { | |||
| 191 | 196 | return is_named_pipe_ipc(); | |
| 192 | 197 | } | |
| 193 | 198 | ||
| 194 | - | ||
| 195 | 199 | int LibuvStreamWrap::ReadStart() { | |
| 196 | - return uv_read_start(stream(), [](uv_handle_t* handle, | ||
| 197 | - size_t suggested_size, | ||
| 198 | - uv_buf_t* buf) { | ||
| 199 | - static_cast<LibuvStreamWrap*>(handle->data)->OnUvAlloc(suggested_size, buf); | ||
| 200 | - }, [](uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { | ||
| 201 | - static_cast<LibuvStreamWrap*>(stream->data)->OnUvRead(nread, buf); | ||
| 202 | - }); | ||
| 200 | + return uv_read_start( | ||
| 201 | + stream(), | ||
| 202 | + [](uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { | ||
| 203 | + static_cast<LibuvStreamWrap*>(handle->data) | ||
| 204 | + ->OnUvAlloc(suggested_size, buf); | ||
| 205 | + }, | ||
| 206 | + [](uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { | ||
| 207 | + LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(stream->data); | ||
| 208 | + TryCatchScope try_catch(wrap->env()); | ||
| 209 | + try_catch.SetVerbose(true); | ||
| 210 | + wrap->OnUvRead(nread, buf); | ||
| 211 | + }); | ||
| 203 | 212 | } | |
| 204 | 213 | ||
| 205 | 214 | ||
@@ -239,8 +248,7 @@ static MaybeLocal<Object> AcceptHandle(Environment* env, | |||
| 239 | 248 | return scope.Escape(wrap_obj); | |
| 240 | 249 | } | |
| 241 | 250 | ||
| 242 | - | ||
| 243 | - void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) { | ||
| 251 | + Maybe<void> LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) { | ||
| 244 | 252 | HandleScope scope(env()->isolate()); | |
| 245 | 253 | Context::Scope context_scope(env()->context()); | |
| 246 | 254 | uv_handle_type type = UV_UNKNOWN_HANDLE; | |
@@ -268,18 +276,21 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) { | |||
| 268 | 276 | } | |
| 269 | 277 | ||
| 270 | 278 | Local<Object> local_pending_obj; | |
| 271 | - if (pending_obj.ToLocal(&local_pending_obj) && | ||
| 272 | - object()->Set(env()->context(), | ||
| 273 | - env()->pending_handle_string(), | ||
| 274 | - local_pending_obj).IsNothing()) { | ||
| 275 | - return; | ||
| 279 | + if (type != UV_UNKNOWN_HANDLE && | ||
| 280 | + (!pending_obj.ToLocal(&local_pending_obj) || | ||
| 281 | + object() | ||
| 282 | + ->Set(env()->context(), | ||
| 283 | + env()->pending_handle_string(), | ||
| 284 | + local_pending_obj) | ||
| 285 | + .IsNothing())) { | ||
| 286 | + return Nothing<void>(); | ||
| 276 | 287 | } | |
| 277 | 288 | } | |
| 278 | 289 | ||
| 279 | 290 | EmitRead(nread, *buf); | |
| 291 | + return JustVoid(); | ||
| 280 | 292 | } | |
| 281 | 293 | ||
| 282 | - | ||
| 283 | 294 | void LibuvStreamWrap::GetWriteQueueSize( | |
| 284 | 295 | const FunctionCallbackInfo<Value>& info) { | |
| 285 | 296 | LibuvStreamWrap* wrap; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,9 +105,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { | |||
| 105 | 105 | ||
| 106 | 106 | // Callbacks for libuv | |
| 107 | 107 | void OnUvAlloc(size_t suggested_size, uv_buf_t* buf); | |
| 108 | - // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate | ||
| 109 | - // if there is a pending exception/termination. | ||
| 110 | - void OnUvRead(ssize_t nread, const uv_buf_t* buf); | ||
| 108 | + v8::Maybe<void> OnUvRead(ssize_t nread, const uv_buf_t* buf); | ||
| 111 | 109 | ||
| 112 | 110 | static void AfterUvWrite(uv_write_t* req, int status); | |
| 113 | 111 | static void AfterUvShutdown(uv_shutdown_t* req, int status); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments