[gjs/split-argv: 1/2] Add file-name context property. - Stores the full path of the program's entry file.
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/split-argv: 1/2] Add file-name context property. - Stores the full path of the program's entry file.
- Date: Sat, 30 Jan 2021 22:09:05 +0000 (UTC)
commit 3c456b3ace79a38b63fbc2780a6bfff2b027d971
Author: Evan Welsh <noreply evanwelsh com>
Date: Mon Jun 1 09:32:03 2020 -0500
Add file-name context property.
- Stores the full path of the program's entry file.
gjs/console.cpp | 9 ++++----
gjs/context-private.h | 3 +++
gjs/context.cpp | 57 ++++++++++++++++++++++++++++++++-------------------
3 files changed, 43 insertions(+), 26 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 9654f0b0..d4a4abf2 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -315,11 +315,10 @@ main(int argc, char **argv)
if (coverage_prefixes)
gjs_coverage_enable();
- js_context = (GjsContext*) g_object_new(GJS_TYPE_CONTEXT,
- "search-path", include_path,
- "program-name", program_name,
- "profiler-enabled", enable_profiler,
- NULL);
+ js_context = (GjsContext*)g_object_new(
+ GJS_TYPE_CONTEXT, "search-path", include_path, "program-name",
+ program_name, "file-name", filename, "profiler-enabled",
+ enable_profiler, NULL);
env_coverage_output_path = g_getenv("GJS_COVERAGE_OUTPUT");
if (env_coverage_output_path != NULL) {
diff --git a/gjs/context-private.h b/gjs/context-private.h
index 4f5adc8a..e950cdec 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -74,6 +74,7 @@ class GjsContextPrivate : public JS::JobQueue {
GThread* m_owner_thread;
char* m_program_name;
+ char* m_file_name;
char** m_search_path;
@@ -170,6 +171,8 @@ class GjsContextPrivate : public JS::JobQueue {
[[nodiscard]] bool sweeping() const { return m_in_gc_sweep; }
[[nodiscard]] const char* program_name() const { return m_program_name; }
void set_program_name(char* value) { m_program_name = value; }
+ GJS_USE const char* file_name(void) const { return m_file_name; }
+ void set_file_name(char* value) { m_file_name = value; }
void set_search_path(char** value) { m_search_path = value; }
void set_should_profile(bool value) { m_should_profile = value; }
void set_should_listen_sigusr2(bool value) {
diff --git a/gjs/context.cpp b/gjs/context.cpp
index f302409c..340c15d2 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -119,6 +119,7 @@ GjsContextPrivate* GjsContextPrivate::from_current_context() {
enum {
PROP_0,
+ PROP_FILE_NAME,
PROP_SEARCH_PATH,
PROP_PROGRAM_NAME,
PROP_PROFILER_ENABLED,
@@ -239,6 +240,13 @@ gjs_context_class_init(GjsContextClass *klass)
pspec);
g_param_spec_unref(pspec);
+ pspec = g_param_spec_string(
+ "file-name", "File Name", "The filename of the launched JS program", "",
+ (GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property(object_class, PROP_FILE_NAME, pspec);
+ g_param_spec_unref(pspec);
+
/**
* GjsContext:profiler-enabled:
*
@@ -399,6 +407,7 @@ void GjsContextPrivate::dispose(void) {
GjsContextPrivate::~GjsContextPrivate(void) {
g_clear_pointer(&m_search_path, g_strfreev);
+ g_clear_pointer(&m_file_name, g_free);
g_clear_pointer(&m_program_name, g_free);
}
@@ -517,12 +526,15 @@ gjs_context_get_property (GObject *object,
GjsContextPrivate* gjs = GjsContextPrivate::from_object(object);
switch (prop_id) {
- case PROP_PROGRAM_NAME:
- g_value_set_string(value, gjs->program_name());
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ case PROP_FILE_NAME:
+ g_value_set_string(value, gjs->file_name());
+ break;
+ case PROP_PROGRAM_NAME:
+ g_value_set_string(value, gjs->program_name());
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
@@ -535,21 +547,24 @@ gjs_context_set_property (GObject *object,
GjsContextPrivate* gjs = GjsContextPrivate::from_object(object);
switch (prop_id) {
- case PROP_SEARCH_PATH:
- gjs->set_search_path(static_cast<char**>(g_value_dup_boxed(value)));
- break;
- case PROP_PROGRAM_NAME:
- gjs->set_program_name(g_value_dup_string(value));
- break;
- case PROP_PROFILER_ENABLED:
- gjs->set_should_profile(g_value_get_boolean(value));
- break;
- case PROP_PROFILER_SIGUSR2:
- gjs->set_should_listen_sigusr2(g_value_get_boolean(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ case PROP_FILE_NAME:
+ gjs->set_file_name(g_value_dup_string(value));
+ break;
+ case PROP_SEARCH_PATH:
+ gjs->set_search_path(static_cast<char**>(g_value_dup_boxed(value)));
+ break;
+ case PROP_PROGRAM_NAME:
+ gjs->set_program_name(g_value_dup_string(value));
+ break;
+ case PROP_PROFILER_ENABLED:
+ gjs->set_should_profile(g_value_get_boolean(value));
+ break;
+ case PROP_PROFILER_SIGUSR2:
+ gjs->set_should_listen_sigusr2(g_value_get_boolean(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]