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

Function load_context_module

gjs/context.cpp:595–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595static 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
640GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
641 : m_public_context(public_context),

Callers 1

GjsContextPrivateMethod · 0.85

Calls 9

gjs_module_loadFunction · 0.85
gjs_log_exceptionFunction · 0.85
add_promise_reactionsFunction · 0.85
gjs_debugFunction · 0.85
gjs_debug_callableFunction · 0.85
gjs_log_exception_fullFunction · 0.85
main_loop_holdMethod · 0.80
main_loop_releaseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected