Skip to content

Commit a96d5d1

Browse files
jasnelltargos
authored andcommitted
src: move more stuff over to use Maybe<void>
PR-URL: #54831 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 12c9d97 commit a96d5d1

12 files changed

+66
-57
lines changed

src/api/environment.cc

+23-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using v8::FunctionCallbackInfo;
3131
using v8::HandleScope;
3232
using v8::Isolate;
3333
using v8::Just;
34+
using v8::JustVoid;
3435
using v8::Local;
3536
using v8::Maybe;
3637
using v8::MaybeLocal;
@@ -635,7 +636,7 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
635636

636637
// This runs at runtime, regardless of whether the context
637638
// is created from a snapshot.
638-
Maybe<bool> InitializeContextRuntime(Local<Context> context) {
639+
Maybe<void> InitializeContextRuntime(Local<Context> context) {
639640
Isolate* isolate = context->GetIsolate();
640641
HandleScope handle_scope(isolate);
641642

@@ -653,7 +654,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
653654
Boolean::New(isolate, is_code_generation_from_strings_allowed));
654655

655656
if (per_process::cli_options->disable_proto == "") {
656-
return Just(true);
657+
return JustVoid();
657658
}
658659

659660
// Remove __proto__
@@ -669,14 +670,14 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
669670
if (!context->Global()
670671
->Get(context, object_string)
671672
.ToLocal(&object_v)) {
672-
return Nothing<bool>();
673+
return Nothing<void>();
673674
}
674675

675676
Local<Value> prototype_v;
676677
if (!object_v.As<Object>()
677678
->Get(context, prototype_string)
678679
.ToLocal(&prototype_v)) {
679-
return Nothing<bool>();
680+
return Nothing<void>();
680681
}
681682

682683
prototype = prototype_v.As<Object>();
@@ -689,13 +690,13 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
689690
if (prototype
690691
->Delete(context, proto_string)
691692
.IsNothing()) {
692-
return Nothing<bool>();
693+
return Nothing<void>();
693694
}
694695
} else if (per_process::cli_options->disable_proto == "throw") {
695696
Local<Value> thrower;
696697
if (!Function::New(context, ProtoThrower)
697698
.ToLocal(&thrower)) {
698-
return Nothing<bool>();
699+
return Nothing<void>();
699700
}
700701

701702
PropertyDescriptor descriptor(thrower, thrower);
@@ -704,17 +705,17 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
704705
if (prototype
705706
->DefineProperty(context, proto_string, descriptor)
706707
.IsNothing()) {
707-
return Nothing<bool>();
708+
return Nothing<void>();
708709
}
709710
} else if (per_process::cli_options->disable_proto != "") {
710711
// Validated in ProcessGlobalArgs
711712
UNREACHABLE("invalid --disable-proto mode");
712713
}
713714

714-
return Just(true);
715+
return JustVoid();
715716
}
716717

717-
Maybe<bool> InitializeBaseContextForSnapshot(Local<Context> context) {
718+
Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
718719
Isolate* isolate = context->GetIsolate();
719720
HandleScope handle_scope(isolate);
720721

@@ -728,18 +729,18 @@ Maybe<bool> InitializeBaseContextForSnapshot(Local<Context> context) {
728729

729730
Local<Value> intl_v;
730731
if (!context->Global()->Get(context, intl_string).ToLocal(&intl_v)) {
731-
return Nothing<bool>();
732+
return Nothing<void>();
732733
}
733734

734735
if (intl_v->IsObject() &&
735736
intl_v.As<Object>()->Delete(context, break_iter_string).IsNothing()) {
736-
return Nothing<bool>();
737+
return Nothing<void>();
737738
}
738739
}
739-
return Just(true);
740+
return JustVoid();
740741
}
741742

742-
Maybe<bool> InitializeMainContextForSnapshot(Local<Context> context) {
743+
Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
743744
Isolate* isolate = context->GetIsolate();
744745
HandleScope handle_scope(isolate);
745746

@@ -750,12 +751,12 @@ Maybe<bool> InitializeMainContextForSnapshot(Local<Context> context) {
750751
ContextEmbedderIndex::kAllowCodeGenerationFromStrings, True(isolate));
751752

752753
if (InitializeBaseContextForSnapshot(context).IsNothing()) {
753-
return Nothing<bool>();
754+
return Nothing<void>();
754755
}
755756
return InitializePrimordials(context);
756757
}
757758

758-
Maybe<bool> InitializePrimordials(Local<Context> context) {
759+
Maybe<void> InitializePrimordials(Local<Context> context) {
759760
// Run per-context JS files.
760761
Isolate* isolate = context->GetIsolate();
761762
Context::Scope context_scope(context);
@@ -769,7 +770,7 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
769770
if (primordials->SetPrototype(context, Null(isolate)).IsNothing() ||
770771
!GetPerContextExports(context).ToLocal(&exports) ||
771772
exports->Set(context, primordials_string, primordials).IsNothing()) {
772-
return Nothing<bool>();
773+
return Nothing<void>();
773774
}
774775

775776
static const char* context_files[] = {"internal/per_context/primordials",
@@ -793,11 +794,11 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
793794
context, *module, arraysize(arguments), arguments, nullptr)
794795
.IsEmpty()) {
795796
// Execution failed during context creation.
796-
return Nothing<bool>();
797+
return Nothing<void>();
797798
}
798799
}
799800

800-
return Just(true);
801+
return JustVoid();
801802
}
802803

803804
// This initializes the main context (i.e. vm contexts are not included).
@@ -806,7 +807,10 @@ Maybe<bool> InitializeContext(Local<Context> context) {
806807
return Nothing<bool>();
807808
}
808809

809-
return InitializeContextRuntime(context);
810+
if (InitializeContextRuntime(context).IsNothing()) {
811+
return Nothing<bool>();
812+
}
813+
return Just(true);
810814
}
811815

