| 1730 | } |
| 1731 | |
| 1732 | bool gjs_context_define_string_array(GjsContext* self, const char* array_name, |
| 1733 | ssize_t array_length, |
| 1734 | const char** array_values, |
| 1735 | GError** error) { |
| 1736 | g_return_val_if_fail(GJS_IS_CONTEXT(self), false); |
| 1737 | GjsContextPrivate* gjs = GjsContextPrivate::from_object(self); |
| 1738 | |
| 1739 | Gjs::AutoMainRealm ar{gjs}; |
| 1740 | |
| 1741 | std::vector<std::string> strings; |
| 1742 | if (array_values) { |
| 1743 | if (array_length < 0) |
| 1744 | array_length = g_strv_length(const_cast<char**>(array_values)); |
| 1745 | strings = {array_values, array_values + array_length}; |
| 1746 | } |
| 1747 | |
| 1748 | // ARGV is a special case to preserve backwards compatibility. |
| 1749 | if (strcmp(array_name, "ARGV") == 0) { |
| 1750 | gjs->set_args(std::move(strings)); |
| 1751 | |
| 1752 | return true; |
| 1753 | } |
| 1754 | |
| 1755 | JS::RootedObject global_root(gjs->context(), gjs->global()); |
| 1756 | if (!gjs_define_string_array(gjs->context(), global_root, array_name, |
| 1757 | strings, JSPROP_READONLY | JSPROP_PERMANENT)) { |
| 1758 | gjs_log_exception(gjs->context()); |
| 1759 | g_set_error(error, |
| 1760 | GJS_ERROR, |
| 1761 | GJS_ERROR_FAILED, |
| 1762 | "gjs_define_string_array() failed"); |
| 1763 | return false; |
| 1764 | } |
| 1765 | |
| 1766 | return true; |
| 1767 | } |
| 1768 | |
| 1769 | void gjs_context_set_argv(GjsContext* self, ssize_t array_length, |
| 1770 | const char** array_values) { |