Skip to content

Commit 060d901

Browse files
committed
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 <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 7b0d867 commit 060d901

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+339
-340
lines changed

src/api/exceptions.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ Local<Value> ErrnoException(Isolate* isolate,
5858
Local<Object> obj = e.As<Object>();
5959
obj->Set(env->context(),
6060
env->errno_string(),
61-
Integer::New(isolate, errorno)).FromJust();
62-
obj->Set(env->context(), env->code_string(), estring).FromJust();
61+
Integer::New(isolate, errorno)).Check();
62+
obj->Set(env->context(), env->code_string(), estring).Check();
6363

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

6868
if (syscall != nullptr) {
6969
obj->Set(env->context(),
7070
env->syscall_string(),
71-
OneByteString(isolate, syscall)).FromJust();
71+
OneByteString(isolate, syscall)).Check();
7272
}
7373

7474
return e;
@@ -144,13 +144,13 @@ Local<Value> UVException(Isolate* isolate,
144144

145145
e->Set(env->context(),
146146
env->errno_string(),
147-
Integer::New(isolate, errorno)).FromJust();
148-
e->Set(env->context(), env->code_string(), js_code).FromJust();
149-
e->Set(env->context(), env->syscall_string(), js_syscall).FromJust();
147+
Integer::New(isolate, errorno)).Check();
148+
e->Set(env->context(), env->code_string(), js_code).Check();
149+
e->Set(env->context(), env->syscall_string(), js_syscall).Check();
150150
if (!js_path.IsEmpty())
151-
e->Set(env->context(), env->path_string(), js_path).FromJust();
151+
e->Set(env->context(), env->path_string(), js_path).Check();
152152
if (!js_dest.IsEmpty())
153-
e->Set(env->context(), env->dest_string(), js_dest).FromJust();
153+
e->Set(env->context(), env->dest_string(), js_dest).Check();
154154

155155
return e;
156156
}
@@ -219,21 +219,21 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
219219

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

224224
if (path != nullptr) {
225225
obj->Set(env->context(),
226226
env->path_string(),
227227
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
228228
.ToLocalChecked())
229-
.FromJust();
229+
.Check();
230230
}
231231

232232
if (syscall != nullptr) {
233233
obj->Set(env->context(),
234234
env->syscall_string(),
235235
OneByteString(isolate, syscall))
236-
.FromJust();
236+
.Check();
237237
}
238238

239239
if (must_free) {

src/api/hooks.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int EmitExit(Environment* env) {
4949
->Set(env->context(),
5050
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
5151
True(env->isolate()))
52-
.FromJust();
52+
.Check();
5353

5454
Local<String> exit_code = env->exit_code_string();
5555
int code = process_object->Get(env->context(), exit_code)

src/async_wrap.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,11 @@ void AsyncWrap::Initialize(Local<Object> target,
487487

488488
target->Set(context,
489489
env->async_ids_stack_string(),
490-
env->async_hooks()->async_ids_stack().GetJSArray()).FromJust();
490+
env->async_hooks()->async_ids_stack().GetJSArray()).Check();
491491

492492
target->Set(context,
493493
FIXED_ONE_BYTE_STRING(env->isolate(), "owner_symbol"),
494-
env->owner_symbol()).FromJust();
494+
env->owner_symbol()).Check();
495495

496496
Local<Object> constants = Object::New(isolate);
497497
#define SET_HOOKS_CONSTANT(name) \
@@ -542,7 +542,7 @@ void AsyncWrap::Initialize(Local<Object> target,
542542
instance_template->SetInternalFieldCount(1);
543543
auto function =
544544
function_template->GetFunction(env->context()).ToLocalChecked();
545-
target->Set(env->context(), class_name, function).FromJust();
545+
target->Set(env->context(), class_name, function).Check();
546546
env->set_async_wrap_object_ctor_template(function_template);
547547
}
548548
}

0 commit comments

Comments
 (0)