Skip to content
Permalink
Browse files

src: clean up PackageConfig pseudo-boolean fields

PR-URL: #21987
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information...
addaleax committed Jul 26, 2018
1 parent f8d34b9 commit a196aa2e24ef7069289fa4a9aa8c6862d82e6b5f
Showing with 16 additions and 19 deletions.
  1. +10 −17 src/env.h
  2. +6 −2 src/module_wrap.cc
@@ -65,23 +65,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

@@ -672,7 +664,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);
@@ -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;
@@ -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;

0 comments on commit a196aa2

Please sign in to comment.
You can’t perform that action at this time.