Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: clean up PackageConfig pseudo-boolean fields #21987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,15 @@ class Worker;
namespace loader {
class ModuleWrap;

struct Exists {
enum Bool { Yes, No };
};

struct IsValid {
enum Bool { Yes, No };
};

struct HasMain {
enum Bool { Yes, No };
};

struct PackageConfig {
const Exists::Bool exists;
const IsValid::Bool is_valid;
const HasMain::Bool has_main;
const std::string main;
enum class Exists { Yes, No };
enum class IsValid { Yes, No };
enum class HasMain { Yes, No };

Exists exists;
IsValid is_valid;
HasMain has_main;
std::string main;
};
} // namespace loader

Expand Down Expand Up @@ -670,7 +662,8 @@ class Environment {

std::unordered_multimap<int, loader::ModuleWrap*> module_map;

std::unordered_map<std::string, loader::PackageConfig> package_json_cache;
std::unordered_map<std::string, const loader::PackageConfig>
package_json_cache;

inline double* heap_statistics_buffer() const;
inline void set_heap_statistics_buffer(double* pointer);
Expand Down
8 changes: 6 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,12 @@ Maybe<uv_file> CheckFile(const std::string& path,
return Just(fd);
}

using Exists = PackageConfig::Exists;
using IsValid = PackageConfig::IsValid;
using HasMain = PackageConfig::HasMain;

const PackageConfig& GetPackageConfig(Environment* env,
const std::string path) {
const std::string& path) {
auto existing = env->package_json_cache.find(path);
if (existing != env->package_json_cache.end()) {
return existing->second;
Expand Down Expand Up @@ -530,7 +534,7 @@ const PackageConfig& GetPackageConfig(Environment* env,
}

Local<Value> pkg_main;
HasMain::Bool has_main = HasMain::No;
HasMain has_main = HasMain::No;
std::string main_std;
if (pkg_json->Get(env->context(), env->main_string()).ToLocal(&pkg_main)) {
has_main = HasMain::Yes;
Expand Down