Skip to content

Commit

Permalink
src: improve node::Dotenv declarations
Browse files Browse the repository at this point in the history
There is no need to explicitly allow copy constructor and copy
assignment, and some of these functions should be marked as const.

PR-URL: #52973
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
tniessen committed May 16, 2024
1 parent b0bd534 commit 3f3226c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ std::vector<std::string> Dotenv::GetPathFromArgs(
}

void Dotenv::SetEnvironment(node::Environment* env) {
if (store_.empty()) {
return;
}

auto isolate = env->isolate();

for (const auto& entry : store_) {
Expand All @@ -67,7 +63,7 @@ void Dotenv::SetEnvironment(node::Environment* env) {
}
}

Local<Object> Dotenv::ToObject(Environment* env) {
Local<Object> Dotenv::ToObject(Environment* env) const {
Local<Object> result = Object::New(env->isolate());

for (const auto& entry : store_) {
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 4 additions & 4 deletions src/node_dotenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Object> ToObject(Environment* env);
v8::Local<v8::Object> ToObject(Environment* env) const;

static std::vector<std::string> GetPathFromArgs(
const std::vector<std::string>& args);
Expand Down

0 comments on commit 3f3226c

Please sign in to comment.