Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
with
16 additions
and
19 deletions.
-
+10
−17
src/env.h
-
+6
−2
src/module_wrap.cc
There are no files selected for viewing
|
|
@@ -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 |
|
|
|
|
|
@@ -673,7 +665,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; |
|
|
|