Refactor ARGV handling and add `system.programArgs`
C API Changes:
- A new
gjs_context_set_argv
function is introduced for API user
JS Changes:
-
imports.system
is renamed toimports._systemNative
-
imports.system
is now a JS script -
imports._systemNative.buildProgramArgs()
builds the ARGV array -
system.programArgs
is set withbuildProgramArgs
and ARGV is a getter forsystem.programArgs
.
To avoid breaking backwards compatibility with API users, gjs_context_define_string_array
redirects "ARGV" to the new implementation.
Goals:
- Use
std::string
andstd::vector
for ARGV handling where ever possible (we can't use them in the public headers) - Avoid using
gjs_context_define_string_array
for ARGV. This method assumes that the global will be defined before a realm is entered. This will have to continue for the current global, but we don't need to further the dependency. - Ensure ARGV is defined in all GJS contexts, regardless of if an API user calls
gjs_context_define_string_array
and sets it up.
Benefits:
- Uses modern C++ instead of C-style string/memory handling
- Avoids pre-realm global dependencies
- Global scope consistency across implementations
- API users don't have to setup ARGV themselves
Edited by Evan Welsh