| 283 | } |
| 284 | |
| 285 | GJS_JSAPI_RETURN_CONVENTION |
| 286 | static bool import_module_init(JSContext* cx, GFile* file, |
| 287 | JS::HandleObject module_obj) { |
| 288 | gsize script_len = 0; // Do not use size_t, may be different width |
| 289 | Gjs::AutoError error; |
| 290 | |
| 291 | GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx); |
| 292 | JS::RootedValue ignored{cx}; |
| 293 | |
| 294 | Gjs::AutoChar script; |
| 295 | if (!g_file_load_contents(file, nullptr, script.out(), &script_len, nullptr, |
| 296 | &error)) { |
| 297 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) && |
| 298 | !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) && |
| 299 | !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { |
| 300 | gjs_throw_gerror_message(cx, error); |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | return true; |
| 305 | } |
| 306 | g_assert(script); |
| 307 | |
| 308 | Gjs::AutoChar full_path{g_file_get_parse_name(file)}; |
| 309 | |
| 310 | return gjs->eval_with_scope(module_obj, script, script_len, full_path, |
| 311 | &ignored); |
| 312 | } |
| 313 | |
| 314 | GJS_JSAPI_RETURN_CONVENTION |
| 315 | static JSObject* load_module_init(JSContext* cx, JS::HandleObject in_object, |
no test coverage detected