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

Function load_async_executor

gjs/internal.cpp:588–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586}
587
588GJS_JSAPI_RETURN_CONVENTION
589static bool load_async_executor(JSContext* cx, unsigned argc, JS::Value* vp) {
590 JS::CallArgs args = CallArgsFromVp(argc, vp);
591 JS::RootedObject resolve(cx), reject(cx);
592 if (!gjs_parse_call_args(cx, "executor", args, "oo", "resolve", &resolve,
593 "reject", &reject))
594 return handle_wrong_args(cx);
595
596 g_assert(JS_ObjectIsFunction(resolve) && "Executor called weirdly");
597 g_assert(JS_ObjectIsFunction(reject) && "Executor called weirdly");
598
599 JS::Value priv_value = js::GetFunctionNativeReserved(&args.callee(), 0);
600 g_assert(!priv_value.isNull() && "Executor called twice");
601 Gjs::AutoUnref<GFile> file{G_FILE(priv_value.toPrivate())};
602 g_assert(file && "Executor called twice");
603 // We now own the GFile, and will pass the reference to the GAsyncResult, so
604 // remove it from the executor's private slot so it doesn't become dangling
605 js::SetFunctionNativeReserved(&args.callee(), 0, JS::NullValue());
606
607 auto* data = new PromiseData(cx, JS_GetObjectFunction(resolve),
608 JS_GetObjectFunction(reject));
609
610 // Hold the main loop until this function resolves...
611 GjsContextPrivate::from_cx(cx)->main_loop_hold();
612 g_file_load_contents_async(file, nullptr, load_async_callback, data);
613
614 args.rval().setUndefined();
615 return true;
616}
617
618bool gjs_internal_load_resource_or_file_async(JSContext* cx, unsigned argc,
619 JS::Value* vp) {

Callers

nothing calls this directly

Calls 3

gjs_parse_call_argsFunction · 0.85
handle_wrong_argsFunction · 0.85
main_loop_holdMethod · 0.80

Tested by

no test coverage detected