@@ -3155,11 +3155,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile( |
3155 | 3155 | return BindingData::FilePathIsFileReturnType::kIsNotFile; |
3156 | 3156 | } |
3157 | 3157 |
|
| 3158 | +namespace { |
| 3159 | + |
| 3160 | +// define the final index of the algorithm resolution |
| 3161 | +// when packageConfig.main is defined. |
| 3162 | +constexpr uint8_t legacy_main_extensions_with_main_end = 7; |
| 3163 | +// define the final index of the algorithm resolution |
| 3164 | +// when packageConfig.main is NOT defined |
| 3165 | +constexpr uint8_t legacy_main_extensions_package_fallback_end = 10; |
3158 | 3166 | // the possible file extensions that should be tested |
3159 | 3167 | // 0-6: when packageConfig.main is defined |
3160 | 3168 | // 7-9: when packageConfig.main is NOT defined, |
3161 | 3169 | // or when the previous case didn't found the file |
3162 | | -const std::array<std::string, 10> BindingData::legacy_main_extensions = { |
| 3170 | +constexpr std::array<std::string_view, 10> legacy_main_extensions = { |
3163 | 3171 | "", |
3164 | 3172 | ".js", |
3165 | 3173 | ".json", |
@@ -3171,6 +3179,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = { |
3171 | 3179 | ".json", |
3172 | 3180 | ".node"}; |
3173 | 3181 |
|
| 3182 | +} // namespace |
| 3183 | + |
3174 | 3184 | void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { |
3175 | 3185 | CHECK_GE(args.Length(), 1); |
3176 | 3186 | CHECK(args[0]->IsString()); |
@@ -3211,9 +3221,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { |
3211 | 3221 |
|
3212 | 3222 | FromNamespacedPath(&initial_file_path); |
3213 | 3223 |
|
3214 | | - for (int i = 0; i < BindingData::legacy_main_extensions_with_main_end; |
3215 | | - i++) { |
3216 | | - file_path = initial_file_path + BindingData::legacy_main_extensions[i]; |
| 3224 | + for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { |
| 3225 | + file_path = initial_file_path + std::string(legacy_main_extensions[i]); |
3217 | 3226 |
|
3218 | 3227 | switch (FilePathIsFile(env, file_path)) { |
3219 | 3228 | case BindingData::FilePathIsFileReturnType::kIsFile: |
@@ -3246,10 +3255,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { |
3246 | 3255 |
|
3247 | 3256 | FromNamespacedPath(&initial_file_path); |
3248 | 3257 |
|
3249 | | - for (int i = BindingData::legacy_main_extensions_with_main_end; |
3250 | | - i < BindingData::legacy_main_extensions_package_fallback_end; |
| 3258 | + for (int i = legacy_main_extensions_with_main_end; |
| 3259 | + i < legacy_main_extensions_package_fallback_end; |
3251 | 3260 | i++) { |
3252 | | - file_path = initial_file_path + BindingData::legacy_main_extensions[i]; |
| 3261 | + file_path = initial_file_path + std::string(legacy_main_extensions[i]); |
3253 | 3262 |
|
3254 | 3263 | switch (FilePathIsFile(env, file_path)) { |
3255 | 3264 | case BindingData::FilePathIsFileReturnType::kIsFile: |
|