From b9a86144cf3bee189133631b85522b746213dc28 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 29 Nov 2024 14:14:39 -0500 Subject: [PATCH] src: converts args to std::span --- src/api/embed_helpers.cc | 4 ++-- src/api/environment.cc | 4 ++-- src/env-inl.h | 4 ++-- src/env.cc | 10 ++++----- src/env.h | 14 ++++++------ src/node.cc | 45 ++++++++++++++++++++----------------- src/node.h | 16 ++++++------- src/node_dotenv.cc | 8 +++---- src/node_dotenv.h | 4 ++-- src/node_internals.h | 8 +++---- src/node_main_instance.cc | 4 ++-- src/node_main_instance.h | 12 +++++----- src/node_options-inl.h | 20 ++++++++--------- src/node_options.cc | 14 ++++++------ src/node_options.h | 13 ++++++----- src/node_sea.cc | 14 ++++++------ src/node_sea.h | 4 ++-- src/node_snapshot_builder.h | 8 +++---- src/node_snapshotable.cc | 18 +++++++-------- src/node_task_runner.cc | 4 ++-- src/node_task_runner.h | 2 +- 21 files changed, 118 insertions(+), 112 deletions(-) diff --git a/src/api/embed_helpers.cc b/src/api/embed_helpers.cc index 34de89a8dc0398..d1ba03c42703a5 100644 --- a/src/api/embed_helpers.cc +++ b/src/api/embed_helpers.cc @@ -188,8 +188,8 @@ std::unique_ptr CommonEnvironmentSetup::CreateForSnapshotting( MultiIsolatePlatform* platform, std::vector* errors, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const SnapshotConfig& snapshot_config) { // It's not guaranteed that a context that goes through // v8_inspector::V8Inspector::contextCreated() is runtime-independent, diff --git a/src/api/environment.cc b/src/api/environment.cc index 2641ea7d7f84f4..0e541731f04c95 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -396,8 +396,8 @@ struct InspectorParentHandleImpl : public InspectorParentHandle { Environment* CreateEnvironment( IsolateData* isolate_data, Local context, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, EnvironmentFlags::Flags flags, ThreadId thread_id, std::unique_ptr inspector_parent_handle) { diff --git a/src/env-inl.h b/src/env-inl.h index d266eca6fc3300..1df5c6dffc27f7 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -442,11 +442,11 @@ inline std::shared_ptr Environment::options() { return options_; } -inline const std::vector& Environment::argv() { +inline const std::vector& Environment::argv() { return argv_; } -inline const std::vector& Environment::exec_argv() { +inline const std::vector& Environment::exec_argv() { return exec_argv_; } diff --git a/src/env.cc b/src/env.cc index 290048304d2d64..7413139b4db269 100644 --- a/src/env.cc +++ b/src/env.cc @@ -763,7 +763,7 @@ std::unique_ptr Environment::release_managed_buffer( return bs; } -std::string Environment::GetExecPath(const std::vector& argv) { +std::string Environment::GetExecPath(const std::vector& argv) { char exec_path_buf[2 * PATH_MAX]; size_t exec_path_len = sizeof(exec_path_buf); std::string exec_path; @@ -791,8 +791,8 @@ std::string Environment::GetExecPath(const std::vector& argv) { Environment::Environment(IsolateData* isolate_data, Isolate* isolate, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const EnvSerializeInfo* env_info, EnvironmentFlags::Flags flags, ThreadId thread_id) @@ -910,10 +910,10 @@ Environment::Environment(IsolateData* isolate_data, TRACING_CATEGORY_NODE1(environment)) != 0) { auto traced_value = tracing::TracedValue::Create(); traced_value->BeginArray("args"); - for (const std::string& arg : args) traced_value->AppendString(arg); + for (const auto& arg : args) traced_value->AppendString(arg.data()); traced_value->EndArray(); traced_value->BeginArray("exec_args"); - for (const std::string& arg : exec_args) traced_value->AppendString(arg); + for (const auto& arg : exec_args) traced_value->AppendString(arg.data()); traced_value->EndArray(); TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment), "Environment", diff --git a/src/env.h b/src/env.h index 11d956710b8969..34841157773ee1 100644 --- a/src/env.h +++ b/src/env.h @@ -620,7 +620,7 @@ class Environment final : public MemoryRetainer { SET_MEMORY_INFO_NAME(Environment) - static std::string GetExecPath(const std::vector& argv); + static std::string GetExecPath(const std::vector& argv); static std::string GetCwd(const std::string& exec_path); inline size_t SelfSize() const override; @@ -664,8 +664,8 @@ class Environment final : public MemoryRetainer { // InitializeMainContext() to initialize a main context for it. Environment(IsolateData* isolate_data, v8::Isolate* isolate, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const EnvSerializeInfo* env_info, EnvironmentFlags::Flags flags, ThreadId thread_id); @@ -674,8 +674,8 @@ class Environment final : public MemoryRetainer { ~Environment() override; void InitializeLibuv(); - inline const std::vector& exec_argv(); - inline const std::vector& argv(); + inline const std::vector& exec_argv(); + inline const std::vector& argv(); const std::string& exec_path() const; void CleanupHandles(); @@ -1143,8 +1143,8 @@ class Environment final : public MemoryRetainer { // the inspector_host_port_->port() will be the actual port being // used. std::shared_ptr> inspector_host_port_; - std::vector exec_argv_; - std::vector argv_; + std::vector exec_argv_; + std::vector argv_; std::string exec_path_; bool is_in_heapsnapshot_heap_limit_callback_ = false; diff --git a/src/node.cc b/src/node.cc index dd52fbffac0dee..d44f67d8633881 100644 --- a/src/node.cc +++ b/src/node.cc @@ -190,7 +190,7 @@ void Environment::InitializeInspector( inspector_path = parent_handle->url(); inspector_agent_->SetParentHandle(std::move(parent_handle)); } else { - inspector_path = argv_.size() > 1 ? argv_[1].c_str() : ""; + inspector_path = argv_.size() > 1 ? argv_[1].data() : ""; } CHECK(!inspector_agent_->IsListening()); @@ -710,12 +710,12 @@ void ResetStdio() { #endif // __POSIX__ } -static ExitCode ProcessGlobalArgsInternal(std::vector* args, - std::vector* exec_args, +static ExitCode ProcessGlobalArgsInternal(std::vector* args, + std::vector* exec_args, std::vector* errors, OptionEnvvarSettings settings) { // Parse a few arguments which are specific to Node. - std::vector v8_args; + std::vector v8_args; Mutex::ScopedLock lock(per_process::cli_options_mutex); options_parser::Parse( @@ -771,12 +771,13 @@ static ExitCode ProcessGlobalArgsInternal(std::vector* args, } #endif - std::vector v8_args_as_char_ptr(v8_args.size()); + std::vector v8_args_as_char_ptr(v8_args.size()); if (v8_args.size() > 0) { for (size_t i = 0; i < v8_args.size(); ++i) v8_args_as_char_ptr[i] = v8_args[i].data(); int argc = v8_args.size(); - V8::SetFlagsFromCommandLine(&argc, v8_args_as_char_ptr.data(), true); + // TODO(anonrig): enable this before landing + // V8::SetFlagsFromCommandLine(&argc, &*v8_args_as_char_ptr.data(), true); v8_args_as_char_ptr.resize(argc); } @@ -790,8 +791,8 @@ static ExitCode ProcessGlobalArgsInternal(std::vector* args, return ExitCode::kNoFailure; } -int ProcessGlobalArgs(std::vector* args, - std::vector* exec_args, +int ProcessGlobalArgs(std::vector* args, + std::vector* exec_args, std::vector* errors, OptionEnvvarSettings settings) { return static_cast( @@ -803,8 +804,8 @@ static std::atomic_bool init_called{false}; // TODO(addaleax): Turn this into a wrapper around InitializeOncePerProcess() // (with the corresponding additional flags set), then eventually remove this. static ExitCode InitializeNodeWithArgsInternal( - std::vector* argv, - std::vector* exec_argv, + std::vector* argv, + std::vector* exec_argv, std::vector* errors, ProcessInitializationFlags::Flags flags) { // Make sure InitializeNodeWithArgs() is called only once. @@ -861,16 +862,16 @@ static ExitCode InitializeNodeWithArgsInternal( case Dotenv::ParseResult::Valid: break; case Dotenv::ParseResult::InvalidContent: - errors->push_back(file_data.path + ": invalid format"); + errors->push_back(std::string(file_data.path) + ": invalid format"); break; case Dotenv::ParseResult::FileError: if (file_data.is_optional) { fprintf(stderr, "%s not found. Continuing without it.\n", - file_data.path.c_str()); + file_data.path.data()); continue; } - errors->push_back(file_data.path + ": not found"); + errors->push_back(std::string(file_data.path) + ": not found"); break; default: UNREACHABLE(); @@ -975,8 +976,8 @@ static ExitCode InitializeNodeWithArgsInternal( return ExitCode::kNoFailure; } -int InitializeNodeWithArgs(std::vector* argv, - std::vector* exec_argv, +int InitializeNodeWithArgs(std::vector* argv, + std::vector* exec_argv, std::vector* errors, ProcessInitializationFlags::Flags flags) { return static_cast( @@ -984,11 +985,11 @@ int InitializeNodeWithArgs(std::vector* argv, } static std::shared_ptr -InitializeOncePerProcessInternal(const std::vector& args, +InitializeOncePerProcessInternal(const std::vector& args, ProcessInitializationFlags::Flags flags = ProcessInitializationFlags::kNoFlags) { auto result = std::make_shared(); - result->args_ = args; + result->args_ = std::move(args); if (!(flags & ProcessInitializationFlags::kNoParseGlobalDebugVariables)) { // Initialized the enabled list for Debug() calls with system @@ -1216,7 +1217,7 @@ InitializeOncePerProcessInternal(const std::vector& args, } std::shared_ptr InitializeOncePerProcess( - const std::vector& args, + const std::vector& args, ProcessInitializationFlags::Flags flags) { return InitializeOncePerProcessInternal(args, flags); } @@ -1286,7 +1287,11 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr, } } else { snapshot_config.builder_script_path = result->args()[1]; - args_maybe_patched = result->args(); + args_maybe_patched.reserve(result->args().size()); + // TODO(anonrig): Avoid copying in here. + for (const auto& arg : result->args()) { + args_maybe_patched.push_back(std::string(arg)); + }; } DCHECK(snapshot_config.builder_script_path.has_value()); const std::string& builder_script = @@ -1429,7 +1434,7 @@ static ExitCode StartInternal(int argc, char** argv) { std::shared_ptr result = InitializeOncePerProcessInternal( - std::vector(argv, argv + argc)); + std::vector(argv, argv + argc)); for (const std::string& error : result->errors()) { FPrintF(stderr, "%s: %s\n", result->args().at(0), error); } diff --git a/src/node.h b/src/node.h index 643f964115b0ae..48554f3bd62a6a 100644 --- a/src/node.h +++ b/src/node.h @@ -301,10 +301,10 @@ class NODE_EXTERN InitializationResult { virtual bool early_return() const = 0; // Returns the parsed list of non-Node.js arguments. - virtual const std::vector& args() const = 0; + virtual const std::vector& args() const = 0; // Returns the parsed list of Node.js arguments. - virtual const std::vector& exec_args() const = 0; + virtual const std::vector& exec_args() const = 0; // Returns an array of errors. Note that these may be warnings // whose existence does not imply a non-zero exit code. @@ -350,7 +350,7 @@ NODE_DEPRECATED("Use InitializeOncePerProcess() instead", // errors encountered during initialization, and a potential suggested // exit code. NODE_EXTERN std::shared_ptr InitializeOncePerProcess( - const std::vector& args, + const std::vector& args, ProcessInitializationFlags::Flags flags = ProcessInitializationFlags::kNoFlags); // Undoes the initialization performed by InitializeOncePerProcess(), @@ -359,7 +359,7 @@ NODE_EXTERN void TearDownOncePerProcess(); // Convenience overload for specifying multiple flags without having // to worry about casts. inline std::shared_ptr InitializeOncePerProcess( - const std::vector& args, + const std::vector& args, std::initializer_list list) { uint64_t flags_accum = ProcessInitializationFlags::kNoFlags; for (const auto flag : list) flags_accum |= static_cast(flag); @@ -704,8 +704,8 @@ struct InspectorParentHandle { NODE_EXTERN Environment* CreateEnvironment( IsolateData* isolate_data, v8::Local context, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, EnvironmentFlags::Flags flags = EnvironmentFlags::kDefaultFlags, ThreadId thread_id = {} /* allocates a thread id automatically */, std::unique_ptr inspector_parent_handle = {}); @@ -923,8 +923,8 @@ class NODE_EXTERN CommonEnvironmentSetup { static std::unique_ptr CreateForSnapshotting( MultiIsolatePlatform* platform, std::vector* errors, - const std::vector& args = {}, - const std::vector& exec_args = {}, + const std::vector& args = {}, + const std::vector& exec_args = {}, const SnapshotConfig& snapshot_config = {}); EmbedderSnapshotData::Pointer CreateSnapshot(); diff --git a/src/node_dotenv.cc b/src/node_dotenv.cc index 049f5cfcb77b9c..aed557bd66ff22 100644 --- a/src/node_dotenv.cc +++ b/src/node_dotenv.cc @@ -12,10 +12,10 @@ using v8::Object; using v8::String; std::vector Dotenv::GetDataFromArgs( - const std::vector& args) { - const std::string_view optional_env_file_flag = "--env-file-if-exists"; + const std::vector& args) { + constexpr std::string_view optional_env_file_flag = "--env-file-if-exists"; - const auto find_match = [](const std::string& arg) { + const auto find_match = [](const std::string_view arg) { return arg == "--" || arg == "--env-file" || arg.starts_with("--env-file=") || arg == "--env-file-if-exists" || arg.starts_with("--env-file-if-exists="); @@ -37,7 +37,7 @@ std::vector Dotenv::GetDataFromArgs( auto flag = matched_arg->substr(0, equal_char_index); auto file_path = matched_arg->substr(equal_char_index + 1); - struct env_file_data env_file_data = { + env_file_data env_file_data = { file_path, flag.starts_with(optional_env_file_flag)}; env_files.push_back(env_file_data); } else { diff --git a/src/node_dotenv.h b/src/node_dotenv.h index d508b13fc5db74..2bc251a01d3d59 100644 --- a/src/node_dotenv.h +++ b/src/node_dotenv.h @@ -14,7 +14,7 @@ class Dotenv { public: enum ParseResult { Valid, FileError, InvalidContent }; struct env_file_data { - std::string path; + std::string_view path; bool is_optional; }; @@ -32,7 +32,7 @@ class Dotenv { v8::Local ToObject(Environment* env) const; static std::vector GetDataFromArgs( - const std::vector& args); + const std::vector& args); private: std::map store_; diff --git a/src/node_internals.h b/src/node_internals.h index 000ba16303740d..b501ca07444e3b 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -346,14 +346,14 @@ class InitializationResultImpl final : public InitializationResult { int exit_code() const { return static_cast(exit_code_enum()); } ExitCode exit_code_enum() const { return exit_code_; } bool early_return() const { return early_return_; } - const std::vector& args() const { return args_; } - const std::vector& exec_args() const { return exec_args_; } + const std::vector& args() const { return args_; } + const std::vector& exec_args() const { return exec_args_; } const std::vector& errors() const { return errors_; } MultiIsolatePlatform* platform() const { return platform_; } ExitCode exit_code_ = ExitCode::kNoFailure; - std::vector args_; - std::vector exec_args_; + std::vector args_; + std::vector exec_args_; std::vector errors_; bool early_return_ = false; MultiIsolatePlatform* platform_ = nullptr; diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 4119ac1b002681..abba6b55b8e831 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -33,8 +33,8 @@ using v8::Locker; NodeMainInstance::NodeMainInstance(const SnapshotData* snapshot_data, uv_loop_t* event_loop, MultiIsolatePlatform* platform, - const std::vector& args, - const std::vector& exec_args) + const std::vector& args, + const std::vector& exec_args) : args_(args), exec_args_(exec_args), array_buffer_allocator_(ArrayBufferAllocator::Create()), diff --git a/src/node_main_instance.h b/src/node_main_instance.h index 2752ff4d0ebc07..b2e9db2ce952a0 100644 --- a/src/node_main_instance.h +++ b/src/node_main_instance.h @@ -26,8 +26,8 @@ class NodeMainInstance { NodeMainInstance(const SnapshotData* snapshot_data, uv_loop_t* event_loop, MultiIsolatePlatform* platform, - const std::vector& args, - const std::vector& exec_args); + const std::vector& args, + const std::vector& exec_args); ~NodeMainInstance(); // Start running the Node.js instances, return the exit code when finished. @@ -48,11 +48,11 @@ class NodeMainInstance { NodeMainInstance(v8::Isolate* isolate, uv_loop_t* event_loop, MultiIsolatePlatform* platform, - const std::vector& args, - const std::vector& exec_args); + const std::vector& args, + const std::vector& exec_args); - std::vector args_; - std::vector exec_args_; + std::vector args_; + std::vector exec_args_; std::unique_ptr array_buffer_allocator_; v8::Isolate* isolate_; MultiIsolatePlatform* platform_; diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 24954e0b583834..5128bea07705d7 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -247,13 +247,13 @@ struct ArgsInfo { // Generally, the idea here is that the first entry in `*underlying` stores // the "0th" argument (the program name), then `synthetic_args` are inserted, // followed by the remainder of `*underlying`. - std::vector* underlying; + std::vector* underlying; std::vector synthetic_args; - std::vector* exec_args; + std::vector* exec_args; - ArgsInfo(std::vector* args, - std::vector* exec_args) + ArgsInfo(std::vector* args, + std::vector* exec_args) : underlying(args), exec_args(exec_args) {} size_t remaining() const { @@ -262,14 +262,14 @@ struct ArgsInfo { } bool empty() const { return remaining() == 0; } - const std::string& program_name() const { return underlying->at(0); } + std::string_view program_name() const { return underlying->front(); } - std::string& first() { + std::string_view first() const { return synthetic_args.empty() ? underlying->at(1) : synthetic_args.front(); } std::string pop_first() { - std::string ret = std::move(first()); + std::string ret = std::string(first()); if (synthetic_args.empty()) { // Only push arguments to `exec_args` that were also originally passed // on the command line (i.e. not generated through alias expansion). @@ -287,9 +287,9 @@ struct ArgsInfo { template void OptionsParser::Parse( - std::vector* const orig_args, - std::vector* const exec_args, - std::vector* const v8_args, + std::vector* const orig_args, + std::vector* const exec_args, + std::vector* const v8_args, Options* const options, OptionEnvvarSettings required_env_settings, std::vector* const errors) const { diff --git a/src/node_options.cc b/src/node_options.cc index 87ea4180f86cfd..968fdcca38e0a5 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -269,8 +269,8 @@ const EnvironmentOptionsParser _eop_instance{_dop_instance}; // This Parse is not dead code. It is used by embedders (e.g., Electron). template <> void Parse( - StringVector* const args, StringVector* const exec_args, - StringVector* const v8_args, + StringViewVector* const args, StringViewVector* const exec_args, + StringViewVector* const v8_args, DebugOptions* const options, OptionEnvvarSettings required_env_settings, StringVector* const errors) { _dop_instance.Parse( @@ -284,8 +284,8 @@ const PerProcessOptionsParser _ppop_instance{_piop_instance}; template <> void Parse( - StringVector* const args, StringVector* const exec_args, - StringVector* const v8_args, + StringViewVector* const args, StringViewVector* const exec_args, + StringViewVector* const v8_args, PerIsolateOptions* const options, OptionEnvvarSettings required_env_settings, StringVector* const errors) { _piop_instance.Parse( @@ -294,8 +294,8 @@ void Parse( template <> void Parse( - StringVector* const args, StringVector* const exec_args, - StringVector* const v8_args, + StringViewVector* const args, StringViewVector* const exec_args, + StringViewVector* const v8_args, PerProcessOptions* const options, OptionEnvvarSettings required_env_settings, StringVector* const errors) { _ppop_instance.Parse( @@ -1566,7 +1566,7 @@ void HandleEnvOptions(std::shared_ptr env_options, std::vector ParseNodeOptionsEnvVar( const std::string& node_options, std::vector* errors) { - std::vector env_argv; + std::vector env_argv; bool is_in_string = false; bool will_start_new_arg = true; diff --git a/src/node_options.h b/src/node_options.h index 8cce0ec019254d..a48bedc1a4dd5a 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -358,7 +358,7 @@ class PerProcessOptions : public Options { // TODO(addaleax): Some of these could probably be per-Environment. std::string use_largepages = "off"; bool trace_sigint = false; - std::vector cmdline; + std::vector cmdline; inline PerIsolateOptions* get_per_isolate_options(); void CheckOptions(std::vector* errors, @@ -473,9 +473,9 @@ class OptionsParser { // // If `*error` is set, the result of the parsing should be discarded and the // contents of any of the argument vectors should be considered undefined. - void Parse(std::vector* const args, - std::vector* const exec_args, - std::vector* const v8_args, + void Parse(std::vector* const args, + std::vector* const exec_args, + std::vector* const v8_args, Options* const options, OptionEnvvarSettings required_env_settings, std::vector* const errors) const; @@ -567,10 +567,11 @@ class OptionsParser { }; using StringVector = std::vector; +using StringViewVector = std::vector; template void Parse( - StringVector* const args, StringVector* const exec_args, - StringVector* const v8_args, OptionsType* const options, + StringViewVector* const args, StringViewVector* const exec_args, + StringViewVector* const v8_args, OptionsType* const options, OptionEnvvarSettings required_env_settings, StringVector* const errors); } // namespace options_parser diff --git a/src/node_sea.cc b/src/node_sea.cc index fb9f933a19fa70..60ca2792b309e2 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -380,15 +380,15 @@ std::optional ParseSingleExecutableConfig( } ExitCode GenerateSnapshotForSEA(const SeaConfig& config, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const std::string& builder_script_content, const SnapshotConfig& snapshot_config, std::vector* snapshot_blob) { SnapshotData snapshot; // TODO(joyeecheung): make the arguments configurable through the JSON // config or a programmatic API. - std::vector patched_args = {args[0], config.main_path}; + std::vector patched_args = {args[0], config.main_path}; ExitCode exit_code = SnapshotBuilder::Generate(&snapshot, patched_args, exec_args, @@ -490,8 +490,8 @@ int BuildAssets(const std::unordered_map& config, ExitCode GenerateSingleExecutableBlob( const SeaConfig& config, - const std::vector& args, - const std::vector& exec_args) { + const std::vector& args, + const std::vector& exec_args) { std::string main_script; // TODO(joyeecheung): unify the file utils. int r = ReadFileSync(&main_script, config.main_path.c_str()); @@ -565,8 +565,8 @@ ExitCode GenerateSingleExecutableBlob( } // anonymous namespace ExitCode BuildSingleExecutableBlob(const std::string& config_path, - const std::vector& args, - const std::vector& exec_args) { + const std::vector& args, + const std::vector& exec_args) { std::optional config_opt = ParseSingleExecutableConfig(config_path); if (config_opt.has_value()) { diff --git a/src/node_sea.h b/src/node_sea.h index f3b3c34d26a969..75a97f787b7c42 100644 --- a/src/node_sea.h +++ b/src/node_sea.h @@ -48,8 +48,8 @@ SeaResource FindSingleExecutableResource(); std::tuple FixupArgsForSEA(int argc, char** argv); node::ExitCode BuildSingleExecutableBlob( const std::string& config_path, - const std::vector& args, - const std::vector& exec_args); + const std::vector& args, + const std::vector& exec_args); // Try loading the Environment as a single-executable application. // Returns true if it is loaded as a single-executable application. diff --git a/src/node_snapshot_builder.h b/src/node_snapshot_builder.h index e2302946d1f8cb..8be8d4a0e9a9a3 100644 --- a/src/node_snapshot_builder.h +++ b/src/node_snapshot_builder.h @@ -21,8 +21,8 @@ std::optional ReadSnapshotConfig(const char* path); class NODE_EXTERN_PRIVATE SnapshotBuilder { public: static ExitCode GenerateAsSource(const char* out_path, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const SnapshotConfig& config, bool use_array_literals = false); @@ -31,8 +31,8 @@ class NODE_EXTERN_PRIVATE SnapshotBuilder { // in case the script is already read for other purposes. static ExitCode Generate( SnapshotData* out, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, std::optional builder_script_content, const SnapshotConfig& config); diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index fe04a8ee8d708b..855fb774d0f98e 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -936,8 +936,8 @@ std::optional ReadSnapshotConfig(const char* config_path) { ExitCode BuildSnapshotWithoutCodeCache( SnapshotData* out, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, std::optional builder_script_content, const SnapshotConfig& config) { DCHECK(builder_script_content.has_value() == @@ -957,7 +957,7 @@ ExitCode BuildSnapshotWithoutCodeCache( per_process::v8_platform.Platform(), &errors, args, exec_args, config); if (!setup) { for (const std::string& err : errors) - fprintf(stderr, "%s: %s\n", args[0].c_str(), err.c_str()); + fprintf(stderr, "%s: %s\n", args[0].data(), err.c_str()); return ExitCode::kBootstrapFailure; } @@ -999,8 +999,8 @@ ExitCode BuildSnapshotWithoutCodeCache( } ExitCode BuildCodeCacheFromSnapshot(SnapshotData* out, - const std::vector& args, - const std::vector& exec_args) { + const std::vector& args, + const std::vector& exec_args) { RAIIIsolate raii_isolate(out); Isolate* isolate = raii_isolate.get(); v8::Locker locker(isolate); @@ -1039,8 +1039,8 @@ ExitCode BuildCodeCacheFromSnapshot(SnapshotData* out, ExitCode SnapshotBuilder::Generate( SnapshotData* out, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, std::optional builder_script_content, const SnapshotConfig& snapshot_config) { ExitCode code = BuildSnapshotWithoutCodeCache( @@ -1177,8 +1177,8 @@ ExitCode SnapshotBuilder::CreateSnapshot(SnapshotData* out, ExitCode SnapshotBuilder::GenerateAsSource( const char* out_path, - const std::vector& args, - const std::vector& exec_args, + const std::vector& args, + const std::vector& exec_args, const SnapshotConfig& config, bool use_array_literals) { std::string builder_script_content; diff --git a/src/node_task_runner.cc b/src/node_task_runner.cc index efaf6f01b3fbf9..4de7a39dfe16dd 100644 --- a/src/node_task_runner.cc +++ b/src/node_task_runner.cc @@ -348,7 +348,7 @@ void RunTask(const std::shared_ptr& result, // If the "--" flag is not found, it returns an empty optional. // Otherwise, it returns the positional arguments as a single string. // Example: "node -- script.js arg1 arg2" returns "arg1 arg2". -PositionalArgs GetPositionalArgs(const std::vector& args) { +PositionalArgs GetPositionalArgs(const std::vector& args) { // If the "--" flag is not found, return an empty optional // Otherwise, return the positional arguments as a single string if (auto dash_dash = std::find(args.begin(), args.end(), "--"); @@ -358,7 +358,7 @@ PositionalArgs GetPositionalArgs(const std::vector& args) { for (auto it = dash_dash + 1; it != args.end(); ++it) { // SAFETY: The following code is safe because the lifetime of the // arguments is guaranteed to be valid until the end of the task runner. - positional_args.emplace_back(it->c_str(), it->size()); + positional_args.push_back(*it); } return positional_args; } diff --git a/src/node_task_runner.h b/src/node_task_runner.h index ec8f2adf45aa4a..4636b59f9a0d10 100644 --- a/src/node_task_runner.h +++ b/src/node_task_runner.h @@ -82,7 +82,7 @@ FindPackageJson(const std::filesystem::path& cwd); void RunTask(const std::shared_ptr& result, std::string_view command_id, const PositionalArgs& positional_args); -PositionalArgs GetPositionalArgs(const std::vector& args); +PositionalArgs GetPositionalArgs(const std::vector& args); std::string EscapeShell(std::string_view command); } // namespace node::task_runner