This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch 3.2.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8895b35368e709ecff23f4b30d04c8d657b504a5
Author: Will Young <[email protected]>
AuthorDate: Mon Nov 22 13:12:53 2021 +0100

    feat(couchjs): add support for SpiderMonkey 91esr
---
 src/couch/priv/couch_js/86/main.cpp | 41 ++++++++++++++++++++++---------------
 src/couch/priv/couch_js/86/util.cpp |  2 +-
 src/couch/rebar.config.script       | 12 ++++++++++-
 3 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/src/couch/priv/couch_js/86/main.cpp 
b/src/couch/priv/couch_js/86/main.cpp
index 291409944..d75f119b2 100644
--- a/src/couch/priv/couch_js/86/main.cpp
+++ b/src/couch/priv/couch_js/86/main.cpp
@@ -186,6 +186,8 @@ quit(JSContext* cx, unsigned int argc, JS::Value* vp)
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
 
     int exit_code = args[0].toInt32();;
+    JS_DestroyContext(cx);
+    JS_ShutDown();
     exit(exit_code);
 }
 
@@ -254,20 +256,7 @@ static JSSecurityCallbacks security_callbacks = {
     nullptr
 };
 
-
-int
-main(int argc, const char* argv[])
-{
-    JSContext* cx = NULL;
-    int i;
-
-    couch_args* args = couch_parse_args(argc, argv);
-
-    JS_Init();
-    cx = JS_NewContext(args->stack_size);
-    if(cx == NULL)
-        return 1;
-
+int runWithContext(JSContext* cx, couch_args* args) {
     JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_BASELINE_ENABLE, 0);
     JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_ION_ENABLE, 0);
 
@@ -293,7 +282,7 @@ main(int argc, const char* argv[])
     if(couch_load_funcs(cx, global, global_functions) != true)
         return 1;
 
-    for(i = 0 ; args->scripts[i] ; i++) {
+    for(int i = 0 ; args->scripts[i] ; i++) {
         const char* filename = args->scripts[i];
 
         // Compile and run
@@ -336,6 +325,26 @@ main(int argc, const char* argv[])
         // Give the GC a chance to run.
         JS_MaybeGC(cx);
     }
-
     return 0;
 }
+
+int
+main(int argc, const char* argv[])
+{
+    JSContext* cx = NULL;
+    int ret;
+
+    couch_args* args = couch_parse_args(argc, argv);
+
+    JS_Init();
+    cx = JS_NewContext(args->stack_size);
+    if(cx == NULL) {
+        JS_ShutDown();
+        return 1;
+    }
+    ret = runWithContext(cx, args);
+    JS_DestroyContext(cx);
+    JS_ShutDown();
+
+    return ret;
+}
diff --git a/src/couch/priv/couch_js/86/util.cpp 
b/src/couch/priv/couch_js/86/util.cpp
index cd120a03f..b61c76ad2 100644
--- a/src/couch/priv/couch_js/86/util.cpp
+++ b/src/couch/priv/couch_js/86/util.cpp
@@ -330,7 +330,7 @@ void
 couch_oom(JSContext* cx, void* data)
 {
     fprintf(stderr, "out of memory\n");
-    exit(1);
+    _Exit(1);
 }
 
 
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index 86b6a5872..a288a96eb 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -65,6 +65,8 @@ SMVsn = case lists:keyfind(spidermonkey_version, 1, 
CouchConfig) of
         "78";
     {_, "86"} ->
         "86";
+    {_, "91"} ->
+        "91";
     undefined ->
         "1.8.5";
     {_, Unsupported} ->
@@ -89,6 +91,8 @@ ConfigH = [
 CouchJSConfig = case SMVsn of
     "78" ->
         "priv/couch_js/86/config.h";
+    "91" ->
+        "priv/couch_js/86/config.h";
     _ ->
         "priv/couch_js/" ++ SMVsn ++ "/config.h"
 end.
@@ -148,6 +152,11 @@ end.
         {
             "-DXP_UNIX -I/usr/include/mozjs-86 -I/usr/local/include/mozjs-86 
-I/opt/homebrew/include/mozjs-86/ -std=c++17 -Wno-invalid-offsetof",
             "-L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-86 -lm"
+        };
+    {unix, _} when SMVsn == "91" ->
+        {
+            "-DXP_UNIX -I/usr/include/mozjs-91 -I/usr/local/include/mozjs-91 
-I/opt/homebrew/include/mozjs-91/ -std=c++17 -Wno-invalid-offsetof",
+            "-L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-91 -lm"
         }
 end.
 
@@ -156,7 +165,8 @@ CouchJSSrc = case SMVsn of
     "60" -> ["priv/couch_js/60/*.cpp"];
     "68" -> ["priv/couch_js/68/*.cpp"];
     "78" -> ["priv/couch_js/86/*.cpp"];
-    "86" -> ["priv/couch_js/86/*.cpp"]
+    "86" -> ["priv/couch_js/86/*.cpp"];
+    "91" -> ["priv/couch_js/86/*.cpp"]
 end.
 
 CouchJSEnv = case SMVsn of

Reply via email to