MCPcopy Create free account
hub / github.com/GNOME/gjs / load_async_callback

Function load_async_callback

gjs/internal.cpp:556–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554};
555
556static 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
588GJS_JSAPI_RETURN_CONVENTION
589static bool load_async_executor(JSContext* cx, unsigned argc, JS::Value* vp) {

Callers

nothing calls this directly

Calls 6

gjs_throw_customFunction · 0.85
gjs_string_from_utf8_nFunction · 0.85
main_loop_releaseMethod · 0.80
getMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected