66#include " node_process-inl.h"
77
88#include < time.h> // tzset(), _tzset()
9+ #include < optional>
910
1011namespace node {
1112using v8::Array;
@@ -19,6 +20,7 @@ using v8::Integer;
1920using v8::Intercepted;
2021using v8::Isolate;
2122using v8::Just;
23+ using v8::JustVoid;
2224using v8::Local;
2325using v8::Maybe;
2426using v8::MaybeLocal;
@@ -38,7 +40,7 @@ using v8::Value;
3840class RealEnvStore final : public KVStore {
3941 public:
4042 MaybeLocal<String> Get (Isolate* isolate, Local<String> key) const override ;
41- Maybe <std::string> Get (const char * key) const override ;
43+ std::optional <std::string> Get (const char * key) const override ;
4244 void Set (Isolate* isolate, Local<String> key, Local<String> value) override ;
4345 int32_t Query (Isolate* isolate, Local<String> key) const override ;
4446 int32_t Query (const char * key) const override ;
@@ -49,7 +51,7 @@ class RealEnvStore final : public KVStore {
4951class MapKVStore final : public KVStore {
5052 public:
5153 MaybeLocal<String> Get (Isolate* isolate, Local<String> key) const override ;
52- Maybe <std::string> Get (const char * key) const override ;
54+ std::optional <std::string> Get (const char * key) const override ;
5355 void Set (Isolate* isolate, Local<String> key, Local<String> value) override ;
5456 int32_t Query (Isolate* isolate, Local<String> key) const override ;
5557 int32_t Query (const char * key) const override ;
@@ -101,7 +103,7 @@ void DateTimeConfigurationChangeNotification(
101103 }
102104}
103105
104- Maybe <std::string> RealEnvStore::Get (const char * key) const {
106+ std::optional <std::string> RealEnvStore::Get (const char * key) const {
105107 Mutex::ScopedLock lock (per_process::env_var_mutex);
106108
107109 size_t init_sz = 256 ;
@@ -116,19 +118,19 @@ Maybe<std::string> RealEnvStore::Get(const char* key) const {
116118 }
117119
118120 if (ret >= 0 ) { // Env key value fetch success.
119- return Just ( std::string (*val, init_sz) );
121+ return std::string (*val, init_sz);
120122 }
121123
122- return Nothing< std::string>() ;
124+ return std::nullopt ;
123125}
124126
125127MaybeLocal<String> RealEnvStore::Get (Isolate* isolate,
126128 Local<String> property) const {
127129 node::Utf8Value key (isolate, property);
128- Maybe <std::string> value = Get (*key);
130+ std::optional <std::string> value = Get (*key);
129131
130- if (value.IsJust ()) {
131- std::string val = value.FromJust ();
132+ if (value.has_value ()) {
133+ std::string val = value.value ();
132134 return String::NewFromUtf8 (
133135 isolate, val.data (), NewStringType::kNormal , val.size ());
134136 }
@@ -229,17 +231,17 @@ std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
229231 return copy;
230232}
231233
232- Maybe <std::string> MapKVStore::Get (const char * key) const {
234+ std::optional <std::string> MapKVStore::Get (const char * key) const {
233235 Mutex::ScopedLock lock (mutex_);
234236 auto it = map_.find (key);
235- return it == map_.end () ? Nothing< std::string>() : Just (it->second );
237+ return it == map_.end () ? std::nullopt : std::make_optional (it->second );
236238}
237239
238240MaybeLocal<String> MapKVStore::Get (Isolate* isolate, Local<String> key) const {
239241 Utf8Value str (isolate, key);
240- Maybe <std::string> value = Get (*str);
241- if (value.IsNothing ()) return Local <String>();
242- std::string val = value.FromJust ();
242+ std::optional <std::string> value = Get (*str);
243+ if (! value.has_value ()) return MaybeLocal <String>();
244+ std::string val = value.value ();
243245 return String::NewFromUtf8 (
244246 isolate, val.data (), NewStringType::kNormal , val.size ());
245247}
@@ -291,30 +293,29 @@ std::shared_ptr<KVStore> KVStore::CreateMapKVStore() {
291293 return std::make_shared<MapKVStore>();
292294}
293295
294- Maybe<bool > KVStore::AssignFromObject (Local<Context> context,
296+ Maybe<void > KVStore::AssignFromObject (Local<Context> context,
295297 Local<Object> entries) {
296298 Isolate* isolate = context->GetIsolate ();
297299 HandleScope handle_scope (isolate);
298300 Local<Array> keys;
299301 if (!entries->GetOwnPropertyNames (context).ToLocal (&keys))
300- return Nothing<bool >();
302+ return Nothing<void >();
301303 uint32_t keys_length = keys->Length ();
302304 for (uint32_t i = 0 ; i < keys_length; i++) {
303305 Local<Value> key;
304- if (!keys->Get (context, i).ToLocal (&key))
305- return Nothing<bool >();
306+ if (!keys->Get (context, i).ToLocal (&key)) return Nothing<void >();
306307 if (!key->IsString ()) continue ;
307308
308309 Local<Value> value;
309310 Local<String> value_string;
310311 if (!entries->Get (context, key).ToLocal (&value) ||
311312 !value->ToString (context).ToLocal (&value_string)) {
312- return Nothing<bool >();
313+ return Nothing<void >();
313314 }
314315
315316 Set (isolate, key.As <String>(), value_string);
316317 }
317- return Just ( true );
318+ return JustVoid ( );
318319}
319320
320321// TODO(bnoordhuis) Not super efficient but called infrequently. Not worth
0 commit comments