Skip to content

Commit

Permalink
src,stream: change return type to Maybe
Browse files Browse the repository at this point in the history
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 daeyeon.dev@gmail.com
  • Loading branch information
daeyeon committed Jun 26, 2022
1 parent 3507b3f commit fcc16f5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void WriteWrap::SetBackingStore(std::unique_ptr<v8::BackingStore> bs) {
backing_store_ = std::move(bs);
}

void StreamReq::Done(int status, const char* error_str) {
v8::Maybe<bool> StreamReq::Done(int status, const char* error_str) {
AsyncWrap* async_wrap = GetAsyncWrap();
Environment* env = async_wrap->env();
if (error_str != nullptr) {
Expand All @@ -287,11 +287,12 @@ void StreamReq::Done(int status, const char* error_str) {
env->context(),
env->error_string(),
OneByteString(env->isolate(), error_str)).IsNothing()) {
return;
return v8::Nothing<bool>();
}
}

OnDone(status);
return v8::Just(true);
}

void StreamReq::ResetObject(v8::Local<v8::Object> obj) {
Expand Down
4 changes: 1 addition & 3 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class StreamReq {
virtual AsyncWrap* GetAsyncWrap() = 0;
inline v8::Local<v8::Object> object();

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

StreamBase* stream() const { return stream_; }
Expand Down
7 changes: 3 additions & 4 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ static MaybeLocal<Object> AcceptHandle(Environment* env,
return scope.Escape(wrap_obj);
}


void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
v8::Maybe<bool> LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
uv_handle_type type = UV_UNKNOWN_HANDLE;
Expand Down Expand Up @@ -272,14 +271,14 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
object()->Set(env()->context(),
env()->pending_handle_string(),
local_pending_obj).IsNothing()) {
return;
return v8::Nothing<bool>();
}
}

EmitRead(nread, *buf);
return v8::Just(true);
}


void LibuvStreamWrap::GetWriteQueueSize(
const FunctionCallbackInfo<Value>& info) {
LibuvStreamWrap* wrap;
Expand Down
4 changes: 1 addition & 3 deletions src/stream_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase {

// Callbacks for libuv
void OnUvAlloc(size_t suggested_size, uv_buf_t* buf);
// TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate
// if there is a pending exception/termination.
void OnUvRead(ssize_t nread, const uv_buf_t* buf);
v8::Maybe<bool> OnUvRead(ssize_t nread, const uv_buf_t* buf);

static void AfterUvWrite(uv_write_t* req, int status);
static void AfterUvShutdown(uv_shutdown_t* req, int status);
Expand Down

0 comments on commit fcc16f5

Please sign in to comment.