| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b5eb24c commit 4578e94
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -472,7 +472,7 @@ void StartProfilers(Environment* env) { | |||
| 472 | 472 | }, env); | |
| 473 | 473 | ||
| 474 | 474 | std::string coverage_str = | |
| 475 | - env->env_vars()->Get("NODE_V8_COVERAGE").FromMaybe(std::string()); | ||
| 475 | + env->env_vars()->Get("NODE_V8_COVERAGE").value_or(std::string()); | ||
| 476 | 476 | if (!coverage_str.empty() || env->options()->test_runner_coverage) { | |
| 477 | 477 | CHECK_NULL(env->coverage_connection()); | |
| 478 | 478 | env->set_coverage_connection(std::make_unique<V8CoverageConnection>(env)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,7 +91,10 @@ bool SafeGetenv(const char* key, | |||
| 91 | 91 | env_vars = per_process::system_environment; | |
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | - return env_vars->Get(key).To(text); | ||
| 94 | + std::optional<std::string> value = env_vars->Get(key); | ||
| 95 | + if (!value.has_value()) return false; | ||
| 96 | + *text = value.value(); | ||
| 97 | + return true; | ||
| 95 | 98 | } | |
| 96 | 99 | ||
| 97 | 100 | static void SafeGetenv(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,7 @@ void Dotenv::SetEnvironment(node::Environment* env) { | |||
| 52 | 52 | ||
| 53 | 53 | auto existing = env->env_vars()->Get(key.data()); | |
| 54 | 54 | ||
| 55 | - if (existing.IsNothing()) { | ||
| 55 | + if (!existing.has_value()) { | ||
| 56 | 56 | env->env_vars()->Set( | |
| 57 | 57 | isolate, | |
| 58 | 58 | v8::String::NewFromUtf8( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "node_process-inl.h" | |
| 7 | 7 | ||
| 8 | 8 | #include <time.h> // tzset(), _tzset() | |
| 9 | + #include <optional> | ||
| 9 | 10 | ||
| 10 | 11 | namespace node { | |
| 11 | 12 | using v8::Array; | |
@@ -19,6 +20,7 @@ using v8::Integer; | |||
| 19 | 20 | using v8::Intercepted; | |
| 20 | 21 | using v8::Isolate; | |
| 21 | 22 | using v8::Just; | |
| 23 | + using v8::JustVoid; | ||
| 22 | 24 | using v8::Local; | |
| 23 | 25 | using v8::Maybe; | |
| 24 | 26 | using v8::MaybeLocal; | |
@@ -38,7 +40,7 @@ using v8::Value; | |||
| 38 | 40 | class RealEnvStore final : public KVStore { | |
| 39 | 41 | public: | |
| 40 | 42 | 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; | ||
| 42 | 44 | void Set(Isolate* isolate, Local<String> key, Local<String> value) override; | |
| 43 | 45 | int32_t Query(Isolate* isolate, Local<String> key) const override; | |
| 44 | 46 | int32_t Query(const char* key) const override; | |
@@ -49,7 +51,7 @@ class RealEnvStore final : public KVStore { | |||
| 49 | 51 | class MapKVStore final : public KVStore { | |
| 50 | 52 | public: | |
| 51 | 53 | 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; | ||
| 53 | 55 | void Set(Isolate* isolate, Local<String> key, Local<String> value) override; | |
| 54 | 56 | int32_t Query(Isolate* isolate, Local<String> key) const override; | |
| 55 | 57 | int32_t Query(const char* key) const override; | |
@@ -101,7 +103,7 @@ void DateTimeConfigurationChangeNotification( | |||
| 101 | 103 | } | |
| 102 | 104 | } | |
| 103 | 105 | ||
| 104 | - Maybe<std::string> RealEnvStore::Get(const char* key) const { | ||
| 106 | + std::optional<std::string> RealEnvStore::Get(const char* key) const { | ||
| 105 | 107 | Mutex::ScopedLock lock(per_process::env_var_mutex); | |
| 106 | 108 | ||
| 107 | 109 | size_t init_sz = 256; | |
@@ -116,19 +118,19 @@ Maybe<std::string> RealEnvStore::Get(const char* key) const { | |||
| 116 | 118 | } | |
| 117 | 119 | ||
| 118 | 120 | if (ret >= 0) { // Env key value fetch success. | |
| 119 | - return Just(std::string(*val, init_sz)); | ||
| 121 | + return std::string(*val, init_sz); | ||
| 120 | 122 | } | |
| 121 | 123 | ||
| 122 | - return Nothing<std::string>(); | ||
| 124 | + return std::nullopt; | ||
| 123 | 125 | } | |
| 124 | 126 | ||
| 125 | 127 | MaybeLocal<String> RealEnvStore::Get(Isolate* isolate, | |
| 126 | 128 | Local<String> property) const { | |
| 127 | 129 | node::Utf8Value key(isolate, property); | |
| 128 | - Maybe<std::string> value = Get(*key); | ||
| 130 | + std::optional<std::string> value = Get(*key); | ||
| 129 | 131 | ||
| 130 | - if (value.IsJust()) { | ||
| 131 | - std::string val = value.FromJust(); | ||
| 132 | + if (value.has_value()) { | ||
| 133 | + std::string val = value.value(); | ||
| 132 | 134 | return String::NewFromUtf8( | |
| 133 | 135 | isolate, val.data(), NewStringType::kNormal, val.size()); | |
| 134 | 136 | } | |
@@ -229,17 +231,17 @@ std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const { | |||
| 229 | 231 | return copy; | |
| 230 | 232 | } | |
| 231 | 233 | ||
| 232 | - Maybe<std::string> MapKVStore::Get(const char* key) const { | ||
| 234 | + std::optional<std::string> MapKVStore::Get(const char* key) const { | ||
| 233 | 235 | Mutex::ScopedLock lock(mutex_); | |
| 234 | 236 | 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); | ||
| 236 | 238 | } | |
| 237 | 239 | ||
| 238 | 240 | MaybeLocal<String> MapKVStore::Get(Isolate* isolate, Local<String> key) const { | |
| 239 | 241 | 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(); | ||
| 243 | 245 | return String::NewFromUtf8( | |
| 244 | 246 | isolate, val.data(), NewStringType::kNormal, val.size()); | |
| 245 | 247 | } | |
@@ -291,30 +293,29 @@ std::shared_ptr<KVStore> KVStore::CreateMapKVStore() { | |||
| 291 | 293 | return std::make_shared<MapKVStore>(); | |
| 292 | 294 | } | |
| 293 | 295 | ||
| 294 | - Maybe<bool> KVStore::AssignFromObject(Local<Context> context, | ||
| 296 | + Maybe<void> KVStore::AssignFromObject(Local<Context> context, | ||
| 295 | 297 | Local<Object> entries) { | |
| 296 | 298 | Isolate* isolate = context->GetIsolate(); | |
| 297 | 299 | HandleScope handle_scope(isolate); | |
| 298 | 300 | Local<Array> keys; | |
| 299 | 301 | if (!entries->GetOwnPropertyNames(context).ToLocal(&keys)) | |
| 300 | - return Nothing<bool>(); | ||
| 302 | + return Nothing<void>(); | ||
| 301 | 303 | uint32_t keys_length = keys->Length(); | |
| 302 | 304 | for (uint32_t i = 0; i < keys_length; i++) { | |
| 303 | 305 | 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>(); | ||
| 306 | 307 | if (!key->IsString()) continue; | |
| 307 | 308 | ||
| 308 | 309 | Local<Value> value; | |
| 309 | 310 | Local<String> value_string; | |
| 310 | 311 | if (!entries->Get(context, key).ToLocal(&value) || | |
| 311 | 312 | !value->ToString(context).ToLocal(&value_string)) { | |
| 312 | - return Nothing<bool>(); | ||
| 313 | + return Nothing<void>(); | ||
| 313 | 314 | } | |
| 314 | 315 | ||
| 315 | 316 | Set(isolate, key.As<String>(), value_string); | |
| 316 | 317 | } | |
| 317 | - return Just(true); | ||
| 318 | + return JustVoid(); | ||
| 318 | 319 | } | |
| 319 | 320 | ||
| 320 | 321 | // TODO(bnoordhuis) Not super efficient but called infrequently. Not worth | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -531,8 +531,12 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { | |||
| 531 | 531 | } else if (args[1]->IsObject()) { | |
| 532 | 532 | // User provided env. | |
| 533 | 533 | env_vars = KVStore::CreateMapKVStore(); | |
| 534 | - env_vars->AssignFromObject(isolate->GetCurrentContext(), | ||
| 535 | - args[1].As<Object>()); | ||
| 534 | + if (env_vars | ||
| 535 | + ->AssignFromObject(isolate->GetCurrentContext(), | ||
| 536 | + args[1].As<Object>()) | ||
| 537 | + .IsNothing()) { | ||
| 538 | + return; | ||
| 539 | + } | ||
| 536 | 540 | } else { | |
| 537 | 541 | // Env is shared. | |
| 538 | 542 | env_vars = env->env_vars(); | |
@@ -542,21 +546,21 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { | |||
| 542 | 546 | per_isolate_opts.reset(new PerIsolateOptions()); | |
| 543 | 547 | ||
| 544 | 548 | HandleEnvOptions(per_isolate_opts->per_env, [&env_vars](const char* name) { | |
| 545 | - return env_vars->Get(name).FromMaybe(""); | ||
| 549 | + return env_vars->Get(name).value_or(""); | ||
| 546 | 550 | }); | |
| 547 | 551 | ||
| 548 | 552 | #ifndef NODE_WITHOUT_NODE_OPTIONS | |
| 549 | - std::string node_options; | ||
| 550 | - if (env_vars->Get("NODE_OPTIONS").To(&node_options)) { | ||
| 553 | + std::optional<std::string> node_options = env_vars->Get("NODE_OPTIONS"); | ||
| 554 | + if (node_options.has_value()) { | ||
| 551 | 555 | std::vector<std::string> errors{}; | |
| 552 | 556 | std::vector<std::string> env_argv = | |
| 553 | - ParseNodeOptionsEnvVar(node_options, &errors); | ||
| 557 | + ParseNodeOptionsEnvVar(node_options.value(), &errors); | ||
| 554 | 558 | // [0] is expected to be the program name, add dummy string. | |
| 555 | 559 | env_argv.insert(env_argv.begin(), ""); | |
| 556 | 560 | std::vector<std::string> invalid_args{}; | |
| 557 | 561 | ||
| 558 | - std::string parent_node_options; | ||
| 559 | - USE(env->env_vars()->Get("NODE_OPTIONS").To(&parent_node_options)); | ||
| 562 | + std::optional<std::string> parent_node_options = | ||
| 563 | + env->env_vars()->Get("NODE_OPTIONS"); | ||
| 560 | 564 | ||
| 561 | 565 | // If the worker code passes { env: { ...process.env, ... } } or | |
| 562 | 566 | // the NODE_OPTIONS is otherwise character-for-character equal to the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ | |||
| 40 | 40 | #include <bit> | |
| 41 | 41 | #include <limits> | |
| 42 | 42 | #include <memory> | |
| 43 | + #include <optional> | ||
| 43 | 44 | #include <set> | |
| 44 | 45 | #include <string> | |
| 45 | 46 | #include <string_view> | |
@@ -306,7 +307,7 @@ class KVStore { | |||
| 306 | 307 | ||
| 307 | 308 | virtual v8::MaybeLocal<v8::String> Get(v8::Isolate* isolate, | |
| 308 | 309 | v8::Local<v8::String> key) const = 0; | |
| 309 | - virtual v8::Maybe<std::string> Get(const char* key) const = 0; | ||
| 310 | + virtual std::optional<std::string> Get(const char* key) const = 0; | ||
| 310 | 311 | virtual void Set(v8::Isolate* isolate, | |
| 311 | 312 | v8::Local<v8::String> key, | |
| 312 | 313 | v8::Local<v8::String> value) = 0; | |
@@ -317,7 +318,7 @@ class KVStore { | |||
| 317 | 318 | virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0; | |
| 318 | 319 | ||
| 319 | 320 | virtual std::shared_ptr<KVStore> Clone(v8::Isolate* isolate) const; | |
| 320 | - virtual v8::Maybe<bool> AssignFromObject(v8::Local<v8::Context> context, | ||
| 321 | + virtual v8::Maybe<void> AssignFromObject(v8::Local<v8::Context> context, | ||
| 321 | 322 | v8::Local<v8::Object> entries); | |
| 322 | 323 | v8::Maybe<bool> AssignToObject(v8::Isolate* isolate, | |
| 323 | 324 | v8::Local<v8::Context> context, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments