| 593 | } |
| 594 | |
| 595 | static void load_context_module(JSContext* cx, const char* uri, |
| 596 | const char* debug_identifier) { |
| 597 | JS::RootedObject loader(cx, gjs_module_load(cx, uri, uri)); |
| 598 | |
| 599 | if (!loader) { |
| 600 | gjs_log_exception(cx); |
| 601 | g_error("Failed to load %s module.", debug_identifier); |
| 602 | } |
| 603 | |
| 604 | if (!JS::ModuleLink(cx, loader)) { |
| 605 | gjs_log_exception(cx); |
| 606 | g_error("Failed to instantiate %s module.", debug_identifier); |
| 607 | } |
| 608 | |
| 609 | JS::RootedValue evaluation_promise(cx); |
| 610 | if (!JS::ModuleEvaluate(cx, loader, &evaluation_promise)) { |
| 611 | gjs_log_exception(cx); |
| 612 | g_error("Failed to evaluate %s module.", debug_identifier); |
| 613 | } |
| 614 | |
| 615 | GjsContextPrivate::from_cx(cx)->main_loop_hold(); |
| 616 | bool ok = add_promise_reactions( |
| 617 | cx, evaluation_promise, on_context_module_resolved, |
| 618 | [](JSContext* cx, unsigned argc, JS::Value* vp) { |
| 619 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 620 | |
| 621 | gjs_debug(GJS_DEBUG_IMPORTER, |
| 622 | "Module evaluation promise rejected: %s", |
| 623 | gjs_debug_callable(&args.callee()).c_str()); |
| 624 | |
| 625 | JS::HandleValue error = args.get(0); |
| 626 | // Abort because this module is required. |
| 627 | gjs_log_exception_full(cx, error, nullptr, G_LOG_LEVEL_ERROR); |
| 628 | |
| 629 | GjsContextPrivate::from_cx(cx)->main_loop_release(); |
| 630 | return false; |
| 631 | }, |
| 632 | debug_identifier); |
| 633 | |
| 634 | if (!ok) { |
| 635 | gjs_log_exception(cx); |
| 636 | g_error("Failed to load %s module.", debug_identifier); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context) |
| 641 | : m_public_context(public_context), |
no test coverage detected