[gjs] modules: Add helper to load context setup modules
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] modules: Add helper to load context setup modules
- Date: Tue, 13 Jul 2021 00:38:57 +0000 (UTC)
commit 1e6cc6892fdb3adb2bbdbf872477e0c2aab87123
Author: Evan Welsh <contact evanwelsh com>
Date: Thu Jul 1 10:17:23 2021 -0700
modules: Add helper to load context setup modules
gjs/context.cpp | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 30abf900..726dad27 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -488,6 +488,26 @@ gjs_context_constructed(GObject *object)
setup_dump_heap();
}
+static void load_context_module(JSContext* cx, const char* uri,
+ const char* debug_identifier) {
+ JS::RootedObject loader(cx, gjs_module_load(cx, uri, uri));
+
+ if (!loader) {
+ gjs_log_exception(cx);
+ g_error("Failed to load %s module.", debug_identifier);
+ }
+
+ if (!JS::ModuleInstantiate(cx, loader)) {
+ gjs_log_exception(cx);
+ g_error("Failed to instantiate %s module.", debug_identifier);
+ }
+
+ if (!JS::ModuleEvaluate(cx, loader)) {
+ gjs_log_exception(cx);
+ g_error("Failed to evaluate %s module.", debug_identifier);
+ }
+}
+
GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
: m_public_context(public_context),
m_cx(cx),
@@ -604,25 +624,9 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
g_error("Failed to load internal module loaders.");
}
- JS::RootedObject loader(
- cx, gjs_module_load(
- cx, "resource:///org/gnome/gjs/modules/internal/loader.js",
- "resource:///org/gnome/gjs/modules/internal/loader.js"));
-
- if (!loader) {
- gjs_log_exception(cx);
- g_error("Failed to load module loader module.");
- }
-
- if (!JS::ModuleInstantiate(cx, loader)) {
- gjs_log_exception(cx);
- g_error("Failed to instantiate module loader module.");
- }
-
- if (!JS::ModuleEvaluate(cx, loader)) {
- gjs_log_exception(cx);
- g_error("Failed to evaluate module loader module.");
- }
+ load_context_module(cx,
+ "resource:///org/gnome/gjs/modules/internal/loader.js",
+ "module loader");
}
void GjsContextPrivate::set_args(std::vector<std::string>&& args) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]