Skip to content

Commit cc16070

Browse files
committed
src,stream: change return type to Maybe
This changes the return types of some functions to indicate that the functions may have a pending exception, and removes some of todos related. Signed-off-by: Daeyeon Jeong [email protected]
1 parent 3507b3f commit cc16070

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

src/stream_base-inl.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void WriteWrap::SetBackingStore(std::unique_ptr<v8::BackingStore> bs) {
278278
backing_store_ = std::move(bs);
279279
}
280280

281-
void StreamReq::Done(int status, const char* error_str) {
281+
v8::Maybe<void> StreamReq::Done(int status, const char* error_str) {
282282
AsyncWrap* async_wrap = GetAsyncWrap();
283283
Environment* env = async_wrap->env();
284284
if (error_str != nullptr) {
@@ -287,11 +287,12 @@ void StreamReq::Done(int status, const char* error_str) {
287287
env->context(),
288288
env->error_string(),
289289
OneByteString(env->isolate(), error_str)).IsNothing()) {
290-
return;
290+
return v8::Nothing<void>();
291291
}
292292
}
293293

294294
OnDone(status);
295+
return v8::JustVoid();
295296
}
296297

297298
void StreamReq::ResetObject(v8::Local<v8::Object> obj) {

src/stream_base.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class StreamReq {
4949
virtual AsyncWrap* GetAsyncWrap() = 0;
5050
inline v8::Local<v8::Object> object();
5151

52-
// TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate
53-
// if there is a pending exception/termination.
54-
inline void Done(int status, const char* error_str = nullptr);
52+
inline v8::Maybe<void> Done(int status, const char* error_str = nullptr);
5553
inline void Dispose();
5654

5755
StreamBase* stream() const { return stream_; }

src/stream_wrap.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ static MaybeLocal<Object> AcceptHandle(Environment* env,
239239
return scope.Escape(wrap_obj);
240240
}
241241

242-
243-
void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
242+
v8::Maybe<void> LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
244243
HandleScope scope(env()->isolate());
245244
Context::Scope context_scope(env()->context());
246245
uv_handle_type type = UV_UNKNOWN_HANDLE;
@@ -272,14 +271,14 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
272271
object()->Set(env()->context(),
273272
env()->pending_handle_string(),
274273
local_pending_obj).IsNothing()) {
275-
return;
274+
return v8::Nothing<void>();
276275
}
277276
}
278277

279278
EmitRead(nread, *buf);
279+
return v8::JustVoid();
280280
}
281281

282-
283282
void LibuvStreamWrap::GetWriteQueueSize(
284283
const FunctionCallbackInfo<Value>& info) {
285284
LibuvStreamWrap* wrap;

src/stream_wrap.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase {
105105

106106
// Callbacks for libuv
107107
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);
111109

112110
static void AfterUvWrite(uv_write_t* req, int status);
113111
static void AfterUvShutdown(uv_shutdown_t* req, int status);

0 commit comments

Comments
 (0)