From 43500fa64652644914f3b4db6301c8c072e9ccd0 Mon Sep 17 00:00:00 2001 From: Jungku Lee Date: Fri, 29 Sep 2023 20:04:48 +0900 Subject: [PATCH] src: move const variable in `node_file.h` to `node_file.cc` PR-URL: https://github.com/nodejs/node/pull/49688 Refs: https://github.com/nodejs/node/pull/48325 Reviewed-By: Yagiz Nizipli --- src/node_file.cc | 23 ++++++++++++++++------- src/node_file.h | 8 -------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index aca7ec82101a60..0e03f4b1f4bd2d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3120,11 +3120,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile( return BindingData::FilePathIsFileReturnType::kIsNotFile; } +namespace { + +// define the final index of the algorithm resolution +// when packageConfig.main is defined. +constexpr uint8_t legacy_main_extensions_with_main_end = 7; +// define the final index of the algorithm resolution +// when packageConfig.main is NOT defined +constexpr uint8_t legacy_main_extensions_package_fallback_end = 10; // the possible file extensions that should be tested // 0-6: when packageConfig.main is defined // 7-9: when packageConfig.main is NOT defined, // or when the previous case didn't found the file -const std::array BindingData::legacy_main_extensions = { +constexpr std::array legacy_main_extensions = { "", ".js", ".json", @@ -3136,6 +3144,8 @@ const std::array BindingData::legacy_main_extensions = { ".json", ".node"}; +} // namespace + void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); @@ -3176,9 +3186,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { FromNamespacedPath(&initial_file_path); - for (int i = 0; i < BindingData::legacy_main_extensions_with_main_end; - i++) { - file_path = initial_file_path + BindingData::legacy_main_extensions[i]; + for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { + file_path = initial_file_path + std::string(legacy_main_extensions[i]); switch (FilePathIsFile(env, file_path)) { case BindingData::FilePathIsFileReturnType::kIsFile: @@ -3211,10 +3220,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { FromNamespacedPath(&initial_file_path); - for (int i = BindingData::legacy_main_extensions_with_main_end; - i < BindingData::legacy_main_extensions_package_fallback_end; + for (int i = legacy_main_extensions_with_main_end; + i < legacy_main_extensions_package_fallback_end; i++) { - file_path = initial_file_path + BindingData::legacy_main_extensions[i]; + file_path = initial_file_path + std::string(legacy_main_extensions[i]); switch (FilePathIsFile(env, file_path)) { case BindingData::FilePathIsFileReturnType::kIsFile: diff --git a/src/node_file.h b/src/node_file.h index 0fa2da0b4f7f8a..f608da5b7a17e2 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -102,14 +102,6 @@ class BindingData : public SnapshotableObject { static FilePathIsFileReturnType FilePathIsFile(Environment* env, const std::string& file_path); - - static const std::array legacy_main_extensions; - // define the final index of the algorithm resolution - // when packageConfig.main is defined. - static const uint8_t legacy_main_extensions_with_main_end = 7; - // define the final index of the algorithm resolution - // when packageConfig.main is NOT defined - static const uint8_t legacy_main_extensions_package_fallback_end = 10; }; // structure used to store state during a complex operation, e.g., mkdirp.