2121#include < string_view>
2222#include < vector>
2323
24+ #ifndef NODE_OPTIONS_STANDALONE
2425using v8::Boolean;
2526using v8::Context;
2627using v8::FunctionCallbackInfo;
@@ -36,12 +37,16 @@ using v8::Object;
3637using v8::String;
3738using v8::Undefined;
3839using v8::Value;
40+ #endif // NODE_OPTIONS_STANDALONE
41+
3942namespace node {
4043
44+ #ifndef NODE_OPTIONS_STANDALONE
4145namespace per_process {
4246Mutex cli_options_mutex;
4347std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions ()};
4448} // namespace per_process
49+ #endif // NODE_OPTIONS_STANDALONE
4550
4651void DebugOptions::CheckOptions (std::vector<std::string>* errors,
4752 std::vector<std::string>* argv) {
@@ -293,64 +298,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
293298
294299namespace options_parser {
295300
296- // Helper function to convert option types to their string representation
297- // and add them to a V8 Map
298- static bool AddOptionTypeToMap (Isolate* isolate,
299- Local<Context> context,
300- Local<Map> map,
301- const std::string& option_name,
302- const OptionType& option_type) {
303- std::string type;
304- switch (static_cast <int >(option_type)) {
305- case 0 : // No-op
306- case 1 : // V8 flags
307- break ; // V8 and NoOp flags are not supported
308-
309- case 2 :
310- type = " boolean" ;
311- break ;
312- case 3 : // integer
313- case 4 : // unsigned integer
314- case 6 : // host port
315- type = " number" ;
316- break ;
317- case 5 : // string
318- type = " string" ;
319- break ;
320- case 7 : // string array
321- type = " array" ;
322- break ;
323- default :
324- UNREACHABLE ();
325- }
326-
327- if (type.empty ()) {
328- return true ; // Skip this entry but continue processing
329- }
330-
331- Local<String> option_key;
332- if (!String::NewFromUtf8 (isolate,
333- option_name.data (),
334- v8::NewStringType::kNormal ,
335- option_name.size ())
336- .ToLocal (&option_key)) {
337- return true ; // Skip this entry but continue processing
338- }
339-
340- Local<String> type_value;
341- if (!String::NewFromUtf8 (
342- isolate, type.data (), v8::NewStringType::kNormal , type.size ())
343- .ToLocal (&type_value)) {
344- return true ; // Skip this entry but continue processing
345- }
346-
347- if (map->Set (context, option_key, type_value).IsEmpty ()) {
348- return false ; // Error occurred, stop processing
349- }
350-
351- return true ;
352- }
353-
354301class DebugOptionsParser : public OptionsParser <DebugOptions> {
355302 public:
356303 DebugOptionsParser ();
@@ -1445,6 +1392,65 @@ HostPort SplitHostPort(const std::string& arg,
14451392 ParseAndValidatePort (arg.substr (colon + 1 ), errors) };
14461393}
14471394
1395+ #ifndef NODE_OPTIONS_STANDALONE
1396+ // Helper function to convert option types to their string representation
1397+ // and add them to a V8 Map
1398+ static bool AddOptionTypeToMap (Isolate* isolate,
1399+ Local<Context> context,
1400+ Local<Map> map,
1401+ const std::string& option_name,
1402+ const OptionType& option_type) {
1403+ std::string type;
1404+ switch (static_cast <int >(option_type)) {
1405+ case 0 : // No-op
1406+ case 1 : // V8 flags
1407+ break ; // V8 and NoOp flags are not supported
1408+
1409+ case 2 :
1410+ type = " boolean" ;
1411+ break ;
1412+ case 3 : // integer
1413+ case 4 : // unsigned integer
1414+ case 6 : // host port
1415+ type = " number" ;
1416+ break ;
1417+ case 5 : // string
1418+ type = " string" ;
1419+ break ;
1420+ case 7 : // string array
1421+ type = " array" ;
1422+ break ;
1423+ default :
1424+ UNREACHABLE ();
1425+ }
1426+
1427+ if (type.empty ()) {
1428+ return true ; // Skip this entry but continue processing
1429+ }
1430+
1431+ Local<String> option_key;
1432+ if (!String::NewFromUtf8 (isolate,
1433+ option_name.data (),
1434+ v8::NewStringType::kNormal ,
1435+ option_name.size ())
1436+ .ToLocal (&option_key)) {
1437+ return true ; // Skip this entry but continue processing
1438+ }
1439+
1440+ Local<String> type_value;
1441+ if (!String::NewFromUtf8 (
1442+ isolate, type.data (), v8::NewStringType::kNormal , type.size ())
1443+ .ToLocal (&type_value)) {
1444+ return true ; // Skip this entry but continue processing
1445+ }
1446+
1447+ if (map->Set (context, option_key, type_value).IsEmpty ()) {
1448+ return false ; // Error occurred, stop processing
1449+ }
1450+
1451+ return true ;
1452+ }
1453+
14481454std::string GetBashCompletion () {
14491455 Mutex::ScopedLock lock (per_process::cli_options_mutex);
14501456 const auto & parser = _ppop_instance;
@@ -2033,14 +2039,17 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
20332039 registry->Register (GetEnvOptionsInputType);
20342040 registry->Register (GetNamespaceOptionsInputType);
20352041}
2042+ #endif // NODE_OPTIONS_STANDALONE
20362043} // namespace options_parser
20372044
2045+ #ifndef NODE_OPTIONS_STANDALONE
20382046void HandleEnvOptions (std::shared_ptr<EnvironmentOptions> env_options) {
20392047 HandleEnvOptions (env_options, [](const char * name) {
20402048 std::string text;
20412049 return credentials::SafeGetenv (name, &text) ? text : " " ;
20422050 });
20432051}
2052+ #endif // NODE_OPTIONS_STANDALONE
20442053
20452054void HandleEnvOptions (std::shared_ptr<EnvironmentOptions> env_options,
20462055 std::function<std::string(const char *)> opt_getter) {
@@ -2100,6 +2109,8 @@ std::vector<std::string> ParseNodeOptionsEnvVar(
21002109}
21012110} // namespace node
21022111
2112+ #ifndef NODE_OPTIONS_STANDALONE
21032113NODE_BINDING_CONTEXT_AWARE_INTERNAL (options, node::options_parser::Initialize)
21042114NODE_BINDING_EXTERNAL_REFERENCE(
21052115 options, node::options_parser::RegisterExternalReferences)
2116+ #endif // NODE_OPTIONS_STANDALONE
0 commit comments