Skip to content

Commit

Permalink
src: replace FromJust() with Check() when possible
Browse files Browse the repository at this point in the history
FromJust() is often used not for its return value, but for its
side-effects. In these cases, Check() exists, and is more clear as to
the intent. From its comment:

  To be used, where the actual value of the Maybe is not needed, like
  Object::Set.

See: https://github.com/nodejs/node/pull/26929/files#r269256335

PR-URL: #27162
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
sam-github committed Apr 12, 2019
1 parent 7b0d867 commit 060d901
Show file tree
Hide file tree
Showing 53 changed files with 339 additions and 340 deletions.
24 changes: 12 additions & 12 deletions src/api/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ Local<Value> ErrnoException(Isolate* isolate,
Local<Object> obj = e.As<Object>();
obj->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
obj->Set(env->context(), env->code_string(), estring).FromJust();
Integer::New(isolate, errorno)).Check();
obj->Set(env->context(), env->code_string(), estring).Check();

if (path_string.IsEmpty() == false) {
obj->Set(env->context(), env->path_string(), path_string).FromJust();
obj->Set(env->context(), env->path_string(), path_string).Check();
}

if (syscall != nullptr) {
obj->Set(env->context(),
env->syscall_string(),
OneByteString(isolate, syscall)).FromJust();
OneByteString(isolate, syscall)).Check();
}

return e;
Expand Down Expand Up @@ -144,13 +144,13 @@ Local<Value> UVException(Isolate* isolate,

e->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
e->Set(env->context(), env->code_string(), js_code).FromJust();
e->Set(env->context(), env->syscall_string(), js_syscall).FromJust();
Integer::New(isolate, errorno)).Check();
e->Set(env->context(), env->code_string(), js_code).Check();
e->Set(env->context(), env->syscall_string(), js_syscall).Check();
if (!js_path.IsEmpty())
e->Set(env->context(), env->path_string(), js_path).FromJust();
e->Set(env->context(), env->path_string(), js_path).Check();
if (!js_dest.IsEmpty())
e->Set(env->context(), env->dest_string(), js_dest).FromJust();
e->Set(env->context(), env->dest_string(), js_dest).Check();

return e;
}
Expand Down Expand Up @@ -219,21 +219,21 @@ Local<Value> WinapiErrnoException(Isolate* isolate,

Local<Object> obj = e.As<Object>();
obj->Set(env->context(), env->errno_string(), Integer::New(isolate, errorno))
.FromJust();
.Check();

if (path != nullptr) {
obj->Set(env->context(),
env->path_string(),
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked())
.FromJust();
.Check();
}

if (syscall != nullptr) {
obj->Set(env->context(),
env->syscall_string(),
OneByteString(isolate, syscall))
.FromJust();
.Check();
}

if (must_free) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int EmitExit(Environment* env) {
->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate()))
.FromJust();
.Check();

Local<String> exit_code = env->exit_code_string();
int code = process_object->Get(env->context(), exit_code)
Expand Down
6 changes: 3 additions & 3 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ void AsyncWrap::Initialize(Local<Object> target,

target->Set(context,
env->async_ids_stack_string(),
env->async_hooks()->async_ids_stack().GetJSArray()).FromJust();
env->async_hooks()->async_ids_stack().GetJSArray()).Check();

target->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "owner_symbol"),
env->owner_symbol()).FromJust();
env->owner_symbol()).Check();

Local<Object> constants = Object::New(isolate);
#define SET_HOOKS_CONSTANT(name) \
Expand Down Expand Up @@ -542,7 +542,7 @@ void AsyncWrap::Initialize(Local<Object> target,
instance_template->SetInternalFieldCount(1);
auto function =
function_template->GetFunction(env->context()).ToLocalChecked();
target->Set(env->context(), class_name, function).FromJust();
target->Set(env->context(), class_name, function).Check();
env->set_async_wrap_object_ctor_template(function_template);
}
}
Expand Down
Loading

0 comments on commit 060d901

Please sign in to comment.