[gjs/ewlsh/whatwg-console: 1/5] modules: Add helper to load context setup modules
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/ewlsh/whatwg-console: 1/5] modules: Add helper to load context setup modules
- Date: Thu, 1 Jul 2021 18:55:57 +0000 (UTC)
commit 4a27abf4d434cd949cc01b8fa7434b1a89986e42
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 948ca8c6..7eef665b 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -485,6 +485,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),
@@ -592,25 +612,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]