| 586 | } |
| 587 | |
| 588 | GJS_JSAPI_RETURN_CONVENTION |
| 589 | static 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 | |
| 618 | bool gjs_internal_load_resource_or_file_async(JSContext* cx, unsigned argc, |
| 619 | JS::Value* vp) { |
nothing calls this directly
no test coverage detected