812816
uv_loop_t* GetCurrentEventLoop(Isolate* isolate) {

src/api/hooks.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Maybe<bool> EmitProcessBeforeExit(Environment* env) {
4646
Local<Integer> exit_code = Integer::New(
4747
isolate, static_cast<int32_t>(env->exit_code(ExitCode::kNoFailure)));
4848

49-
return ProcessEmit(env, "beforeExit", exit_code).IsEmpty() ?
50-
Nothing<bool>() : Just(true);
49+
return ProcessEmit(env, "beforeExit", exit_code).IsEmpty() ? Nothing<bool>()
50+
: Just(true);
5151
}
5252

5353
static ExitCode EmitExitInternal(Environment* env) {

src/base_object.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using v8::FunctionCallbackInfo;
1010
using v8::FunctionTemplate;
1111
using v8::HandleScope;
1212
using v8::Just;
13+
using v8::JustVoid;
1314
using v8::Local;
1415
using v8::Maybe;
1516
using v8::Object;
@@ -110,9 +111,9 @@ Maybe<std::vector<BaseObjectPtr<BaseObject>>> BaseObject::NestedTransferables()
110111
return Just(std::vector<BaseObjectPtr<BaseObject>>{});
111112
}
112113

113-
Maybe<bool> BaseObject::FinalizeTransferRead(Local<Context> context,
114+
Maybe<void> BaseObject::FinalizeTransferRead(Local<Context> context,
114115
ValueDeserializer* deserializer) {
115-
return Just(true);
116+
return JustVoid();
116117
}
117118

118119
BaseObject::PointerData* BaseObject::pointer_data() {

src/base_object.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class BaseObject : public MemoryRetainer {
173173
virtual std::unique_ptr<worker::TransferData> CloneForMessaging() const;
174174
virtual v8::Maybe<std::vector<BaseObjectPtrImpl<BaseObject, false>>>
175175
NestedTransferables() const;
176-
virtual v8::Maybe<bool> FinalizeTransferRead(
176+
virtual v8::Maybe<void> FinalizeTransferRead(
177177
v8::Local<v8::Context> context, v8::ValueDeserializer* deserializer);
178178

179179
// Indicates whether this object is expected to use a strong reference during

src/cares_wrap.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,13 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
14801480

14811481
switch (order) {
14821482
case DNS_ORDER_IPV4_FIRST:
1483-
if (add(true, false).IsNothing()) return;
1484-
if (add(false, true).IsNothing()) return;
1483+
if (add(true, false).IsNothing() || add(false, true).IsNothing())
1484+
return;
14851485

14861486
break;
14871487
case DNS_ORDER_IPV6_FIRST:
1488-
if (add(false, true).IsNothing()) return;
1489-
if (add(true, false).IsNothing()) return;
1488+
if (add(false, true).IsNothing() || add(true, false).IsNothing())
1489+
return;
14901490

14911491
break;
14921492
default:

src/node_env_var.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ using v8::HandleScope;
1919
using v8::Integer;
2020
using v8::Intercepted;
2121
using v8::Isolate;
22-
using v8::Just;
2322
using v8::JustVoid;
2423
using v8::Local;
2524
using v8::Maybe;
@@ -320,7 +319,7 @@ Maybe<void> KVStore::AssignFromObject(Local<Context> context,
320319

321320
// TODO(bnoordhuis) Not super efficient but called infrequently. Not worth
322321
// the trouble yet of specializing for RealEnvStore and MapKVStore.
323-
Maybe<bool> KVStore::AssignToObject(v8::Isolate* isolate,
322+
Maybe<void> KVStore::AssignToObject(v8::Isolate* isolate,
324323
v8::Local<v8::Context> context,
325324
v8::Local<v8::Object> object) {
326325
HandleScope scope(isolate);
@@ -333,9 +332,9 @@ Maybe<bool> KVStore::AssignToObject(v8::Isolate* isolate,
333332
ok = ok && key->IsString();
334333
ok = ok && Get(isolate, key.As<String>()).ToLocal(&value);
335334
ok = ok && object->Set(context, key, value).To(&ok);
336-
if (!ok) return Nothing<bool>();
335+
if (!ok) return Nothing<void>();
337336
}
338-
return Just(true);
337+
return JustVoid();
339338
}
340339

341340
static Intercepted EnvGetter(Local<Name> property,

src/node_internals.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ void SignalExit(int signal, siginfo_t* info, void* ucontext);
110110
std::string GetProcessTitle(const char* default_title);
111111
std::string GetHumanReadableProcessName();
112112

113-
v8::Maybe<bool> InitializeBaseContextForSnapshot(
113+
v8::Maybe<void> InitializeBaseContextForSnapshot(
114114
v8::Local<v8::Context> context);
115-
v8::Maybe<bool> InitializeContextRuntime(v8::Local<v8::Context> context);
116-
v8::Maybe<bool> InitializePrimordials(v8::Local<v8::Context> context);
115+
v8::Maybe<void> InitializeContextRuntime(v8::Local<v8::Context> context);
116+
v8::Maybe<void> InitializePrimordials(v8::Local<v8::Context> context);
117117

118118
class NodeArrayBufferAllocator : public ArrayBufferAllocator {
119119
public:

src/node_messaging.cc

+12-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using v8::Global;
2525
using v8::HandleScope;
2626
using v8::Isolate;
2727
using v8::Just;
28+
using v8::JustVoid;
2829
using v8::Local;
2930
using v8::Maybe;
3031
using v8::MaybeLocal;
@@ -337,7 +338,11 @@ class SerializerDelegate : public ValueSerializer::Delegate {
337338
// methods like toString(). It's probably confusing if that gets lost
338339
// in transmission.
339340
Local<Object> normal_object = Object::New(isolate);
340-
env_->env_vars()->AssignToObject(isolate, env_->context(), normal_object);
341+
if (env_->env_vars()
342+
->AssignToObject(isolate, env_->context(), normal_object)
343+
.IsNothing()) {
344+
return Nothing<bool>();
345+
}
341346
serializer->WriteUint32(kNormalObject); // Instead of a BaseObject.
342347
return serializer->WriteValue(env_->context(), normal_object);
343348
}
@@ -1389,25 +1394,25 @@ JSTransferable::NestedTransferables() const {
13891394
return Just(ret);
13901395
}
13911396

1392-
Maybe<bool> JSTransferable::FinalizeTransferRead(
1397+
Maybe<void> JSTransferable::FinalizeTransferRead(
13931398
Local<Context> context, ValueDeserializer* deserializer) {
13941399
// Call `this[kDeserialize](data)` where `data` comes from the return value
13951400
// of `this[kTransfer]()` or `this[kClone]()`.
13961401
HandleScope handle_scope(env()->isolate());
13971402
Local<Value> data;
1398-
if (!deserializer->ReadValue(context).ToLocal(&data)) return Nothing<bool>();
1403+
if (!deserializer->ReadValue(context).ToLocal(&data)) return Nothing<void>();
13991404

14001405
Local<Symbol> method_name = env()->messaging_deserialize_symbol();
14011406
Local<Value> method;
14021407
if (!target()->Get(context, method_name).ToLocal(&method)) {
1403-
return Nothing<bool>();
1408+
return Nothing<void>();
14041409
}
1405-
if (!method->IsFunction()) return Just(true);
1410+
if (!method->IsFunction()) return JustVoid();
14061411

14071412
if (method.As<Function>()->Call(context, target(), 1, &data).IsEmpty()) {
1408-
return Nothing<bool>();
1413+
return Nothing<void>();
14091414
}
1410-
return Just(true);
1415+
return JustVoid();
14111416
}
14121417

14131418
JSTransferable::Data::Data(std::string&& deserialize_info,

src/node_messaging.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class JSTransferable : public BaseObject {
340340
std::unique_ptr<TransferData> CloneForMessaging() const override;
341341
v8::Maybe<std::vector<BaseObjectPtr<BaseObject>>>
342342
NestedTransferables() const override;
343-
v8::Maybe<bool> FinalizeTransferRead(
343+
v8::Maybe<void> FinalizeTransferRead(
344344
v8::Local<v8::Context> context,
345345
v8::ValueDeserializer* deserializer) override;
346346

0 commit comments

Comments
 (0)