| 196 | } |
| 197 | |
| 198 | JSObject* gjs_build_string_array(JSContext* cx, |
| 199 | const std::vector<std::string>& strings) { |
| 200 | JS::RootedValueVector elems{cx}; |
| 201 | if (!elems.reserve(strings.size())) { |
| 202 | JS_ReportOutOfMemory(cx); |
| 203 | return nullptr; |
| 204 | } |
| 205 | |
| 206 | for (const std::string& string : strings) { |
| 207 | JS::ConstUTF8CharsZ chars(string.c_str(), string.size()); |
| 208 | JS::RootedValue element{ |
| 209 | cx, JS::StringValue(JS_NewStringCopyUTF8Z(cx, chars))}; |
| 210 | elems.infallibleAppend(element); |
| 211 | } |
| 212 | |
| 213 | return JS::NewArrayObject(cx, elems); |
| 214 | } |
| 215 | |
| 216 | JSObject* gjs_define_string_array(JSContext* cx, JS::HandleObject in_object, |
| 217 | const char* array_name, |
no test coverage detected