This is an automated email from the ASF dual-hosted git repository. ronny pushed a commit to branch sm91-as-default in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit b254a8adc6b9034f763f012c3243a47949de72b1 Author: Ronny Berndt <[email protected]> AuthorDate: Wed Jan 4 13:45:03 2023 +0100 Remove Spidermonkey 1.8.5 Removes the old Spidermonkey 1.8.5 source code. Spidermonkey 91 is set as the new default version. --- configure | 2 +- configure.ps1 | 5 +- src/couch/priv/couch_js/1.8.5/help.h | 79 --------- src/couch/priv/couch_js/1.8.5/main.c | 307 ----------------------------------- src/couch/priv/couch_js/1.8.5/utf8.c | 297 --------------------------------- src/couch/priv/couch_js/1.8.5/utf8.h | 19 --- src/couch/priv/couch_js/1.8.5/util.c | 296 --------------------------------- src/couch/priv/couch_js/1.8.5/util.h | 35 ---- src/couch/rebar.config.script | 23 +-- 9 files changed, 6 insertions(+), 1057 deletions(-) diff --git a/configure b/configure index 9f8cb6828..25b4eeddb 100755 --- a/configure +++ b/configure @@ -31,7 +31,7 @@ ERLANG_MD5="false" SKIP_DEPS=0 COUCHDB_USER="$(whoami 2>/dev/null || echo couchdb)" -SM_VSN=${SM_VSN:-"1.8.5"} +SM_VSN=${SM_VSN:-"91"} ARCH="$(uname -m)" ERLANG_VER="$(erl -eval 'io:put_chars(erlang:system_info(otp_release)), halt().' -noshell)" diff --git a/configure.ps1 b/configure.ps1 index 7584630d6..ad08f80f4 100644 --- a/configure.ps1 +++ b/configure.ps1 @@ -9,7 +9,7 @@ -DisableDocs request build process skip building documentation (default false) -SkipDeps do not update Erlang dependencies (default false) -CouchDBUser USER set the username to run as (defaults to current user) - -SpiderMonkeyVersion VSN select the version of SpiderMonkey to use (defaults to 1.8.5) + -SpiderMonkeyVersion VSN select the version of SpiderMonkey to use (default 91) Installation directories: -Prefix PREFIX install architecture-independent files in PREFIX @@ -48,7 +48,7 @@ Param( [ValidateNotNullOrEmpty()] [string]$CouchDBUser = [Environment]::UserName, # set the username to run as (defaults to current user) [ValidateNotNullOrEmpty()] - [string]$SpiderMonkeyVersion = "1.8.5", # select the version of SpiderMonkey to use (default 1.8.5) + [string]$SpiderMonkeyVersion = "91", # select the version of SpiderMonkey to use (default 91) [ValidateNotNullOrEmpty()] [string]$Prefix = "C:\Program Files\Apache\CouchDB", # install architecture-independent file location (default C:\Program Files\Apache\CouchDB) [ValidateNotNullOrEmpty()] @@ -138,6 +138,7 @@ $CouchDBConfig = @" {node_name, "-name couchdb@localhost"}. {cluster_port, 5984}. {backend_port, 5986}. +{prometheus_port, 17986}. "@ $CouchDBConfig | Out-File "$rootdir\rel\couchdb.config" -encoding ascii diff --git a/src/couch/priv/couch_js/1.8.5/help.h b/src/couch/priv/couch_js/1.8.5/help.h deleted file mode 100644 index 3a19901f0..000000000 --- a/src/couch/priv/couch_js/1.8.5/help.h +++ /dev/null @@ -1,79 +0,0 @@ -// 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. - -#ifndef COUCHJS_HELP_H -#define COUCHJS_HELP_H - -#include "config.h" - -static const char VERSION_TEMPLATE[] = - "%s - %s (SpiderMonkey 1.8.5)\n" - "\n" - "Licensed under the Apache License, Version 2.0 (the \"License\"); you may " - "not use\n" - "this file except in compliance with the License. You may obtain a copy of" - "the\n" - "License at\n" - "\n" - " http://www.apache.org/licenses/LICENSE-2.0\n" - "\n" - "Unless required by applicable law or agreed to in writing, software " - "distributed\n" - "under the License is distributed on an \"AS IS\" BASIS, WITHOUT " - "WARRANTIES OR\n" - "CONDITIONS OF ANY KIND, either express or implied. See the License " - "for the\n" - "specific language governing permissions and limitations under the " - "License.\n"; - -static const char USAGE_TEMPLATE[] = - "Usage: %s [FILE]\n" - "\n" - "The %s command runs the %s JavaScript interpreter.\n" - "\n" - "The exit status is 0 for success or 1 for failure.\n" - "\n" - "Options:\n" - "\n" - " -h display a short help message and exit\n" - " -V display version information and exit\n" - " -S SIZE specify that the runtime should allow at\n" - " most SIZE bytes of memory to be allocated\n" - " default is 64 MiB\n" - " --eval Enable runtime code evaluation (dangerous!)\n" - "\n" - "Report bugs at <%s>.\n"; - -#define BASENAME COUCHJS_NAME - -#define couch_version(basename) \ - fprintf( \ - stdout, \ - VERSION_TEMPLATE, \ - basename, \ - PACKAGE_STRING) - -#define DISPLAY_VERSION couch_version(BASENAME) - - -#define couch_usage(basename) \ - fprintf( \ - stdout, \ - USAGE_TEMPLATE, \ - basename, \ - basename, \ - PACKAGE_NAME, \ - PACKAGE_BUGREPORT) - -#define DISPLAY_USAGE couch_usage(BASENAME) - -#endif // Included help.h diff --git a/src/couch/priv/couch_js/1.8.5/main.c b/src/couch/priv/couch_js/1.8.5/main.c deleted file mode 100644 index c8e385cc9..000000000 --- a/src/couch/priv/couch_js/1.8.5/main.c +++ /dev/null @@ -1,307 +0,0 @@ -// 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. - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#ifdef XP_WIN -#include <windows.h> -#else -#include <unistd.h> -#endif - -#include <jsapi.h> -#include "config.h" -#include "utf8.h" -#include "util.h" - - -#define SETUP_REQUEST(cx) \ - JS_SetContextThread(cx); \ - JS_BeginRequest(cx); -#define FINISH_REQUEST(cx) \ - JS_EndRequest(cx); \ - JS_ClearContextThread(cx); - - -static JSClass global_class = { - "GlobalClass", - JSCLASS_GLOBAL_FLAGS, - JS_PropertyStub, - JS_PropertyStub, - JS_PropertyStub, - JS_StrictPropertyStub, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, - JS_FinalizeStub, - JSCLASS_NO_OPTIONAL_MEMBERS -}; - -static JSBool -evalcx(JSContext *cx, uintN argc, jsval* vp) -{ - jsval* argv = JS_ARGV(cx, vp); - JSString* str; - JSObject* sandbox; - JSObject* global; - JSContext* subcx; - JSCrossCompartmentCall* call = NULL; - const jschar* src; - size_t srclen; - jsval rval; - JSBool ret = JS_FALSE; - char *name = NULL; - - sandbox = NULL; - if(!JS_ConvertArguments(cx, argc, argv, "S / o", &str, &sandbox)) { - return JS_FALSE; - } - - subcx = JS_NewContext(JS_GetRuntime(cx), 8L * 1024L); - if(!subcx) { - JS_ReportOutOfMemory(cx); - return JS_FALSE; - } - - SETUP_REQUEST(subcx); - - src = JS_GetStringCharsAndLength(cx, str, &srclen); - - // Re-use the compartment associated with the main context, - // rather than creating a new compartment */ - global = JS_GetGlobalObject(cx); - if(global == NULL) goto done; - call = JS_EnterCrossCompartmentCall(subcx, global); - - if(!sandbox) { - sandbox = JS_NewGlobalObject(subcx, &global_class); - if(!sandbox || !JS_InitStandardClasses(subcx, sandbox)) { - goto done; - } - } - - if(argc > 2) { - name = enc_string(cx, argv[2], NULL); - } - - if(srclen == 0) { - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(sandbox)); - } else { - JS_EvaluateUCScript(subcx, sandbox, src, srclen, name, 1, &rval); - JS_SET_RVAL(cx, vp, rval); - } - - ret = JS_TRUE; - -done: - if(name) JS_free(cx, name); - JS_LeaveCrossCompartmentCall(call); - FINISH_REQUEST(subcx); - JS_DestroyContext(subcx); - return ret; -} - - -static JSBool -gc(JSContext* cx, uintN argc, jsval* vp) -{ - JS_GC(cx); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return JS_TRUE; -} - - -static JSBool -print(JSContext* cx, uintN argc, jsval* vp) -{ - jsval* argv = JS_ARGV(cx, vp); - couch_print(cx, argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return JS_TRUE; -} - - -static JSBool -quit(JSContext* cx, uintN argc, jsval* vp) -{ - jsval* argv = JS_ARGV(cx, vp); - int exit_code = 0; - JS_ConvertArguments(cx, argc, argv, "/i", &exit_code); - exit(exit_code); -} - - -static JSBool -readline(JSContext* cx, uintN argc, jsval* vp) -{ - JSString* line; - - /* GC Occasionally */ - JS_MaybeGC(cx); - - line = couch_readline(cx, stdin); - if(line == NULL) return JS_FALSE; - - JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(line)); - return JS_TRUE; -} - - -static JSBool -seal(JSContext* cx, uintN argc, jsval* vp) -{ - jsval* argv = JS_ARGV(cx, vp); - JSObject *target; - JSBool deep = JS_FALSE; - JSBool ret; - - if(!JS_ConvertArguments(cx, argc, argv, "o/b", &target, &deep)) - return JS_FALSE; - - if(!target) { - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return JS_TRUE; - } - - - ret = deep ? JS_DeepFreezeObject(cx, target) : JS_FreezeObject(cx, target); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return ret; -} - - -static JSFunctionSpec global_functions[] = { - JS_FS("evalcx", evalcx, 0, 0), - JS_FS("gc", gc, 0, 0), - JS_FS("print", print, 0, 0), - JS_FS("quit", quit, 0, 0), - JS_FS("readline", readline, 0, 0), - JS_FS("seal", seal, 0, 0), - JS_FS_END -}; - - -static JSBool -csp_allows(JSContext* cx) -{ - couch_args *args = (couch_args*)JS_GetContextPrivate(cx); - if(args->eval) { - return JS_TRUE; - } else { - return JS_FALSE; - } -} - - -static JSSecurityCallbacks security_callbacks = { - NULL, - NULL, - NULL, - csp_allows -}; - - -int -main(int argc, const char* argv[]) -{ - JSRuntime* rt = NULL; - JSContext* cx = NULL; - JSObject* global = NULL; - JSCrossCompartmentCall *call = NULL; - JSSCRIPT_TYPE script; - JSString* scriptsrc; - const jschar* schars; - size_t slen; - jsval sroot; - jsval result; - int i; - - couch_args* args = couch_parse_args(argc, argv); - - rt = JS_NewRuntime(args->stack_size); - if(rt == NULL) - return 1; - - cx = JS_NewContext(rt, 8L * 1024L); - if(cx == NULL) - return 1; - - JS_SetErrorReporter(cx, couch_error); - JS_ToggleOptions(cx, JSOPTION_XML); - JS_SetOptions(cx, JSOPTION_METHODJIT); -#ifdef JSOPTION_TYPE_INFERENCE - JS_SetOptions(cx, JSOPTION_TYPE_INFERENCE); -#endif - JS_SetContextPrivate(cx, args); - JS_SetRuntimeSecurityCallbacks(rt, &security_callbacks); - - SETUP_REQUEST(cx); - - global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); - if(global == NULL) - return 1; - - call = JS_EnterCrossCompartmentCall(cx, global); - - JS_SetGlobalObject(cx, global); - - if(!JS_InitStandardClasses(cx, global)) - return 1; - - if(couch_load_funcs(cx, global, global_functions) != JS_TRUE) - return 1; - - for(i = 0 ; args->scripts[i] ; i++) { - // Convert script source to jschars. - scriptsrc = couch_readfile(cx, args->scripts[i]); - if(!scriptsrc) - return 1; - - schars = JS_GetStringCharsAndLength(cx, scriptsrc, &slen); - - // Root it so GC doesn't collect it. - sroot = STRING_TO_JSVAL(scriptsrc); - if(JS_AddValueRoot(cx, &sroot) != JS_TRUE) { - fprintf(stderr, "Internal root error.\n"); - return 1; - } - - // Compile and run - script = JS_CompileUCScript(cx, global, schars, slen, - args->scripts[i], 1); - if(!script) { - fprintf(stderr, "Failed to compile script.\n"); - return 1; - } - - if(JS_ExecuteScript(cx, global, script, &result) != JS_TRUE) { - fprintf(stderr, "Failed to execute script.\n"); - return 1; - } - - // Warning message if we don't remove it. - JS_RemoveValueRoot(cx, &sroot); - - // Give the GC a chance to run. - JS_MaybeGC(cx); - } - - JS_LeaveCrossCompartmentCall(call); - FINISH_REQUEST(cx); - JS_DestroyContext(cx); - JS_DestroyRuntime(rt); - JS_ShutDown(); - - return 0; -} diff --git a/src/couch/priv/couch_js/1.8.5/utf8.c b/src/couch/priv/couch_js/1.8.5/utf8.c deleted file mode 100644 index 4cdb9c21f..000000000 --- a/src/couch/priv/couch_js/1.8.5/utf8.c +++ /dev/null @@ -1,297 +0,0 @@ -// 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. - -#include <jsapi.h> -#include "config.h" - -static int -enc_char(uint8 *utf8Buffer, uint32 ucs4Char) -{ - int utf8Length = 1; - - if (ucs4Char < 0x80) - { - *utf8Buffer = (uint8)ucs4Char; - } - else - { - int i; - uint32 a = ucs4Char >> 11; - utf8Length = 2; - while(a) - { - a >>= 5; - utf8Length++; - } - i = utf8Length; - while(--i) - { - utf8Buffer[i] = (uint8)((ucs4Char & 0x3F) | 0x80); - ucs4Char >>= 6; - } - *utf8Buffer = (uint8)(0x100 - (1 << (8-utf8Length)) + ucs4Char); - } - - return utf8Length; -} - -static JSBool -enc_charbuf(const jschar* src, size_t srclen, char* dst, size_t* dstlenp) -{ - size_t i; - size_t utf8Len; - size_t dstlen = *dstlenp; - size_t origDstlen = dstlen; - jschar c; - jschar c2; - uint32 v; - uint8 utf8buf[6]; - - if(!dst) - { - dstlen = origDstlen = (size_t) -1; - } - - while(srclen) - { - c = *src++; - srclen--; - - if(c <= 0xD7FF || c >= 0xE000) - { - v = (uint32) c; - } - else if(c >= 0xD800 && c <= 0xDBFF) - { - if(srclen < 1) goto buffer_too_small; - c2 = *src++; - srclen--; - if(c2 >= 0xDC00 && c2 <= 0xDFFF) - { - v = (uint32) (((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000); - } - else - { - // Invalid second half of surrogate pair - v = (uint32) 0xFFFD; - // Undo our character advancement - src--; - srclen++; - } - } - else - { - // Invalid first half surrogate pair - v = (uint32) 0xFFFD; - } - - if(v < 0x0080) - { - /* no encoding necessary - performance hack */ - if(!dstlen) goto buffer_too_small; - if(dst) *dst++ = (char) v; - utf8Len = 1; - } - else - { - utf8Len = enc_char(utf8buf, v); - if(utf8Len > dstlen) goto buffer_too_small; - if(dst) - { - for (i = 0; i < utf8Len; i++) - { - *dst++ = (char) utf8buf[i]; - } - } - } - dstlen -= utf8Len; - } - - *dstlenp = (origDstlen - dstlen); - return JS_TRUE; - -buffer_too_small: - *dstlenp = (origDstlen - dstlen); - return JS_FALSE; -} - -char* -enc_string(JSContext* cx, jsval arg, size_t* buflen) -{ - JSString* str = NULL; - const jschar* src = NULL; - char* bytes = NULL; - size_t srclen = 0; - size_t byteslen = 0; - - str = JS_ValueToString(cx, arg); - if(!str) goto error; - -#ifdef HAVE_JS_GET_STRING_CHARS_AND_LENGTH - src = JS_GetStringCharsAndLength(cx, str, &srclen); -#else - src = JS_GetStringChars(str); - srclen = JS_GetStringLength(str); -#endif - - if(!enc_charbuf(src, srclen, NULL, &byteslen)) goto error; - - bytes = JS_malloc(cx, (byteslen) + 1); - bytes[byteslen] = 0; - - if(!enc_charbuf(src, srclen, bytes, &byteslen)) goto error; - - if(buflen) *buflen = byteslen; - goto success; - -error: - if(bytes != NULL) JS_free(cx, bytes); - bytes = NULL; - -success: - return bytes; -} - -static uint32 -dec_char(const uint8 *utf8Buffer, int utf8Length) -{ - uint32 ucs4Char; - uint32 minucs4Char; - - /* from Unicode 3.1, non-shortest form is illegal */ - static const uint32 minucs4Table[] = { - 0x00000080, 0x00000800, 0x0001000, 0x0020000, 0x0400000 - }; - - if (utf8Length == 1) - { - ucs4Char = *utf8Buffer; - } - else - { - ucs4Char = *utf8Buffer++ & ((1<<(7-utf8Length))-1); - minucs4Char = minucs4Table[utf8Length-2]; - while(--utf8Length) - { - ucs4Char = ucs4Char<<6 | (*utf8Buffer++ & 0x3F); - } - if(ucs4Char < minucs4Char || ucs4Char == 0xFFFE || ucs4Char == 0xFFFF) - { - ucs4Char = 0xFFFD; - } - } - - return ucs4Char; -} - -static JSBool -dec_charbuf(const char *src, size_t srclen, jschar *dst, size_t *dstlenp) -{ - uint32 v; - size_t offset = 0; - size_t j; - size_t n; - size_t dstlen = *dstlenp; - size_t origDstlen = dstlen; - - if(!dst) dstlen = origDstlen = (size_t) -1; - - while(srclen) - { - v = (uint8) *src; - n = 1; - - if(v & 0x80) - { - while(v & (0x80 >> n)) - { - n++; - } - - if(n > srclen) goto buffer_too_small; - if(n == 1 || n > 6) goto bad_character; - - for(j = 1; j < n; j++) - { - if((src[j] & 0xC0) != 0x80) goto bad_character; - } - - v = dec_char((const uint8 *) src, n); - if(v >= 0x10000) - { - v -= 0x10000; - - if(v > 0xFFFFF || dstlen < 2) - { - *dstlenp = (origDstlen - dstlen); - return JS_FALSE; - } - - if(dstlen < 2) goto buffer_too_small; - - if(dst) - { - *dst++ = (jschar)((v >> 10) + 0xD800); - v = (jschar)((v & 0x3FF) + 0xDC00); - } - dstlen--; - } - } - - if(!dstlen) goto buffer_too_small; - if(dst) *dst++ = (jschar) v; - - dstlen--; - offset += n; - src += n; - srclen -= n; - } - - *dstlenp = (origDstlen - dstlen); - return JS_TRUE; - -bad_character: - *dstlenp = (origDstlen - dstlen); - return JS_FALSE; - -buffer_too_small: - *dstlenp = (origDstlen - dstlen); - return JS_FALSE; -} - -JSString* -dec_string(JSContext* cx, const char* bytes, size_t byteslen) -{ - JSString* str = NULL; - jschar* chars = NULL; - size_t charslen; - - if(!dec_charbuf(bytes, byteslen, NULL, &charslen)) goto error; - - chars = JS_malloc(cx, (charslen + 1) * sizeof(jschar)); - if(!chars) return NULL; - chars[charslen] = 0; - - if(!dec_charbuf(bytes, byteslen, chars, &charslen)) goto error; - - str = JS_NewUCString(cx, chars, charslen - 1); - if(!str) goto error; - - goto success; - -error: - if(chars != NULL) JS_free(cx, chars); - str = NULL; - -success: - return str; -} diff --git a/src/couch/priv/couch_js/1.8.5/utf8.h b/src/couch/priv/couch_js/1.8.5/utf8.h deleted file mode 100644 index c5cb86c46..000000000 --- a/src/couch/priv/couch_js/1.8.5/utf8.h +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -#ifndef COUCH_JS_UTF_8_H -#define COUCH_JS_UTF_8_H - -char* enc_string(JSContext* cx, jsval arg, size_t* buflen); -JSString* dec_string(JSContext* cx, const char* buf, size_t buflen); - -#endif diff --git a/src/couch/priv/couch_js/1.8.5/util.c b/src/couch/priv/couch_js/1.8.5/util.c deleted file mode 100644 index 5cf94b63a..000000000 --- a/src/couch/priv/couch_js/1.8.5/util.c +++ /dev/null @@ -1,296 +0,0 @@ -// 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. - -#include <stdlib.h> -#include <string.h> - -#include <jsapi.h> - -#include "help.h" -#include "util.h" -#include "utf8.h" - - -size_t -slurp_file(const char* file, char** outbuf_p) -{ - FILE* fp; - char fbuf[16384]; - char *buf = NULL; - char* tmp; - size_t nread = 0; - size_t buflen = 0; - - if(strcmp(file, "-") == 0) { - fp = stdin; - } else { - fp = fopen(file, "r"); - if(fp == NULL) { - fprintf(stderr, "Failed to read file: %s\n", file); - exit(3); - } - } - - while((nread = fread(fbuf, 1, 16384, fp)) > 0) { - if(buf == NULL) { - buf = (char*) malloc(nread + 1); - if(buf == NULL) { - fprintf(stderr, "Out of memory.\n"); - exit(3); - } - memcpy(buf, fbuf, nread); - } else { - tmp = (char*) malloc(buflen + nread + 1); - if(tmp == NULL) { - fprintf(stderr, "Out of memory.\n"); - exit(3); - } - memcpy(tmp, buf, buflen); - memcpy(tmp+buflen, fbuf, nread); - free(buf); - buf = tmp; - } - buflen += nread; - buf[buflen] = '\0'; - } - *outbuf_p = buf; - return buflen + 1; -} - -couch_args* -couch_parse_args(int argc, const char* argv[]) -{ - couch_args* args; - int i = 1; - - args = (couch_args*) malloc(sizeof(couch_args)); - if(args == NULL) - return NULL; - - memset(args, '\0', sizeof(couch_args)); - args->stack_size = 64L * 1024L * 1024L; - - while(i < argc) { - if(strcmp("-h", argv[i]) == 0) { - DISPLAY_USAGE; - exit(0); - } else if(strcmp("-V", argv[i]) == 0) { - DISPLAY_VERSION; - exit(0); - } else if(strcmp("-H", argv[i]) == 0) { - args->use_http = 1; - } else if(strcmp("-T", argv[i]) == 0) { - args->use_test_funs = 1; - } else if(strcmp("-S", argv[i]) == 0) { - args->stack_size = atoi(argv[++i]); - if(args->stack_size <= 0) { - fprintf(stderr, "Invalid stack size.\n"); - exit(2); - } - } else if(strcmp("--eval", argv[i]) == 0) { - args->eval = 1; - } else if(strcmp("--", argv[i]) == 0) { - i++; - break; - } else { - break; - } - i++; - } - - if(i >= argc) { - DISPLAY_USAGE; - exit(3); - } - args->scripts = argv + i; - - return args; -} - - -int -couch_fgets(char* buf, int size, FILE* fp) -{ - int n, i, c; - - if(size <= 0) return -1; - n = size - 1; - - for(i = 0; i < n && (c = getc(fp)) != EOF; i++) { - buf[i] = c; - if(c == '\n') { - i++; - break; - } - } - - buf[i] = '\0'; - return i; -} - - -JSString* -couch_readline(JSContext* cx, FILE* fp) -{ - JSString* str; - char* bytes = NULL; - char* tmp = NULL; - size_t used = 0; - size_t byteslen = 256; - size_t readlen = 0; - - bytes = JS_malloc(cx, byteslen); - if(bytes == NULL) return NULL; - - while((readlen = couch_fgets(bytes+used, byteslen-used, fp)) > 0) { - used += readlen; - - if(bytes[used-1] == '\n') { - bytes[used-1] = '\0'; - break; - } - - // Double our buffer and read more. - byteslen *= 2; - tmp = JS_realloc(cx, bytes, byteslen); - if(!tmp) { - JS_free(cx, bytes); - return NULL; - } - - bytes = tmp; - } - - // Treat empty strings specially - if(used == 0) { - JS_free(cx, bytes); - return JSVAL_TO_STRING(JS_GetEmptyStringValue(cx)); - } - - // Shring the buffer to the actual data size - tmp = JS_realloc(cx, bytes, used); - if(!tmp) { - JS_free(cx, bytes); - return NULL; - } - bytes = tmp; - byteslen = used; - - str = dec_string(cx, bytes, byteslen); - JS_free(cx, bytes); - return str; -} - - -JSString* -couch_readfile(JSContext* cx, const char* filename) -{ - JSString *string; - size_t byteslen; - char *bytes; - - if((byteslen = slurp_file(filename, &bytes))) { - string = dec_string(cx, bytes, byteslen); - - free(bytes); - return string; - } - return NULL; -} - - -void -couch_print(JSContext* cx, uintN argc, jsval* argv) -{ - char *bytes = NULL; - FILE *stream = stdout; - - if (argc) { - if (argc > 1 && argv[1] == JSVAL_TRUE) { - stream = stderr; - } - bytes = enc_string(cx, argv[0], NULL); - if(!bytes) return; - fprintf(stream, "%s", bytes); - JS_free(cx, bytes); - } - - fputc('\n', stream); - fflush(stream); -} - - -void -couch_error(JSContext* cx, const char* mesg, JSErrorReport* report) -{ - jsval v, replace; - char* bytes; - JSObject* regexp, *stack; - jsval re_args[2]; - - if(!report || !JSREPORT_IS_WARNING(report->flags)) - { - fprintf(stderr, "%s\n", mesg); - - // Print a stack trace, if available. - if (JSREPORT_IS_EXCEPTION(report->flags) && - JS_GetPendingException(cx, &v)) - { - // Clear the exception before an JS method calls or the result is - // infinite, recursive error report generation. - JS_ClearPendingException(cx); - - // Use JS regexp to indent the stack trace. - // If the regexp can't be created, don't JS_ReportError since it is - // probably not productive to wind up here again. -#ifdef SM185 - if(JS_GetProperty(cx, JSVAL_TO_OBJECT(v), "stack", &v) && - (regexp = JS_NewRegExpObjectNoStatics( - cx, "^(?=.)", 6, JSREG_GLOB | JSREG_MULTILINE))) -#else - if(JS_GetProperty(cx, JSVAL_TO_OBJECT(v), "stack", &v) && - (regexp = JS_NewRegExpObject( - cx, "^(?=.)", 6, JSREG_GLOB | JSREG_MULTILINE))) -#endif - { - // Set up the arguments to ``String.replace()`` - re_args[0] = OBJECT_TO_JSVAL(regexp); - re_args[1] = STRING_TO_JSVAL(JS_InternString(cx, "\t")); - - // Perform the replacement - if(JS_ValueToObject(cx, v, &stack) && - JS_GetProperty(cx, stack, "replace", &replace) && - JS_CallFunctionValue(cx, stack, replace, 2, re_args, &v)) - { - // Print the result - bytes = enc_string(cx, v, NULL); - fprintf(stderr, "Stacktrace:\n%s", bytes); - JS_free(cx, bytes); - } - } - } - } -} - - -JSBool -couch_load_funcs(JSContext* cx, JSObject* obj, JSFunctionSpec* funcs) -{ - JSFunctionSpec* f; - for(f = funcs; f->name != NULL; f++) { - if(!JS_DefineFunction(cx, obj, f->name, f->call, f->nargs, f->flags)) { - fprintf(stderr, "Failed to create function: %s\n", f->name); - return JS_FALSE; - } - } - return JS_TRUE; -} diff --git a/src/couch/priv/couch_js/1.8.5/util.h b/src/couch/priv/couch_js/1.8.5/util.h deleted file mode 100644 index 9dd290a4c..000000000 --- a/src/couch/priv/couch_js/1.8.5/util.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -#ifndef COUCHJS_UTIL_H -#define COUCHJS_UTIL_H - -#include <jsapi.h> - -typedef struct { - int eval; - int use_http; - int use_test_funs; - int stack_size; - const char** scripts; -} couch_args; - -couch_args* couch_parse_args(int argc, const char* argv[]); -int couch_fgets(char* buf, int size, FILE* fp); -JSString* couch_readline(JSContext* cx, FILE* fp); -JSString* couch_readfile(JSContext* cx, const char* filename); -void couch_print(JSContext* cx, uintN argc, jsval* argv); -void couch_error(JSContext* cx, const char* mesg, JSErrorReport* report); -JSBool couch_load_funcs(JSContext* cx, JSObject* obj, JSFunctionSpec* funcs); - - -#endif // Included util.h diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script index f0b465135..fda42d1fc 100644 --- a/src/couch/rebar.config.script +++ b/src/couch/rebar.config.script @@ -57,8 +57,6 @@ CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of end. SMVsn = case lists:keyfind(spidermonkey_version, 1, CouchConfig) of - {_, "1.8.5"} -> - "1.8.5"; {_, "60"} -> "60"; {_, "68"} -> @@ -70,16 +68,15 @@ SMVsn = case lists:keyfind(spidermonkey_version, 1, CouchConfig) of {_, "91"} -> "91"; undefined -> - "1.8.5"; + "91"; {_, Unsupported} -> io:format(standard_error, "Unsupported SpiderMonkey version: ~s~n", [Unsupported]), erlang:halt(1); false -> - "1.8.5" + "91" end. ConfigH = [ - {"SM185", ""}, {"HAVE_JS_GET_STRING_CHARS_AND_LENGTH", "1"}, {"JSSCRIPT_TYPE", "JSObject*"}, {"COUCHJS_NAME", "\"" ++ CouchJSName++ "\""}, @@ -115,16 +112,6 @@ ProperConfig = case code:lib_dir(proper) of end. {JS_CFLAGS, JS_LDFLAGS} = case os:type() of - {win32, _} when SMVsn == "1.8.5" -> - { - "/DXP_WIN", - "mozjs185-1.0.lib" - }; - {unix, _} when SMVsn == "1.8.5" -> - { - "-DXP_UNIX -I/usr/include/js -I/usr/local/include/js", - "-L/usr/local/lib -lmozjs185 -lm" - }; {win32, _} when SMVsn == "60" -> { "/DXP_WIN", @@ -168,7 +155,6 @@ end. end. CouchJSSrc = case SMVsn of - "1.8.5" -> ["priv/couch_js/1.8.5/*.c"]; "60" -> ["priv/couch_js/60/*.cpp"]; "68" -> ["priv/couch_js/68/*.cpp"]; "78" -> ["priv/couch_js/86/*.cpp"]; @@ -177,11 +163,6 @@ CouchJSSrc = case SMVsn of end. CouchJSEnv = case SMVsn of - "1.8.5" -> - [ - {"CFLAGS", JS_CFLAGS}, - {"LDFLAGS", JS_LDFLAGS} - ]; _ -> [ {"CXXFLAGS", JS_CFLAGS},
