summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Berndt <ronny@apache.org>2022-12-05 11:49:50 +0100
committerRonny Berndt <ronny@apache.org>2022-12-07 09:37:07 +0100
commite6e50766626520e4023b2dd8c395377ba4c2e605 (patch)
treea5ffc9c7f00d8aaedb8e1c6ee49cb56f4e7e8c5f
parent51e1cd28710354ca54fcd00d4f0ad2571ff1435f (diff)
downloadcouchdb-e6e50766626520e4023b2dd8c395377ba4c2e605.tar.gz
Update couch_spidermonkey.erl
-rw-r--r--src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp14
-rw-r--r--src/couch/rebar.config.script2
-rw-r--r--src/couch/src/couch_spidermonkey.erl6
3 files changed, 14 insertions, 8 deletions
diff --git a/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp b/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
index 783f55365..98b28f3d2 100644
--- a/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
+++ b/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
@@ -12,7 +12,7 @@
* the License.
*/
-#include <string.h>
+#include <string>
#include <jsapi.h>
#include "erl_nif.h"
@@ -27,10 +27,16 @@ get_spidermonkey_version(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
// JS_GetImplementationVersion()
// returns "JavaScript-CMAJOR.MINOR.PATCH"
const string FULLVERSION = JS_GetImplementationVersion();
- int full_len = FULLVERSION.length();
- //trim off "JavaScript-C"
- string result = FULLVERSION.substr(js_len, full_len-js_len);
+ string result;
+ size_t foundJSString = FULLVERSION.find(JAVASCRIPT);
+ if (foundJSString != string::npos) {
+ //trim off "JavaScript-C",
+ result = FULLVERSION.substr(js_len);
+ } else {
+ //something changed in JS_GetImplementationVersion(), return original
+ result = FULLVERSION;
+ }
return enif_make_string(env, result.c_str(), ERL_NIF_LATIN1);
}
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index aa4117a2a..771614498 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -190,7 +190,7 @@ CouchJSEnv = case SMVsn of
end.
SpiderEnv = case SMVsn of
- "91" ->
+ _ ->
[
{"CXXFLAGS", JS_CFLAGS},
{"LDFLAGS", JS_LDFLAGS}
diff --git a/src/couch/src/couch_spidermonkey.erl b/src/couch/src/couch_spidermonkey.erl
index ad42bb0c0..472fb8a58 100644
--- a/src/couch/src/couch_spidermonkey.erl
+++ b/src/couch/src/couch_spidermonkey.erl
@@ -19,8 +19,8 @@
-on_load(init/0).
init() ->
- Dir = code:priv_dir(couch),
- ok = erlang:load_nif(filename:join(Dir, ?MODULE), 0).
+ Dir = code:priv_dir(couch),
+ ok = erlang:load_nif(filename:join(Dir, ?MODULE), 0).
get_spidermonkey_version() ->
- exit(nif_library_not_loaded). \ No newline at end of file
+ exit(nif_library_not_loaded).