[gjs: 4/9] console: --jsversion shell option
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/9] console: --jsversion shell option
- Date: Sat, 12 May 2018 17:40:05 +0000 (UTC)
commit 5ad5b777f933ecfeeb659b2a9b66aed646394b63
Author: Philip Chimento <philip endlessm com>
Date: Tue Nov 21 12:44:13 2017 -0800
console: --jsversion shell option
This adds a --jsversion command line option that prints whatever
SpiderMonkey provides as its version. Also adds public API that does the
same, gjs_get_js_version(), in case an embedding program such as GNOME
Shell would want to print the version as well.
gjs/console.cpp | 9 +++++++++
gjs/context.cpp | 13 +++++++++++++
gjs/context.h | 3 +++
installed-tests/scripts/testCommandLine.sh | 26 ++++++++++++++------------
4 files changed, 39 insertions(+), 12 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 9e8deec1..4c997227 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -36,6 +36,7 @@ static char *coverage_output_path = NULL;
static char *profile_output_path = nullptr;
static char *command = NULL;
static gboolean print_version = false;
+static gboolean print_js_version = false;
static bool enable_profiler = false;
static gboolean parse_profile_arg(const char *, const char *, void *, GError **);
@@ -43,6 +44,8 @@ static gboolean parse_profile_arg(const char *, const char *, void *, GError **)
/* Keep in sync with entries in check_script_args_for_stray_gjs_args() */
static GOptionEntry entries[] = {
{ "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print GJS version and exit" },
+ { "jsversion", 0, 0, G_OPTION_ARG_NONE, &print_js_version,
+ "Print version of the JS engine and exit" },
{ "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Program passed in as a string", "COMMAND" },
{ "coverage-prefix", 'C', 0, G_OPTION_ARG_STRING_ARRAY, &coverage_prefixes, "Add the prefix PREFIX to
the list of files to generate coverage info for", "PREFIX" },
{ "coverage-output", 0, 0, G_OPTION_ARG_STRING, &coverage_output_path, "Write coverage output to a
directory DIR. This option is mandatory when using --coverage-path", "DIR", },
@@ -244,6 +247,7 @@ main(int argc, char **argv)
coverage_output_path = NULL;
command = NULL;
print_version = false;
+ print_js_version = false;
g_option_context_set_ignore_unknown_options(context, false);
g_option_context_set_help_enabled(context, true);
if (!g_option_context_parse_strv(context, &gjs_argv, &error))
@@ -256,6 +260,11 @@ main(int argc, char **argv)
exit(0);
}
+ if (print_js_version) {
+ g_print("%s\n", gjs_get_js_version());
+ exit(0);
+ }
+
gjs_argc = g_strv_length(gjs_argv);
if (command != NULL) {
script = command;
diff --git a/gjs/context.cpp b/gjs/context.cpp
index e66a9f82..ff0b2097 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1077,3 +1077,16 @@ gjs_context_get_profiler(GjsContext *self)
{
return self->profiler;
}
+
+/**
+ * gjs_get_js_version:
+ *
+ * Returns the underlying version of the JS engine.
+ *
+ * Returns: a string
+ */
+const char *
+gjs_get_js_version(void)
+{
+ return JS_GetImplementationVersion();
+}
diff --git a/gjs/context.h b/gjs/context.h
index 8a2df292..5dfa3497 100644
--- a/gjs/context.h
+++ b/gjs/context.h
@@ -102,6 +102,9 @@ bool gjs_profiler_chain_signal(GjsContext *context,
GJS_EXPORT
void gjs_dumpstack (void);
+GJS_EXPORT
+const char *gjs_get_js_version(void);
+
G_END_DECLS
#endif /* __GJS_CONTEXT_H__ */
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh
index 040eb04f..a3d8738c 100755
--- a/installed-tests/scripts/testCommandLine.sh
+++ b/installed-tests/scripts/testCommandLine.sh
@@ -159,18 +159,20 @@ $gjs -c 'imports.system.exit(0)' --profile=foo 2>&1 | grep -q 'Gjs-WARNING.*--pr
report "--profile after script should succeed but give a warning"
rm -rf foo
-# --version works
-$gjs --version >/dev/null
-report "--version should work"
-test -n "$($gjs --version)"
-report "--version should print something"
-
-# --version after a script goes to the script
-script='if(ARGV[0] !== "--version") imports.system.exit(1)'
-$gjs -c "$script" --version
-report "--version after -c should be passed to script"
-test -z "$($gjs -c "$script" --version)"
-report "--version after -c should not print anything"
+for version_arg in --version --jsversion; do
+ # --version and --jsversion work
+ $gjs $version_arg >/dev/null
+ report "$version_arg should work"
+ test -n "$($gjs $version_arg)"
+ report "$version_arg should print something"
+
+ # --version and --jsversion after a script go to the script
+ script="if(ARGV[0] !== '$version_arg') imports.system.exit(1)"
+ $gjs -c "$script" $version_arg
+ report "$version_arg after -c should be passed to script"
+ test -z "$($gjs -c "$script" $version_arg)"
+ report "$version_arg after -c should not print anything"
+done
# --profile
rm -f gjs-*.syscap foo.syscap
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]