From 0d4985c63b27d55bd89f5e0dc04486caf27792ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Thu, 16 May 2024 21:33:17 +0200 Subject: [PATCH] src: improve node::Dotenv declarations There is no need to explicitly allow copy constructor and copy assignment, and some of these functions should be marked as const. PR-URL: https://github.com/nodejs/node/pull/52973 Reviewed-By: Yagiz Nizipli Reviewed-By: Benjamin Gruenbaum --- src/node_dotenv.cc | 8 ++------ src/node_dotenv.h | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/node_dotenv.cc b/src/node_dotenv.cc index 27f9c30c55714a..af7433d2a08369 100644 --- a/src/node_dotenv.cc +++ b/src/node_dotenv.cc @@ -42,10 +42,6 @@ std::vector Dotenv::GetPathFromArgs( } void Dotenv::SetEnvironment(node::Environment* env) { - if (store_.empty()) { - return; - } - auto isolate = env->isolate(); for (const auto& entry : store_) { @@ -67,7 +63,7 @@ void Dotenv::SetEnvironment(node::Environment* env) { } } -Local Dotenv::ToObject(Environment* env) { +Local Dotenv::ToObject(Environment* env) const { Local result = Object::New(env->isolate()); for (const auto& entry : store_) { @@ -263,7 +259,7 @@ Dotenv::ParseResult Dotenv::ParsePath(const std::string_view path) { return ParseResult::Valid; } -void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) { +void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) const { auto match = store_.find("NODE_OPTIONS"); if (match != store_.end()) { diff --git a/src/node_dotenv.h b/src/node_dotenv.h index 33ed63a9bef33f..ef9ee54a9e75ce 100644 --- a/src/node_dotenv.h +++ b/src/node_dotenv.h @@ -15,17 +15,17 @@ class Dotenv { enum ParseResult { Valid, FileError, InvalidContent }; Dotenv() = default; - Dotenv(const Dotenv& d) = default; + Dotenv(const Dotenv& d) = delete; Dotenv(Dotenv&& d) noexcept = default; Dotenv& operator=(Dotenv&& d) noexcept = default; - Dotenv& operator=(const Dotenv& d) = default; + Dotenv& operator=(const Dotenv& d) = delete; ~Dotenv() = default; void ParseContent(const std::string_view content); ParseResult ParsePath(const std::string_view path); - void AssignNodeOptionsIfAvailable(std::string* node_options); + void AssignNodeOptionsIfAvailable(std::string* node_options) const; void SetEnvironment(Environment* env); - v8::Local ToObject(Environment* env); + v8::Local ToObject(Environment* env) const; static std::vector GetPathFromArgs( const std::vector& args);