summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Berndt <ronny@apache.org>2022-12-15 23:30:55 +0100
committerGitHub <noreply@github.com>2022-12-15 23:30:55 +0100
commitebd7ce2e9648d4d33a62e80ee6848f7561f2ea7c (patch)
tree5c3053f21a9ebe8a65f3ab01c4592e27f01b52ba
parentbe1d36a01e32b56f5499da00a0ce01e38418de53 (diff)
downloadcouchdb-ebd7ce2e9648d4d33a62e80ee6848f7561f2ea7c.tar.gz
Show version of spidermonkey runtime in couchjs (#4262)
-rw-r--r--src/couch/priv/couch_js/86/help.h5
-rw-r--r--src/couch/priv/couch_js/86/util.cpp23
-rw-r--r--src/couch/priv/couch_js/86/util.h2
3 files changed, 28 insertions, 2 deletions
diff --git a/src/couch/priv/couch_js/86/help.h b/src/couch/priv/couch_js/86/help.h
index 6a23172af..28a2f6455 100644
--- a/src/couch/priv/couch_js/86/help.h
+++ b/src/couch/priv/couch_js/86/help.h
@@ -16,7 +16,7 @@
#include "config.h"
static const char VERSION_TEMPLATE[] =
- "%s - %s (SpiderMonkey 86)\n"
+ "%s - %s (SpiderMonkey %s)\n"
"\n"
"Licensed under the Apache License, Version 2.0 (the \"License\"); you may "
"not use\n"
@@ -60,7 +60,8 @@ static const char USAGE_TEMPLATE[] =
stdout, \
VERSION_TEMPLATE, \
basename, \
- PACKAGE_STRING)
+ PACKAGE_STRING, \
+ get_spidermonkey_version())
#define DISPLAY_VERSION couch_version(BASENAME)
diff --git a/src/couch/priv/couch_js/86/util.cpp b/src/couch/priv/couch_js/86/util.cpp
index b61c76ad2..ec8871255 100644
--- a/src/couch/priv/couch_js/86/util.cpp
+++ b/src/couch/priv/couch_js/86/util.cpp
@@ -26,6 +26,29 @@
#include "help.h"
#include "util.h"
+const char*
+get_spidermonkey_version() {
+ const char *JAVASCRIPT = "JavaScript-C";
+ int js_len = strlen(JAVASCRIPT);
+
+ // JS_GetImplementationVersion()
+ // returns "JavaScript-CMAJOR.MINOR.PATCH"
+ const char *FULLVERSION = JS_GetImplementationVersion();
+ int fv_len = strlen(FULLVERSION);
+
+ const char* foundJSString = strstr(FULLVERSION,JAVASCRIPT);
+ if (foundJSString != NULL) {
+ //trim off "JavaScript-C",
+ char *buf = (char*) malloc((fv_len - js_len + 1) * sizeof(char));
+ strncpy(buf, &FULLVERSION[js_len], fv_len - js_len);
+ buf[fv_len - js_len] = '\0';
+ return buf;
+ } else {
+ //something changed in JS_GetImplementationVersion(), return original
+ return FULLVERSION;
+ }
+}
+
std::string
js_to_string(JSContext* cx, JS::HandleValue val)
{
diff --git a/src/couch/priv/couch_js/86/util.h b/src/couch/priv/couch_js/86/util.h
index bd7843eb9..28d44f4ba 100644
--- a/src/couch/priv/couch_js/86/util.h
+++ b/src/couch/priv/couch_js/86/util.h
@@ -25,6 +25,8 @@ typedef struct {
JSString* uri;
} couch_args;
+const char* get_spidermonkey_version();
+
std::string js_to_string(JSContext* cx, JS::HandleValue val);
bool js_to_string(JSContext* cx, JS::HandleValue val, std::string& str);
JSString* string_to_js(JSContext* cx, const std::string& s);