summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2020-01-06 11:06:40 -0600
committerPaul J. Davis <paul.joseph.davis@gmail.com>2020-01-06 17:32:24 -0600
commit641a535e63c627717624df9522981cd825601da2 (patch)
tree9ee87c78aeb029f2d71490d03e810a3b8b974265
parentc9038ecbdebee613bd4793a87f4ab9be94c59c3d (diff)
downloadcouchdb-sm-60-make-oom-errors-fatal.tar.gz
Match the OOM beahvior of 1.8.5sm-60-make-oom-errors-fatal
Apparently SpiderMonkey 60 changed the behavior of OOM errors to not exit the VM. This updates the SpiderMonkey 60 implementation to match that behavior.
-rw-r--r--src/couch/priv/couch_js/60/main.cpp1
-rw-r--r--src/couch/priv/couch_js/60/util.cpp8
-rw-r--r--src/couch/priv/couch_js/60/util.h1
-rw-r--r--src/couch/test/eunit/couch_js_tests.erl45
4 files changed, 55 insertions, 0 deletions
diff --git a/src/couch/priv/couch_js/60/main.cpp b/src/couch/priv/couch_js/60/main.cpp
index ecedfbd3b..e36bc619b 100644
--- a/src/couch/priv/couch_js/60/main.cpp
+++ b/src/couch/priv/couch_js/60/main.cpp
@@ -420,6 +420,7 @@ main(int argc, const char* argv[])
return 1;
JS::SetWarningReporter(cx, couch_error);
+ JS::SetOutOfMemoryCallback(cx, couch_oom, NULL);
JS_SetContextPrivate(cx, args);
JS_SetSecurityCallbacks(cx, &security_callbacks);
diff --git a/src/couch/priv/couch_js/60/util.cpp b/src/couch/priv/couch_js/60/util.cpp
index 894b4254e..92c6cbf4a 100644
--- a/src/couch/priv/couch_js/60/util.cpp
+++ b/src/couch/priv/couch_js/60/util.cpp
@@ -309,6 +309,14 @@ couch_error(JSContext* cx, JSErrorReport* report)
}
+void
+couch_oom(JSContext* cx, void* data)
+{
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+}
+
+
bool
couch_load_funcs(JSContext* cx, JS::HandleObject obj, JSFunctionSpec* funcs)
{
diff --git a/src/couch/priv/couch_js/60/util.h b/src/couch/priv/couch_js/60/util.h
index 45caa341f..407e3e602 100644
--- a/src/couch/priv/couch_js/60/util.h
+++ b/src/couch/priv/couch_js/60/util.h
@@ -35,6 +35,7 @@ JSString* couch_readline(JSContext* cx, FILE* fp);
size_t couch_readfile(const char* file, char** outbuf_p);
void couch_print(JSContext* cx, unsigned int argc, JS::CallArgs argv);
void couch_error(JSContext* cx, JSErrorReport* report);
+void couch_oom(JSContext* cx, void* data);
bool couch_load_funcs(JSContext* cx, JS::HandleObject obj, JSFunctionSpec* funcs);
diff --git a/src/couch/test/eunit/couch_js_tests.erl b/src/couch/test/eunit/couch_js_tests.erl
new file mode 100644
index 000000000..d3d92a288
--- /dev/null
+++ b/src/couch/test/eunit/couch_js_tests.erl
@@ -0,0 +1,45 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_js_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+
+-define(FUNC, <<
+ "function(doc) {\n"
+ " var val = \"0123456789ABCDEF\";\n"
+ " while(true) {emit(val, val);}\n"
+ "}\n"
+>>).
+
+
+couch_js_test_() ->
+ {
+ "Test couchjs",
+ {
+ setup,
+ fun test_util:start_couch/0,
+ fun test_util:stop_couch/1,
+ [
+ fun should_exit_on_oom/0
+ ]
+ }
+ }.
+
+
+should_exit_on_oom() ->
+ Proc = couch_query_servers:get_os_process(<<"javascript">>),
+ true = couch_query_servers:proc_prompt(Proc, [<<"add_fun">>, ?FUNC]),
+ ?assertThrow(
+ {os_process_error, {exit_status, 1}},
+ couch_query_servers:proc_prompt(Proc, [<<"map_doc">>, <<"{}">>])
+ ).