| 554 | }; |
| 555 | |
| 556 | static void load_async_callback(GObject* file, GAsyncResult* res, void* data) { |
| 557 | std::unique_ptr<PromiseData> promise(PromiseData::from_ptr(data)); |
| 558 | |
| 559 | GjsContextPrivate* gjs = GjsContextPrivate::from_cx(promise->cx); |
| 560 | gjs->main_loop_release(); |
| 561 | |
| 562 | Gjs::AutoMainRealm ar{gjs}; |
| 563 | |
| 564 | char* contents; |
| 565 | size_t length; |
| 566 | Gjs::AutoError error; |
| 567 | if (!g_file_load_contents_finish(G_FILE(file), res, &contents, &length, |
| 568 | /* etag_out = */ nullptr, &error)) { |
| 569 | Gjs::AutoChar uri{g_file_get_uri(G_FILE(file))}; |
| 570 | gjs_throw_custom(promise->cx, JSEXN_ERR, "ImportError", |
| 571 | "Unable to load file async from: %s (%s)", uri.get(), |
| 572 | error->message); |
| 573 | promise->reject_with_pending_exception(); |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | JS::RootedValue text(promise->cx); |
| 578 | bool ok = gjs_string_from_utf8_n(promise->cx, contents, length, &text); |
| 579 | g_free(contents); |
| 580 | if (!ok) { |
| 581 | promise->reject_with_pending_exception(); |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | promise->resolve(text); |
| 586 | } |
| 587 | |
| 588 | GJS_JSAPI_RETURN_CONVENTION |
| 589 | static bool load_async_executor(JSContext* cx, unsigned argc, JS::Value* vp) { |
nothing calls this directly
no test coverage detected