Skip to content
Permalink
Browse files

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

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 9, 2019
1 parent 7b0d867 commit 060d901f87b3d87314f8540eb02f315e2952f581
Showing with 339 additions and 340 deletions.
  1. +12 −12 src/api/exceptions.cc
  2. +1 −1 src/api/hooks.cc
  3. +3 −3 src/async_wrap.cc
  4. +79 −79 src/cares_wrap.cc
  5. +2 −2 src/env-inl.h
  6. +7 −7 src/env.cc
  7. +1 −1 src/fs_event_wrap.cc
  8. +1 −1 src/inspector_agent.cc
  9. +1 −1 src/inspector_js_api.cc
  10. +2 −2 src/js_stream.cc
  11. +3 −3 src/module_wrap.cc
  12. +1 −2 src/node.cc
  13. +3 −3 src/node.h
  14. +1 −1 src/node_binding.cc
  15. +2 −2 src/node_buffer.cc
  16. +9 −9 src/node_constants.cc
  17. +6 −6 src/node_contextify.cc
  18. +51 −51 src/node_crypto.cc
  19. +1 −1 src/node_errors.h
  20. +21 −21 src/node_file.cc
  21. +6 −6 src/node_http2.cc
  22. +7 −7 src/node_http_parser_impl.h
  23. +4 −4 src/node_messaging.cc
  24. +6 −6 src/node_native_module.cc
  25. +2 −2 src/node_options.cc
  26. +6 −6 src/node_os.cc
  27. +10 −10 src/node_perf.cc
  28. +3 −3 src/node_process_object.cc
  29. +3 −3 src/node_serdes.cc
  30. +1 −1 src/node_stat_watcher.cc
  31. +1 −1 src/node_symbols.cc
  32. +2 −2 src/node_task_queue.cc
  33. +3 −3 src/node_trace_events.cc
  34. +3 −3 src/node_util.cc
  35. +7 −7 src/node_v8.cc
  36. +7 −7 src/node_worker.cc
  37. +2 −2 src/node_zlib.cc
  38. +3 −3 src/pipe_wrap.cc
  39. +2 −2 src/process_wrap.cc
  40. +1 −1 src/signal_wrap.cc
  41. +12 −12 src/spawn_sync.cc
  42. +3 −3 src/stream_base-inl.h
  43. +1 −1 src/stream_base.cc
  44. +5 −5 src/stream_pipe.cc
  45. +4 −4 src/stream_wrap.cc
  46. +2 −2 src/string_decoder.cc
  47. +10 −10 src/tcp_wrap.cc
  48. +1 −1 src/timers.cc
  49. +5 −5 src/tls_wrap.cc
  50. +2 −2 src/tty_wrap.cc
  51. +3 −3 src/udp_wrap.cc
  52. +3 −3 src/util.h
  53. +2 −2 src/uv.cc
@@ -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;
@@ -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;
}
@@ -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) {
@@ -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)
@@ -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) \
@@ -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);
}
}

0 comments on commit 060d901

Please sign in to comment.
You can’t perform that action at this time.