Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: replace FromJust() with Check() when possible
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
  • Loading branch information
sam-github committed Apr 11, 2019
commit f974f1ef8aa4b362f70a18ea46ce7763592c7267
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